Skip to content

Instantly share code, notes, and snippets.

View sirpengi's full-sized avatar

shu.chen sirpengi

View GitHub Profile
@sirpengi
sirpengi / dict_top_n.py
Created December 14, 2012 04:52
Filter top N elements of dict, looking for a more pythonic | performant | cleaner way to do this
from operator import itemgetter
def dict_top_n_items(d, n):
"""Take dictionary of form {key: count} and return a list
with only the top n entries (based on count)
If there is a tie for n-th place, include all keys that
meet the tie (thus, return list could have more than n items)
"""
if n == 0:
@sirpengi
sirpengi / euler2,rb
Created September 18, 2012 04:46
ruby woe
fib = Generator.new { |fib|
a = 0
b = 1
while true
fib.yield b
a, b = b, a + b
end
}
fib.take_while { |i| i < 4000000 }.select { |i| i.even? }.inject(0, :+)
@sirpengi
sirpengi / app_config.py
Created September 14, 2012 07:10
<3 dforsyth
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
sys.path.append('/home/sirpengi/code/r3/r3/test')
INPUT_STREAMS = [
'count_words_stream.CountWordsStream'
]
@sirpengi
sirpengi / fizzbuzz.py
Last active October 9, 2015 05:17
fizzbuzz
def Y(func):
def _(f):
return f(f)
def o(O):
def x(X):
return O(O)(X)
return func(x)
return _(o) # o_O
def fizzbuzz(c):
@sirpengi
sirpengi / loggy log log
Created July 30, 2012 13:13
What happened to ##proggit

You're probably wondering why we're in #proggit and not ##proggit (which redirects you to #anime).

The short version is that the internet is full of drama. The longer version goes like this:

We've never really had full control of ##proggit to begin with. ##proggit was started a long time ago by some other folks, who have since left the channel to do other things. So the people that remained fought it out amongst themselves and the victorious Sixthgear remained. He has been the de-facto leader of ##proggit, despite not having actual control over the channel (he had to defer to someone else to get ops added or removed, etc).

In any case, the ##proggit owner rejoined the channel recently, and decided to ban everyone, removed all ops, and set the channel to redirect to #anime. I can't say for certain the reasoning behind this, but you can come to your own conclusion based on the last logs.

Can we save ##proggit? Probably not. Despite the owner being gone for years at a time from the channel, there is no

@sirpengi
sirpengi / demobuild.php
Created July 27, 2012 07:42 — forked from jkuroiwa/demobuild.php
Demo for Socrata API JSON import into MySQL
<?php
function hobo_escape($val){
// because there is no good way to escape a dynamic table/field name
$ret = preg_replace('/[^a-zA-Z _]+/', '', $val);
$ret = preg_replace('/\s+/', '_', $ret);
return $ret;
}
// Credentialing for MySQL server if you want the code to create table and load data automatically
diff --git a/.project b/.project
index 78c3215..bf8d3bc 100644
--- a/.project
+++ b/.project
@@ -1,25 +1,25 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>CreativeMarket</name>
- <comment></comment>
- <projects>
print "\n".join(map(lambda x:((str(x[0]) if x[1]%5 else '') if (x[0]%3) else 'fizz')+('' if (x[1]%5) else 'buzz'),zip(range(1,1001),range(1,1001))))
@sirpengi
sirpengi / output
Created June 16, 2012 05:46
mah output
4 5
5
0
6
8
1
1
0
0
0
def one(iterable, condition=None):
"""True if only one value in the iterable evaluates to True."""
if condition is None:
condition = bool
gen = (i for i in iterable if condition(i))
try:
gen.next()
except StopIteration:
return False
try: