Skip to content

Instantly share code, notes, and snippets.

FastVector attributes = new FastVector();
attributes.addElement(numericAttribute);
attributes.addElement(nominalAttribute);
attributes.addElement(stringAttribute);
attributes.addElement(anyOtherAttribute);
attributes.addElement(anotherAttribute);
Instances dataSet = new Instances("dataSetName", attributes, 50);
dataSet.setClassIndex(dataSet.numAttributes() - 1);
@happyrobots
happyrobots / upload.rb
Created February 19, 2011 23:55
quick and dirty file upload
def upload(to_be_uploaded, upload_directory)
uuid = UUIDTools::UUID.random_create
uniq_name = "#{uuid}#{to_be_uploaded.original_filename}"
uploaded_file = File.join(upload_directory, uniq_name)
File.open(uploaded_file, "w") { |f| f.write(to_be_uploaded.read) }
uploaded_file
end
# https://github.com/arsduo/koala/wiki
# https://github.com/arsduo/koala/wiki/Test-Users
# routes.rb
match ‘/auth/failure’, :to => ‘profiles#failure’
# profiles_controller.rb
class ProfilesController < ApplicationController
def failure
redirect_to login_url, :flash => {:alert => "Could not log you in. #{params[:message]}"}
@happyrobots
happyrobots / install-linalg.txt
Created March 10, 2011 12:42
Installing Linalg on Fedora 14
1. Download or clone from https://github.com/quix/linalg
( Assume installation folder is linalg )
2. Install dependencies (Lapack, BLAS and legacy Fortran library header)
$ su
# yum install lapack lapack-devel blas blas-devel gcc-gfortran.i686 compat-gcc-34.i686 compat-gcc-34-g77.i686
3. Locate the Fortran header ( g2c.h )
# updatedb
# locate g2c.h
/usr/lib/gcc/i686-redhat-linux/3.4.6/include/g2c.h
Flash objects do not obey z-index. This is particularly often found on youtube vids..
To solve this, pass wmode parameter with transparent value... like this: www.youtube.com/embed/somecode?wmode=transparent
$(function() {}); seems to wait for document ready forever, if it's invoked on a popup. Well um.. or probably because the document is already 'ready', the piece of code inside that function won't be even executed.
Instead, put the thing inside that function near the end of </body> tag... please, only if it's a popup. lolplz..
class Array
# Largest range with different subsequence,
# without any kind of clever optimization.
def range_with_diff_subseq(other)
self_size = self.size
other_size = other.size
low = 0
max_pos = self_size < other_size ? self_size : other_size
@happyrobots
happyrobots / benchmark.rb
Created June 5, 2011 20:34
RSpec basic benchmark matchers
require "benchmark"
require "rspec"
module RSpec
module Benchmark
class Result
attr_accessor :slowest, :fastest, :average, :elapsed
def initialize(elapsed)
@elapsed = elapsed
@happyrobots
happyrobots / bm_map_vs_push.rb
Created July 6, 2011 14:23
Map is incredibly slow. Of course it's a little bit weird to let Ruby run 10M loop.
require 'benchmark'
MAX = 10_000_000
Benchmark.bm(3) do |b|
b.report("push") do
arr = []
MAX.times {|i| arr.push(i.to_s)}
end
class OptionFilter
def initialize(default_opts)
@default_opts = default_opts
end
def generate(param_name, label_value_pairs)
@copy = @default_opts.clone
@current_param = param_name
label_value_pairs.each { |pair| yield pair[0], opts_for(pair[1]) }
end
# rm /var/lib/pgsql/data
# service postgresql initdb
# service postgresql start
# vim /var/lib/pgsql/data/pg_hba.conf
replace ident with trust