Skip to content

Instantly share code, notes, and snippets.

@RobertFischer
RobertFischer / MagnusProperty.groovy
Created August 25, 2015 22:34
Example of type-safe properties
@CompileStatic
abstract class MagnusProperty<T> {
final String key;
MagnusProperty(String key) {
assert key : "No key provided!"
this.key = key
}
@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 / 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 / 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 / check_this.js
Created July 8, 2014 18:04
JavaScript's hamstrung sanity checking
$(".foo").attr('bar', true);
@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 / 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 / geb_boilerplate.groovy
Created August 6, 2014 18:44
Geb Boilerplate Script
// The first time you run this, it will take a very long, annoyingly silent pause while it loads libraries
@Grapes([
@Grab("org.gebish:geb-core:0.9.3"),
@Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.41.0"),
@Grab("org.seleniumhq.selenium:selenium-support:2.41.0")
])
import geb.Browser
Browser.drive {
@RobertFischer
RobertFischer / Namespaced CSS
Created August 11, 2014 18:59
Namespsaced CSS
<!--
In your SCSS file:
.bootstrap {
// All your bootstrap specific SCSS here
}
-->
<body class="bootstrap">
<!--
Widgets here will get "bootstrap"-namespaced styling
@RobertFischer
RobertFischer / gist:e42fb29b76bbad4a903f
Created August 12, 2014 16:07
Lazybones: Attempting to do something without authorization
lazybones$ gradle -i --stacktrace publishAllTemplates
Starting Build
Settings evaluated using empty settings script.
Projects loaded. Root project using build file '/Users/RCFischer/webonise/lazybones/build.gradle'.
Included projects: [root project 'lazybones']
Evaluating root project 'lazybones' using build file '/Users/RCFischer/webonise/lazybones/build.gradle'.
All projects evaluated.
Selected primary task 'DefaultTaskParameter{taskName='publishAllTemplates',projectPath='null'}'
Tasks to be executed: [task ':packageTemplateExtGeb', task ':publishTemplateExtGeb', task ':publishAllTemplates']
:packageTemplateExtGeb (Thread[main,5,main]) started.