Skip to content

Instantly share code, notes, and snippets.

@joshpencheon
joshpencheon / demo.html
Created August 18, 2011 22:26
basic raphael graph demo
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://raphaeljs.com/raphael.js"></script>
</head>
<body>
<script type="text/javascript" charset="utf-8">
@joshpencheon
joshpencheon / vector.js
Created September 5, 2011 12:39
vector
var V = {
init: function(x, y, z) {
return { x: x, y: y, z: z };
},
add: function(v1, v2) {
return {
x: v1.x + v2.x,
y: v1.y + v2.y,
z: v1.z + v2.z
@joshpencheon
joshpencheon / hash_bm.rb
Created May 21, 2014 20:59
Hash performance
require 'benchmark'
require 'rubygems'
require 'active_support/all'
@config = []
10.times do |x|
options = {}
10.times { |y| options["key#{y}"] = "value#{y}" }
@config << ["name#{x}", options]
end
require 'beaneater'
require 'json'
@beanstalk = Beaneater::Pool.new(['localhost:11300'])
total = 0
puts "Listening for jobs..."
@beanstalk.jobs.register('test-tube') do |job|
payments = crossfilter([
{ date: "2011-11-14T16:17:54Z", total: 190, tip: 100, type: "tab" },
{ date: "2011-11-14T16:20:19Z", total: 190, tip: 100, type: "tab" },
{ date: "2011-11-14T16:28:54Z", total: 300, tip: 200, type: "visa" },
{ date: "2011-11-14T16:30:43Z", total: 90, tip: 0, type: "tab" },
{ date: "2011-11-14T16:48:46Z", total: 90, tip: 0, type: "tab" },
{ date: "2011-11-14T16:53:41Z", total: 90, tip: 0, type: "tab" },
{ date: "2011-11-14T16:54:06Z", total: 100, tip: 0, type: "cash" },
{ date: "2011-11-14T16:58:03Z", total: 90, tip: 0, type: "tab" },
{ date: "2011-11-14T17:07:21Z", total: 90, tip: 10, type: "tab" },
db.dummies.aggregate([
{
$group: {
_id: { num: "$num" },
records: { $push: "$$ROOT" }
}
},
{
$project: {
_id: 0,
@joshpencheon
joshpencheon / USAGE
Last active August 29, 2015 14:26
Proof-of-concept for shelling out to achieve syck-to-psych up serialization
$ irb -r ./up_serializer.rb
irb(main):001:0> YAML.load YAML::UpSerializer.new('1.9.3-p484').up_serialize "---\nkey: ,oh,dear\n"
=> {"key"=>",oh,dear"}
irb(main):002:0>
@joshpencheon
joshpencheon / .block
Last active June 26, 2016 12:05
D3 Jazz demo
border: no
height: 1000
@joshpencheon
joshpencheon / compare_trunk_to_branch.sh
Last active May 7, 2017 16:15
Support Material for ruby/ruby stdlib CSV pull request
#!/bin/sh
git checkout trunk
ruby benchmark.rb > benchmark-trunk.log
ruby allocations.rb > allocations-trunk.log
git checkout csv_allocation_reduction
ruby benchmark.rb > benchmark-patch.log
ruby allocations.rb > allocations-patch.log
@joshpencheon
joshpencheon / planio.rb
Last active July 6, 2017 13:20
Update plan.io tickets programmatically, by parsing SVN commit messages
#!/usr/bin/env ruby
@revision = ENV.fetch('REVISION')
@message = ENV.fetch('COMMIT_MESSAGE')
@user = ENV.fetch('SVN_USERNAME')
@api_key = ENV.fetch('REDMINE_API_KEY')
require 'json'
require 'net/http'