Friday, May 22, 2015

Grails use an external properties file for datasource configuration

Grails use an external properties file for datasource configuration


1.configure the DataSource.groovy file like this:



import org.springframework.core.io.ClassPathResource
import org.springframework.core.io.support.PropertiesLoaderUtils

def properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource('datasource.properties'))

dataSource
pooled = true
driverClassName = properties.getProperty("dataSource.driverClassName")
username = properties.getProperty("dataSource.username")
password = properties.getProperty("dataSource.password")
url = properties.getProperty("dataSource.url")

hibernate
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'

// environment specific settings
environments
development
dataSource
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''


test
dataSource
dbCreate = "update"


production
dataSource
dbCreate = "update"



2.Create the external database configuration properties file, below is the contents of datasource.properties


dataSource.driverClassName = com.mysql.jdbc.Driver
dataSource.url=jdbc:mysql://localhost:3306/a5go?useUnicode=true&characterEncoding=utf-8
dataSource.username=root
dataSource.password=password


Grails use an external properties file for datasource configuration

Thursday, May 21, 2015

use an external properties file in grails

use an external properties file in grails


1.Create the properties file.


dbCreate=update
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=UTF8
username=root
password=password

2.add following line in the Config.groovy:


grails.config.locations = ["classpath:test1.properties", "classpath:Test2.properties"]

if set variables in config use following line


def props = new Properties()

url= props.getProperty("url")

3.in controller/services


import org.codehaus.groovy.grails.commons.ConfigurationHolder


def grailsApplication


def test1= ConfigurationHolder.config.test

def url= grailsApplication.config.url


use an external properties file in grails

Sunday, April 26, 2015

grails compilation error encoded string too long

Compiling 71 GSP files for package [test]

java.io.UTFDataFormatException: encoded string too long: 292932 bytes

at java.io.DataOutputStream.writeUTF(DataOutputStream.java:347)

at java.io.DataOutputStream.writeUTF(DataOutputStream.java:306)

at java.lang.Thread.run(Thread.java:662)


You have two options upgrade or follow the below steps


1. Find all the gsp pages with file size greater than 64K.

2. Add to the middle of your static pages (add it to the end of html tags, for example after

etc).

grails compilation error encoded string too long

Tuesday, February 24, 2015

PHP - Fatal error: Call to undefined function curl_init()

PHP – Fatal error: Call to undefined function curl_init()


On current versions of Debian and Ubuntu, you can likely solve this by installing the Curl extension for PHP, and restarting the webserver.


sudo apt-get install php5-curl


It’s possible you’ll need to install more:


sudo apt-get install curl libcurl3 libcurl3-dev;



PHP - Fatal error: Call to undefined function curl_init()

Monday, January 12, 2015

"Restart computer" failed when installing SQL Server 2012

“Restart computer” failed when installing SQL Server 2012


cd sql server folder

run

setup.exe /SkipRules=RebootRequiredCheck /ACTION=install



"Restart computer" failed when installing SQL Server 2012

Sunday, January 4, 2015

How to setting "Custom Naming Strategy" in grails project

How to setting “Custom Naming Strategy” in grails project


By default Grails uses Hibernate’s ImprovedNamingStrategy to convert domain class Class and field names to SQL table and column names by converting from camel-cased Strings to ones that use underscores as word separators. You can customize these on a per-class basis in the mapping closure but if there’s a consistent pattern you can specify a different NamingStrategy class to use.

Configure the class name to be used in grails-app/conf/DataSource.groovy in the hibernate section, e.g.


hibernate

cache.use_second_level_cache = true

cache.use_query_cache = false

cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'

naming_strategy = com.a5go.CustomNamingStrategy


You can use an existing class or write your own, for example one that prefixes table names and column names:

package com.a5go


import org.hibernate.cfg.ImprovedNamingStrategy

import org.hibernate.util.StringHelper


class CustomNamingStrategy extends ImprovedNamingStrategy


String classToTableName(String className)

"T_" + StringHelper.unqualify(className)




How to setting "Custom Naming Strategy" in grails project

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?

How to save uploaded image in grails

How to save uploaded image in grails

View


