Skip to content

Instantly share code, notes, and snippets.

View RobertFischer's full-sized avatar

Robert Fischer RobertFischer

View GitHub Profile
@RobertFischer
RobertFischer / ModelTestBase.java
Created July 24, 2014 15:33
Example of a base class for models.
/**
* The base class for models.
*
* @param <T> The type of the model under test.
*/
public abstract class ModelTestBase<T extends Serializable> {
/**
* Responsible for generating a test instance.
*
@RobertFischer
RobertFischer / Rakefile.rb
Created July 16, 2014 13:28
Addition to Rakefile to enable database name
# I don't think these database names are wrong, but you should be able to get the idea
class ActiveRecord::Migration
def self.whSalesDbName
return "DevSalesDb" if(ENV['NODE_ENV'] != "production")
return "SalesDb"
end
end
@RobertFischer
RobertFischer / check_this.js
Created July 8, 2014 18:04
JavaScript's hamstrung sanity checking
$(".foo").attr('bar', true);
@RobertFischer
RobertFischer / uglifier.rb
Created June 27, 2014 12:36
Who needs static typing when we can roll our own?
# Starts on line 91 in uglifier-2.5.0
# Initialize new context for Uglifier with given options
#
# options - Hash of options to override Uglifier::DEFAULTS
def initialize(options = {})
(options.keys - DEFAULTS.keys - [:comments, :squeeze, :copyright])[0..1].each do |missing|
raise ArgumentError.new("Invalid option: #{missing}")
end
@RobertFischer
RobertFischer / function_template.js
Created May 29, 2014 16:46
Demonstration of template function pattern
var function_template = function(method,cssClass,attr) {
return $(this.bulkUpdateEle)[method](cssClass).data(attr);
};
var foo_the_bars = _.partial(function_template, "foo", "bar");
var baz = _.partial(function_template, "baz");
foo({value1:true});
baz("quux", {value1:true});
foo({value2:false});
@RobertFischer
RobertFischer / dynamic_win.py
Created February 3, 2014 19:32
Why have static type safety when we can roll it ourselves?
@postcondition(http_code_error)
def ptest_bauth(base_url=config['base_url'], action='post', user=config['puser'],
pw=config['ppw'], header=config['pauth_header'], token=''):
valid_actions = ['post', 'delete']
if action not in valid_actions:
assert False, "framework error: action is not in " + str(valid_actions)
@RobertFischer
RobertFischer / WhatWorks.java
Last active December 18, 2015 19:38
ClassCircularityError Avoidance 101
// To avoid the ClassCircularityError, I have to log a message to the root logger before attaching a handler to it.
// But even that has to be done in a very particular way.
// I tried this:
Logger rootLogger = Logger.getLogger("");
rootLogger.log(rootLogger.getLevel(), "Some message");
// But that gives a ClassCircularityError
// Then I tried this:
Logger rootLogger = Logger.getLogger("");
@RobertFischer
RobertFischer / wtf.rb
Created September 14, 2012 19:55
Ruby erring out because a constant is *NOT* missing
Loaded suite ./test/unit/musicians_test
Started
E.
Finished in 0.027968 seconds.
1) Error:
test_load_one(MusiciansTest):
ArgumentError: Object is not missing constant Musician!
/home/rcfischer/.rvm/gems/ree-1.8.7-2012.02@reverbnation/gems/activesupport-2.2.3/lib/active_support/dependencies.rb:419:in `load_missing_constant'
/home/rcfischer/.rvm/gems/ree-1.8.7-2012.02@reverbnation/gems/activesupport-2.2.3/lib/active_support/dependencies.rb:77:in `const_missing'
@RobertFischer
RobertFischer / ampersand.rb
Created September 7, 2012 19:47
Ampersand Equivalency
foos.find(&:bar)
foos.find do |it|
it.bar
end
@RobertFischer
RobertFischer / freeze-fail.rb
Created August 27, 2012 18:45
Ruby Ain't Functional, So Freezing Doesn't Propagate
x = ["abc"].freeze
x[0][0] = "xyz"
puts x[0] # "xyzbc"