Skip to content

Instantly share code, notes, and snippets.

View iwan's full-sized avatar

Iwan Buetti iwan

  • Milano, Italy
View GitHub Profile
@iwan
iwan / mongoid_without_rails.rb
Created October 11, 2013 08:00
How to use Mongodb with Mongoid gem in Ruby
# file: mongoid.yml
default:
sessions:
production:
database: foobar
hosts:
- localhost:27017
# file: mongoid.rb
@iwan
iwan / query_biomart
Created October 17, 2013 15:50
Biomart: manually send a query
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 December 27, 2015 00:09
Get multiple checkboxes in a index view

Routes file (routes.rb):

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

The controller:

@iwan
iwan / net_http.rb
Last active December 29, 2015 14:46 — forked from a-chernykh/net_http.rb
require 'net/http'
def download_net_http(uris, thread_count)
queue = Queue.new
uris.map { |uri| queue << uri }
threads = thread_count.times.map do
Thread.new do
while !queue.empty? && uri = queue.pop
@iwan
iwan / _locale_navbar_item.html.haml
Last active March 1, 2016 14:50
Add internationalization to a Rails project
%li.dropdown
%a.dropdown-toggle{"data-toggle" => "dropdown", :href => "#"}
= t(".#{I18n.locale}")
%b.caret
%ul.dropdown-menu
- (I18n.available_locales.map(&:to_s)-[I18n.locale.to_s]).each do |loc|
%li= link_to t(".#{loc}"), locale: loc
class Fixnum
def autoref?
a = to_s.rjust(10, "0").split("").map(&:to_i) # a = [2,3,1,1,3,4,5,5,1,9]
h = Hash[(0..9).map{|e| [e, 0]}]
a.each{|e| h[e]+=1}
a.each_with_index do |n, i|
return false if n!=h[i]
end
true
end
@iwan
iwan / README.md
Last active March 31, 2016 15:18
Drawing histogram based on table row values

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:

@iwan
iwan / tar_gz_squeeze.rb
Last active April 6, 2016 07:40
Compress all *.json files of a directory using tar and gzip
require 'rubygems/package'
def tar_gz_squeeze(dirname, filename: nil)
filename = filename || dirname
File.open("#{filename}.tar.gz", "wb") do |file|
Zlib::GzipWriter.wrap(file) do |gz|
Gem::Package::TarWriter.new(gz) do |tar|
Dir.glob("#{dirname}/*.json").each do |f|
puts "adding #{File.basename(f)}..."
@iwan
iwan / 1.yml
Created February 17, 2017 12:40 — forked from ndelitski/1.yml
drone.yml examples
clone:
path: github.com/gogits/gogs
build:
image: golang:$$GO_VERSION
environment:
- TAGS="pam sqlite"
- BUILD_OS="windows linux darwin freebsd openbsd netbsd"
@iwan
iwan / new.html
Created February 22, 2017 21:41 — forked from mediasota/new.html
Refactor Rails application layout to use HTML5 semantics with HAML
<!DOCTYPE html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset='utf-8'>