Skip to content

Instantly share code, notes, and snippets.

View alassek's full-sized avatar

Adam Lassek alassek

View GitHub Profile
activesupport (3.0.3) lib/active_support/dependencies.rb:304:in `depend_on'
activesupport (3.0.3) lib/active_support/dependencies.rb:216:in `require_dependency'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:148:in `modules_for_helpers'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:144:in `map!'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:144:in `modules_for_helpers'
actionpack (3.0.3) lib/action_controller/metal/helpers.rb:101:in `modules_for_helpers'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:97:in `helper'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:161:in `default_helper_module!'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:24:in `inherited'
actionpack (3.0.3) lib/abstract_controller/helpers.rb:24:in `class_eval'
@alassek
alassek / load_erb.rb
Created February 18, 2011 22:41
support ERB in a YAML file
class << YAML
def load_erb(file)
load(
ERB.new(
IO.read(file)
).result
)
end
end
@alassek
alassek / get_flash.rb
Created March 16, 2011 19:58
Get a flash message from a Rails Controller in a Sinatra action
def get_flash
signed_message = request.cookies['_project_name_session']
if signed_message.present?
secret = ProjectName::Application.config.secret_token
verifier = ActiveSupport::MessageVerifier.new(secret)
session = verifier.verify(signed_message)
@flash = session.delete('flash')
@alassek
alassek / konami.js
Created April 28, 2011 07:39
konami code for jQuery
(function ($) {
$.fn.konami = function (callback, code) {
code = code || "38,38,40,40,37,39,37,39,66,65,13";
return this.each(function () {
var kkeys = [];
$(this).keydown(function (e) {
kkeys.push(e.keyCode);
if (kkeys.toString().indexOf(code) >= 0) {
$(this).unbind('keydown', arguments.callee);
callback(e);
@alassek
alassek / store_ext.js
Created September 8, 2011 19:48
amplify.store.remove
amplify.store.remove = function ( key ) {
var value = amplify.store( key );
amplify.store( key, null );
return value;
}
@alassek
alassek / typeIntent.js
Created September 14, 2011 22:13
Trigger change event without hitting enter, like Google Live Search
/*
* Copyright (c) 2011 Lyconic, LLC.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@alassek
alassek / extendEach.js
Created September 19, 2011 22:19
Easy multiple-inheritance in Backbone.js
(function () {
function extendEach () {
var args = Array.prototype.slice.call(arguments),
child = this;
_.each(args, function (proto) {
child = child.extend(proto);
});
# By Henrik Nyh <http://henrik.nyh.se> 2008-01-30.
# Free to modify and redistribute with credit.
require "rubygems"
require "hpricot"
module TextHelper
# Like the Rails _truncate_ helper but doesn't break HTML tags or entities.
def truncate_html(text, max_length = 30, ellipsis = "...")
@alassek
alassek / location.js
Last active December 10, 2015 20:58
window.location sucks
/**
* `window.location` is a BAD api. Doesn't have a prototype, 'too much recursion' error
* if you try to inspect the constructor. Monkey-patching causes random disappearances
* of the monkey-patched function in Chrome, cloning causes 'too much recursion' in FF.
*
* This is what I'm reduced to. ಠ_ಠ
**/
(function () {
function Location () {
@alassek
alassek / application_controller.rb
Created May 5, 2014 22:00
SSL Auth for Services
class ApplicationController < ActionController::Base
before_filter :require_authentication
private
def require_authentication
unless current_certificate.verify(public_key)
head :forbidden
end
end