Skip to content

Instantly share code, notes, and snippets.

View BiggerNoise's full-sized avatar

Andy Davis BiggerNoise

View GitHub Profile
@BiggerNoise
BiggerNoise / app.js
Created September 1, 2012 21:19
A better javascript namespace/module pattern
app = (function () {
var Namespace = function () {
}
var Module = function () {
}
Namespace.prototype.createModule = function () {
var m = new Module;
if(arguments.length > 0)
@BiggerNoise
BiggerNoise / revalingModule.js
Created September 1, 2012 21:48
Basic Revealing Module
mything = (function(){
var Foo, Bar, binky, boo;
binky = function() {
// does something useful
};
boo = function() {
// does something amazing
};
@BiggerNoise
BiggerNoise / ns_module1.js
Created September 2, 2012 03:56
Namespace & Module Use I
company = app.namespace(company);
company.master= app.namespace(company.master)
@BiggerNoise
BiggerNoise / usermodule.js
Created September 2, 2012 04:00
Namespace/Module Use 2
company.master.users = company.master.createModule( function(){
var RevealedClass, hiddenFunction
RevealedClass = function(){
// stuff
};
hiddenFunction = function(){};
// this is the private area of the module
this.privateThing = 42;
@BiggerNoise
BiggerNoise / user_exposed.js
Created September 2, 2012 04:00
Namespace/Module Use 3
company.master.users = company.master.users.extend(function(){
// use it
var myLocalThing = this.privateThing,
ExposedClass = function(){
};
return {
Exposed:ExposedClass
}
});
@BiggerNoise
BiggerNoise / additional_parameters.js
Created September 2, 2012 04:01
Namespace/Module Use 4
company.master.users = company.master.users.extend(function($, log){
}, $, loggingSystem);
@BiggerNoise
BiggerNoise / read_flawed_spreadsheet.rb
Created January 25, 2013 18:38
Shows using the spreadsheet gem to read a file that is flawed. Worksheets and dimensions are correct, but cell data cannot be read. File that causes the issue can be found at: http://dl.dropbox.com/u/83477489/sample.xls
#!/usr/bin/env ruby
wb = Spreadsheet.open('sample.xls')
puts "Opened Spreadsheet, #{wb.sheet_count} sheets encountered"
(0..wb.sheet_count-1).each do |sheet_number|
ws = wb.worksheet(sheet_number)
puts "\tWorksheet #{ws.name} has #{ws.row_count} rows and #{ws.column_count} columns}; and Dimensions: #{ws.dimensions}"
end
@BiggerNoise
BiggerNoise / document_read_test.rb
Created July 1, 2013 01:15
Trying to demonstrate an issue that I am having when running capybara with a page that has an on document ready callback
require "capybara"
html = DATA.read
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
sess = Capybara::Session.new(:selenium, app)
sess.visit("/")
puts 'You Lose' unless sess.has_content? 'Here it Is'
@BiggerNoise
BiggerNoise / task_poller.rb
Created September 4, 2013 20:04
Proposed way to rework the execute() method in ActivityTaskPoller so that it does not mark an activity as failed when only the completion notification fails
def execute(task)
activity_type = task.activity_type
begin
context = ActivityExecutionContext.new(@service, @domain, task)
activity_implementation = @activity_definition_map[activity_type]
raise "This activity worker was told to work on activity type #{activity_type.name}, but this activity worker only knows how to work on #{@activity_definition_map.keys.map(&:name).join ' '}" unless activity_implementation
output = activity_implementation.execute(task.input, context)
@logger.debug "Responding on task_token #{task.task_token} for task #{task}"
rescue ActivityFailureException => e
respond_activity_task_failed_with_retry(task.task_token, e.message, e.details)
@BiggerNoise
BiggerNoise / assign_case_command.rb
Created March 3, 2014 21:10
Command Pattern at work
class AssignCaseCommand < Command
attribute :case, Case
attribute :owner, User
attribute :created_by, User
attribute :comments, String
attribute :distribute_at, DateTime
attribute :distribute_rule_name, String
attribute :require_initial, Boolean