Skip to content

Instantly share code, notes, and snippets.

View kbaribeau's full-sized avatar

Kevin Baribeau kbaribeau

  • Test Double
  • Saskatoon, SK, Canada
View GitHub Profile
ree-1.8.7-2011.03 :003 > hash = Hash.new([])
=> {}
ree-1.8.7-2011.03 :004 > hash[:asdf] << 1
=> [1]
ree-1.8.7-2011.03 :005 > hash[:fdsa]
=> [1]
ree-1.8.7-2011.03 :006 >
@kbaribeau
kbaribeau / gist:2936794
Created June 15, 2012 14:41
ugly line of js
var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
@kbaribeau
kbaribeau / gist:3123533
Created July 16, 2012 16:07
using custom ssl certs on osx
#see http://jjinux.blogspot.com/2012/02/ruby-working-around-ssl-errors-on-os-x.html
require 'open-uri'
require 'net/https'
module Net
class HTTP
alias_method :original_use_ssl=, :use_ssl=
def use_ssl=(flag)
window.CountCalculator=window.PriceCalculator=window.TaxCalculator=window.ShippingCaclulator = {
calculate: (num) -> (num == undefined ? 0 : num + 1) }
ChainsCalls =
chain: (dependencies, method) ->
_(dependencies).inject((memo, dependency) ->
dependency[method](memo)
, undefined)
Invoice =
@kbaribeau
kbaribeau / gist:3452778
Created August 24, 2012 16:48
Ruby style poll
#Do you prefer this?
merchant["thing"] = important_stuff.map { |important_thing| important_thing["units"] }.inject(&:+)
#Or this?
important_stuff.each { |important_thing| merchant["thing"] += important_thing["units"] }
#Why? Is it completely objective? Or are ruby's idioms/social mores/conventions the deciding factor?
@kbaribeau
kbaribeau / gist:3784044
Created September 25, 2012 19:51 — forked from nhajratw/gist:3783890
accessing functions??
var cycleTimeFunctionThatNeedsABetterName = function(acceptedDate, inProgressDate) {
var cycleTime = Math.round(Ext.Date.getElapsed(acceptedDate,inProgressDate) / 1000 / 60 / 60 / 24);
if (cycleTime === 0) cycleTime = 1;
return cycleTime;
};
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
function fix-file-endings () {
for f in `git ls-files`
do
newline='
'
lastline=$(tail -n 1 $f; echo x); lastline=${lastline%x}
[ "${lastline#"${lastline%?}"}" != "$newline" ] && echo >> $f
done
}
@kbaribeau
kbaribeau / gist:4495181
Created January 9, 2013 17:46
The source code for the unix `ping` command, taken from here: http://ftp.arl.army.mil/~mike/ping.html
# This is a shell archive. Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file". (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# Makefile ping.1 ping.c ping.shar newping.1 newping.c
echo x - Makefile
cat > "Makefile" << '//E*O*F Makefile//'
@kbaribeau
kbaribeau / gist:8508798
Created January 19, 2014 18:20
convert pdf files to text for further parsing
(ns pdf-text-extractor.core
(:import [com.snowtide.pdf OutputTarget PDFTextStream]))
(defn pdf-to-text [file]
(let [pdfts (new PDFTextStream file)
output (new StringBuilder 1024)]
(.pipe pdfts (new OutputTarget output))
(.close pdfts)
output))
@kbaribeau
kbaribeau / gist:9027116
Created February 15, 2014 23:58
v8 error when calling it with dieter using ns-resolve
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x0000000116e2a1c2, pid=22721, tid=3335
#
# JRE version: Java(TM) SE Runtime Environment (7.0_45-b18) (build 1.7.0_45-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C [libv8wrapper.dylib+0x21c2] run+0x22
#