Skip to content

Instantly share code, notes, and snippets.

View spalladino's full-sized avatar
🔷

Santiago Palladino spalladino

🔷
View GitHub Profile
@spalladino
spalladino / recordings.rb
Created June 11, 2012 14:28
Retrieve recordings duration for steps in call flow for Verboice from exported vrb
require 'yaml'
require 'csv'
FILE = 'sample.vrb'
class Recording < Struct.new(:step_id, :step_name, :message, :duration)
def self.from_step(step, message='message')
self.new(step['id'], step['name'], message, (step[message]['duration'] rescue nil))
end
end
@spalladino
spalladino / Response.java
Created September 19, 2012 18:40
OneLogin SAML Java client with attributes support
package com.onelogin.saml;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.xml.crypto.dsig.XMLSignature;
import javax.xml.crypto.dsig.XMLSignatureFactory;
import javax.xml.crypto.dsig.dom.DOMValidateContext;
@spalladino
spalladino / vertica_adapter.rb
Created November 29, 2012 20:47
ActiveRecord adapter for Vertica compatible with version 3.2.8
# Based on version by https://github.com/mgbaron/activerecord_vertica_adapter2/blob/master/lib/active_record/connection_adapters/vertica_adapter.rb
# Place this file in lib/extras/active_record/connection_adapters/vertica_adapter.rb and require it when needed
# You may use a different connection by specifying `establish_connection Rails.configuration.database_configuration["census"]`
require 'active_record/connection_adapters/abstract_adapter'
require 'arel/visitors/bind_visitor'
module ActiveRecord
class Base
# Establishes a connection to the database that's used by all Active Record objects
@spalladino
spalladino / san.msupn.rb
Last active March 20, 2018 13:38
Extracting Subject Alternative Name Other Name (1.3.6.1.4.1.311.20.2.3) from Microsoft authorization client certificates
cert = OpenSSL::X509::Certificate.new(certificate_string)
subject_alt_name = cert.extensions.find {|e| e.oid == "subjectAltName"}
# Parse the subject alternate name certificate extension as ASN1, first value should be the key
asn_san = OpenSSL::ASN1.decode(subject_alt_name)
raise "Expected ASN1 Subject Alternate Name extension key to be subjectAltName but was #{asn_san.value[0].value}" if asn_san.value[0].value != 'subjectAltName'
# And the second value should be a nested ASN1 sequence
asn_san_sequence = OpenSSL::ASN1.decode(asn_san.value[1].value)
@spalladino
spalladino / array_first_with_block.rb
Created June 14, 2013 21:39
Array#first redefinition so it can accept a block and behave like find, for compatibility with .NET LINQ programmers
class Array
def first_with_block(&block)
block_given? ? find(&block) : first_without_block
end
alias_method_chain :first, :block
end
# 1.9.3p0 :009 > [1,2,3,4,5].first{|x| x > 2}
# => 3
# 1.9.3p0 :010 > [1,2,3,4,5].first
@spalladino
spalladino / update-icmls.py
Created July 17, 2013 17:36
Updates the icml files for the handbook's chapters based on a diff file from txt extracts
import re
import fileinput
import os
from glob import glob
ICML_DIR = "icml"
OUT_DIR = "output"
# Get icml files in memory
@spalladino
spalladino / Capfile
Created September 2, 2013 22:13
Hacking an erlang application deployment with Capistrano 3
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
namespace :deploy do
@spalladino
spalladino / stats.py
Created January 5, 2014 16:31
Count number of lines of code per language per week in git repository using cloc
import csv
import os
import sys
from os.path import isfile
from datetime import date, timedelta
from subprocess import call, check_output
# Script expects that each project is in a folder with the same name in the working directory
PROJECTS = ['my-project', 'another-project']
@spalladino
spalladino / leaflet-nobounce.js
Created August 22, 2014 21:20
Handler for leaflet.js to manage max bounds without bouncing
// Initialize OSM source, based on map.html example
var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib});
// Create map with max bounds
var map = L.map('map')
.setView([50.5, 30.51], 15)
.addLayer(osm)
.setMaxBounds([[50.52979753992208, 30.527229309082035],[50.497049833624224, 30.458564758300785]]);
@spalladino
spalladino / changelog.py
Created November 7, 2014 15:32
Create changelog for a new Cepheid version based on git log and fogbugz data
#! /usr/bin/python
from fogbugz import FogBugz
from datetime import datetime, timedelta
from itertools import groupby
import subprocess
import re
import sys