Skip to content

Instantly share code, notes, and snippets.

View chuckbergeron's full-sized avatar
🎯
pooltogether.com

Chuck Bergeron chuckbergeron

🎯
pooltogether.com
View GitHub Profile
@chuckbergeron
chuckbergeron / Facebook-stupid-POST-stuff.rb
Created March 9, 2011 15:36
Because Facebook broke REST
... New routes w/ scope/controller ...
resources :users, :only => [ :update ]
renders:
user PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
@chuckbergeron
chuckbergeron / Tabs.js
Created June 9, 2011 16:39
jQuery Promise / Deferred / AJAX methods in sequence
var Tab = function() {
/*
* EXTRAS
*/
var Extras = function() {
var show = function( id ) {
var extra = $( "#" + id ),
d = $.Deferred();
chained = d;
@chuckbergeron
chuckbergeron / deferred_promise_sequences.js
Created June 12, 2011 10:56
jQuery Promise / Deferred functions in sequence
<!DOCTYPE html>
<html lang="en">
<head>
<title>JS Sequence Test</title>
<script src="jquery-1.6.1.min.js"></script>
</head>
<body>
<div id="green-box" style="width:100px;height:100px;background:#484;margin:0 0 10px 0;display:none">
</div>
@chuckbergeron
chuckbergeron / deferred_promise_sequences_ajax.js
Created June 12, 2011 10:57
jQuery Promise / Deferred / AJAX functions in sequence
<!DOCTYPE html>
<html lang="en">
<head>
<title>JS Sequence Test</title>
<script src="jquery-1.6.1.min.js"></script>
</head>
<body>
<div id="green-box" style="width:100px;height:100px;background:#484;margin:0 0 10px 0;display:none">
</div>
@chuckbergeron
chuckbergeron / hack-1.md
Created September 15, 2011 17:06 — forked from timuruski/hack-1.md
Hack Night project

Basic Hack-Night Arbiter

  • User can start a hack-night with a list of emails
  • Emails are sent to users with URL to provide availability
  • Users can mark their availabilities per night for 2-week window
  • Once all availabilities are provided, a series of overlapping nights is presented

Advanced topics might include deciding on a topic, each hack could have a silly name to make it memorable after large amounts of drinking.

Requirements

@chuckbergeron
chuckbergeron / external_resource.rb
Created November 24, 2011 18:18
ExternalResource
module ExternalResource
# TODO: handle: Timeout::Error (time's up!):
# Requires a block with the HTTPClient.get call or what-have-you
# see InvitationRequestsController for details
def self.load( name = "" )
retries = 12
total = retries
# Faker stuff for dev
if Rails.env.development?
require "faker"
%w[ Event Recipe ].each { |const| Object.const_get( const ).delete_all }
# Standard MEEZ Events
20.times do
e = Event.create( {
:name => Faker::Name.name,
@chuckbergeron
chuckbergeron / announcements_controller.rb
Created January 19, 2012 20:58
Append to an array, create the array first if it doesn't already exist
class AnnouncementsController < ApplicationController
# Creates an array (if needed) and stores that array in the session so we know which
# announcements the current_user has seen
#
# @todo: Add test
#
def hide
( session[:announcement_ids] ||= [] ) << params[:id]
@chuckbergeron
chuckbergeron / .bash_profile
Created January 30, 2012 20:46
Add Git branch to terminal (CLI) output
# Customize Prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\[\033[01;30m\]\u@\h\[\033[m\] : \[\033[01;34m\]\w\[\033[m\] \[\033[31m\]\$(parse_git_branch) \[\033[00m\]\$ "
@chuckbergeron
chuckbergeron / ability.rb
Created February 9, 2012 04:04
CanCan is a gobbledigook.
# VERSION 1:
can [ :create, :read, :download ], Attachment do |attachment|
user.can? :read, attachment.attachable
end
can [ :update, :destroy ], Attachment do |attachment|
user.administrator? or attachment.try( :user_id ) == user.id
end
# VERSION 2:
can do |action, subject_class, subject|