Skip to content

Instantly share code, notes, and snippets.

@henix
henix / shBrushTcl.js
Created June 1, 2012 11:46
SyntaxHighlighter brush for Tcl
/**
* SyntaxHighlighter brush for Tcl
*
* more info:
* http://blog.henix.info/blog/tcl-syntaxhighlighter-brush.html
*
* @version 0.3
*
* @copyright
* Copyright (C) 2011-2012 henix.
@henix
henix / zathurarc
Created February 3, 2013 06:05
zathura: View pdf in custom bg color
set default-bg "#C7EDCC"
set recolor true
set recolor-lightcolor "#C7EDCC"
set recolor-darkcolor "#000000"
@henix
henix / jillus-intro.md
Last active December 15, 2015 00:49
jillus - A type-safe parser combinator in Java

先放代码:https://github.com/henix/jillus

什么是 Parsing

  • 把序列化的数据变成你自己的数据结构(参见:三大 DSL
  • 处理的数据结构通常带递归

如何描述语法,或:带递归的数据结构

  • EBNF - 请参见编译教科书
@henix
henix / bri.sh
Created April 19, 2013 11:25
bri: show, set and store the brightness of your laptop (BTW, check the battery)
#!/bin/bash
BRIFILE=/sys/class/backlight/acpi_video0/brightness
if [ $# -lt 1 ]; then
cat $BRIFILE
else
echo $1 > $BRIFILE
echo $1 > /root/.bri
fi
@henix
henix / game24.pro
Last active December 16, 2015 11:39
A 24-game solver in Prolog
/* RPN = Reverse Polish notation */
operator(add).
operator(sub).
operator(mul).
operator(div).
doop(add, A, B, C) :- C = A + B.
doop(sub, A, B, C) :- C = A - B.
doop(mul, A, B, C) :- C = A * B.
@henix
henix / mklibclass.sh
Created April 26, 2013 02:18
./mklibclass > libclass ; gvim libclass ; /\.ClassName # find full class name in your project, for vimer writing scala
#!/bin/sh
find . -name "*.jar" | xargs -L 1 unzip -l | grep 'class$' | awk '{print $4}' | sed -e 's/\.class$//g' -e 's/\//./g'
@henix
henix / web2pdf.css
Last active December 16, 2015 22:28
convert a web page to pdf using [prince](http://www.princexml.com/) 8.1
* {
font-family: "DejaVu Serif", "AR PL New Sung", "WenQuanYi Zen Hei", serif;
}
@page {
/*background-color: #C7EDCC;*/
background-color: #CCB995;
margin: 1.5cm;
}
@henix
henix / highvote.mk
Created May 6, 2013 17:11
Download top 50 highest voted ${tag} questions on stackoverflow, and convert them to pdf. depends on web2pdf.sh
.PHONY: all
all: highvote-pdf.mk
make -j4 -f $< WEB2PDF=/home/henix/web2pdf.sh
highvote-pdf.mk: highvote.html
xmllint --html --xpath "//a[@class='question-hyperlink']/@href" $< 2> /dev/null | sed -e 's/ href="//g' -e 's/"/\n/g' | lua link2mk.lua > $@
highvote.html:
curl 'http://stackoverflow.com/questions/tagged/scala?sort=votes&pagesize=50' > $@
@henix
henix / qpdecode.scala
Last active December 17, 2015 04:48
quoted-printable decode scala script # for manually decode an email
#!/bin/sh
REPO=~/.m2/repository
exec scala -classpath $REPO/commons-io/commons-io/2.4/commons-io-2.4.jar:$REPO/javax/mail/mail/1.4.6/mail-1.4.6.jar:$REPO/javax/activation/activation/1.1.1/activation-1.1.1.jar "$0" "$@"
!#
import java.io.InputStreamReader
import java.nio.charset.Charset
import javax.mail.internet.MimeUtility
import org.apache.commons.io.IOUtils
@henix
henix / javaescn.sed
Created June 21, 2013 09:18
Encode a file into a Java string, with newline inserted at each \n
# http://stackoverflow.com/questions/1251999/sed-how-can-i-replace-a-newline-n
:a
N
$!ba
s/\\/\\\\/g
s/"/\\"/g
s/\r/\\r/g
s/\t/\\t/g
s/\f/\\f/g
s/\n/\\n" +\n"/g