Skip to content

Instantly share code, notes, and snippets.

View nmartinet's full-sized avatar

Nicolas Martinet nmartinet

View GitHub Profile
function(){
alert();
}()
@nmartinet
nmartinet / rubyNest.rb
Last active December 15, 2015 23:47
nesting function
def nest(data, keys, rollup=nil)
def recNest(data, keys, rollup=nil)
return data if keys.length == 0
data
.group_by{|x| keys[0].call(x) }
.map{|key, val|
d = [recNest(val, keys[1, keys.length - 1], rollup)]
d << val.reduce(rollup[0], &rollup[1]) unless rollup.nil?
{ key => d.flatten }
@nmartinet
nmartinet / extracVBAModules.rb
Created December 13, 2015 19:30
extract all VBA modules from the given workbooks. Use full paths, and enable access to the vba project object model in excel
def extract_vb_modules(paths)
require 'win32ole'
excel_app = WIN32OLE.new('Excel.Application')
excel_app.ScreenUpdating = false
excel_app.EnableEvents = false
excel_app.DisplayAlerts = false
#excel_app.Calculation = -4135
@nmartinet
nmartinet / busy.rb
Created December 13, 2015 19:06
ruby printing
def busy(t=10, label="")
st = t.kind_of?(Array) ? t[0]+rand(t[1]) : t
start = Time.now
l = ["|","/","-","\\"]
i = 0
while ((Time.now - start)) < st do
print "\r", label, l[i]
i = (i == 3) ? 0 : i+1