Skip to content

Instantly share code, notes, and snippets.

View luikore's full-sized avatar

luikore luikore

View GitHub Profile
@luikore
luikore / hat-cache-miss.md
Last active May 5, 2016 15:22
Comparing cache-miss of triez, fast_trie and hash reads

To test out the cache miss behavior of read operations, run a program building the index (30k entries) then another program building then reading the index (30k queries), and find their diff.

Here's how to generate the test script cmd.sh

3.times do |i|
  %w[triez hash da].each do |ty|
    puts "valgrind --tool=cachegrind --cachegrind-out-file=tmp/#{ty} ruby t.rb #{ty}"
    puts "valgrind --tool=cachegrind --cachegrind-out-file=tmp/#{ty}.read ruby t.rb #{ty} read"
    puts "cg_diff tmp/#{ty} tmp/#{ty}.read > tmp/#{ty}#{i}.diff"
@luikore
luikore / test_marshal_json.rb
Last active December 12, 2015 04:59
marshal is faster and smaller than json
require "json"
require "benchmark"
h = {}
1000.times{|i|h[i]=0}
print "marshaled size: "
marshaled = Marshal.dump(h)
puts marshaled.bytesize
@luikore
luikore / debug_patch.rb
Created April 20, 2012 03:36
Monkey patch debug.rb to make source listing command work
class DEBUGGER__
def Context
def display_list(b, e, file, line)
stdout.printf "[%d, %d] in %s\n", b, e, file
lines = SCRIPT_LINES__[file]
if !lines
lines = File.readlines file rescue nil
end
if lines and lines != true
b.upto(e) do |n|
@luikore
luikore / y.rb
Created April 4, 2012 09:58
y combinator in ruby
# this is a bit shorter than the one I made several years ago
def Y f
g = -> h, *x { f[h[h], *x] }.curry 2
g[g]
end
factorial = Y -> f, n { n == 0 ? 1 : f[n - 1] * n }
puts factorial.(6)
@luikore
luikore / gist:1663128
Created January 23, 2012 13:29
Textmate command to search api (input = selected or current word)
#! /usr/bin/env ruby
word = gets.strip.gsub "'", ''
mods =
case ENV['TM_FILENAME'][/\w+$/]
when 'js', 'coffee'
%w[module_gecko.js module_jquery.js]
when 'rb'
%w[module_rubyrails.js rubystdlib.js]
@luikore
luikore / tampermonkey enable wiki.js
Created January 18, 2012 06:25
in Chi-na we suffer from no-wiki every day
// ==UserScript==
// @name wiki
// @namespace wiki
// @version 0.1
// @description only for today
// @include http://en.wikipedia.org/*
// @copyright 2011+, You
// ==/UserScript==
runOnce = function(){
@luikore
luikore / clean_url.user.js
Created January 18, 2012 05:06
Stop google tracking search click with redirect
// ==UserScript==
// @match https://www.google.com/*
// ==/UserScript==
interval = 400
clean = function(){
console.log('cleaning')
var links = document.querySelectorAll('#search h3 a')
var i
for(i=0; i<links.length; i++){
@luikore
luikore / gc.hpp
Created September 24, 2011 15:52
Incremental tri-color GC
#pragma once
#include <stdlib.h>
#include <stdint.h>
#include <stack>
#include "obj.hpp"
using namespace std;
class GC {
Obj head;
@luikore
luikore / tex.js
Created June 9, 2011 04:40
bookmarklet for latex formula wrapped with [;...;], \[...\], $$...$$, $...$
javascript:(function(){
var R = /\[;.+?;\]|\\\[.+?\\\]|\$\$.+?\$\$|\$.+?\$|./g;
/* var R = /\[;.+?;\]|\\\[.+?\\\]|\$\$.+?\$\$|./g; */
var spanClick = function(){
this.nextElementSibling.style.display = 'inline';
this.style.display = 'none'
};
var imgClick = function() {
@luikore
luikore / hoptoad-link.js
Created April 19, 2011 07:05
This bookmarklet makes all hoptoad trace openable by textmate. Change prj and gem for different projects.