Skip to content

Instantly share code, notes, and snippets.

@kevinjqiu
kevinjqiu / hexspeak.py
Created April 22, 2011 03:04
hexspeak.py
def words():
with open('/usr/share/dict/words', 'r') as f:
return (x.strip().upper() for x in f.readlines())
MAPPING = {'A':'A', 'B':'B', 'C':'C', 'D':'D',
'E':'E', 'F':'F', 'O':'0', 'S':'5', 'I':'1'}
def main():
is_hexword = lambda word: all(ch in MAPPING for ch in word)
for word in filter(is_hexword, words()):
@kevinjqiu
kevinjqiu / wibblefish.clj
Created September 15, 2011 04:20
wibblefish in Clojure
(defn fizzbuzz []
(map #(cond (= 0 (mod % 15)) "wibblefish" (= 0 (mod % 3)) "wibble" (= 0 (mod % 5)) "fish" :else %) (range 1 101)))
@kevinjqiu
kevinjqiu / monty_hall.py
Created October 4, 2011 18:00
empirically prove monty hall
import random
import sys
def pick(switch):
doors = ['car', 'goat', 'goat']
random.shuffle(doors)
choices = zip(range(len(doors)), doors)
my_choice = random.choice(choices)
rest_choices = filter(lambda x: x!=my_choice, choices)
@kevinjqiu
kevinjqiu / jsontidy.py
Created March 27, 2012 21:19
jsontidy
#! /usr/bin/env python
import sys
import json
print json.dumps(json.loads(sys.stdin.read()), sort_keys=True, indent=4)
<script type="text/javascript" src="https://catastrophy.freshbooksdev.com/external/embed/embed.js"></script>
<div id="freshbooks-quoteme" class="container"></div>
@kevinjqiu
kevinjqiu / gist:3087883
Created July 11, 2012 03:55
change ca-bundle on devimage
cd /root;
rm -f cacert.pem*;
wget http://curl.haxx.se/ca/cacert.pem;
chattr -i /usr/share/curl/curl-ca-bundle.crt;
chattr -i /usr/share/ssl/certs/ca-bundle.crt;
rm -f /usr/share/curl/curl-ca-bundle.crt;
rm -f /usr/share/ssl/certs/ca-bundle.crt;
cp -f cacert.pem /usr/share/curl/curl-ca-bundle.crt;
cp -f cacert.pem /usr/share/ssl/certs/ca-bundle.crt;
chmod 644 /usr/share/curl/curl-ca-bundle.crt;
@kevinjqiu
kevinjqiu / sq_palindrome.md
Created July 15, 2012 15:27
square palindrome
print [ x*x for x in xrange(1000) if list(str(x*x)) == list(reversed(str(x*x)))]
$ python foo.py 
[0, 1, 4, 9, 121, 484, 676, 10201, 12321, 14641, 40804, 44944, 69696, 94249, 698896]
// Install dependencies with 'npm install'
// Run as 'node level00.js'
var express = require('express'), // Web framework
mu = require('mu2'), // Mustache.js templating
sqlite3 = require('sqlite3'); // SQLite (database) driver
// Look for templates in the current directory
mu.root = __dirname;
<html>
<head>
<title>Secret Safe</title>
</head>
<body>
{{#namespace}}
<div style="border-width: 2px; border-style: outset; padding: 5px">
Showing secrets for <strong>{{namespace}}</strong>:
<table>
<thead>