Skip to content

Instantly share code, notes, and snippets.

import XMonad
import XMonad.Config.Desktop
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO
screenLockProg = "sxlock"
myModMask = mod4Mask
@ZhanruiLiang
ZhanruiLiang / dist.py
Created June 10, 2015 06:56
Distribution of generated numbers by a given total sum
from matplotlib import pyplot as plt
def validate(func, s=100, n=5, trails=100000):
counts = [0] * (s + 1)
for _ in xrange(trails):
for x in func(s, n):
counts[x] += 1
plt.plot(range(s + 1), counts)
plt.show()
@ZhanruiLiang
ZhanruiLiang / test.xml
Created January 20, 2014 17:21
Convert XML to human readable format with proper visual indent and without closing tags or pointy brackets.
<?xml version="1.0" ?>
<project>
<tag1 a1="v1" a2="v2" a3="v3">
<ctag1>
hello
</ctag1>
<ctag2>
world
</ctag2>
</tag1>
@ZhanruiLiang
ZhanruiLiang / fish-1.hs
Last active December 25, 2015 12:49
Godegolf Fish interpreter. In haskell.
import qualified Data.Map as M
import System.Environment
import Data.Char
import Control.Monad
import System.Random
type StackT = Int
type Pos = (Int, Int)
data Mode = StringParse | Normal deriving Show
@ZhanruiLiang
ZhanruiLiang / fkgfw2.py
Last active December 25, 2015 04:29
More advanced than the older version.
#! /usr/bin/python2
import pexpect
import os, sys
from time import sleep
CONFIG_PATH = os.path.expanduser('~/.fkgfw_config')
CHECK_DURATION = 5
FIFO = '/tmp/fkgfw_fifo'
class Proxy:
"""
@ZhanruiLiang
ZhanruiLiang / polygon.py
Last active December 21, 2015 10:28
Is vertex in polygon ?
import pygame as pg
import math
W, H = 1000, 600
pg.display.init()
pg.font.init()
font = pg.font.SysFont('serif', 20)
X, Y = 0, 1
@ZhanruiLiang
ZhanruiLiang / KMPAt.hs
Created June 14, 2013 17:12
KMP automaton in Haskell
-- module KMPAt where
import System.IO
import Control.Monad
import Data.Maybe
import Data.String
import System.TimeIt
data KMPAt = AuxNode (Maybe KMPAt)
| KMPNode (Maybe KMPAt) KMPAt (Char->Bool)
@ZhanruiLiang
ZhanruiLiang / KMP.hs
Created June 14, 2013 17:11
Knuth-Morris-Pratt in Haskell
import Control.Monad
import System.IO
import Data.Array.Unboxed
import System.TimeIt
match patt s = matches 0 0 s where
matches j i s | j == m = i : matches (f!j) i s
| i == n = []
matches j i (c:s) = matches (back j c + 1) (i+1) (s)
@ZhanruiLiang
ZhanruiLiang / SYSU-2013-05-04-board.txt
Last active December 17, 2015 00:09
中大ACM省赛前集训(5月4日)总board.
| Team| Solved| Penalty| A| B| C| D| E| F| G| H| I| J
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
> SYSU_TimeWizard| 7| 696| (4)| 1:27:23(1)| 2:37:22(1)| 0:42:34| | | 3:51:29(3)| 0:04:25| 0:24:06| 0:29:27(1) <
| sysu_stardust| 6| 700| | 3:04:55(4)| | 1:19:22| | | 4:20:29(1)| 0:07:49| 0:18:54(1)| 0:28:56 |
> MagnetWarrior| 6| 819| | 2:40:05| | 2:45:02(2)| | | 4:02:23(1)| 0:46:13| 0:54:45| 1:11:17(1) <
| sysu_3idiots| 5| 309| | (3)| | 1:00:11| | | 2:48:47(1)| 0:13:16| 0:19:30| 0:27:21 |
> DarkMagician|
@ZhanruiLiang
ZhanruiLiang / brcki.py
Last active December 13, 2015 18:58
break out game. Written in python 3 with Pygame and PIL.
import pygame as pg
import bz2
import itertools
import Image
import ImageDraw
import pickle
from random import randint
from math import pi,sin,cos,sqrt,atan2
norm = lambda c:c/abs(c)