Skip to content

Instantly share code, notes, and snippets.

@phillbaker
phillbaker / DataManager.h
Created August 7, 2012 15:43 — forked from rojotek/DataManager.h
Core Data singleton manager class capable of being run from a static library - updated for ARC.
// DataManager.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
extern NSString * const DataManagerDidSaveNotification;
extern NSString * const DataManagerDidSaveFailedNotification;
@interface DataManager : NSObject {
}
@phillbaker
phillbaker / gist:3918047
Created October 19, 2012 12:39
DataMapper semi-equivalent of ActiveRecord's reflect_on_all_associations method
# Originally http://pastie.org/pastes/233178
def reflect_on_all_associations
# Datamapper, you're crazy...
relationships.map { |name, relationship|
#TODO :has_and_belongs_to_many
if relationship.options[:min].nil?
macro = :belongs_to
if relationship.options[:class_name]
# In a belongs_to, the side with the class name uses
# the parent model, but child key for the foreign key...
@phillbaker
phillbaker / index.html
Last active October 12, 2015 02:57
HTML5 starter with boostrap cdn + jquery cdn
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
<style>
/*Styles*/
</style>
@phillbaker
phillbaker / lmu.m
Created November 17, 2012 20:23
Macbook ambient light sensor data
// Compile with $ gcc -o lmutracker lmu.m -framework IOKit -framework CoreFoundation -framework Foundation
// Usage: ./lmu [now]
// Prints out the value from the ambient light sensor and the back light LED every 1/10 of a second. Optionally print just one value.
// Inspired by the code found at
// http://google-mac-qtz-patches.googlecode.com/svn-history/r5/trunk/AmbientLightSensor
// and http://osxbook.com/book/bonus/chapter10/light/
// and http://en.wikipedia.org/wiki/Wikipedia:Reference_desk/Archives/Computing/2010_February_10#Mac_OS_X_keyboard_backlight_drivers
// http://forums.macrumors.com/showthread.php?t=1133446
#include <stdio.h>
@phillbaker
phillbaker / Gemfile
Last active December 11, 2015 07:18
Rails Gemfile
source 'https://rubygems.org'
RAILS_VERSION = '~> 3.2.8'
gem 'activesupport', RAILS_VERSION, :require => 'active_support'
gem 'actionpack', RAILS_VERSION, :require => 'action_pack'
gem 'actionmailer', RAILS_VERSION, :require => 'action_mailer'
gem 'activeresource', RAILS_VERSION, :require => 'active_resource'
gem 'railties', RAILS_VERSION, :require => 'rails'
gem 'tzinfo', '~> 0.3.32'
@phillbaker
phillbaker / Gemfile
Last active December 13, 2019 13:28
Sinatra-Assetpack + LESS (Twitter Bootstrap) demo
source :rubygems
gem 'sinatra'
gem 'sinatra-assetpack'
gem 'json'
gem 'therubyracer'
gem 'less'
// jQuery Plugin ifExists
// v0.0.1
// @phillbaker
//
// To be used if you want to call a (non-core jquery) function on the result of a jquery selector.
//
// Example:
//
// html:
// <button id="start">Start</button>
require 'rubygems'
require 'bundler/setup'
require 'eventmachine'
require 'em-http-request'
EM.run do
work = 0..1000
concurrent_workers = 100
EM::Iterator.new(work, concurrent_workers).each do |num, em_iter|
@phillbaker
phillbaker / 0_setup_rails_backbone.sh
Last active December 27, 2015 02:29
Rails + Backbone setup
mkdir -p app/assets/javascripts/backbone/lib/ \
app/assets/javascripts/backbone/models/ \
app/assets/javascripts/backbone/routers/ \
app/assets/javascripts/backbone/templates/ \
app/assets/javascripts/backbone/views/
touch app/assets/javascripts/backbone/lib/.keep \
app/assets/javascripts/backbone/models/.keep \
app/assets/javascripts/backbone/routers/.keep \
app/assets/javascripts/backbone/templates/.keep \
app/assets/javascripts/backbone/views/.keep
@phillbaker
phillbaker / README.md
Last active November 1, 2017 17:44
A micro Gem for rspec controller spec default parameters.