Skip to content

Instantly share code, notes, and snippets.

View zonble's full-sized avatar

Weizhong Yang a.k.a zonble zonble

View GitHub Profile
import re
MAP = {",":".", "!":"?", "(":")", "{":"}", "[":"]", "<":">", "@":"#",
";":":", ".":",", "?":"!", ")":"(", "}":"{", "]":"[", ">":"<", "#":"@", ":":";"}
c_t = lambda x: ''.join(c.lower() if c.isupper() else c.upper()
for c in x.group(0)[::-1])
c_n = lambda x: str(9 - int(x.group(0)))
c_s = lambda x: MAP.get(x.group(0), x.group(0))
def twist(text):
text = re.sub(r'[a-zA-Z]*', c_t, text)
text = re.sub(r'\s+', ' ', text); text = re.sub(r'[0-9]', c_n, text)
import string
MAP = {",":".", "!":"?", "(":")", "{":"}", "[":"]", "<":">", "@":"#",
";":":", ".":",", "?":"!", ")":"(", "}":"{", "]":"[", ">":"<", "#":"@", ":":";"}
go = lambda x: ''.join(c.lower() if c.isupper() else c.upper() for c in x[::-1])
def twist(text):
out = ""; buf = "";
for c in text:
if c not in string.ascii_letters:
if len(buf): out += go(buf); buf = ""
if c == " ": out += " " if out[-1] != " " else ''
import string
SYMBOL_MAP = {",": ".", "!": "?", "(": ")", "{": "}", "[": "]",
"<": ">", "@": "#", ";": ":", ".": ",", "?": "!", ")": "(",
"}": "{", "]": "[", ">": "<", "#": "@", ":": ";"}
SYMBOL_RANGE = "!#$%&()*+,-./:;<=>?@[\]^_`{|}~"
def detect_type(c):
return "sp" if c == " " else "w" if c in string.ascii_letters else \
"n" if c in string.digits else "s" if c in SYMBOL_RANGE else "m"
def convert_tokens_to_output(tokens):
return ''.join(" " if t[0] == "sp" else
@zonble
zonble / abcdefghi.c
Last active April 6, 2016 15:29
abcdefghi.c
#include <stdio.h>
#include <stdlib.h>
int stack[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int *make_next_level(int *level, int count, int remove_index) {
int *rtn = calloc(count, sizeof(int));
int index = 0;
for (int i = 0; i < count; i++) {
if (i == remove_index) {
@zonble
zonble / abcdefghi.py
Created April 6, 2016 14:50
abcdefghi.py
digits = range(2, 10)
stack = []
results = []
def travel(this_level):
if len(this_level) == 0:
a,b,c,d,e,f,g,h = stack
ef = (a * 10 + b) - (c * 10 + d)
if ef == (e *10 +f) and ef + (g * 10 + h) == 111:
results.append(stack[:])
@zonble
zonble / abcdefghi.swift
Created April 6, 2016 14:33
abcdefghi.swift
import Cocoa
let digits :[Int] = Array(2...9)
var stack :[Int] = [Int]()
var results = [[Int]]()
func travel(inArray: [Int]) {
if inArray.count == 0 {
let a = stack[0], b = stack[1], c = stack[2], d = stack[3], e = stack[4], f = stack[5], g = stack[6], h = stack[7]
let ef = (a * 10 + b) - (c * 10 + d)
# To solve https://scontent-tpe1-1.xx.fbcdn.net/hphotos-xpt1/v/t1.0-9/12140762_10206383163957694_3005844752527088716_n.jpg?oh=b08035a7d4b6e98257a7b4cbc773a883&oe=579521DB
valid_p = 0
def check(a, b, c, d, g, h):
global valid_p # I always hate to use global vars...
ef = (a * 10 + b) - (c * 10 + d)
e = ef / 10;
f = ef % 10
import UIKit
let SingletonErrorDomain = "SingletonErrorDomain"
class Singleton {
static let sharedInstance = Singleton()
var activeTask :NSURLSessionDataTask?
final func getURL(URLString :String, HTTPMethod :String, completion :(NSDictionary?, NSError?) -> Void) {
import UIKit
class MyCell :UITableViewCell {
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
let block :()->() = {
let color = selected ? UIColor.redColor() : UIColor.grayColor()
self.textLabel?.textColor = color
self.textLabel?.layer.borderColor = color.CGColor
self.textLabel?.layer.borderWidth = 1
//: Playground - noun: a place where people can play
import UIKit
let ZBTaipeiParkingErrorDomain = "ZBTaipeiParking"
enum ZBTaipeiParkingErrorType : Int {
case NoData
case NOJSONObject
}