Skip to content

Instantly share code, notes, and snippets.

View iwan's full-sized avatar

Iwan Buetti iwan

  • Milano, Italy
View GitHub Profile
@spalladino
spalladino / mysql-docker.sh
Created December 22, 2015 13:47
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@ndelitski
ndelitski / 1.yml
Created November 30, 2015 15:03
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"
@davidejmancino
davidejmancino / province.geojson
Created October 31, 2015 09:11
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.
@nepsilon
nepsilon / postgres-import-export-csv.md
Last active September 23, 2022 14:57
Importing and Exporting CSV files with PostgreSQL — First published in fullweb.io issue #19

Importing and exporting CSV files with PostgreSQL

Let’s see how to use PostgreSQL to import and export CSV files painlessly with the COPY command.

Import CSV into table t_words:

COPY t_words FROM '/path/to/file.csv' DELIMITER ',' CSV;

You can tell quote char with QUOTE and change delimiter with DELIMITER.

@masciugo
masciugo / test.rb
Last active August 29, 2015 14:26
boilerplate code for a ruby script with bundler/inline
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
@kule
kule / user_tracking.rb
Last active October 8, 2023 15:35
Simple User Tracking For Rails
# (concern) e.g. for Post model
module UserTrackable
extend ActiveSupport::Concern
included do
before_create :set_created_by
before_save :set_updated_by
belongs_to :created_by, class_name: 'User', foreign_key: 'created_by_id'
@hofmannsven
hofmannsven / README.md
Last active November 8, 2023 22:49
SCSS Cheatsheet
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@mgamini
mgamini / Elixir Email Validation
Last active March 27, 2023 17:42
Elixir Email Validation
defmodule EmailValidator do
# ensure that the email looks valid
def validate_email(email) when is_binary(email) do
case Regex.run(~r/^[\w.!#$%&’*+\-\/=?\^`{|}~]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/i, email) do
nil ->
{:error, "Invalid email"}
[email] ->
try do
Regex.run(~r/(\w+)@([\w.]+)/, email) |> validate_email
require 'net/http'
def download_net_http(urls, thread_count)
queue = Queue.new
urls.map { |url| queue << url }
threads = thread_count.times.map do
Thread.new do
Net::HTTP.start('our-s3-bucket.s3.amazonaws.com', 80) do |http|
while !queue.empty? && url = queue.pop