Skip to content

Instantly share code, notes, and snippets.

View amiel's full-sized avatar

Amiel Martin amiel

View GitHub Profile
module Foo
class Bar;end
end
module Foo
class Baz
# lookup order: Foo::Baz::Bar, Foo::Bar, Bar
Bar.new # => #<Foo::Bar:...>
end
end
@amiel
amiel / gist:6075112
Created July 24, 2013 22:14
Ruby private weirdness
class Foo
private
attr_accessor :foo
public
def access_foo
foo # => nil # as expected
self.foo # => NoMethodError: private method...
end
@amiel
amiel / whaty_is_my_public_api.rb
Created June 13, 2013 20:59
Discover what methods in a class are actually being used. Either use dependency injection or completely replace your object with this one.
class WhatIsMyPublicApi < BasicObject
def initialize(*arguments)
method_missing('initialize', *arguments)
end
def method_missing(method, *arguments)
::File.open('what_is_my_public_api.log', 'a') do |f|
args = arguments.inspect.gsub(/^\[|\]$/, '')
f.write("#{method}(#{args})\n")
end
@amiel
amiel / no_workie_2.rb
Last active December 18, 2015 11:38
ARC vs GC gotcha example
describe WebService
def test_request(t, path, params, &block)
# Local variable t persists in both callbacks
# However, `block` doesn't make it
@result = nil
WebService.post(path, params) do |result|
@result = result
t.resume
end
@amiel
amiel / smarttrips_api_spec.md
Last active December 18, 2015 03:29
SmartTrips API spec draft

API Spec

POST /api/employers/trips

  • requires HTTP Basic authorization

Attributes

  • user_email -- users email required
import sublime_plugin
import os
class PomodoroStatus(sublime_plugin.EventListener):
# TODO: set up an interval callback on_activated
def update_pomodoro_status(self, view):
f = os.popen('~/Dropbox/dotfiles/bin/pomodoro time')
view.set_status("0_pomodoro_status", f.read())
@amiel
amiel / Charlie.ino
Last active December 16, 2015 04:29
Digispark Charlieplex http://digistump.com/products/13 using this charlieplexing library http://playground.arduino.cc/code/charlieplex
#include <Charlieplex.h>
#define NUMBER_OF_PINS 5
byte pins[] = {0,1,2,3,4};
Charlieplex charlieplex = Charlieplex(pins,NUMBER_OF_PINS);
typedef bool grid[6][5];
int h = 5;
int w = 4;
@amiel
amiel / 1_fat_controller.rb
Last active December 16, 2015 00:48
An oversimplification of some rails best practices over time.
class WidgetsController < ApplicationController
def create
@widget = Widget.new(params[:widget])
if @widget.save
SpamMailer.widget_spam(@widget).deliver
redirect_to widget, notice: 'Widget created'
else
render 'new'
end
@amiel
amiel / gist:5320486
Created April 5, 2013 16:03
Hack to undecorate resource for forms. Regarding https://github.com/gregbell/active_admin/issues/2013
module ActiveAdmin
module ViewHelpers
module FormHelper
def active_admin_form_for(resource, options = {}, &block)
options = Marshal.load( Marshal.dump(options) )
options[:builder] ||= ActiveAdmin::FormBuilder
+ resource = resource.respond_to?(:model) ? resource.model : resource
semantic_form_for resource, options, &block
end
@amiel
amiel / RestKitManager.mm
Last active December 15, 2015 17:10
My RestKit mappings
// I have a RestKitManager.m that holds general methods to help set up mappings and routings
@implementation RestKitManager
- (void)initialize {
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:[AppDelegate appUrlForKey:BASE_URL_KEY]]];
[RKObjectManager setSharedManager:objectManager];