Skip to content

Instantly share code, notes, and snippets.

View saml's full-sized avatar

Sam Lee saml

  • New York, NY
View GitHub Profile
def pprint(d, level=0):
value = d.get('value', None)
left = d.get('left', None)
right = d.get('right', None)
if value is not None:
print('%s%s' % (' ' * level, value))
if left is not None:
pprint(left, level+4)
if right is not None:
pprint(right, level+4)
import sys
import re
import fileinput
LogRE = re.compile(r'^(\S+) (\S+) (\S+) (\S+ -0400) ("[^"]+") (\S+) (\S+) ')
if __name__ == '__main__':
lines = fileinput.input() if len(sys.argv) < 2 else fileinput.input(sys.argv[1])
for line in lines:
m = LogRE.match(line)
http {
proxy_cache_path /var/www/cache levels=2:2 keys_zone=default:30m inactive=24h max_size=1024m;
proxy_temp_path /var/www/tmp;
proxy_buffers 8 256k;
proxy_buffer_size 128k;
proxy_busy_buffers_size 256k;
server {
location /proxy/graph.facebook.com/ {
proxy_cache default;
for city in newyork boston chicago losangeles philadelphia sanfrancisco
do
if [[ -d "$basedir/$city" ]]
then
baseurl="http://$city.$domain"
if [[ "newyork" = "$city" ]]
then
baseurl="http://www.$domain"
fi
if @nickpass
if @email
privmsg 'NickServ', "IDENTIFY #@email #@nickpass"
else
privmsg 'NickServ', "IDENTIFY #@nickpass"
end
end
@email = (@config['email'] or nil)
  1. Dining philosopher

They want food so they wait. And end up eating each other.

  1. Given a random number generator that returns a number between [0,1], how would you build a RNG that accounted for weighting?

WAT?

  1. You have two arrays with N integers in them. Merge those arrays using a recursive algorithm so that the integers in the final array are sorted.

This program performs fast cross-validation on Census Income data set in CSV format. It's main purpose is for run time comparison with Weka.

>{-# LANGUAGE DataKinds #-}
>{-# LANGUAGE TypeFamilies #-}
>{-# LANGUAGE BangPatterns #-}
>{-# LANGUAGE TemplateHaskell #-}
>
>import HLearn.Algebra

>import HLearn.Models.Distributions

@saml
saml / play base.scala.html
Last active December 18, 2015 07:59
base template with default stylesheet and scripts
@(title: String, stylesheets: Html = null, scripts: Html = null)(content: Html)
@defaultStylesheets = {
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet" />
}
@defaultScripts = {
}
<!doctype html>
/**
* puts file to Storage .
*
* readBytes: File => Option[Array[Byte]]
* put: Array[Byte] => Id
*/
def putFrom(file: File, cleanUp: Boolean): Option[ID] = Exception.allCatch.andFinally {
if (cleanUp) file.delete()
} opt {
readBytes(file).map(put(_))
package tmp
import scala.concurrent.{Future, future}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Try, Failure, Success}
/**
* author: saml
*/