Skip to content

Instantly share code, notes, and snippets.

@emonkak
emonkak / reverse_array.c
Created March 4, 2010 13:26
reverse_array.c
#include <stdio.h>
void
reverse(int *src, int length)
{
if (length < 2)
return;
int tmp = src[0];
@emonkak
emonkak / ptex-3.1.10_p20090610-refuse_time_bomb.patch
Created September 6, 2010 06:12
ptex-3.1.10_p20090610-refuse_time_bomb.patch
--- ptetex3-20090610.orig/3extract-texmf.sh 2010-09-06 14:31:07.051612994 +0900
+++ ptetex3-20090610/3extract-texmf.sh 2010-09-06 14:31:09.911613003 +0900
@@ -20,7 +20,7 @@
# refuse time bomb (65 months since 2003/12)
distcp $TEXMF tex/latex/base latex.ltx
-perlprint 's/65$/77/g' $TEXMF/tex/latex/base/latex.ltx
+perlprint 's/^\\ifnum\\count@>65$/\\iffalse/' $TEXMF/tex/latex/base/latex.ltx
# update config.ps with TeX Live 2007 svn (10/25)
@emonkak
emonkak / Looping.hs
Created February 21, 2011 14:30
Looping.hs
import System.CPUTime
calc n n0 = n0 + (1 - 2 * (n `rem` 2))
looping 0 n _ = n
looping c n n0 = let n1 = calc n n0
in n1 `seq` looping (c - 1) n1 n
main = do
start <- getCPUTime
print $ looping 2147483647 1 0
@emonkak
emonkak / putty-0.60-fix-font.patch
Created April 11, 2011 06:08
putty-0.60-fix-font.patch
--- WINDOWS/window.c~ Thu Dec 24 13:17:48 2009
+++ WINDOWS/window.c Sun Nov 28 22:09:15 2010
@@ -1759,8 +1759,8 @@
else {
font_height = cfg.font.height;
if (font_height > 0) {
- font_height =
- -MulDiv(font_height, GetDeviceCaps(hdc, LOGPIXELSY), 72);
+ font_height = font_height > 0 ?
+ -MulDiv(font_height, GetDeviceCaps(hdc, LOGPIXELSY), 72) : font_height;
@emonkak
emonkak / ibus-mozc-1.1.773.102.ebuild
Created July 27, 2011 04:16
ibus-mozc-1.1.773.102.ebuild
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/app-i18n/ibus-mozc/ibus-mozc-1.1.773.102.ebuild,v 1.1 2011/07/20 14:52:13 matsuu Exp $
EAPI="3"
PYTHON_DEPEND="2"
inherit elisp-common eutils multilib python toolchain-funcs flag-o-matic
MY_P="${P/ibus-}"
PROTOBUF_PV="2.4.1"
@emonkak
emonkak / UnNesting.hs
Created July 29, 2011 01:43
UnNesting.hs
data Item a = Atom a
| List [Item a]
deriving (Eq, Show)
flatten :: Item a -> [a]
flatten (Atom x) = [x]
flatten (List xs) = concat $ map flatten xs
flatten' :: Item a -> [a]
flatten' (Atom x) = [x]
module Main where
import Control.Arrow
import Control.Monad.ST
import Debug.Trace
import System.Random
import Test.QuickCheck
import Test.QuickCheck.Gen
@emonkak
emonkak / agqr
Created August 3, 2011 13:16
agqr on linux
#!/bin/sh
URI="http://www.uniqueradio.jp/agplayer/ag_movie.asx"
SID="bffcd85ca284fa09d605095f02210251114ac3a0"
MPLAYER_OPTS="-quiet -demuxer lavf -lavfdopts cryptokey=${SID}"
PLAYLIST_P=true
while getopts ":1234amvh" opt; do
case ${opt} in
1 | 2 | 3 | 4)
@emonkak
emonkak / functional.vim
Created September 1, 2011 02:30
functional.vim
function! s:foldl(F, Z, XS)
let wrapper = {'F': a:F}
function wrapper.go(Z, XS) dict
if empty(a:XS)
return a:Z
else
let [X; XS] = a:XS
return self.go(self.F(a:Z, X), XS)
endif
endfunction
@emonkak
emonkak / AnimasExample.hs
Created September 5, 2011 01:31
AnimasExample.hs
{-# LANGUAGE Arrows #-}
import Control.Applicative
import Data.Char
import FRP.Animas
import System.IO
initialize :: IO (Event Char)
initialize = do
hSetBuffering stdin NoBuffering