Skip to content

Instantly share code, notes, and snippets.

View eiiches's full-sized avatar

Eiichi Sato eiiches

View GitHub Profile
@eiiches
eiiches / gnome-terminal-transparency.sh
Created November 15, 2010 03:32
a script for changing gnome-terminal's background transparency from the command line.
#!/bin/sh
if [ $# -lt 1 ]; then
echo "Usage: $0 (darkness in 0.0 - 1.0)" 1>&2
fi
tmpfile=`mktemp`
gnome-terminal --save-config="$tmpfile"
profile=`grep "^ProfileID=" "$tmpfile" | cut -c 11-`
rm -f "$tmpfile"
@eiiches
eiiches / search_available_host.sh
Created February 27, 2011 07:53
Search hosts available for SSH.
#!/bin/bash
grep 'ant\|bee\|cat\|dog\|emu' /etc/hosts | while read ip host; do
nc -w 1 -z "$ip" 22 > /dev/null && echo "$host" &
done
@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 / 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 / latex.mk
Created June 24, 2011 16:34
Makefile for LaTeX
# vim: ft=make
TEX = platex
.SUFFIXES: .tex .dvi
.tex.dvi:
nkf -e $< | $(TEX) -no-parse-first-line -interaction=nonstopmode -shell-escape -jobname=$(basename $< .tex) /dev/stdin
nkf -e $< | $(TEX) -no-parse-first-line -interaction=nonstopmode -shell-escape -jobname=$(basename $< .tex) /dev/stdin
# .SUFFIXES: .dvi .pdf
@eiiches
eiiches / resizewindow.vim
Created July 17, 2011 17:12
Continous window resize in vim.
function! PrintMode(mode)
if &showmode
echoh ModeMsg | echo a:mode | echohl None
redraw
endif
endfunction
function! ResizeMode()
while 1
call PrintMode('-- RESIZE --')
@eiiches
eiiches / lambda.py
Created July 21, 2011 20:01
Concealing 'lambda' as λ in vim.
# -*- coding: utf-8 -*-
from functools import partial
(lambda x: x*2)((lambda y: y+3)(2))
(lambda x: 5)(10)
(lambda x:(lambda y:x+3*y))(12)(4)
def church2num(church):
try: return church(lambda x: x+1, 0)
@eiiches
eiiches / comprehension.py
Created August 8, 2011 16:39
List Comprehension / Generator in Python2.7 and 3.
# I found this already described in:
# Comprehensions in a class definition mostly cannot access class variable
# [ http://bugs.python.org/issue11796 ]
# ...and my understanding is that this is not going to be fixed.
class Foo1:
def foo(i): return i
bar = (foo(i) for i in range(10))
print(Foo1.bar)
@eiiches
eiiches / imagediff
Created August 12, 2011 07:23
A git-difftool script for images.
#!/bin/bash
tmp=`tempfile`
composite -compose difference "$1" "$2" "$tmp";
evince "$tmp"
@eiiches
eiiches / glib-valgrind.sh
Created September 28, 2011 10:13
glib-valgrind.sh
#!/bin/bash
export G_SLICE=always-malloc
export G_DEBUG=gc-friendly
valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=20 "$@"