Skip to content

Instantly share code, notes, and snippets.

@huydx
huydx / recommender.rb
Created May 10, 2013 14:45
recommender
# -*- coding: utf-8 -*-
$:.unshift File.dirname(__FILE__)
require 'yaml'
require 'bundler'
require 'rgl/adjacency'
require 'rgl/bidirectional'
#load all necessary environment related things
def loadenv
config = YAML.load_file('config.yml')
@huydx
huydx / benchmark.rb
Created May 11, 2013 14:17
mongo benchmark
%self total self wait child calls name
3.65 0.405 0.254 0.000 0.151 3001 Mongo::Cursor#initialize
3.53 0.791 0.246 0.000 0.545 12001 *Mutex#synchronize
3.51 0.904 0.245 0.000 0.660 3000 Mongo::Collection#find
3.44 0.240 0.240 0.000 0.000 8116 <Class::IO>#select
2.95 0.775 0.205 0.000 0.570 3001 Mongo::Collection#initialize
2.52 0.226 0.175 0.000 0.051 9003 BSON::ByteBuffer#put_binary
2.05 0.546 0.143 0.000 0.403 3001 Mongo::Networking#read_documents
1.82 0.466 0.126 0.000 0.340 8116 Mongo::TCPSocket#read
1.77 1.552 0.123 0.000 1.429 16075 *Class#new
@huydx
huydx / stack.js
Created May 11, 2013 17:14
stack function
function foo(i) {
if (i < 0)
return;
document.writeln('begin:' + i);
foo(i - 1);
document.writeln('end:' + i);
}
foo(3);
@huydx
huydx / hamlconvert.sh
Created May 29, 2013 13:27
haml conversion
for i in `find app/views/devise/ -name '*.erb'` ; do html2haml -e $i ${i%erb}haml ; rm $i ; done
@huydx
huydx / file0.txt
Created June 5, 2013 06:59
Rubyで間違いやすい配列の範囲指定 ref: http://qiita.com/items/7f9737a191bb92cca81d
arr = [1,2,3,4,5,6]
arr[1..2]
arr[1,2]
@huydx
huydx / guneffect.js
Created June 7, 2013 12:49
guneffect.js
function BufferLoader(context, urlList, callback) {
this.context = context;
this.urlList = urlList;
this.onload = callback;
this.bufferList = new Array();
this.loadCount = 0;
}
BufferLoader.prototype.loadBuffer = function(url, index) {
// Load buffer asynchronously
@huydx
huydx / init.rb
Created June 13, 2013 14:31
init.rb
def initialize(options={})
options.each do |key, value|
key = key.to_s
FriendRecommenderDB.class_eval do
attr_accessor key
end
send("#{key}=", value)
end
end
@huydx
huydx / get_linefunc.py
Created June 23, 2013 06:20
get_linefunc.py
def get_linefunc(self, start_p, end_p): #just for 2nd euclidian space
x1, y1 = start_p[0], start_p[1]
x2, y2 = end_p[0], end_p[1]
a = 0 if ((x2-x1) == 0) else (y2-y1)/(x2-x1)
b = -1
c = x1*a - y1
return {'a':a, 'b':b, 'c':c}
source 'https://rubygems.org'
gem 'active_model_serializers', git: 'git://github.com/rails-api/active_model_serializers.git'
gem 'ember-rails', git: 'git://github.com/emberjs/ember-rails.git' # so we get the pre version
gem 'rack-mini-profiler', git: 'git://github.com/SamSaffron/MiniProfiler'
gem 'vestal_versions', git: 'git://github.com/zhangyuan/vestal_versions'
gem 'message_bus', path: 'vendor/gems/message_bus'
gem 'rails_multisite', path: 'vendor/gems/rails_multisite'
gem 'simple_handlebars_rails', path: 'vendor/gems/simple_handlebars_rails'
@huydx
huydx / file0.txt
Created July 9, 2013 14:40
rubyでランダム文字列を生成 ref: http://qiita.com/huydx@github/items/1834326738c1e96393aa
rand(36**length).to_s(36)