Skip to content

Instantly share code, notes, and snippets.

View indirect's full-sized avatar

André Arko indirect

View GitHub Profile
var setTextMeasure = function (contentElement, targetMeasure, maxSize, minSize) {
if (!contentElement) contentElement = document.createElement('p');
if (!targetMeasure) targetMeasure = 66;
if (!maxSize) maxSize = 16;
if (!minSize) minSize = 9;
var sizer = contentElement.cloneNode();
sizer.style.cssText = 'margin: 0; padding: 0; color: transparent; background-color: transparent; position: absolute;';
require File.expand_path('../../spec_helper', File.dirname(__FILE__))
describe Admin::ForumsController do
describe 'routing' do
# controller only implements #index, #show and #update
specify { get('/admin/forums').should have_routing('admin/forums#index') }
specify { get('/admin/forums/foo').should have_routing('admin/forums#show', :id => 'foo') }
specify { put('/admin/forums/foo').should have_routing('admin/forums#update', :id => 'foo') }
# the remaining RESTful actions aren't recognized
@eventualbuddha
eventualbuddha / seed_file.rb
Created July 9, 2010 01:51
SeedFile, a helper for doing database setup in a Rails 3 app
# Helper class for importing files with records to the database.
class SeedFile
def self.import(path)
new(path).import
end
attr_reader :path
def initialize(path)
@path = Pathname(path)
require 'v8'
class HandlebarsTemplateHandler
def self.js
Thread.current[:v8_context] ||= begin
V8::Context.new do |js|
js.load(File.join(Rails.root, 'vendor', 'javascripts', 'handlebars.js'))
js.eval("Templates = {}")
end
@tenderlove
tenderlove / person_test.rb
Created February 10, 2011 23:04
Use minitest/spec with Rails 3
require 'test_helper'
require 'minitest/autorun'
module Tenderlove
class Spec < MiniTest::Spec
include ActiveSupport::Testing::SetupAndTeardown
include ActiveRecord::TestFixtures
alias :method_name :__name__ if defined? :__name__
self.fixture_path = File.join(Rails.root, 'test', 'fixtures')
@lenary
lenary / gitconfig.ini
Created February 18, 2011 01:21
a special excerpt of my gitconfig
$ git clone github:lenary/guides.git
Cloning into guides...
remote: Counting objects: 255, done.
remote: Compressing objects: 100% (216/216), done.
remote: Total 255 (delta 111), reused 163 (delta 35)
Receiving objects: 100% (255/255), 1.49 MiB | 564 KiB/s, done.
Resolving deltas: 100% (111/111), done.
$ cd guides
$ git remote -v
module Test
module Unit
TestCase = RSpec::Core::ExampleGroup
end
end
class Test::Unit::TestCase
def self.inherited(host)
host.set_it_up host.name.gsub(/(Spec|Test)/,'')
def host.method_added(name)
@indirect
indirect / better_logger.rb
Created July 19, 2011 07:00
Rails 3 logs with severity and PIDs
# You must require this file in application.rb, above the Application
# definition, for this to work. For example:
#
# # Syslog-like Rails logs
# if Rails.env.production?
# require File.expand_path('../../lib/better_logger', __FILE__)
# end
#
# module MyApp
# class Application < Rails::Application
@omz
omz / gist:1102091
Created July 24, 2011 01:40
Creating arbitrarily-colored icons from a black-with-alpha master image (iOS)
// Usage example:
// input image: http://f.cl.ly/items/3v0S3w2B3N0p3e0I082d/Image%202011.07.22%2011:29:25%20PM.png
//
// UIImage *buttonImage = [UIImage ipMaskedImageNamed:@"UIButtonBarAction.png" color:[UIColor redColor]];
// .h
@interface UIImage (IPImageUtils)
+ (UIImage *)ipMaskedImageNamed:(NSString *)name color:(UIColor *)color;
@end
@mitchellh
mitchellh / gist:1171262
Created August 25, 2011 17:44
They see me wiresharkin'... they hatin'...
#!/usr/bin/env python
"""
This Python scripts listens for all HTTP requests to the
Turntable CDNs and downloads the file requested into the
current directory.
Disclaimer: This is a proof of concept. The author of this
script is not responsible for how this is used.
"""