<g:form action="upload" method="post" ENCTYPE="multipart/form-data">
<div class="file-upload">
<label>Choose image</label>
<input id="fileupload" type="file" name="fileupload"/>
<input type="submit" value="Upload file" />
</div>

</g:form>

Controller


class TestController 

def index()

def upload()
if (params.fileupload)
if (params.fileupload instanceof org.springframework.web.multipart.commons.CommonsMultipartFile)
// new FileOutputStream('testimage.jpg').leftShift( params.fileupload.getInputStream() )
params.fileupload.transferTo(new File('testimage.jpg'))
else
log.error("")







How to save uploaded image in grails

How to save a base64 decoded image in the filesystem using grails

How to save a base64 decoded image in the filesystem using grails

Controller


import sun.misc.BASE64Decoder

class TestController

def index()

def save()
def file = params.file.toString().substring((params.file.toString().indexOf(",") + 1), params.file.toString().size())
byte[] decodedBytes = new BASE64Decoder().decodeBuffer(file)
def image = new File("C:/Users/Steven/Desktop/test/testimage.jpg")
image.setBytes(decodedBytes)


View


<!DOCTYPE HTML>
<html>
<head>
<style>
body
margin: 0px;
padding: 0px;

#buttons
position: absolute;
left: 10px;
top: 0px;

button
margin-top: 10px;
display: block;

</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<button id="save">
Save
</button>
</div>
<script type="text/javascript" src="$resource(dir: 'js', file: 'jquery-1.7.min.js')"></script>
<script type="text/javascript" src="$resource(dir: 'js', file: 'sammy.js')"></script>
<script type="text/javascript" src="$resource(dir: 'js', file: 'kinetic-v5.1.0.min.js')"></script>
<script defer="defer">
var stage = new Kinetic.Stage(
container: 'container',
width: 578,
height: 200
);
var layer = new Kinetic.Layer();

var box = new Kinetic.Rect(
x: 200,
y: 80,
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
draggable: true,
dragOnTop: true
);

box.on('mouseover', function()
document.body.style.cursor = 'pointer';
);

box.on('mouseout', function()
document.body.style.cursor = 'default';
);

var box2 = new Kinetic.Rect(
x: 200,
y: 80,
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
draggable: true,
dragOnTop: true
);

box2.on('mouseover', function()
document.body.style.cursor = 'pointer';
);

box2.on('mouseout', function()
document.body.style.cursor = 'default';
);

var box3 = new Kinetic.Rect(
x: 200,
y: 80,
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
draggable: true,
dragOnTop: true
);

box3.on('mouseover', function()
document.body.style.cursor = 'pointer';
);

box3.on('mouseout', function()
document.body.style.cursor = 'default';
);

var box = new Kinetic.Rect(
x: 200,
y: 80,
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
draggable: true,
dragOnTop: true
);




layer.add(box);
layer.add(box2);
layer.add(box3);
stage.add(layer);

// $(stage.content).on('mousewheel', ui.zoom);

document.getElementById('save').addEventListener('click', function()

stage.toDataURL(
callback: function(dataUrl)

$.ajax(
type: "POST",
url: "save",
data: file: dataUrl
).done(function( respond )
alert(respond);
);

// window.open(dataUrl);

);
, false);
</script>
</body>
</html>


How to save a base64 decoded image in the filesystem using grails

Wednesday, November 5, 2014

Cheap VPS:sugarhosts.com November Specials @ 2014

sugarhosts.com November Specials @ 2014


Shared Web Hosting


Promotion #1: Free Dedicated IP for Shared Pro Plan


Valid On: Any New Shared Pro Annual, Biennial and Triennial Orders


Valid Until: November 30, 2014 GMT


* Please contact Sales Department for dedicated IP after ordering.

* This can be applied UNLIMITED TIMES per client globally.

Promotion #2: 30% Off First Payment


Promotion Code: November2014


Valid On: Any New Shared Standard and Shared Pro Annual, Biennial and Triennial Orders


Valid Until: November 30, 2014 GMT


* Not valid on renewal invoices

* This can be applied UNLIMITED TIMES per client globally.

Promotion #3: Get Hong Kong Hosting at the same price as hosting in other datacenters


