Skip to content

Instantly share code, notes, and snippets.

View siburu's full-sized avatar

YOSHIDA Masanori siburu

View GitHub Profile
@siburu
siburu / gist:804330
Created January 31, 2011 16:43
qsort in Erlang
-module(qsort).
-export([qsort/1]).
% qsort/1
qsort([]) -> [];
qsort([Head|Rest]) ->
{Less,Geq} = partition(Rest,Head),
concat(qsort(Less), Head, qsort(Geq)).
% partition/2
-module(parse).
-export([parse/1]).
% parse("((1+2)*3)") => {mul,{add,{num,1},{num,2}},{num,3}}
parse(Str) ->
{Parsed, []} = parse_addsub(nil, nil, skip_space(Str)),
Parsed.
parse_addsub(Left, Op, Str) ->
{Term, Rest} = parse_muldiv(nil, nil, Str),
@siburu
siburu / make.sh
Created October 10, 2014 13:39
Ban -j option
#!/bin/sh
args=
afterj=false
for arg in $*
do
if [ "$arg" = '-j' ]
then
afterj=true
@siburu
siburu / td-agent2-es-plugin-cent7.md
Last active August 29, 2015 14:07
Error report: Failed to install fluent-plugin-elasticsearch via td-agent2 on CentOS7

Environment

  • Google Compute Engine
  • g1-small instance
  • CentOS7 image (provided by Google Cloud Platform)

Incident

I created an instance and then executed the following commands:

$ sudo yum update
$ curl -O http://packages.treasuredata.com/2/redhat/6/x86_64/td-agent-2.1.0-0.x86_64.rpm
@siburu
siburu / es6-integer-overflow.es
Created September 5, 2015 05:10
What if you go beyond Number.MAX_SAFE_INTEGER?
console.log('MAX_SAFE_INTEGER is ' + Number.MAX_SAFE_INTEGER);
let i = Number.MAX_SAFE_INTEGER - 100;
while (i + 1 > i) { i = i + 1; }
console.log('True max integer is ' + i);
console.log('Overflowed integer is ' + (i + 1));
package main
import "net/http"
func main() {
http.ListenAndServe(":8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("HELLO!!!"))
}))
}
@siburu
siburu / syscall.go
Created November 27, 2015 07:11
Call syscalls in Golang
package main
import (
"fmt"
"log"
"syscall"
)
const filePath = "data.dat"
/*
A HTTP*S* server.
The path /ws is special, dedicated for WebSocket connection.
The other paths work as ordinary (non-WebSocket) resource.
*/
package main
import (
"crypto/tls"
#!/bin/sh
# This script explains how to generate a self signed certificate (DER format).
if [ $# = 0 ]
then
echo 'Usage: $0 <name>'
exit 1
fi
name=$1

Must configure

sudo sysctl -w net.core.somaxconn=65535
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=65535

Also important

net.ipv4.tcp_syncookies