Skip to content

Instantly share code, notes, and snippets.

@flou
flou / ETL.py
Created June 13, 2011 14:38
Python ETL script
#!/usr/local/bin/python3.2
# -*- coding: UTF-8 -*-
import sys
import re
import subprocess
COMMAND = "./extract.sh"
class ETL:
@flou
flou / validateIban.js
Created May 4, 2012 08:55
Validate IBAN
function validateIban (iban) {
const ibanValidationModulo = 97;
// On force les caractères alphabétiques en majuscule
iban = iban.toUpperCase();
// on supprime les espaces
iban = iban.replace(new RegExp(" ", "g"), "");
// le code iban doit faire plus de 4 caractères
if (iban.length < 5) {
module Password
CHARS = [*('A'..'Z'), *('a'..'z'), *(0..9), '$']
def self.generate(size = 4)
chunks = []
size.times do
chunks << create_chunk
end
chunks.join('-')
end
formula = "%d.0 + 13 * %d.0 / %d.0 + %d.0 + 12 * %d.0 - %d.0 - 11 + %d.0 * %d.0 / %d.0 - 10"
combinations = (1..9).to_a.permutation.map(&:join)
combinations.each do |combination|
expr = format(formula, *combination.split(''))
result = eval(expr)
puts expr.gsub(/\.0/, '') if result == 66.0
end
class Network
# Create a new network
# @param address [String] the address of the network formatted as
# "10.0.0.0/16" or "10.0.0.0/255.255.255.0"
def initialize(address)
@address = address
@ip = to_binary(address.split("/")[0])
@mask = to_binary(address.split("/")[1])
end
require "xml/xml"
def payload
%(<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>)
end
@flou
flou / learncrystal.cr
Last active August 29, 2015 14:27
Learn Crystal in Y minutes
# Comments start with a hash
# First and foremost: Everything is an object.
# Numbers are objects
3.class # => Int32
3.to_s # => "3"
#!/bin/sh
# requires imgcat (https://github.com/gnachman/iTerm2/blob/master/tests/imgcat)
xkcd_issue=$1
TMP_FILE=$(mktemp /tmp/xkcd-$xkcd_issue.json.XXXXXXXX)
curl -s http://xkcd.com/$xkcd_issue/info.0.json > $TMP_FILE
imgurl=$(jq '.img' $TMP_FILE | tr -d \")
imgtitle=$(jq '.title' $TMP_FILE | tr -d \")
imgalt=$(jq '.alt' $TMP_FILE | tr -d \")
settings =
lang: 'fr'
# Locale Strings
locale =
en:
weekdays: [
'Sunday'
'Monday'
'Tuesday'
import glob
import json
import os
def find_nodes(node, key, debug=False):
if isinstance(node, unicode) or isinstance(node, list):
return