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 / 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'>
@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 / 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 / province.geojson
Last active February 18, 2019 13:18 — forked from davidejmancino/province.geojson
Confini amministrativi delle province italiane
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.