Skip to content

Instantly share code, notes, and snippets.

View jj1bdx's full-sized avatar
🏠
Working from home

Kenji Rikitake jj1bdx

🏠
Working from home
View GitHub Profile
@jj1bdx
jj1bdx / check64.c.diff
Created September 3, 2011 15:09
Tiny Mersenne Twister patch for TinyMT-src-1.0 ( see http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/TINYMT/index.html )
This is a fix for 32bit runtime environment (tested on FreeBSD/i386 8.2-RELEASE)
(Note: tested on gcc 4.5.4 20110825)
--- tinymt/check64.c.FCS 2011-06-20 16:09:18.000000000 +0900
+++ tinymt/check64.c 2011-09-03 23:49:08.000000000 +0900
@@ -27,7 +27,7 @@
tinymt64_t tinymt;
tinymt.mat1 = strtoul(argv[1], NULL, 16);
tinymt.mat2 = strtoul(argv[2], NULL, 16);
- tinymt.tmat = strtoul(argv[3], NULL, 16);
@jj1bdx
jj1bdx / gist:2015136
Created March 11, 2012 05:19
Erlang IPv6 address conversion to a hex-based tuple (for easy reading and reuse)
105> f(A).
ok
106> {ok, A} = inet:getaddr("www.kame.net", inet6).
{ok,{8193,512,3583,65521,534,16127,65201,17623}}
107> A.
{8193,512,3583,65521,534,16127,65201,17623}
108> io:format("{16#~4.16.0b,16#~4.16.0b,16#~4.16.0b,16#~4.16.0b,16#~4.16.0b,16#~4.16.0b,16#~4.16.0b,16#~4.16.0b}~n", tuple_to_list(A)).
{16#2001,16#0200,16#0dff,16#fff1,16#0216,16#3eff,16#feb1,16#44d7}
ok
109> {16#2001,16#0200,16#0dff,16#fff1,16#0216,16#3eff,16#feb1,16#44d7}.
@jj1bdx
jj1bdx / v6hex.erl
Created March 11, 2012 06:37
v6hex.erl: an example module for IPv6-address tuple to hex string conversion
%% This file has been moved to the following GitHub repository:
%% https://github.com/jj1bdx/v6hex/
%% v6hex.erl:
%% IPv6-address tuple to hex string conversion
%% by Kenji Rikitake
%% MIT license (see the end of this module)
-module(v6hex).
@jj1bdx
jj1bdx / test-gmake.sh
Created April 7, 2012 08:19
Detecting gmake and if exists set it to $MAKE, else set $MAKE as "make" (useful for FreeBSD)
#!/bin/sh
which gmake 1>/dev/null 2>/dev/null && echo "we've got gmake"
which gmake 1>/dev/null 2>/dev/null && MAKE=gmake
MAKE=${MAKE:-make}
# Originally by Tuncer Ayaz from
# https://github.com/tuncer/re2/blob/master/c_src/build_deps.sh
@jj1bdx
jj1bdx / getuidtest.c
Created April 7, 2012 08:36
getuid() test for FreeBSD.
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <syslog.h>
#include <stdarg.h>
char *nullenv[] = { NULL };
int main(int argc, char **argv) {
@jj1bdx
jj1bdx / riak.md
Created May 30, 2012 13:09 — forked from taichi/riak.md
some suggestion to riak.

(Note: this is a rough translation added to the original Japanese. No warranty.)

RpbErrorResp の errcode はより適切な値が設定されるべきである。(The errcode of RpbErrorResp should be set to more appropriate value.)

PBC API ではエラーが起きると、RpbErrorRespが返るがRIAKC_ERR_GENERALが常に設定されており意味がないのでREST APIと同等の値が設定されているべきです。 (When an error occurs on the PBC API, the value of RpbErrorResp is returned, though RpbErrorResp is always set to RIAKC_ERR_GENERAL so that the recipient cannot find what the real cause is. The value should be set the same as with the REST API.)

例えば、get operation において、notfound が返るのは多くの場合クライアント側にとって特に問題ないので、コストの高い例外処理がトリガーされない事が望ましい。
一方で、modifiedが返る場合、データのリペアをトリガするべきか、単に再度getするべきかはアプリケーションの設計の問題である。 (For example, on get operation the clients will find no problem when notfound is returned - exceptions of higher cost should not be triggered. On the other hand, if modified is returned, it is up to how the application is designed to trigger the repairment of the data, or to re-execute the get operation.)

errmsgフィールドの様にHum

@jj1bdx
jj1bdx / erlang-loopback.sh
Created June 12, 2012 04:30
Erlang with loopback-only distribution
#!/bin/sh
# https://twitter.com/etrepum/status/198481550713692160
# Erlang with loopback-only distribution
env ERL_EPMD_ADDRESS=127.0.0.1 erl -kernel inet_dist_use_interface "{127,0,0,1}" -name shell@127.0.0.1
@jj1bdx
jj1bdx / gist:2915108
Created June 12, 2012 04:51
Erlang R15B01 SHA256 does not accept bitstrings which do not fit to the byte boundary
2> crypto:sha256(<<255:7>>).
** exception error: bad argument
in function crypto:sha256_nif/1
called as crypto:sha256_nif(<<127:7>>)
in call from crypto:sha256/1 (crypto.erl, line 231)
3> crypto:sha256(<<255:8>>).
<<168,16,10,230,170,25,64,208,182,99,187,49,205,70,97,66,
235,189,189,81,135,19,27,146,217,56,24,152,120,...>>
4> crypto:sha256(<<255:9>>).
** exception error: bad argument
@jj1bdx
jj1bdx / tinymt32-compile-example.txt
Created June 12, 2012 05:06
Erlang example of BEAM source output
2> compile:file("src/tinymt32.erl", [{i, "include/"},'S']).
{ok,tinymt32}
@jj1bdx
jj1bdx / erlang12-report.md
Created September 24, 2012 03:12
Erlang'12 + CUFP Report: for Erlang Study Meeting in Tokyo 28-SEP-2012

Erlang Workshop 2012
+ CUFP 2012 report
(28-SEP-2012 by Kenji Rikitake)


Venue

  • DGI-byen, Copenhagen, Denmark

DGI-byens