Skip to content

Instantly share code, notes, and snippets.

View bloudermilk's full-sized avatar

Brendan Loudermilk bloudermilk

View GitHub Profile
@bloudermilk
bloudermilk / date.coffee
Created February 20, 2010 22:13
Javascript Date prototypes for finding the beginning and end of days and weeks. Beginning of the week is defined as Sunday
Date::beginningOfMonth = ->
beginningOfMonth = @beginningOfDay()
beginningOfMonth.setDate(1)
beginningOfMonth
Date::endOfMonth = ->
endOfMonth = @endOfDay()
endOfMonth.setMonth(endOfMonth.getMonth() + 1)
endOfMonth.setDate(0)
endOfMonth
@bloudermilk
bloudermilk / gist:1235737
Created September 22, 2011 19:19
CoffeseSript + Mongoose
BootModel = Mongoose.model "Boot", new Schema
laces: Number
tied: Boolean
class Boot extends BootModel
boot = new Boot
boot.laces = 4
boot.tied = true
@bloudermilk
bloudermilk / overflow.html
Created November 27, 2011 10:52
Overflow example for a SO question
<!DOCTYPE HTML>
<html>
<head>
<title>Overflow!</title>
<style type="text/css">
#outer {
height: 200px;
position: relative;
overflow: hidden;
background-color: red;
@bloudermilk
bloudermilk / README.md
Created March 23, 2012 19:07
Facebook Page Categories

All of the categories!

I wrote a really simple JavaScript script that uses jQuery to extract all the categories from Facebook's "Create a page" page.

Instructions

  1. Navigate to the Create a page page.
  2. jQuerify the page.
  3. Open up your JavaScript console of choice and run the following script:
@bloudermilk
bloudermilk / explorer.rb
Created May 2, 2012 04:35
DCell Explorer Problem
require 'dcell/explorer'
DCell::Explorer.supervise("127.0.0.1", 8000)
@bloudermilk
bloudermilk / _README.md
Created June 6, 2012 21:32
Convert integer-keyed Hash parameters to Arrays in Rails

Fix for strong_parameters when using accepts_nested_attributes_for

The following before filter looks for any Hash parameters where all the keys are integers and turns them into Arrays. It searches recursively to allow the used of nested attributes within nested attributes. This is necessary to circumvent a bug in the strong_parameters gem which was reported in April 2012. Given params like:

{
  "person" => {
    "dogs_attributes" => {
      "0" => {
 "name" =&gt; "Fido"
@bloudermilk
bloudermilk / gist:3147421
Created July 19, 2012 22:52
Lein (uber)jar fails
projects $ lein -v
Leiningen 2.0.0-preview7 on Java 1.6.0_33 Java HotSpot(TM) 64-Bit Server VM
projects $ lein new test
Generating a project called test based on the 'default' template.
To see other templates (app, lein plugin, etc), try `lein help new`.
projects $ cd test/
projects $ vim project.clj
test $ cat project.clj
(defproject test "0.1.0-SNAPSHOT"
:description "FIXME: write description"
@bloudermilk
bloudermilk / admin.rb
Created August 8, 2012 23:03
Stupid-simple invitations with Devise
class Admin < ActiveRecord::Base
attr_accessor :invite
devise :database_authenticatable, :registerable, :recoverable, :rememberable,
:trackable, :validatable
def self.new_invited(attributes)
new(attributes.merge(invite: true))
end
@bloudermilk
bloudermilk / fb_init.coffee
Created August 24, 2012 21:45 — forked from patbenatar/fb_init.coffee
Initialize Facebook JS SDK in Coffeescript
@FBootloader = new class FBootloader
callbacks: []
isReady: false
ready: ->
callback() for callback in @callbacks
bind: (callback) ->
if @isReady
callback()
@bloudermilk
bloudermilk / _routes.rb
Created September 7, 2012 20:18
devise + strong_parameters
# config/routes.rb
MyApp::Application.routes.draw do
devise_for :users, controllers: {
registrations: "users/registrations"
}
end