Skip to content

Instantly share code, notes, and snippets.

View stubotnik's full-sized avatar

Stu Gray stubotnik

  • Dublin, Ireland
View GitHub Profile
@stubotnik
stubotnik / xAjaxRequest.js
Created December 2, 2011 16:46
pre-onComplete handler for all Ajax requests
xAjaxRequest = Class.create({
initialize: function (url, options) {
//if the request has a callback, wrap that in our own callback
if (typeof options.onComplete == "function") {
var f = options.onComplete;
options.onComplete =
@stubotnik
stubotnik / kt.rb
Created February 10, 2012 16:44
Knights Tour
# Knights Tour - unpolished
module KnightsTour
class Game
def initialize (boardHeight, boardWidth)
@board = Array.new(boardHeight) {Array.new(boardWidth, 0)}
@moveCounter = 0;
end
@stubotnik
stubotnik / auto-pop.js
Created April 3, 2012 15:13
Auto-populate sign-up
(function(){
$("firstName").value = "Joe";
$("lastName").value = "Test";
$("email").value = $("emailConfirm").value = "user" + Math.round(Math.random() * 1000000) + "@example.com";
$("birthMonth").selectedIndex = 1;
$("birthDate").selectedIndex = 2;
$("birthYear").selectedIndex = 10;
$("phone").value = "123456789"
$("accName").value = "Tst" + Math.round(Math.random() * 1000000);
$("pwd").value = $("pwdConfirm").value = "Tester1234";
@stubotnik
stubotnik / z-indexes.scss
Created July 11, 2012 13:13
Manage complex z-index layouts with SASS variables
$pages-z-index: 1;
$menu-z-index: $pages-z-index - 1;
$betcard-mask-z-index: $pages-z-index + 1;
$betcard-z-index: $betcard-mask-z-index + 1;
$header-z-index: $betcard-z-index + 1;
$alert-dialog-z-index: $header-z-index + 1;
$betcard-delay-z-index: $alert-dialog-z-index + 1;
$ajax-blocker-z-index: $betcard-delay-z-index;
@stubotnik
stubotnik / DynResourceLoader.js
Created July 19, 2012 07:41
Dynamic resource loading with LAB.js
DynResourceLoader = Class.create({
initialize: function () {
document.observe("custom:pageAddedToDOM", this.load.bind(this));
},
load: function (e) {
var page = e.memo;
if (page.hasAttribute("data-required-js")) {
@stubotnik
stubotnik / minesweeper.rb
Created July 20, 2012 14:41
Minesweeper Kata
module Minesweeper
class Game
attr_reader :fields
def initialize
@fields = []
@allow_input = true
@stubotnik
stubotnik / app.rb
Created September 21, 2012 08:58
uninitialized constant error
class MyProject < Padrino::Application
register Padrino::Rendering
register Padrino::Mailer
register Padrino::Helpers
MY_CONST = 123
end
@stubotnik
stubotnik / gist:3762230
Created September 21, 2012 15:37
uninitialized constant - padrino free example
class Thing
MY_CONST = 123
def doStuff (&block)
p "doStuff: #{self.class}" # => "doStuff: Thing"
p "doStuff: #{MY_CONST}" # => "doStuff: 123"
instance_eval &block
end
@stubotnik
stubotnik / gist:3825846
Created October 3, 2012 08:44
Stored Proc return codes in Sequel
def self.return_code_test
return_code = @db.synchronize do |conn|
stmnt = conn.prepareCall('{ ? = call dbo.sp_tmp_stu_sequel_test() }')
stmnt.registerOutParameter(1, java::sql::Types::INTEGER)
stmnt.execute
# output parameters have not yet been processed, must call getMoreResults() first.
stmnt.getMoreResults
stmnt.getInt(1)
end
@stubotnik
stubotnik / gist:3833770
Created October 4, 2012 14:13
do while
existing_raf_code = ':-(' # no do-while in Ruby
until existing_raf_code.nil?
new_client_raf_code = SIASquirrel::SIA::RAFReferrer.generateRAFCode
existing_raf_code = SIASquirrel::SIA::RAFReferrer[:rafcode => new_client_raf_code]
end