Valid On: Any New Hong Kong Shared Web Hosting Orders


Valid Until: November 30, 2014 GMT


* 40% price increase is waived in November.


Visit cheap vps services provider: sugarhosts.com!



Cheap VPS:sugarhosts.com November Specials @ 2014

New Servers Arrived NeedaServer.Net Great Offer- Promo Code K9Z5XQV2R2


New Servers Arrived NeedaServer.Net Great Offer- Promo Code K9Z5XQV2R2


The Bronze is Dual Quad Core 24 GB RAM 1TB SATA Drive or 128 GB SSD Drive with 100 Mbps Unmetered for only $53.96 with this Promo Code K9Z5XQV2R2


The Silver Starts $71.95 with this 2 x Hex Core Intel Processors- 100 Mbps 1 TB SATA Drive 24 GB RAM – Use Discount Code K9Z5XQV2R2


Order quick while they last- The Bronze can be up today, allow till Friday for Silver or Gold


Visit NeedaServer.Net!



New Servers Arrived NeedaServer.Net Great Offer- Promo Code K9Z5XQV2R2

Friday, October 31, 2014

HAPPY HALLOWEEN! LIMITED TIME OFFER NOW AVAILABLE!JSUTHOST WEB HOSTING $2.50 PER MONTH*

HAPPY HALLOWEEN! LIMITED TIME OFFER NOW AVAILABLE!JSUTHOST WEB HOSTING $2.50 PER MONTH*


AFFORDABLE WEB HOSTING MADE EASY


Get the last hosting account you’ll ever need today


UNLIMITED WebsitesFREE Domain IncludedUNLIMITED StorageFREE Site BuildersUNLIMITED DomainsFREE Instant SetupUNLIMITED Email AccountsFREE 24/7 Phone Support

ANYTIME

MONEY-BACK

GUARANTEE

$2.50 PER

MONTH*

INTRODUCTORY OFFER


Website Hosting


give you the following web hosting features:


Domain Name Registration

Site Builder with Templates

e-Commerce Shopping Carts

$100 Google Advertising Offer

Control Panel – Powered by cPanel

Instant Setup!

<a href=”//www.justhost.com/track/nacom/” target=”_blank”>

<img border=”0″ src=”//justhost-cdn.com/media/partner/images/nacom/430×288/jh-ppc-banners-dynamic-430×288.png”>

</a>



HAPPY HALLOWEEN! LIMITED TIME OFFER NOW AVAILABLE!JSUTHOST WEB HOSTING $2.50 PER MONTH*

Thursday, October 30, 2014

mediatemple Premium WordPress hosting for just $5.

mediatemple Premium WordPress hosting for just $5.


For two days only, promote our unbeatable web hosting at an unbelievable introductory price: $5 for the first month of Premium WordPress hosting. Just use promo code PremiumWP5 at checkout. Offer valid for the first month only.

This offer is only good for 2 days only, so hurry up, click below link:



mediatemple Premium WordPress hosting for just $5.

How To Set Up SSH Keys on Debian/Ubuntu

How To Set Up SSH Keys on Debian/Ubuntu


ssh-keygen -t rsa

You will be prompted for a location to save the keys, and a passphrase for the keys. This passphrase will protect your private key while it’s stored on the hard drive and be required to use the keys every time you need to login to a key-based system:


Generating public/private rsa key pair.

Enter file in which to save the key (/home/b/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/b/.ssh/id_rsa.

Your public key has been saved in /home/b/.ssh/id_rsa.pub.


cp id_rsa.pub authorized_keys
chmod 700 ~/.ssh
chmod 600 authorized_keys

Then edit your /etc/ssh/sshd_config to:


AuthorizedKeysFile /etc/ssh/%u/authorized_keys

Finally, restart ssh with:



service ssh restart

On the host computer, ensure that the /etc/ssh/sshd_config contains the following lines, and that they are uncommented;


PubkeyAuthentication yes

RSAAuthentication yes


if disable the PasswordAuthentication,change

PasswordAuthentication yes

to

PasswordAuthentication no



How To Set Up SSH Keys on Debian/Ubuntu