Skip to content

Instantly share code, notes, and snippets.

View zachpendleton's full-sized avatar

Zach Pendleton zachpendleton

View GitHub Profile
use strict;
sub event_send_text {
my ($text, $server, $win_item) = @_;
$text =~ s/:-1:/👎/g;
$text =~ s/:\+1:/👍/g;
$text =~ s/:poop:/💩/g;
$text =~ s/:no_good:/🙅/g;
$text =~ s/:ok_woman:/🙆/g;
web: bundle exec unicorn -c vendor/plugins/zachp-local/unicorn.rb
guard: bundle exec guard start --no-interactions
job: bundle exec script/delayed_job run > /dev/null
mail: bundle exec mailtrap run

1:

  description: I know the problem, I know the solution, and it's only a few lines.
  examples:
  - CNVS-4242
  - CNVS-4203
  - CNVS-3100

2:

  description: I know the problem and solution, but it isn't as trivial as a 1. Or the
    problem seems small and I know the code, but may not know exactly what's causing it.

require 'erb'
require 'json'
require 'net/https'
module Jira
class Service
JIRA_URL = 'https://instructure.atlassian.net/rest/api/2/search'
def initialize(username = ENV['JIRA_USERNAME'], password = ENV['JIRA_PASSWORD'])
self.username = username
@zachpendleton
zachpendleton / inject_example.rb
Created June 5, 2013 14:55
Example of Ruby's Inject method.
Enrollment = Struct.new(:name, :type)
enrollments = [
Enrollment.new('Don Draper', 'Teacher'),
Enrollment.new('Peggy Olson', 'Student'),
Enrollment.new('Pete Campbell', 'Student'),
Enrollment.new('Roger Sterling', 'TA')
]
grouped_enrollments = enrollments.inject({}) do |result, enrollment|
@zachpendleton
zachpendleton / rescue_bm.rb
Created August 13, 2013 16:07
Rescuing in Ruby sucks
require 'benchmark'
Benchmark.benchmark do |x|
x.report {
100_000.times { nil.to_sym rescue :or }
}
x.report {
100_000.times { nil.try(:to_sym) || :or
}
@zachpendleton
zachpendleton / application.hbs
Created August 24, 2013 04:20
Accessible Ember buttonset component.
<!-- see http://jsbin.com/erIBAba/1 -->
<h1>Buttonset example</h1>
{{#zp-buttonset bindTo=filter}}
{{zp-button label="Open"}}
{{zp-button label="Upcoming"}}
{{zp-button label="Closed"}}
{{/zp-buttonset}}
#header {
background: red;
height: 200px;
}
module Foo
class Bar
def speak; "Hello, world!"; end
end
end
module Foo
class Baz
# this works
def speak; Bar.new.speak; end
Node = Struct.new(:value, :left, :right)
class KDTree
attr_reader :root
# points - an array of arrays containing x,y coordinates (e.g. [[1,1], [5,1]])
def initialize(points)
@root = init_tree(points.clone)
end