Skip to content

Instantly share code, notes, and snippets.

View bradhe's full-sized avatar
👋
looking for friendship

Brad Heller bradhe

👋
looking for friendship
  • Berlin
View GitHub Profile
@bradhe
bradhe / basecamp.rb
Created December 29, 2011 08:08
Monkey patch for adding the ability to deliver notifications with messages in from basecamp-wrapper
module Basecamp
class Message
attr_accessor :notify
def to_xml(arg={})
# Little heavy handed but...it does the trick.
doc = Nokogiri::XML(super(arg))
# This doesn't create a "request" element by default, so lets
# create one.
@bradhe
bradhe / basecamp.rb
Created January 8, 2012 21:14
Add support for querying for people that are assigned to a project to basecamp-wrapper.
module Basecamp
class Project
def people
get(:people).map { |h| Basecamp::Person.new(h) }
end
end
end
@bradhe
bradhe / basecamp.rb
Created January 8, 2012 21:45
Add support for querying for people and adding notifications to messages.
module Basecamp
class Message
attr_accessor :notify
def to_xml(arg={})
# Little heavy handed but...it does the trick.
doc = Nokogiri::XML(super(arg))
# This doesn't create a "request" element by default, so lets
# create one.
@bradhe
bradhe / application.rb
Created March 10, 2012 05:07
Generates a set of JavaScript functions that behave very similarly to Rails' named routes. Even plays nice with the assets pipeline.
module Sprockets::Helpers::RailsHelper
require File.join(Rails.root, "app", "helpers", "assets_helper.rb")
include AssetsHelper
end
@bradhe
bradhe / reddit.com.js
Created April 2, 2012 07:28 — forked from built/reddit.com.js
An improvement for the Reddit killer
$(function() {
$('body').empty();
document.title = "REDDIT IS A WASTE OF TIME";
});
1.9.3p125 :009 > "don't feel".match(/(?<word>feel|don't feel)/)
=> #<MatchData "don't feel" word:"don't feel">
@bradhe
bradhe / flip.c
Created May 8, 2012 08:03
Given a string (provided as parameter), randomly flip ONE BIT in it.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void flip(char * str, int len) {
int byte, bit, bias;
char mask;
/* mmm, seeeds */
require 'uri/http'
# Blatently stolen from http://www.simonecarletti.com/blog/2009/04/validating-the-format-of-an-url-with-rails/
#
# Validates whether the value of the specified attribute matches the format of an URL,
# as defined by RFC 2396. See URI#parse for more information on URI decompositon and parsing.
#
# This method doesn't validate the existence of the domain, nor it validates the domain itself.
#
# Allowed values include http://foo.bar, http://www.foo.bar and even http://foo.
@bradhe
bradhe / backbone-patch.js
Created June 7, 2012 18:01
Backbone patch for Rails. Makes it play nice with Rails' verb expectations, adds ability to ignore attributes, adds ability to generate attributes on a callback, and adds ability to specify a format that we want to send back/forth.
(function() {
var methodMap = {
'create': 'POST',
'update': 'PUT',
'delete': 'DELETE',
'read' : 'GET'
};
var getUrl = function(object) {
if (!(object && object.url)) return null;
@bradhe
bradhe / redis.rake
Created June 14, 2012 16:50
Rake task for managing Redis, including connecting via CLI in current enviro.
require 'open3'
namespace :redis do
task :cli do
redis_config = File.expand_path('../../../config/redis.yml', __FILE__)
config_data = YAML.load_file(redis_config)
uri = URI.parse(config_data[ENV['RAILS_ENV'] || 'development'])
cli = File.expand_path('/path/to/redis-cli', __FILE__)