Skip to content

Instantly share code, notes, and snippets.

@ongspxm
ongspxm / script-AVL_tree_implementation.py
Last active August 29, 2015 14:07
Implementation of self balancing trees
class Node:
def __init__(self, key, data = None):
self.left = None
self.right = None
self.bal = 0
self.key = key
self.data = []
if data: self.data.append(data)
@ongspxm
ongspxm / form_pdf_booklet.py
Last active August 29, 2015 14:07
Forming booklets from PDF files
import sys, pyPdf
def addPage(opdf, ipdf, pg):
if pg>=len(pages):
opdf.addBlankPage(w, h)
else:
opdf.addPage(ipdf.getPage(pages[pg]))
try:
args = sys.argv[1:]
@ongspxm
ongspxm / mobile_fb_tag_removal.user.js
Last active August 29, 2015 14:09
User Script to Remove FB Photo tags through the mobile interface
// ==UserScript==
// @name Mobile FB Photo Tag Removal
// @namespace http://your.homepage/
// @version 3.0
// @description Remove photo tags using the FB Mobile Interface
// @author Metta Ong
// @match https://m.facebook.com/photo.php?*
// @grant none
// @run-at document-end
// ==/UserScript==
@ongspxm
ongspxm / webpy-sessions.py
Last active August 29, 2015 14:10
Using sessions with web.py
import web
### Standard URL handling
urls = [
'/', 'Index',
'k', 'Kill'
]
app = web.application(urls, globals())
# Store the session someplace we can access from anywhere
@ongspxm
ongspxm / mangareaderDownload.py
Last active October 18, 2015 05:22
Manga reader downloader
"""MangaReader downloader.
Usage:
dw.py <manga> [<chapter>] [<page>]
Options:
-h --help Show this screen
--version Show version
"""
@ongspxm
ongspxm / a.py
Created May 22, 2016 02:17
2016 codejam 1C
T = input()
grps = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for t in range(T):
N = input()
P = map(int, raw_input().split())
plans = []
while sum(P)>0:
idx = P.index(max(P))
P[idx] -= 1
@ongspxm
ongspxm / b.py
Created May 22, 2016 02:18
2016 codejam 1C
T = input()
for t in range(T):
B, M = map(int, raw_input().split())
fixed = []
if M>2**(B-2):
print 'Case #%d: IMPOSSIBLE'%(t+1)
else:
config = bin(M-1)[2:]
if B==2: config=''
@ongspxm
ongspxm / c.py
Created May 22, 2016 02:20
2016 codejam 1C
T = input()
for t in range(T):
J, P, S, K = map(int, raw_input().split())
poss = []
for j in range(1, J+1):
for p in range(1, P+1):
if K>=S:
for s in range(1, S+1): poss.append('%d %d %d'%(j, p, s))
else:
@ongspxm
ongspxm / script-extract_dictionary_com_to_stardict.py
Last active July 9, 2016 15:54
Script - Extracting dictionary.com data into stardict format
import sqlite3
def encode(string):
return string.encode("ascii", "xmlcharrefreplace")
def importData(db):
conn = sqlite3.connect(db)
cur = conn.cursor()
sep=unichr(183); br="\\n"
@ongspxm
ongspxm / rdark.scss
Created August 19, 2016 15:02
dark theme for pygment code highlighter
.highlight { background: #1e2426; color: #babdb6}
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #656763} /* Comment */
.highlight .err { color: #babdb6} /* Error */
.highlight .g { color: #babdb6} /* Generic */
.highlight .k { color: #729fcf} /* Keyword */
.highlight .l { color: #babdb6} /* Literal */
.highlight .n { color: #babdb6} /* Name */
.highlight .o { color: #babdb6} /* Operator */
.highlight .x { color: #babdb6} /* Other */