Skip to content

Instantly share code, notes, and snippets.

function BaseballGame(home_team_name, away_team_name) {
var home_goals = 0;
var away_goals = 0;
function home_team_run_scored() {
home_goals++;
}
function away_team_run_scored() {
@bwiggs
bwiggs / profanities.json
Created February 20, 2014 22:51
epic profanity list
[
"$hit",
"$hit$",
"$hits",
"$hitted",
"$hitter",
"$hitting",
"3some",
"53x",
"60 nine",
@bwiggs
bwiggs / array_like_objects.js
Last active December 24, 2015 05:19
This shows how one can use Array's prototype methods on any object by using `call`.
var CarLot = {
name: 'We-Buy-Cars',
length: 0,
buy: function(num) {
return Array.prototype.push.call(this, num);
},
sell: function() {
return Array.prototype.pop.call(this);
},
report: function() {
@bwiggs
bwiggs / .autotest
Created September 25, 2013 19:08
This makes autotest ignore certain files.
Autotest.add_hook :initialize do |at|
%w{log coverage}.each {|exception| at.add_exception(exception)}
end
@bwiggs
bwiggs / article_decorator_spec.rb
Created September 24, 2013 23:50
This was how I solved mocking the request object for a Draper decorator from RSpec.
describe 'ArticleDecorator'
describe '#opengraph_image_url' do
it 'should provide the default image as a fallback' do
request = stub(host: 'local.example.com', port: 3000)
ArticleDecorator.any_instance.stub request: request
ArticleDecorator.new(Article.new).opengraph_image_url.should == "http://local.example.com:3000/images/default.png"
end
end
end
@bwiggs
bwiggs / action.html.slim
Created July 29, 2013 16:25
Can't get nested layouts working in Rails 3
= render template: "layouts/sub_layout"
- content_for :content_body
h3 'action.html.slim'
<?php
namespace CI\Twig;
use Silex\Application;
class AssetTwigExtension extends \Twig_Extension
{
private $CDN = null;
event = [...]
@events = {
in_progress: events.select { |event| event.state == "in-progress" } || [],
pregame: events.select { |event| event.state == "pregame" } || [],
final: events.select { |event| event.state == "final" } || []
}
@bwiggs
bwiggs / Event.rb
Last active December 12, 2015 03:58
require 'ostruct'
module MyModule
class MyClass < OpenStruct
end
end
#`<module:MyModule>': uninitialized constant OpenStruct (NameError)
@bwiggs
bwiggs / Event.rb
Last active December 12, 2015 03:58
class Event
attr_reader :uid, :event_date, :sports
def initialize(args)
args.keys.each do |name|
instance_variable_set "@" + name.to_s, args[name]
end
end
end