Skip to content

Instantly share code, notes, and snippets.

Avatar

Iwan Buetti iwan

View GitHub Profile
@iwan
iwan / cinque_province_senza_id.geojson
Created Feb 18, 2019
Cinque province italiane (senza id)
View cinque_province_senza_id.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@iwan
iwan / cinque_province.geojson
Last active Feb 18, 2019
Cinque province italiane (con id)
View cinque_province.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@iwan
iwan / province.geojson
Last active Feb 18, 2019 — forked from datajournalism-it/province.geojson
Confini amministrativi delle province italiane
View province.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@iwan
iwan / prime.ex
Created Jul 9, 2018
Primality test in Elixir - a simple method
View prime.ex
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
View excel_columns_convertions.rb
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 / rand_string_generator.rb
Created May 23, 2018
Random string generator
View rand_string_generator.rb
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
@iwan
iwan / elixir_phoenix_notes.md
Created Apr 4, 2018 — forked from hmans/elixir_phoenix_notes.md
Notes on learning Elixir and Phoenix
View elixir_phoenix_notes.md

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 / mergia.rb
Created Jan 26, 2018
Script to merge multiple similar .xls file into one
View mergia.rb
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 / check_internet_is_reachable.sh
Last active Nov 13, 2017
Bash script to check if Internet is reachable (infinity loop)
View check_internet_is_reachable.sh
#!/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 / move_files_with_date.rb
Created Aug 3, 2017
Ruby script used to move and reorder pdf files with a date in name
View move_files_with_date.rb
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')
You can’t perform that action at this time.