Thursday, December 4, 2014

How to make System command calls in Groovy?

package ping

import java.io.*
import java.util.*

class PingController

def index()
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = 'ping 127.0.0.1'.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println "out> $sout err> $serr"

def ping()
StringBuffer buf = new StringBuffer();
String s = "";
Process process;
try

process = Runtime.getRuntime().exec( "cmd /c " + "ping 8.8.8.8" );
BufferedReader br = new BufferedReader( new InputStreamReader(
process.getInputStream() ) );
while ( ( s = br.readLine() ) != null )

buf.append( s + "\r\n" );


process.waitFor();
System.out.println( buf );
catch ( Exception ex )

ex.printStackTrace();





How to make System command calls in Groovy?

Wednesday, November 26, 2014

svn: Can't open file '.svn/text-base/

root@debian:/var/www# svn update

svn: Can’t open file ‘.svn/text-base/details.html.svn-base': No such file or directory


How to solve:

TortoiseSVN -> Repo-Browser -> select file details.html -> Delete -> Commit

Re check-in details.html to svn



svn: Can't open file '.svn/text-base/

Enabling Server Side Includes (SSI) on Apache and Debian/Ubuntu

Enabling Server Side Includes (SSI) on Apache and Debian/Ubuntu


Enable the Include module


a2enmod include

or


ln -s /etc/apache2/mods-available/include.load /etc/apache2/mods-enabled

Edit the config file

vim /etc/apache2/sites-available/default

add

AddType text/html .shtml

AddOutputFilter INCLUDES .shtml

and

Options Indexes FollowSymLinks MultiViews +Includes

the complete file like below:


 DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
#Order allow,deny
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Options Indexes FollowSymLinks MultiViews +Includes
</Directory>

Restart Apache


service apache2 restart

Test,create shtml file


<html>
<head>
<title>SSI Test Page</title>
</head>
<body>
<!--#config timefmt="%A %B %d, %Y" -->
Today is <!--#echo var="DATE_LOCAL" -->
</body>
</html>


Enabling Server Side Includes (SSI) on Apache and Debian/Ubuntu

Tuesday, November 18, 2014

How to remove BOM from UTF-8 using sed?

How to remove BOM from UTF-8 using sed?

fetch BOM files

grep -rIlo $’^\xEF\xBB\xBF’ ./


remove BOM files

grep -rIlo $’^\xEF\xBB\xBF’ . | xargs sed –in-place -e ‘s/\xef\xbb\xbf//’


exclude .svn dir

grep -rIlo –exclude-dir=”.svn” $’^\xEF\xBB\xBF’ . | xargs sed –in-place -e ‘s/\xef\xbb\xbf//’



How to remove BOM from UTF-8 using sed?

Monday, November 10, 2014

How to find More than 1 GB files of the Bash command line for Linux

How to find More than 1 GB files of the Bash command line for Linux


find / -type f -size +10000000k;

find / -size +1000M -exec ls -l \;


How to find More than 1 GB files of the Bash command line for Linux

SQL Server Split function

SQL Server Split function


USE [A5GODB]
GO
/****** Object: UserDefinedFunction [dbo].[SPLIT_FUNC] Script Date: 10/23/2014 10:08:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[SPLIT_FUNC](@string nvarchar(1000),@spliter char(1)=',')
returns @table table(id int identity(1,1) primary key,items varchar(100) not null)
AS
begin
if patindex('%'+@spliter+'%',@string)=1
begin
set @string=substring(@string,2,len(@string))
end

if patindex('%'+@spliter+'%',reverse(@string))=1
begin
set @string=reverse(substring(reverse(@string),2,len(@string)))
end

while patindex('%'+@spliter+'%',@string)>0
begin
declare @file varchar(1000)
set @file=substring(@string,0,patindex('%'+@spliter+'%',@string))

insert into @table(items)
select @file
set @string=substring(@string,patindex('%'+@spliter+'%',@string)+1,len(@string))
end

if patindex('%'+@spliter+'%',@string)=0
begin
select @file=substring(@string,0,len(@string)+1)

insert into @table(items)
select @file
end
return
end


SQL Server Split function

Sunday, November 9, 2014

How to show preview of image before upload using HTML5?

How to show preview of image before upload using HTML5?


<!DOCTYPE HTML>
<html>
<head>

</head>
<body>
<input type="file" onchange="previewFile()"><br>
<img src="" height="200" alt="Image preview...">

<script defer="defer">
function previewFile()
var preview = document.querySelector('img');
var file = document.querySelector('input[type=file]').files[0];
alert (file);
var reader = new FileReader();

reader.onloadend = function ()
preview.src = reader.result;
alert (preview.src);


if (file)
reader.readAsDataURL(file);
else
preview.src = "";


</script>
</body>
</html>


How to show preview of image before upload using HTML5?