Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <time.h>
typedef unsigned int uint32;
typedef long long int64;
template<typename F, typename V>
V collision_point(const F& f, V x) {
V slow = x;
V fast = f(x);
// setup
int status = 0;
do {
// preconditions
status = doSomething();
if (status) break;
status = doSomethingElse();
if (status) break;
@mikea
mikea / gist:563022
Created September 2, 2010 21:55
appengine: upload data to blob programmatically
PAYLOAD_TEMPLATE = \
"""--==boundary\r
Content-Disposition: form-data; name="file"; filename="%s"\r
Content-Type: %s\r
\r
%s\r
--==boundary--\r
"""
destination_url = blobstore.create_upload_url('/upload-sink')
@mikea
mikea / latency.txt
Created May 31, 2012 15:23 — 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 4x mutex op, 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
@mikea
mikea / latency.txt
Created May 31, 2012 15:27 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns 3 µs
Send 2K bytes over 1 Gbps network 20,000 ns 20 µs
Read 1 MB sequentially from memory 250,000 ns 250 µs
Round trip within same datacenter 500,000 ns 0.5 ms
Disk seek 10,000,000 ns 10 ms
; Function Attrs: nounwind readonly uwtable
define double @_Z10DotProductRK6VectorS1_(%class.Vector* nocapture %v1, %class.Vector* nocapture %v2) #0 {
entry:
%size_.i = getelementptr inbounds %class.Vector* %v1, i64 0, i32 0
%0 = load i64* %size_.i, align 8, !tbaa !0
%data_.i = getelementptr inbounds %class.Vector* %v1, i64 0, i32 1
%1 = load double** %data_.i, align 8, !tbaa !3
%size_.i8 = getelementptr inbounds %class.Vector* %v2, i64 0, i32 0
%2 = load i64* %size_.i8, align 8, !tbaa !0
%data_.i9 = getelementptr inbounds %class.Vector* %v2, i64 0, i32 1
@mikea
mikea / gist:7259269
Last active December 27, 2015 03:29
I want C[T] to have different method sets based on T. I thought I could use implicits, but can't make it work. Any idea how to fix this example?
class Printer[T](_t: T) {
def t = _t
def print():Unit = { println(t) }
}
class IterablePrinter[T, I <: Iterable[T]](p : Printer[I]) {
def printEach() = p.t.foreach(println)
}
object Test extends App {
@mikea
mikea / HeadTest.java
Created May 14, 2014 18:23
Attempt to implement headAndTail function. Using publish().refCount() to avoid double reading a file. Doesn't work at all.
public class HeadTest {
public static void main(String[] args) {
Observable<Integer> fileReader = Observable.create((Observable.OnSubscribe<Integer>) subscriber -> {
System.out.println("Reading from a file");
subscriber.onNext(100); // header
for (int i = 0; i < 10; ++i) {
subscriber.onNext(i);
}
@mikea
mikea / HeadTest.java
Created May 14, 2014 18:24
Attempt to implement headAndTail function. Results in double reading a file.
public class HeadTest {
public static void main(String[] args) {
Observable<Integer> fileReader = Observable.create((Observable.OnSubscribe<Integer>) subscriber -> {
System.out.println("Reading from a file");
subscriber.onNext(100); // header
for (int i = 0; i < 10; ++i) {
subscriber.onNext(i);
}
@mikea
mikea / gist:4c053e72a60d6f187cb6
Created June 12, 2014 18:52
Put cursor on ints in Arrays.asList expression and invoke Analyze Dataflow To Here
public class Test {
private static void foo(String value, int...ints) {
System.out.println(value + " " + Arrays.asList(ints));
}
private static void bar(String value, int...ints) {
foo(value, ints);
}
private static void baz(String value) {