Skip to content

Instantly share code, notes, and snippets.

@cesarkawakami
cesarkawakami / ggroups.js
Created November 21, 2010 02:35
Google Groups statistics gatherer
var v = [];
var text = '<table>';
var months = [
{name: 'Jan', index: '01'},
{name: 'Feb', index: '02'},
{name: 'Mar', index: '03'},
{name: 'Apr', index: '04'},
{name: 'May', index: '05'},
{name: 'Jun', index: '06'},
{name: 'Jul', index: '07'},
# -*- coding: utf-8 -*-
BOOTSTRAP = r"""
html,body{margin:0;padding:0;}
h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,cite,code,del,dfn,em,img,q,s,samp,small,strike,strong,sub,sup,tt,var,dd,dl,dt,li,ol,ul,fieldset,form,label,legend,button,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;font-weight:normal;font-style:normal;font-size:100%;line-height:1;font-family:inherit;}
table{border-collapse:collapse;border-spacing:0;}
ol,ul{list-style:none;}
q:before,q:after,blockquote:before,blockquote:after{content:"";}
html{overflow-y:scroll;font-size:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;}
a:focus{outline:thin dotted;}
a:hover,a:active{outline:0;}
@cesarkawakami
cesarkawakami / parallel_radix_sort.cpp
Created November 18, 2012 22:53
Quick parallel out-of-place radix-sort implementation
#include <algorithm>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <pthread.h>
#include <random>
const int DATA_LENGTH = 1000000000;
class F(object):
def __init__(self):
self._x = None
@property
def x(self):
return self._x
@x.setter
class F(object):
pass
place_data_items = {}
place_data_items["state"] = [F(), F(), F()]
for pt, items in place_data_items.iteritems():
if pt == 'state':
for i in items:
print "update loop: %s" % i
import urllib2
import html5lib
import cssselect
url = "http://ahr13.mapyourshow.com/5_0/exhibitor_results.cfm?alpha=%40&type=alpha&page=1"
html = urllib2.urlopen(url).read()
root = html5lib.parse(html, treebuilder="lxml", namespaceHTMLElements=False)
xpath = cssselect.HTMLTranslator().css_to_xpath(".mys-elastic.mys-left a")
for element in root.xpath(xpath):
print element.get("href")
@cesarkawakami
cesarkawakami / x.py
Last active December 10, 2015 14:38
with open("log.txt", "r") as f:
for line in f:
if re.match(r"^\d{2}-\w{3}", line):
date = line[:6]
continue
if date == "02-Jan":
if re.search("Error", line):
# something's wrong, better to call my creator!
"""Backport of importlib.import_module from 3.x."""
# While not critical (and in no way guaranteed!), it would be nice to keep this
# code compatible with Python 2.3.
import sys
def _resolve_name(name, package, level):
"""Return the absolute name of the module to be imported."""
if not hasattr(package, 'rindex'):
raise ValueError("'package' not set to a string")
dot = len(package)
class Number(object):
def __init__(self, value):
self.value = value
def __add__(self, other):
return Average(self.value, 1) + other
def __radd__(self, other):
return Average(self.value, 1) + other
while True:
v = input()
if v.lower() == "none":
v = None
break
try:
v = int(v)
except ValueError: