This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([], []). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" | \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
class SyntaxError(Exception): | |
pass | |
class RegexParser(object): | |
""" | |
Alt ::= Concat ('|' Alt)* | |
| Concat | |
Concat ::= Star Star* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}]]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = {- | |
#if 0 | |
0 + """".to_i => 0} | |
print `cat flag` | |
__END__ | |
""".find('x')} | |
import os | |
p = os.system;{ | |
#endif | |
1}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import select | |
import socket | |
import pycares | |
class CAresError(socket.error): | |
def __init__(self, errno, strerror): | |
super(CAresError, self).__init__(errno, strerror) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bucket(object): | |
def __init__(self): | |
self.next = None | |
class Entry(object): | |
def __init__(self, key, val): | |
self.key = key | |
self.val = val | |
self.next = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Lexer(object): | |
def __init__(self, s): | |
self.s = s | |
self.idx = 0 | |
self.token = None | |
def peek(self): | |
if self.idx >= len(self.s): | |
return None | |
else: |