Skip to content

Instantly share code, notes, and snippets.

View whalec's full-sized avatar

Cameron Barrie whalec

View GitHub Profile
@whalec
whalec / Class method mocking?
Created July 20, 2011 09:37
Thoughts on how the API for class mocking in ObjectiveC should look
// I'd think that if NSString doesn't get sent stringWithFormat here before the end of this test, it should raise an error? It's mocking after all, not stubbing.
- (void)testClassMethodMocking {
[NSString mock:@selector(stringWithFormat:) andReturn:@"someString"];
NSString *string = [NSString stringWithFormat@"abc123"];
GHAssertEqual(string, @"someString", "NSString hasn't been mocked")
}
// This guy wouldn't raise.
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /app http://foo.heroku.com
ProxyPassReverse /app http://foo.heroku.com
@whalec
whalec / gist:1015901
Created June 9, 2011 02:12
Not tested. Probably doesn't even run. Hacked together jquery plugin. Now plus ninja tip
(function($) {
$.fn.credit_card = function(opts) {
this.opts = opts
this.change(function(){
var val = $(this).val()
if (val[0] == "4"){
$(opts.visa).addClass("highlighted");
return false;
}
@whalec
whalec / gist:944098
Created April 27, 2011 11:35
horrid sql
shops = self.find_by_sql(["
SELECT s.*,
make_rating(user_rating.avg, admin_rank.avg) AS rating,
admin_rank.avg AS admin_rank,
enumerable_rating.rank AS ranking
FROM categories_shops cs,
shops AS s
LEFT OUTER JOIN
-- Take Users ratings and join them
(SELECT s.id, avg(r.rating) AS avg
@whalec
whalec / Help bubble
Created April 14, 2011 21:52
A help bubble implementation in javascript from about 4 years ago.
$.fn.helpBubble = function() {
var widget = $(this);
$(this).prepend("<div class=\"information\"><a href='javascript:void(0);'><img src='/images/information.png' /></a></div>");
var info = $(".information");
info.css({
"position": "absolute",
"margin" : "-1px 0 0 " + (widget.innerWidth() - 17) + "px"
});
var info = widget.find(".infomation");
var title = widget.attr("title");
☠ Can view all articles in a sector
NativeException - com.gargoylesoftware.htmlunit.ScriptException: Exception invoking jsxFunction_getComputedStyle
(druby://127.0.0.1:55134) /usr/local/Cellar/gems/1.8/gems/akephalos-0.2.5/lib/akephalos/client.rb:76:in `visit'
(druby://127.0.0.1:55134) org/jruby/RubyKernel.java:2042:in `send'
(druby://127.0.0.1:55134) file:/usr/local/Cellar/gems/1.8/gems/jruby-jars-1.6.0/lib/jruby-stdlib-1.6.0.jar!/META-INF/jruby.home/lib/ruby/1.8/drb/drb.rb:1593:in `perform_without_block'
(druby://127.0.0.1:55134) file:/usr/local/Cellar/gems/1.8/gems/jruby-jars-1.6.0/lib/jruby-stdlib-1.6.0.jar!/META-INF/jruby.home/lib/ruby/1.8/drb/drb.rb:1553:in `perform'
(druby://127.0.0.1:55134) file:/usr/local/Cellar/gems/1.8/gems/jruby-jars-1.6.0/lib/jruby-stdlib-1.6.0.jar!/META-INF/jruby.home/lib/ruby/1.8/drb/drb.rb:1627:in `main_loop'
(druby://127.0.0.1:55134) org/jruby/RubyKernel.java:1417:in `loop'
(druby://127.0.0.1:55134) file:/usr/local/Cellar/gems/1.8/gems/jruby-jars-1.6.0/lib/jru
>> Image.facets
NoMethodError: undefined method `title' for "finance":String
from /usr/local/Cellar/gems/1.8/gems/thinking-sphinx-2.0.1/lib/thinking_sphinx/facet.rb:107:in `send'
from /usr/local/Cellar/gems/1.8/gems/thinking-sphinx-2.0.1/lib/thinking_sphinx/facet.rb:107:in `translate'
from /usr/local/Cellar/gems/1.8/gems/thinking-sphinx-2.0.1/lib/thinking_sphinx/facet.rb:80:in `value'
from /usr/local/Cellar/gems/1.8/gems/thinking-sphinx-2.0.1/lib/thinking_sphinx/facet_search.rb:125:in `add_from_results'
from /usr/local/Cellar/gems/1.8/gems/thinking-sphinx-2.0.1/lib/thinking_sphinx/search.rb:273:in `each_with_match'
from /usr/local/Cellar/gems/1.8/gems/activesupport-3.0.5/lib/active_support/callbacks.rb:400:in `each_with_index'
from /usr/local/Cellar/gems/1.8/gems/thinking-sphinx-2.0.1/lib/thinking_sphinx/search.rb:272:in `each'
from /usr/local/Cellar/gems/1.8/gems/thinking-sphinx-2.0.1/lib/thinking_sphinx/search.rb:272:in `each_with_index'
@implementation InspectionFollowupDateToPropertyMigration
- (BOOL)createRelationshipsForDestinationInstance:(NSManagedObject *)source entityMapping:(NSEntityMapping *)mapping
manager:(NSMigrationManager *)manager error:(NSError **)error
{
NSMutableSet *inspections = [source valueForKey:@"inspections"];
for (id inspection in inspections)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
>> re = Course.search "Short Course", :conditions => {:categories_facet => "category-2"}
>> re.each{|r| p r.categories.map{|c| c.index_slug}.include?("category-2")}
true
false
true
false
false
false
false
>> Course.make
ActiveRecord::RecordInvalid: Validation failed: Index slug has already been taken
from /usr/local/Cellar/gems/1.8/gems/activerecord-3.0.3/lib/active_record/validations.rb:49:in `save!'
from /usr/local/Cellar/gems/1.8/gems/activerecord-3.0.3/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
from /usr/local/Cellar/gems/1.8/gems/activerecord-3.0.3/lib/active_record/transactions.rb:242:in `save!'
from /usr/local/Cellar/gems/1.8/gems/activerecord-3.0.3/lib/active_record/transactions.rb:289:in `with_transaction_returning_status'
from /usr/local/Cellar/gems/1.8/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
from /usr/local/Cellar/gems/1.8/gems/activerecord-3.0.3/lib/active_record/transactions.rb:204:in `transaction'
from /usr/local/Cellar/gems/1.8/gems/activerecord-3.0.3/lib/active_record/transactions.rb:287:in `with_transaction_returning_status'
from /usr/local/Cellar/gems/1.8/gems/activerecord-3.0.3/lib/active_recor