Skip to content

Instantly share code, notes, and snippets.

Avatar

Iwan Buetti iwan

View GitHub Profile
@iwan
iwan / git.css
Last active Aug 29, 2015 — forked from neilgee/git.css
View git.css
/* Set up Git Configuration */
git config --global user.email "you@yourdomain.com"
git config --global user.name "Your Name"
git config --global core.editor "vi"
git config --global color.ui true
@iwan
iwan / alone.rb
Last active Aug 29, 2015
Convert a string numeric array to numeri array
View alone.rb
module StringToArrayConverter
NUMERIC_ARRAY_REGEX = /^\[([\d,\s\.\-\+]+)\]$/
def to_numeric_array
m = NUMERIC_ARRAY_REGEX.match(self.strip)
m[1].split(",").map{|e| e.include?(".") ? e.to_f : e.to_i}
end
def is_a_numeric_array?
!NUMERIC_ARRAY_REGEX.match(self.strip).nil?
@iwan
iwan / rspec_w_and_wo_cleaning.md
Last active Aug 29, 2015
Spec results with and without database cleaning
View rspec_w_and_wo_cleaning.md

Spec

require 'rails_helper'

describe "Foo", type: :model do
  it "ex3" do
    puts "--ex3--"
    puts "rep: #{@rep.inspect}"
    puts "Report count: #{Report.count}"
@iwan
iwan / activities.js.coffee
Last active Sep 18, 2015
Re-sort table rows using buttons/links and jquery on Ruby on Rails
View activities.js.coffee
$(document).ready ->
$("a.sortable").on "click", (e) ->
e.preventDefault()
id = $(this).data('id')
dir = $(this).data('direction') # "up" or "down"
sel = $("#item_#{id}") # selector of current
$.ajax
url: "/activities/#{id}/move"
View 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 / devise_invitable.it.yml
Last active Mar 20, 2018
Italian translation for for DeviseInvitable
View devise_invitable.it.yml
it:
devise:
failure:
invited: "Hai un invito in sospeso, accettalo per completare la creazione del tuo account."
invitations:
send_instructions: "Un'email di invito è stata inoltrata a %{email}."
invitation_token_invalid: "Il token di invito fornito non è valido!"
updated: "La tua password è stata impostata correttamente. Ora sei connesso."
updated_not_active: "La tua password è stata impostata correttamente."
no_invitations_remaining: "Non sono più disponibili inviti."
@iwan
iwan / _locale_navbar_item.html.haml
Last active Mar 1, 2016
Add internationalization to a Rails project
View _locale_navbar_item.html.haml
%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
View brute_force_solution.rb
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 / tar_gz_squeeze.rb
Last active Apr 6, 2016
Compress all *.json files of a directory using tar and gzip
View tar_gz_squeeze.rb
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 / devise.it.yml
Last active Mar 20, 2018 — forked from epistrephein/devise.it.yml
Italian translation for Devise 3.5
View devise.it.yml
# Italian translation for Devise 4.2
# Date: 2016-08-01
# Author: epistrephein, iwan
# Note: Thanks to xpepper (https://gist.github.com/xpepper/8052632)
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
it:
devise:
confirmations:
confirmed: "Il tuo account è stato correttamente confermato."
You can’t perform that action at this time.