Skip to content

Instantly share code, notes, and snippets.

View hatahet's full-sized avatar

Ziad Hatahet hatahet

  • Uber
  • New York, NY
View GitHub Profile
@hatahet
hatahet / remi.rs
Created June 16, 2013 03:50 — forked from bstrie/remi.rs
struct Vec { x: float, y: float }
trait VecRhs {
fn add_to_Vec(&self, lhs: &Vec) -> Vec;
}
impl<R: VecRhs> Add<R, Vec> for Vec {
fn add(&self, rhs: &R) -> Vec {
rhs.add_to_Vec(self)
}
extern mod extra;
use extra::json::*;
/*
* This function manages to do absolutely no copying, which is pretty cool.
*
* "What are all those `'r`s?" you ask. Well, they're liftime parameters. They
* indicate how long something lasts (before it's freed). They can't change how
* long something lives for, they only allow you to tell the compiler stuff it
import requests
from dateiterator import daterange
from BeautifulSoup import BeautifulSoup
def dataOf(date):
stockdata = []
postdata = {'Date':date}
r = requests.post("http://www.nepalstock.com/datanepse/previous.php",data=postdata)
content = r.text
soup = BeautifulSoup(content)
@hatahet
hatahet / palin.py
Created April 21, 2013 21:26 — forked from macobo/palin.py
from bisect import bisect_left
from sys import stdin
def is_palin(n):
s = str(n)
return s == s[::-1]
def fair(n):
return is_palin(n) and is_palin(n**2)
@hatahet
hatahet / go.scala
Created November 8, 2012 10:27 — forked from joa/go.scala
Go Channels in Scala
package go
import java.util.concurrent.{
BlockingQueue => JBlockingQueue,
ArrayBlockingQueue => JArrayBlockingQueue
}
object Channel {
def empty[A]: Channel[A] = new BlockingChannel()
def make[A]: Channel[A] = make(1)
@hatahet
hatahet / sudoku_solver.cpp
Created August 15, 2012 12:02 — forked from keveman/sudoku_solver.cpp
Sudoku solver in C++11
#include <iterator>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <cassert>
#include <memory>
#include <future>
#include <chrono>
@hatahet
hatahet / rust-poly.md
Created August 10, 2012 06:37 — forked from megakorre/rust-poly.md
rust pollymorpism

EDIT! full code can be found here gist

So I played around with rust a bit now. And I thought I might share some random stuff.

So say you wanted to represent a expression tree with plus and minus nodes and a node for values. One way to do this would be to use rust's enum's.

In rust enums are like haskell's union types so you can specify the different values to be constructors carrying data.

@hatahet
hatahet / gist:3214490
Created July 31, 2012 07:23 — forked from erickt/gist:3132223
pure unique lists
enum list<T> {
cons(T, ~list<T>),
nil,
}
fn iter<T>(xs: list<T>, f: fn(T)) {
alt xs {
cons(x, xs) {
f(x);
iter::<T>(*xs, f)
@hatahet
hatahet / wulf.md
Created June 20, 2012 03:52
Bill Wulf's Resignation Letter

Comp. Sci. Prof. William Wulf’s resignation letter

BY on June 19, 2012

Below is a resignation letter submitted [to the Cavalier Daily] this morning by Computer Science Prof. William Wulf:

Dean and Interim President Zeithaml,

By this email I am submitting my resignation, effective immediately. I do not wish to be associated with an institution being as badly run as the current UVa. A BOV that so poorly understands UVa, and academic culture more generally, is going to make a lot more dumb decisions, so the University is headed for disaster, and I don’t want to be any part of that. And, frankly, I think you should be ashamed to be party to this debacle!

@hatahet
hatahet / latency.txt
Created June 3, 2012 06:01 — forked from jboner/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD 150,000 ns 0.15 ms
Read 1 MB sequentially from memory 250,000 ns 0.25 ms
Round trip within same datacenter 500,000 ns 0.5 ms