Wednesday, February 26, 2014

Haproxy - Install and Configure on Haproxy

#Server Information
#LB ip 10.xxx.22.33
#server-1 10.xxx.27.49
#server-2 10.xxx.26.50
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
uid 99
gid 99
daemon
log-send-hostname
#debug
#quiet
defaults
log global
listen webfarm 10.xxx.22.33:80
mode http
option httpchk GET /l7check.html HTTP/1.0
option log-health-checks
option forwardfor
option httpclose
cookie SERVERID rewrite
cookie JSESSIONID prefix
balance roundrobin
stats enable
stats uri /admin
server xvadm01.ncli 10.xxx.27.49:80 cookie admin_portal_1 check inter 1000 rise 2 fall 5
server xvadm02.ncli 10.xxx.26.50:80 cookie admin_portal_2 check inter 1000 rise 2 fall 5
$ /etc/init.d/haproxy start
view raw haproxy.cfg hosted with ❤ by GitHub
$ wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.22.tar.gz
$ tar xvfz haproxy-1.4.24.tar.gz
$ cd harproxy-1.4.24
$ make TARGET=linux26 ARCH=x86_64
$ make install
$ cd examples
$ cp haproxy.init /etc/rc.d/init.d/haproxy
$ chmod 755 /etc/rc.d/init.d/haproxy
$ mkdir -p /etc/haproxy/
$ cp /usr/local/src/haproxy-1.4.24/examples/haproxy.cfg /etc/haproxy/
$ mkdir -p /etc/haproxy/errors/
$ cp /usr/local/src/haproxy-1.4.24/examples/errorfiles/* /etc/haproxy/errors/
$ cd /usr/sbin
$ ln -s /usr/local/sbin/haproxy haproxy
$ vi /etc/haproxy/haproxy.cfg

Link - Proxy Socket

@ The websocket of apache.
http://blog.alex.org.uk/2012/02/16/using-apache-websocket-to-proxy-tcp-connection/

@ The module for webSocket on Apache.
https://github.com/disconnect/apache-websocket

@ Load Balance and support webSocket or socketJs.
  It will need to handshake twice.
http://haproxy.1wt.eu/

@ Setting for Haproxy
https://github.com/sockjs/sockjs-node/blob/master/examples/haproxy.cfg

@ Mod_pywebsocket
http://code.google.com/p/pywebsocket/

@Haproxy Load Balance
http://tagnee.tistory.com/25
http://helloworld.naver.com/helloworld/284659

Tuesday, February 25, 2014

Gradle - How to implement Maven's profile mechanism in Gradle

@/config/staging/resources

final String DEFAULT_PROFILE = 'staging'
allprojects {
    if (!project.hasProperty('profile') || !profile) {
        ext.profile = DEFAULT_PROFILE
    }
    sourceSets {
        main {
            resources {
                srcDir "config/${profile}/resources"
            }
        }
    }
}

@ Command
$ gradle zip -Pprofile=staging

Monday, February 24, 2014

Javascript - Json map sort by key

<!doctype html>
<head>
<meta charset="utf-8">
<title>json</title>
<script src="js/json2.js"></script>
</head>
<body>
Json test
<script>
var sampleJson = "{\"a1\":0, \"a3\":\"1000\", \"a2\":\"abca\"}";
var keys = [], k, i, len;
var obj = JSON.parse(sampleJson);
for (k in obj)
{
//alert(">>" + k);
if (obj.hasOwnProperty(k))
{
keys.push(k);
}
}
keys.sort();
len = keys.length;
for (i = 0; i < len; i++)
{
k = keys[i];
alert(k + ':' + obj[k]);
}
</script>
</body>
</html>
view raw JsonToSort.html hosted with ❤ by GitHub

Thursday, February 20, 2014

Link - SpriteBuilder

@SpriteBuilder
https://www.makegameswith.us/tutorials/getting-started-with-spritebuilder/

Wednesday, February 19, 2014

Ajax - Client and Server side processing.

<!DOCTYPE html>
<html>
<head>
<title>Test for Ajax</title>
<link href="http://fonts.googleapis.com/css?family=Abel" rel="stylesheet" type="text/css">
<link href="http://monologue-js.herokuapp.com/style.css" rel="stylesheet" type="text/css">
<script src="/htmlTest/js/jquery-1.9.1.js"></script>
<script src="/htmlTest/js/json2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#new-status form').submit(function(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: 'http://localhost:8080/admin/real/test.sg',
contentType: "application/json",
dataType: "json",
data: "{ 'text' : '" + $('#new-status').find('textarea').val() + "'}",
success: function(data, textStatus, jqXHR) {
// {"aaa":"ddd"}, Don't do this like that {'aaa':'ddd'}
alert(">>>" + data.aaa); // >>>ddd
$('#statuses').append('<li>' + data.aaa + '</li>');
$('#new-status').find('textarea').val('');
},
error: function(xhr, status) {
//alert(xhr.responseText);
}
});
});
});
</script>
</head>
<body>
<div id="new-status">
<h2>New monolog</h2>
<form action="">
<textarea></textarea><br>
<input type="submit" value="Post"/>
</form>
</div>
<div id="statuses">
<h2>Monologs</h2>
<ul></ul>
</div>
</body>
</html>
view raw AjaxClient hosted with ❤ by GitHub
package jp.test.controller;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/real")
public class TestController extends AbstractBaseController {
@RequestMapping(value = {"test.sg"})
public void test(@RequestBody String body, HttpServletResponse response) throws Exception {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache");
PrintWriter pw = response.getWriter();
pw.write("{\"aaa\":\"ddd\"}");
pw.flush();
pw.close();
}
}
view raw AjaxServer hosted with ❤ by GitHub

Monday, February 17, 2014

PlayFramework - Setting up your preferred IDE

■ Move to your project directory.
$ cd /usr/local/git/project

■ Start play on your project
$ play

■ Start play on your project
[your_project] eclipse


@Refer to this following URL
http://www.playframework.com/documentation/2.2.x/IDE

Thursday, February 6, 2014

Git - Switched and Make a new branch at a time.

@ How to revert to a commit point on a branch.

@ Option -b is to make branch
@ dev-bug is a branch name
@ dc41eaf is SHA code
@ Like the following command
$ git checkout -b dev-bug dc41eaf

@Switched and make a new branch at a time.
$ git checkout -b newBranchName

@Make a new branch
$ git branch newBranchName

@Switched to a new branch
$ git checkout newBranchName

Tuesday, February 4, 2014

Shell - Calculate the sum on Shell.

@ $9 is a place where there is numbers in T.S.V.
$ cat ./logName.log | grep needWord | gawk -F'\t' '{print $9}' > sum.txt

@ Sum the values from the file.
$ awk '{s+=$1} END {print s}' ./sum.txt