Skip to content

Instantly share code, notes, and snippets.

View eiiches's full-sized avatar

Eiichi Sato eiiches

View GitHub Profile
@eiiches
eiiches / i_prefer_c.py
Created May 16, 2012 12:53
C++ to C converter
import sys
print '''
#include <stdlib.h>
#include <stdio.h>
const char *prg = "{0}";
int main(int argc, char **argv) {{
char *tmp = tempnam("/tmp", "hoge-");
FILE *fp = fopen(tmp, "w");
fprintf(fp, "%s", prg);
fclose(fp);
@eiiches
eiiches / bk-tree.hpp
Created March 11, 2012 12:17
BK-tree implementation in C++
/*
* BK-tree implementation in C++
* Copyright (C) 2012 Eiichi Sato
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class Test {
private static final int N = 128 * 1024 * 1024;
public static void main(String[] args) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
{
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
@eiiches
eiiches / openmp.py
Created June 22, 2011 16:37
OpenMP with Python/Weave
#!/usr/bin/python
# -*- coding: utf-8 -*-
import scipy.weave as weave
code = \
'''
#pragma omp parallel
{
printf("ほむほむ\\n");
@eiiches
eiiches / qsort.sh
Created April 18, 2011 02:06
Quicksort in Bash
#!/bin/bash
filter () {
f="$1"; shift
for e in "$@"; do
if $f "$e"; then
echo -n "$e "
fi
done
}
@eiiches
eiiches / c.snip
Created August 9, 2012 16:38
Neocomplcache snippet for extending gobject.
snippet gobject
/* class: ${1:CAPITAL_CASE}, ${2:CamelCase}, ${3:lower_case}, ${4:simple_name} */
/* base: ${5:G_TYPE_OBJECT}, ${6:GObject} */
/* prefix: ${7:EGG} */
/* ===== Header ===== */
#ifndef _$1_H_
#define _$1_H_
@eiiches
eiiches / fib.cpp
Created March 26, 2012 10:13
Fibonatti
#include <iostream>
template <int i>
struct fib {
static const int value = fib<i-1>::value + fib<i-2>::value;
};
template <>
struct fib<0> {
static const int value = 1;
@eiiches
eiiches / integer_sum.cpp
Created March 26, 2012 02:30
1から100までの整数の和を表示するプログラムを作れ
#include <iostream>
#include <boost/mpl/range_c.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/fold.hpp>
using namespace boost;
int
main(int argc, char **argv)
@eiiches
eiiches / gist:1771948
Created February 8, 2012 18:27
tcpdump result
03:26:12.795292 IP6 2002:8533:5452:b:68d0:41eb:532e:7b52.52698 > 2404:6800:4004:b::6.www: Flags [S], seq 4145269032, win 65535, options [mss 1440,nop,wscale 2,nop,nop,TS val 723215303 ecr 0,sackOK,eol], length 0
03:26:12.795490 IP6 2002:8533:5452:b:68d0:41eb:532e:7b52.52698 > 2404:6800:4004:b::6.www: Flags [S], seq 4145269032, win 65535, options [mss 1440,nop,wscale 2,nop,nop,TS val 723215303 ecr 0,sackOK,eol], length 0
03:26:12.795494 IP6 2002:8533:5452:b:68d0:41eb:532e:7b52.52698 > 2404:6800:4004:b::6.www: Flags [S], seq 4145269032, win 65535, options [mss 1440,nop,wscale 2,nop,nop,TS val 723215303 ecr 0,sackOK,eol], length 0
03:26:12.795673 IP6 2002:8533:5452:b:68d0:41eb:532e:7b52.52698 > 2404:6800:4004:b::6.www: Flags [S], seq 4145269032, win 65535, options [mss 1440,nop,wscale 2,nop,nop,TS val 723215303 ecr 0,sackOK,eol], length 0
03:26:12.795677 IP6 2002:8533:5452:b:68d0:41eb:532e:7b52.52698 > 2404:6800:4004:b::6.www: Flags [S], seq 4145269032, win 65535, options [mss 1440,nop,wscale 2,nop,nop,TS val 72
@eiiches
eiiches / morse.sh
Created November 17, 2011 16:18
Morse on numlock LED. To run, echo "モールス信号" | ./morse.sh
#!/bin/zsh
int_short=0.1
int_long=$(($int_short * 3))
int_between_char=$(($int_short * 3))
int_between_word=$(($int_short * 7))
ledon() {
setleds +num +caps +scroll < /dev/tty7
}