Skip to content

Instantly share code, notes, and snippets.

View pyrocat101's full-sized avatar

Linjie Ding pyrocat101

View GitHub Profile
import select
import socket
import pycares
class CAresError(socket.error):
def __init__(self, errno, strerror):
super(CAresError, self).__init__(errno, strerror)
@pyrocat101
pyrocat101 / poly
Created August 19, 2014 21:58
HITCON CTF2014 - polyglot (Python2/Python3/C/Ruby/Haskell polyglot to `cat flag`)
x = {-
#if 0
0 + """".to_i => 0}
print `cat flag`
__END__
""".find('x')}
import os
p = os.system;{
#endif
1};
type maybe = True of string
| Maybe
| False
type regex = Alt of regex * regex * maybe array
| Then of regex * regex * maybe array
| Star of regex * maybe array
| Char of char
let make_memo () = Array.make 101 Maybe
Simplify[RSolve[{a[n] == (B + 1) a[n - 1] - a[n - 2], a[0] == 0, a[1] == B}, a[n], n]]
Block[{B = 2}, Simplify[Table[a[n] /. First[%], {n, 10}]]]
@pyrocat101
pyrocat101 / regex-parser.py
Created April 23, 2014 07:30
Regex Parser (Python version)
from collections import deque
class SyntaxError(Exception):
pass
class RegexParser(object):
"""
Alt ::= Concat ('|' Alt)*
| Concat
Concat ::= Star Star*
@pyrocat101
pyrocat101 / parse-regex.clj
Last active August 29, 2015 14:00
Regex Parser
(defn syntax-error []
(throw (ex-info "Syntax Error" {})))
(declare alt then star prime)
(defn expect [s c]
(if (not= (first s) c)
(syntax-error)
(rest s)))
@pyrocat101
pyrocat101 / buildwords.sh
Last active May 18, 2018 08:48
CS35L - Homework 2
# get content in <td>...</td>
sed -n 's/<td>\(.*\)<\/td>/\1/gip' | \
# remove empty lines
grep -v "^\s*$" | \
# remove odd lines
sed -n '1~2!p' | \
# remove <u> tags
sed 's/<u>\(.*\)<\/u>/\1/gi' | \
# convert apostrophe (` -> ')
sed "s/\`/'/g" | \
@pyrocat101
pyrocat101 / verbalArithmetic.pl
Created March 10, 2014 22:35
Generalized Verbal Arithmetic in Prolog.
pad(W1, W2, X, Y) :-
length(W1, L1),
length(W2, L2),
padZero(W1, W2, L1, L2, X, Y).
padZero(W1, W2, L, L, [0|W1], [0|W2]).
padZero(W1, W2, L1, L2, X, Y) :- L1 #> L2, pad(W1, [0|W2], X, Y).
padZero(W1, W2, L1, L2, X, Y) :- L1 #< L2, padZero(W2, W1, L2, L1, Y, X).
stripZero([], []).
@pyrocat101
pyrocat101 / wildcard_lookup.py
Created February 11, 2014 03:26
Wildcard Dictionary Lookup
class TRIE(object):
"""
>>> "foo" in TRIE(["foo", "bar"])
True
>>> "fo." in TRIE(["foo", "bar"])
True
>>> "f.o" in TRIE(["foo", "bar"])
True
>>> ".oo" in TRIE(["foo", "bar"])
True
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix.
;;
;; * :use makes functions available without a namespace prefix
;; (i.e., refers functions to the current namespace).
;;
;; * :import refers Java classes to the current namespace.
;;