Skip to content

Instantly share code, notes, and snippets.

View gnab's full-sized avatar

Ole Petter Bang gnab

  • Onyx CenterSource
  • Tønsberg, Norway
View GitHub Profile
@gnab
gnab / session_store.rb
Created August 10, 2011 07:13
JavaServletStore::AbstractStore Rails 3 Fix
# Needed for JRuby-Rack to locate ActionController::Session::JavaServletStore::AbstractStore on Rails 3.0.9
require 'action_dispatch/session/java_servlet_store' if defined?($servlet_context)
MyApp::Application.config.session_store(:active_record_store, :key => '_my_app_session')
@gnab
gnab / namespace.js
Created August 22, 2011 07:41
JavaScript Module Namespace
var module = {};
module.namespace = function recurse(path, base) {
base = base || this;
if (!path) {
return base;
}
var name = path.substring(0, path.indexOf('.')) || path;
@gnab
gnab / gist:1661423
Created January 23, 2012 07:40
C# JSON Stuff
abstract class Object<T>
{
private readonly List<T> _properties;
protected abstract string FormatString { get; }
protected Object(params T[] properties)
{
_properties = new List<T>(properties);
}
@gnab
gnab / gist:2764171
Created May 21, 2012 19:35
guess.rb
number = rand(10).to_i
puts "Guess the number!"
puts "Wrong answer!" until (gets || '').strip.to_i == number
puts "Correct, the number was #{number}."
@gnab
gnab / grep.hs
Last active October 5, 2015 10:27
Haskell stdin grep
import System.Environment
import Data.List
main = do
args <- getArgs
case args of
[word] -> interact $ unlines . filter (isInfixOf word) . lines
_ -> putStrLn "No word to match against specified!"
@gnab
gnab / wc.hs
Created May 26, 2012 09:21
Haskell stdin word count
main = interact $ show . length . words
@gnab
gnab / find-that-bastard.js
Created September 14, 2012 11:46
Find the event handler blocking events (event.preventDefault())
// Scenario: Some event handler is blocking events (event.preventDefault()) that shouldn't be blocked, i.e. because it binds to document instead of a more specific element
// 1) Place this before all other JavaScript
var originalPreventDefault = Event.prototype.preventDefault;
Event.prototype.preventDefault = function () {
// Lookup specific event you're expecting, i.e. pressing space
if (this instanceof KeyboardEvent && this.keyCode === 32) {
// This will log an error with full stack trace
make_error_to_see_stacktrace
@gnab
gnab / tictactoe.hs
Created October 22, 2012 20:23
Haskell 3x3 Tic-Tac-Toe
data Cell = X | O | N deriving (Show, Eq)
board = [X,X,O,
O,X,X,
X,O,O]
winner [a,b,c,
d,e,f,
g,h,i] | isWinner X = X
| isWinner O = O
@gnab
gnab / ruter.rb
Created October 25, 2012 19:29
Ruter MinSide Ruby wrapper for retrieving travel card information
# encoding: utf-8
require 'mechanize'
class Ruter
class NotLoggedInError < StandardError; end
def self.log_in(username, password)
agent = Mechanize.new
agent.ca_file = '/usr/lib/ssl/certs/ca-certificates.crt'
@gnab
gnab / gulesider.rb
Created October 25, 2012 19:56
GuleSider Min Side Ruby wrapper for sending SMS
# encoding: utf-8
require 'mechanize'
class GuleSider
class NotLoggedInError < StandardError; end
def self.log_in(username, password)
agent = Mechanize.new
agent.ca_file = '/usr/lib/ssl/certs/ca-certificates.crt'