Skip to content

Instantly share code, notes, and snippets.

Iwan Buetti iwan

View GitHub Profile
@iwan
iwan / iwan.rb
Created Sep 24, 2009
Reading a csv file using FasterCSV
We couldn’t find that file to show.
@iwan
iwan / array_to_hash.rb
Last active Dec 23, 2015
Ruby. From Array to Hash
View array_to_hash.rb
# Given an array
arr = [1, 2, 3]
# I want to build an hash starting from an array
# like { 1 => 1, 2 => 4, 3 => 9} (where the values are the square of keys)
# long form:
hash = {}
arr.each do |e|
hash[e] = e**2
@iwan
iwan / mongoid_without_rails.rb
Created Oct 11, 2013
How to use Mongodb with Mongoid gem in Ruby
View mongoid_without_rails.rb
# file: mongoid.yml
default:
sessions:
production:
database: foobar
hosts:
- localhost:27017
# file: mongoid.rb
@iwan
iwan / query_biomart
Created Oct 17, 2013
Biomart: manually send a query
View query_biomart
Write the file q1.txt:
query=
<!DOCTYPE Query>
<Query client="true" processor="TSV" limit="100" header="1">
<Dataset name="hsapiens_snp" config="snp_1_config">
<Filter name="chr_name" value="22"/>
<Filter name="chrom_start" value="1"/>
<Filter name="chrom_end" value="80000000"/>
<Attribute name="refsnp_id"/>
@iwan
iwan / multiple_action_on_index.md
Last active Dec 27, 2015
Get multiple checkboxes in a index view
View multiple_action_on_index.md

Routes file (routes.rb):

resources :data_loaders do
  collection do
    delete 'multiple_destroy'
  end
end

The controller:

@iwan
iwan / sort_with
Last active Aug 29, 2015
Sorting two arrays
View sort_with
# Given two 'linked' array, you want to sort one and reorder the second to preserve the same sequence of the first:
a = [3,2,7,5,1,9,3]
b = [:a, :b, :c, :d, :e, :f, :g]
def a.sort_with(arr)
raise "the two array must have the same size" if size!=arr.size
h = self.collect.with_index{|e,i| [e, arr[i]]}.sort{|x,y| y.first<=>x.first}
[h.map{|e| e.first}, h.map{|e| e.last}]
end
View nokogiri_libxml_homebrew_lion_installation.sh
FIXME:
WARNING: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.7.8
or
ERROR -: Incompatible library version: nokogiri.bundle requires version 11.0.0 or later, but libxml2.2.dylib provides version 10.0.0
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
View route.rb
# NOTE below gems are only for development purpose can be removed and commented out as per requirement
group :development do
gem 'rails-erd','1.0.0'
gem 'hirb','0.7.0'
gem 'railroady'
gem 'itslog','0.6.1'
gem 'quiet_assets'
gem 'sextant' # now included in Rails 4.0
end
@iwan
iwan / gist:50deff48f6d4163260b8
Last active Aug 29, 2015
Template for Rails concern file
View gist:50deff48f6d4163260b8
module Zo
extend ActiveSupport::Concern
included do
# ...
end
def an_instance_method
# ...
end
@iwan
iwan / README.md
Last active Mar 31, 2016
Drawing histogram based on table row values
View README.md

Visualize the magnitude of table row values

The goal is to visualize the magnitude of table row values using histogram bars.

Languages and libraries:

  • html + css
  • coffescript / javascript
  • d3 library

Features:

You can’t perform that action at this time.