Skip to content

Instantly share code, notes, and snippets.

View tebeka's full-sized avatar
💭
alive

Miki Tebeka tebeka

💭
alive
View GitHub Profile
Churchill: Madam, would you sleep with me for five million pounds?
Woman: My goodness, Mr. Churchill… Well, I suppose… we would have to discuss terms, of course…
Churchill: Would you sleep with me for five pounds?
Woman: Mr. Churchill, what kind of woman do you think I am?!
Churchill: Madam, we’ve already established that. Now we are haggling about the price.
@Test(groups = { "functest" })
public class AppTest {
/**
* Rigourous Test :-)
*/
@Test(expectedExceptions = { IllegalArgumentException.class })
public void testApp() {
Assert.assertTrue(true);
import java.util.Map;
import java.util.HashMap;
public class Make {
private Make() {};
@SuppressWarnings(value = "unchecked")
public static <K, V> Map<K, V> map(Object... items) {
if ((items.length % 2) != 0) {
throw new IllegalArgumentException(
@tebeka
tebeka / gist:815967
Created February 8, 2011 06:06
Reading CSV
(ns csv
(import com.csvreader.CsvReader))
(defn csv-seq
"Return a lazy sequence of records (vectors) from CSV file"
[filename]
(let [csv (CsvReader. filename)
read-record (fn []
(when (.readRecord csv)
(into [] (.getValues csv))))]
@tebeka
tebeka / dbcopy.py
Created March 24, 2011 22:50
Database copy
'''Example on how to copy data from one database to the other'''
import sqlite3
SCHEMA_SQL = "CREATE TABLE people (name TEXT, id INT)"
INSERT_SQL = "INSERT INTO people VALUES (?, ?)"
GET_SQL = "SELECT * FROM people"
COUNT = 100
def setup_dbs():
"Setup source and destination databases, create schema and populate source"
@tebeka
tebeka / gist:967968
Created May 12, 2011 05:14
Counting records in Avro file
#include <stdio.h>
#include <avro.h>
#include <stdlib.h>
int
main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "usage: reader FILENAME\n");
exit(1);
}
@tebeka
tebeka / gist:1001299
Created May 31, 2011 21:12
Get exchange rate for two currencies
#!/usr/bin/env python
# Print exchange rate
import yql
QUERY = 'SELECT * FROM yahoo.finance.xchange WHERE pair in ("%s%s")'
ENV = "store://datatables.org/alltableswithkeys"
def main(argv=None):
import sys
name: Daffy Duck
age: 80
frenemies: ["Bugs Bunny", "Taz"]
# Find the greatest product of five consecutive digits in the 1000-digit number.
from operator import mul
n = '''
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
import sqlite3
UPDATE_SQL = '''
UPDATE phonebook
SET phone = ?
WHERE name = ?
'''
INSERT_SQL = '''
INSERT INTO phonebook