Skip to content

Instantly share code, notes, and snippets.

View alexrothenberg's full-sized avatar

Alex Rothenberg alexrothenberg

View GitHub Profile
@alexrothenberg
alexrothenberg / gist:9393607
Created March 6, 2014 16:31
MRI/JRuby/Rubinius discrepency
MRI - detect with a lambda complains about 2 parameters but map works
$ irb
2.1.1 :001 > lambda = ->(word, index) { word.length == 3 }
=> #<Proc:0x007fb52d00ab38@(irb):1 (lambda)>
2.1.1 :002 > %w(Hi there how are you).each_with_index.detect &lambda
ArgumentError: wrong number of arguments (1 for 2)
from (irb):1:in `block in irb_binding'
from (irb):2:in `each'
from (irb):2:in `each_with_index'
@alexrothenberg
alexrothenberg / Rakefile
Created March 19, 2014 14:10
stub api calls for rubymotion calabash tests
Motion::Project::App.setup do |app|
app.info_plist['API_BASE_URL'] = ENV['API_BASE_URL'] || 'http://api.myserver.com'
end
task :cucumber => [:stub, :'build:simulator', :'calabash:run']
task :stub do
ENV['API_BASE_URL'] = 'http://stub.example.com'
end
### Keybase proof
I hereby claim:
* I am alexrothenberg on github.
* I am alexrothenberg (https://keybase.io/alexrothenberg) on keybase.
* I have a public key whose fingerprint is BD37 11A2 4CA9 9DC3 FE1F 1F4B E978 24DB 3CDB 639F
To claim this, I am signing this object:
@alexrothenberg
alexrothenberg / gist:8d50d3302ebe234e94cf
Created December 19, 2014 16:24
Simple caching for angular.js
"use strict";
angular.module('gatewayApp')
.factory('Cache', [function(){
var cache = {};
var _get = function(key) {
var cacheHit = cache[key];
if (_exists(cacheHit) && _notExpired(cacheHit)) {
return cacheHit.value;
} else {
'use strict';
describe('Offers : controller', function(){
beforeEach(module('client'));
var $scope,
genericService;
class Person #existing implementation
def find_by_name name
filter = adapter.create_equality_filter('uid', "*#{name}*")
results = find(:base => '', :attributes => attribute_mapping.values, :filter => filter)
build_array_of_people_from results
end
def find_by_exact_name name
filter = adapter.create_equality_filter('uid', "#{name}")
results = find(:base => '', :attributes => attribute_mapping.values, :filter => filter)
if (results.size > 1)
def to_factory model
model.columns.each do |c|
if c.null == false
value = case c.type
when :integer
"7"
when :string
"'hi'"
when :boolean
'false'
# Install admin_data
plugin 'admin_data', :git => 'git://github.com/alexrothenberg/admin_data.git'
# In DOS type
### cd \workshop
### mkdir ruby_exercises
### cd ruby_exercises
# Open the e editor
### e .
# Create a new file called string_exercise.rb