Skip to content

Instantly share code, notes, and snippets.

@jboner
jboner / latency.txt
Last active May 3, 2024 15:17
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
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 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@sadache
sadache / gist:2939230
Created June 15, 2012 23:37
Parsing progressively a csv like file with Play2 and Iteratees

If your csv doesn't contain escaped newlines then it is pretty easy to do a progressive parsing without putting the whole file into memory. The iteratee library comes with a method search inside play.api.libs.iteratee.Parsing :

def search (needle: Array[Byte]): Enumeratee[Array[Byte], MatchInfo[Array[Byte]]]

which will partition your stream into Matched[Array[Byte]] and Unmatched[Array[Byte]]

Then you can combine a first iteratee that takes a header and another that will fold into the umatched results. This should look like the following code:

// break at each match and concat unmatches and drop the last received element (the match)
@mbbx6spp
mbbx6spp / GITHUB-COMPARE-LINKS.md
Created June 21, 2012 03:37
This Gist is worth a million beers. So buy me one (or send me a really cool t-shirt, make sure it is REALLY cool though)! :)
@sadache
sadache / gist:3026886
Created July 1, 2012 05:01
Bits'bout Play2 Architecture

Bits'bout Play2 Architecture

Play2 Simple HTTP API

Essential blueprint of Play2 architecture is pretty simple and it should be easy to explain in a fairly short blog post. The framework can be understood progressively at different levels; each time having better exposure to some aspects of its design.

The core of Play2 is really small, surrounded by a fair amount of useful APIs, services and structure to make Web Programming tasks easier.

Basically, Play2 is an API that abstractly have the folllowing type

@sadache
sadache / AA.md
Created July 8, 2012 21:29
Is socket.push(bytes) all you need to program Realtime Web apps?

Is socket.push(bytes) all you need to program Realtime Web apps?

One of the goals of Play2 architecture is to provide a programming model for what is called Realtime Web Applications.

Realtime Web Applications

Realtime Web Applications are applications that make use of Websockets, Server Sent Events, Comet or other protocols offering/simulating an open socket between the browser and the server for continuous communication. Basically, these applications let users work with information as it is published - without having to periodically ping the service.

There are quite a few web frameworks that target the development of this type of application: but usually the solution is to simply provide an API that allows developers to push/receive messages from/to an open channel, something like:

@samklr
samklr / MixedTweets.md
Created August 5, 2012 18:57 — forked from loicdescotte/MixedTweets.md
How to push 2 mixed searches from twitter with Scala, Play2, Iteratee and Comet

##MixedTweets

We will see how to mix 2 twitter searches and push the results to the browser in real time.

First, checkout this mini project

To try it, you need to install Play 2.0

###Controller

@turbofart
turbofart / tsp.py
Created August 22, 2012 20:06
Applying a genetic algorithm to the travelling salesman problem
#!/usr/bin/env python
"""
This Python code is based on Java code by Lee Jacobson found in an article
entitled "Applying a genetic algorithm to the travelling salesman problem"
that can be found at: http://goo.gl/cJEY1
"""
import math
import random
@KWMalik
KWMalik / interviewitems.MD
Created September 16, 2012 22:04 — forked from amaxwell01/interviewitems.MD
My answers to over 100 Google interview questions

##Google Interview Questions: Product Marketing Manager

  • Why do you want to join Google? -- Because I want to create tools for others to learn, for free. I didn't have a lot of money when growing up so I didn't get access to the same books, computers and resources that others had which caused money, I want to help ensure that others can learn on the same playing field regardless of their families wealth status or location.
  • What do you know about Google’s product and technology? -- A lot actually, I am a beta tester for numerous products, I use most of the Google tools such as: Search, Gmaill, Drive, Reader, Calendar, G+, YouTube, Web Master Tools, Keyword tools, Analytics etc.
  • If you are Product Manager for Google’s Adwords, how do you plan to market this?
  • What would you say during an AdWords or AdSense product seminar?
  • Who are Google’s competitors, and how does Google compete with them? -- Google competes on numerous fields: --- Search: Baidu, Bing, Duck Duck Go
@MansurAshraf
MansurAshraf / product_recommendations.csv
Created March 31, 2013 00:31
Product Recommendations
Bandolino Shoes Rampage Shoes 0.6702
Bandolino Shoes Marc Fisher Shoes 0.73206
Bandolino Shoes Nine West Shoes 0.81128
Cable & Gauge Top INC International Concepts Top 0.65449
Cable & Gauge Top Karen Scott Top 0.68115
Cable & Gauge Top Style&co. Top 0.9547
INC International Concepts Jeans MICHAEL Michael Kors Jeans 0.69658
INC International Concepts Jeans Tommy Hilfiger Jeans 0.75921
INC International Concepts Jeans Levi's 512 0.80887
INC International Concepts Top Karen Scott Top 0.47929