Skip to content

Instantly share code, notes, and snippets.

Zhanrui ZhanruiLiang

Block or report user

Report or block ZhanruiLiang

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:1d38fad0f2347099c97d03510f229253
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 Jun 10, 2015
Distribution of generated numbers by a given total sum
View dist.py
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 Jan 20, 2014
Convert XML to human readable format with proper visual indent and without closing tags or pointy brackets.
View test.xml
<?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 Dec 25, 2015
Godegolf Fish interpreter. In haskell.
View fish-1.hs
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 Dec 25, 2015
More advanced than the older version.
View fkgfw2.py
#! /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 Dec 21, 2015
Is vertex in polygon ?
View polygon.py
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 Jun 14, 2013
KMP automaton in Haskell
View KMPAt.hs
-- 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 Jun 14, 2013
Knuth-Morris-Pratt in Haskell
View KMP.hs
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 Dec 17, 2015
中大ACM省赛前集训(5月4日)总board.
View SYSU-2013-05-04-board.txt
| 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 Dec 13, 2015
break out game. Written in python 3 with Pygame and PIL.
View brcki.py
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)
You can’t perform that action at this time.