Skip to content

Instantly share code, notes, and snippets.

View nojima's full-sized avatar
o_O

Yusuke Nojima nojima

o_O
View GitHub Profile
@nojima
nojima / build_hadoop.sh
Created March 5, 2014 03:32
Build Hadoop 2.2.0 in Ubuntu
#!/bin/sh
set -xe
sudo apt-get update
sudo apt-get install -y wget build-essential openjdk-7-jdk cmake maven pkg-config libssl-dev
# install protobuf
cd
wget https://protobuf.googlecode.com/files/protobuf-2.5.0.tar.gz
@nojima
nojima / lxc-ssh.sh
Created March 5, 2014 04:38
ssh to an LXC container.
#!/bin/sh -e
if [ "$1" = "" ]; then
echo "Usage: lxc-ssh NAME [ARGS]"
exit 1
fi
NAME=$1
ADDR=$(sudo lxc-info -n $NAME | awk -F': *' '/^IP:/ { print $2 }')
shift
@nojima
nojima / label.py
Created March 19, 2014 09:19
指定されたコマンドを実行して、その出力にラベルを付与して出力するコマンド
#!/usr/bin/python
from argparse import ArgumentParser, REMAINDER
import os
import select
from subprocess import Popen, PIPE
import sys
def read_and_write(poll, rem, files, label):
for fd, _ in poll.poll():
buf = os.read(fd, 1024)

socat が便利だったのでメモ。

socat [options] <address> <address>

一方の address から入ってきたデータを他方の address に流すツール。 address には様々なデータストリームを指定できる。(標準入出力, TCP, UDP, ファイル, コマンドなど)

普通は address は read/write モードでオープンされる。

@nojima
nojima / lxc-ubuntu-nojima.diff
Created June 22, 2014 09:17
LXC の Ubuntu テンプレートを改造して /etc/hosts にコンテナの IP アドレスを書いておけば、lxc-create の時に自動的にそれを $rootfs/etc/network/interfaces に設定するようにしてみた。(※ netmask や gateway や dns-nameserver のアドレスは決め打ちなので、流用する場合はネットワークの設定に合わせて変更してください)
--- /usr/share/lxc/templates/lxc-ubuntu 2014-04-15 00:49:58.000000000 +0900
+++ /usr/share/lxc/templates/lxc-ubuntu-nojima 2014-06-22 18:03:15.209620112 +0900
@@ -53,21 +53,41 @@
release=$3
user=$4
password=$5
# configure the network using the dhcp
- cat <<EOF > $rootfs/etc/network/interfaces
+ ipaddr=$(sed -e 's/#.*$//' /etc/hosts | awk "\$2~/^${hostname}\$/ { print \$1 }")
#!/bin/sh
if [ $# -ne 1 ]; then
echo "Usage: create-container NAME" 1>&2
exit 1
fi
name=$1
ipaddr=$(sed -e 's/#.*$//' /etc/hosts | awk "\$2~/^${name}\$/ { print \$1 }")
if [ -z "$ipaddr" ]; then
echo "ERROR: IP address of ${name} was not found in /etc/hosts." 1>&2
exit 1

zsh の history に関するメモ

設定

# 履歴を複数の zsh プロセスで共有する
setopt share_history

# 履歴サイズ
HISTSIZE=10000

scrooloose/syntastic

NeoBundle 'scrooloose/syntastic'

...

" syntastic {{{
let g:syntastic_cpp_compiler = 'g++'
let g:syntastic_cpp_compiler_options = ' -std=gnu++11 -DCACHELINE_SIZE=64'
@nojima
nojima / icfpc-2014-lambda-man-ai.scm
Created July 28, 2014 11:58
ICFPC 2014 の Lambda man の AI
(define rnd 123456)
(define (flatten xs)
(if (null? xs)
()
(append (car xs) (flatten (cdr xs)))))
(define (field-ref field w y x)
(vector-ref field (+ (* y w) x)))
(define (field-set field w y x value)
@nojima
nojima / icfpc-2014-ai.gcc
Created July 28, 2014 12:04
ICFPC 2014 に提出した AI のコード (コンパイル後)
DUM 111 ; 0
LDC 0 ; 0
LDC 0 ; 0
LDC 0 ; 0
LDC 0 ; 0
LDC 0 ; 0
LDC 0 ; 0
LDC 0 ; 0
LDC 0 ; 0
LDC 0 ; 0