Skip to content

Instantly share code, notes, and snippets.

View benjamintanweihao's full-sized avatar

Benjamin Tan Wei Hao benjamintanweihao

View GitHub Profile
require "active_record"
puts "AR Version: #{ActiveRecord::VERSION::MAJOR}"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Schema.define do
create_table :languages do |t|
t.string :type
end
class Order
def initialize
@line_items = []
end
def add_line_item(line_item)
@line_items << line_item
end
def total
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RedirectMatch ^/$ http://www.longurl.com
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9A-Za-z]+)/?$ /yourls-go.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+/?$ /yourls-infos.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+all/?$ /yourls-infos.php?id=$1&amp;all=1 [L]
@benjamintanweihao
benjamintanweihao / search.java
Created December 2, 2013 08:53
For Low Wee ... prolly delete when i"m done
@Override
@TargetApi(11)
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.fragment_cheng_yu_list, menu);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
MenuItem searchItem = menu.findItem(R.id.menu_item_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
@benjamintanweihao
benjamintanweihao / forlowee.java
Created December 3, 2013 16:10
I gist for Low Wee.
package com.benjamintanweihao.bookeesg.product;
import com.benjamintanweihao.bookeesg.R;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
package com.benjamintanweihao.bookeesg.product;
import com.benjamintanweihao.bookeesg.R;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
# Video: http://rubyhoedown2008.confreaks.com/08-chris-wanstrath-keynote.html
Hi everyone, I'm Chris Wanstrath.
When Jeremy asked me to come talk, I said yes. Hell yes. Immediately. But
then I took a few moments and thought, Wait, why? Why me? What am I supposed
to say that's interesting? Something about Ruby, perhaps. Maybe the
future of it. The future of something, at least. That sounds
keynote-y.
defmodule Crypto do
def md5(s) do
list_to_binary(Enum.map(bitstring_to_list(:crypto.md5(s)), fn(x) -> integer_to_binary(x, 16) end))
end
end
# brew install mahout
# export MAHOUT_DIR="/usr/local/Cellar/mahout/0.8/"
puts "#{ENV['MAHOUT_DIR']}libexec/*.jar"
Dir.glob("#{ENV['MAHOUT_DIR']}/libexec/*.jar").each { |d| require d }
MahoutFile = org.apache.mahout.cf.taste.impl.model.file
model = MahoutFile.FileDataModel.new(java.io.File.new("data.csv"))
MahoutSimilarity = org.apache.mahout.cf.taste.impl.similarity
similarity = MahoutSimilarity.TanimotoCoefficientSimilarity.new(model)
MahoutFile = org.apache.mahout.cf.taste.impl.model.file
model = MahoutFile.FileDataModel.new(java.io.File.new("data.csv"))
MahoutSimilarity = org.apache.mahout.cf.taste.impl.similarity
# similarity = MahoutSimilarity.TanimotoCoefficientSimilarity.new(model)
similarity = MahoutSimilarity.LogLikelihoodSimilarity.new(model)
MahoutNeighborhood = org.apache.mahout.cf.taste.impl.neighborhood
neighborhood = MahoutNeighborhood.NearestNUserNeighborhood.new(2, similarity, model)