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 / move_files_with_date.rb
Created August 3, 2017 09:15
Ruby script used to move and reorder pdf files with a date in name
require 'fileutils'
require 'byebug'
# What it do
# ============
# It parse the 'dir' directory searching for
# pdf files with name matching the "xxx yyy - 2017-04-16"
# pattern and move them into a date named folder
# (like '2017-04-16')
@iwan
iwan / check_internet_is_reachable.sh
Last active November 13, 2017 15:50
Bash script to check if Internet is reachable (infinity loop)
#!/bin/bash
echo "Started at $(date)"
while true
do
nc -z 8.8.8.8 53 >/dev/null 2>&1
online=$?
if [ $online -eq 0 ]; then
echo "Online"
else
@iwan
iwan / mergia.rb
Created January 26, 2018 15:16
Script to merge multiple similar .xls file into one
require 'spreadsheet' # https://github.com/zdavatz/spreadsheet/blob/master/GUIDE.md
require 'fileutils'
require 'date'
base_path = File.join(Dir.home, "Downloads", "Esito_aste_STOGIT")
input_xls_path = File.join(base_path, "input")
output_xls_path = File.join(base_path, "merged")
class AuctionFile
attr_reader :filepath, :filename, :book
@iwan
iwan / devise_invitable.it.yml
Last active March 20, 2018 20:29
Italian translation for for DeviseInvitable
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 / devise.it.yml
Last active March 20, 2018 20:30 — forked from epistrephein/devise.it.yml
Italian translation for Devise 3.5
# 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."
@iwan
iwan / elixir_phoenix_notes.md
Created April 4, 2018 12:33 — forked from hmans/elixir_phoenix_notes.md
Notes on learning Elixir and Phoenix

Notes on learning Elixir and Phoenix

Just some assorted notes I've made while digging into Phoenix, Elixir and friends. I'm coming from a strong Rails background, so many of these will refer to features from that framework.

Views / Templates

Biggest difference from Rails?

Unlike Rails, where rendering is almost always performed by a template file, the responsibility of rendering a response in Phoenix lies with a view module (that typically corresponds to the current controller module.) This view module will typically offer a whole bunch of render functions (matching different parameters, first and foremost the template name.) Templates (found in web/templates/) will directly compile into such functions.

@iwan
iwan / rand_string_generator.rb
Created May 23, 2018 15:21
Random string generator
def random_string(length=16)
source = ("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a
Array.new(length){|e| source[rand(source.size)]}.join
end
module ExcelColumnsConverions
# convert the column name ("A", "ACB", ...) to an number (1-based)
def excel_col_number(str)
offset = 'A'.ord - 1
str.chars.inject(0){ |x,c| x*26 + c.ord - offset }.to_i
end
# convert the column number to a string ("A", "ACB", ...)
def excel_col_string(number)
@iwan
iwan / prime.ex
Created July 9, 2018 10:25
Primality test in Elixir - a simple method
defmodule Prime do
# https://en.wikipedia.org/wiki/Primality_test#Simple_methods
def is_prime(0) do
false
end
def is_prime(1) do
false
end
@iwan
iwan / cinque_province.geojson
Last active February 18, 2019 11:57
Cinque province italiane (con id)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.