Skip to content

Instantly share code, notes, and snippets.

"""
usage: cutter.py src destPrefix
"""
import sys, os
from time import sleep
CHUNK = 8 * 1024
BLOCK = 2 * 1024 ** 3 - 1
src = sys.argv[1]
destPrefix = sys.argv[2]
@ZhanruiLiang
ZhanruiLiang / fo.cpp
Created August 20, 2012 16:46
Data structure: Factor Oracle implement with c++
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<vector>
#include<cstring>
#include<algorithm>
#include<vector>
#define For(i, n) for(i = 0; i < n; i++)
@ZhanruiLiang
ZhanruiLiang / acauto_compact.cpp
Created August 20, 2012 16:56
AC automaton implement in C++
#include<iostream>
#include<sstream>
#include<string>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<vector>
#include<cstring>
#include<algorithm>
@ZhanruiLiang
ZhanruiLiang / suffixtree.cpp
Created August 20, 2012 17:05
Suffix tree construction with Ukkonen's online algorithm. Implement in C++.
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<vector>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
@ZhanruiLiang
ZhanruiLiang / MyServer.java
Created October 9, 2012 04:28
Java Socket exp
import java.io.*;
import java.net.*;
import java.util.Scanner;
import java.util.NoSuchElementException;
public class MyServer{
ServerSocket serverSocket;
Socket clientSocket;
Scanner in;
BufferedWriter out;
@ZhanruiLiang
ZhanruiLiang / MyClient.java
Created October 9, 2012 04:33
Java Socket exp(Client)
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class MyClient{
Socket clientSocket;
OutputStreamWriter out;
Scanner in;
public void connect(String dest, int port){
try{
@ZhanruiLiang
ZhanruiLiang / spfa.py
Created January 27, 2013 08:52
This gist test if SPFA can be performed with a stack. The result is, NO.
from collections import deque
import random
def gen_graph(n, m):
a = [[None] * n for i in range(n)]
for i in range(m):
x = random.randint(0, n-1)
y = random.randint(0, n-1)
c = random.randint(1, 100)
a[x][y] = c
return a
@ZhanruiLiang
ZhanruiLiang / quadtree.py
Created February 3, 2013 19:15
Quad tree implement using bin tree. Uses pygame to display.
#!/usr/bin/env python2
import pygame
from pygame.locals import *
COLOR_BG = (0xff, 0xff, 0xff, 0xff)
COLOR_BLACK = (0, 0, 0, 0xff)
COLOR_TRANS = (0, 0, 0, 0)
G = 1
class SMTNode:
@ZhanruiLiang
ZhanruiLiang / decovsmuli.py
Created February 4, 2013 08:30
Decorator Pattern vs. Multiple Inheritance.
#!/usr/bin/python2
class Window(object):
def draw(self, device):
device.append('flat window')
def info(self):
pass
# The subclass approch
class BorderedWindow(Window):
@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)