Skip to content

Instantly share code, notes, and snippets.

View chaoxu's full-sized avatar
😀

Chao Xu chaoxu

😀
  • University of Electronic Science and Technology of China
  • Chengdu, Sichuan, China
View GitHub Profile
@chaoxu
chaoxu / open.sh
Created March 12, 2011 17:21
Open a file by association. -o to open -e to edit.
#!/bin/bash
#long file extension usually means it's a text
SELF="$(cd ${0%/*} && echo $PWD/${0##*/})"
if [[ $1 == "-o" ]]; then
a="$HOME/.association"
text="vim -u /usr/share/vim/vim73/macros/less.vim"
default="xdg-open"
elif [[ $1 == "-e" ]]; then
a="$HOME/.associationedit"
text="vim"
@chaoxu
chaoxu / history_combine.py
Created May 2, 2011 07:56
Combine freetalk history files
#!/usr/bin/python2
#usage: scriptname file1 file2 ...
import sys
import re
def toarray(a):
entrystart = re.compile('[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} \[[^\s]*@[^\s]*\]')
a2 = []
for line in a:
match = entrystart.match(line)
if match is not None:
@chaoxu
chaoxu / find.nb
Created May 5, 2011 00:49
Pebbling graph test
A = Import["pebble.txt", "Table"];
A = Select[A,
Function[x,
If[x[[1]] == x[[7]]
&& x[[3]] == Floor[Log[2, x[[1]]]]
&& x[[2]] < 2^(Floor[Log[2, x[[1]]]] + 1)
, True,
False
]]];
B = Table[
@chaoxu
chaoxu / latex2html.php
Created June 22, 2011 04:36
latex 2 html
<?php
function latex2html($text){
$s[] = '/\\\\begin{theorem}\\[(.*?)\\]\\s/';
$r[] = '<blockquote class="theorem"><strong>Theorem ($1)</strong> ';
$s[] = '/\\\\begin{lemma}\\[(.*?)\\]\\s/';
$r[] = '<blockquote class="theorem"><strong>Lemma ($1)</strong> ';
$s[] = '/\\\\begin{problem}\\[(.*?)\\]\\s/';
$r[] = '<blockquote class="problem"><strong>Problem ($1)</strong> ';
$s[] = '/\\\\begin{corollary}\\[(.*?)\\]\\s/';
$r[] = '<blockquote class="theorem"><strong>Corollary ($1)</strong> ';
@chaoxu
chaoxu / word_problem_braid_group.hs
Created June 23, 2011 05:54
Word Problem for Braid Group
default (Int, Integer, Rational, Double)
if' :: Bool -> a -> a -> a
if' True x _ = x
if' False _ y = y
isBraidIdentity x n =
[1..n] == concat (map (braidReduce x) [[y] | y <- [1..n]])
braidReduce = flip (foldr homomorphism)
@chaoxu
chaoxu / latex2html.hs
Created June 26, 2011 02:56
LaTeX 2 HTML, still updating
import Data.Tree
import Data.List
import Debug.Trace
import Maybe
--the last int is the amount of argument
data Label = Command String
| Constant String
| Declaration
deriving Show
@chaoxu
chaoxu / binaryMaximumInterval.hs
Created June 27, 2011 07:21
testing some data
import Data.List
binaryArray n = a [] n
a list 0 = [list]
a list n = (a (0:list) (n-1))++(a (1:list) (n-1))
f list = map (fx list) [1..length list]
fx list j = 1 + (length (takeWhile ((/=) (maximum result)) result))
where result = map (sum . (take j) . (flip drop list)) [0..(length list)-j]
@chaoxu
chaoxu / freetalk.py
Created July 2, 2011 00:18
Freetalk write last message
import commands
import time
f = '~/.freetalk/history/mgcclx@gmail.com/SESSION'
s = commands.getoutput('cat ' + f + ' | tail --lines 1 | cut -c 21-')
s = s.replace('[','<fc=#ffffff>',1)
s = s.replace(']',':</fc>',1)
s = s.replace('@gmail.com','',1)
s = s.rstrip()
u = unicode(s, "utf-8")
print u[0:100].encode("utf-8")
@chaoxu
chaoxu / word_problem_b3.hs
Created July 6, 2011 00:31
Word Problem for B_3
--Word Problem for B_3
--Input a word, 1 = generator \sigma_1, 2 = generator \sigma 2, -1 and -2 are their inverse respectively.
--Return true if it's trivial, else return false
isTrivialBraid3 list =
(remainword == []) && (pdelta+delta == 0)
where (remainword, pdelta) = positiveDelta' word [] 0
(word,delta) = negativeDelta' list [] 0
positiveDelta' before after delta
| (suffix == [1,2,1] || suffix == [2,1,2]) = positiveDelta' before (drop 3 after) (delta + 1)
@chaoxu
chaoxu / Counter.java
Created July 11, 2011 07:33
LaTeX2HTML Java version
import java.util.HashMap;
public class Counter {
public HashMap<String, Integer> counters;
Counter(){
//initialize counters
counters = new HashMap<String, Integer>();
newCounter("part");