Skip to content

Instantly share code, notes, and snippets.

@mig-hub
mig-hub / liste_pays.rb
Created August 21, 2011 09:17
Liste de tous les Pays avec les codes
PAYS = [
{ :alpha2 => 'AF', :name => 'Afghanistan', :alpha3 => 'AFG', :numeric => '004' },
{ :alpha2 => 'AL', :name => 'Albanie', :alpha3 => 'ALB', :numeric => '008' },
{ :alpha2 => 'DZ', :name => 'Algérie', :alpha3 => 'DZA', :numeric => '012' },
{ :alpha2 => 'AS', :name => 'Samoa Américaines', :alpha3 => 'ASM', :numeric => '016' },
{ :alpha2 => 'AD', :name => 'Andorre', :alpha3 => 'AND', :numeric => '020' },
{ :alpha2 => 'AO', :name => 'Angola', :alpha3 => 'AGO', :numeric => '024' },
{ :alpha2 => 'AI', :name => 'Anguilla', :alpha3 => 'AIA', :numeric => '660' },
{ :alpha2 => 'AG', :name => 'Antigua et Barbuda', :alpha3 => 'ATG', :numeric => '028' },
{ :alpha2 => 'AR', :name => 'Argentine', :alpha3 => 'ARG', :numeric => '032' },
@mig-hub
mig-hub / chat.rb
Last active March 28, 2020 16:56 — forked from rkh/chat.rb
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@mig-hub
mig-hub / gist:f86942bf8c0dc7501a62
Last active August 29, 2015 14:08
Include module from another object
class Egg
module Boilable
def boil
temperature.rise
end
end
@mig-hub
mig-hub / interpolation.rb
Created July 7, 2015 09:01
Late interpolation in ruby
# Immediate interpolation
firstname = 'John'
lastname = 'Doe'
fullname = "#{firstname} #{lastname}"
# Late interpolation (percent instead of pound sign)
fullname_template = "%{firstname} %{lastname}"
joey = {firstname: 'Joey', lastname: 'Ramone'}
deedee = {firstname: 'Dee Dee', lastname: 'Ramone'}
fullname = fullname_template % joey
@mig-hub
mig-hub / dotenv.sh
Created July 10, 2015 08:27
Add local environment variables on any command
# This is quite common to have some local environment variables in
# a file called `.env` which is then ignored in your repository.
# This is for example a feature of `foreman`.
# Here is a small function which does this but for any command.
# Whatever the language or the command is, you just prepend
# your command with `dotenv` and it will load environment variables
# from your `.env` file.
# Comments are allowed in your `.env`.
dotenv() {
@mig-hub
mig-hub / only_options_parse.rb
Created July 10, 2015 11:01
Parse only options from the command line in Ruby
# Here is a simple trick if you have a command line which
# needs to accept options on the command line of the form:
# $ mycommand domain=github.com ssl=true
defaults = {
domain: 'www.example.com',
port: 80,
ssl: false
}
o = defaults.merge(
@mig-hub
mig-hub / webserver.rs
Created July 13, 2015 08:58
A web server example in Rust using Iron
extern crate iron;
extern crate router;
fn main() {
use iron::prelude::*;
use iron::status;
use router::Router;
let mut control = Router::new();
control
@mig-hub
mig-hub / minitest-runner.zsh
Created October 21, 2016 11:38
Simple minitest shell runner
# This is a very simple runner which assumes that all your
# tests match "test/test_*.rb" and what can be required is in "lib" and "test".
# It also assumes you use bundle.
# Run `mt api` if you want to run "test/test_api.rb".
# Just run `mt` if you want to run all tests.
mt() {
eval "bundle exec ruby -Ilib:test -e \"ARGV.reject{|f| f.match(/^-/)}.each{|f| require f.sub('test/','').sub('.rb','')}\" test/test_${1:=*}.rb --pride"
}
@mig-hub
mig-hub / usa.rb
Created February 26, 2019 12:48
Ruby module with United States of America (Name and ISO code)
module USA
extend self
def full_state_list
[
self.state_list,
self.outlying_territories,
self.armed_forces
].reduce(&:concat)
@mig-hub
mig-hub / Static_Website.mk
Last active September 27, 2024 22:49
Makefile for generating a static website
SRC_DIR = src
DST_DIR = build
CSS_DIR = $(DST_DIR)/css
SCSS_DIR = $(SRC_DIR)/scss
SCSS_INCLUDES_DIR = $(SCSS_DIR)/includes
SCSS_FILES = $(wildcard $(SCSS_DIR)/*.scss)
CSS_FILES=$(patsubst $(SCSS_DIR)/%.scss, $(CSS_DIR)/%.css, $(SCSS_FILES))