Skip to content

Instantly share code, notes, and snippets.

View Fonsan's full-sized avatar

Erik Fonselius Fonsan

View GitHub Profile
url = "http#{schemes.sample}://#{
#subdomains
tlds.sample(1 + rand(3)).join('.')
}.#{
#host
host
}.#{
#tlds
tlds.sample
}#{
{
"7fb0d9"=>6028200,
"366d16"=>6035040,
"57d44a"=>6020760,
"d32228"=>6019140,
"027d29"=>6043620,
"cbc570"=>6000600,
"5f0756"=>6029820,
"798c69"=>6043860,
"803566"=>6024780,
class ConcurrentHashMap < Hash; end
ConcurrentHashMap.send(:include,(Module.new do
def []=(key,value)
warn 'This method is slow'
super(key,value)
end
end))
h = ConcurrentHashMap.new
module I18n
class << self
def translate(*args)
args.inspect
end
def localize(*args)
args.inspect
end
alias_method :l, :localize
@Fonsan
Fonsan / eye.html
Created October 12, 2011 12:37
Eyetracking
<div id="sas">
<embed src="http://rich-ads.s3.amazonaws.com/a27f1e29edc38a7be523ad69b6b73258.swf" name="FlashID1x" quality="autohigh" wmode="opaque" swliveconnect="true" width="1010" height="120" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" title="Flash">
</div>
@Fonsan
Fonsan / blocks.rb
Created May 9, 2012 18:24
First class citizen methods in ruby
def do_something
yield 'something'
end
do_something do |thing|
puts thing
end
def do_complex(first, second)
thing = 'nothing'
@Fonsan
Fonsan / window.js
Created May 25, 2012 13:39
Mock window
var createWindow = function() {
var events = kafkaFactory();
var register = function(wantedObj, wantedType, callback) {
events.register(function(obj, type, event) {
if (wantedObj === obj && wantedType === type) {
callback(event);
}
});
};
var evented = function() {
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hello;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
@Fonsan
Fonsan / Sample output
Created November 30, 2012 11:40
Keepalive tester MIT license
$ sh keepalive.sh
Normal get
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 30 Nov 2012 11:38:26 GMT
Content-Type: text/plain
Content-Length: 2
Connection: keep-alive
jQuery('.song-name a').each(function() {
var e = $(this)
var frame = $('<iframe/>')
frame.attr('src', e.attr('href'));
frame.attr('height', '200px')
frame.attr('width', '500px')
e.parent().parent().after(frame);
var w = frame.first()[0].contentWindow;
w.addEventListener('load', function() {
w.scroll(0,300)