Skip to content

Instantly share code, notes, and snippets.

View johnnymo87's full-sized avatar

Jonathan Mohrbacher johnnymo87

View GitHub Profile
@johnnymo87
johnnymo87 / gist:98388c9bc295bbb953ca
Created November 15, 2014 18:35
RSpec 2.99 deprecation warnings
Deprecation Warnings: [35/1389]
Use of rspec-core's `its` method is deprecated. Use the rspec-its gem instead. Called from /Users/johnnymo87/ruby/LocalSupport/spec/mailers/admin_mailer_spec.rb:6:in `block in <top (required)>'.
Use of rspec-core's `its` method is deprecated. Use the rspec-its gem instead. Called from /Users/johnnymo87/ruby/LocalSupport/spec/mailers/admin_mailer_spec.rb:7:in `block in <top (required)>'.
Use of rspec-core's `its` method is deprecated. Use the rspec-its gem instead. Called from /Users/johnnymo87/ruby/LocalSupport/spec/mailers/admin_mailer_spec.rb:8:in `block in <top (required)>'.
Too many uses of deprecated 'Use of rspec-core's `its` method'. Pass `--deprecation-out` or set `config.deprecation_stream` to a file for full output.
`and_return` on a negative message expectation is deprecated. Called from /Users/
@johnnymo87
johnnymo87 / gist:4771101448d2849af3f4
Last active August 29, 2015 14:07
Function.prototype.bind
// without Function.prototype.bind
window.user = {
data: [
{name:"T. Woods", age:37},
{name:"P. Mickelson", age:43}
],
clickHandler:function(obj) {
return function(e) {
e.preventDefault();
var randomNum = ((Math.random() * 2 | 0) + 1) - 1;
class TwitterFetcher
include Sidekiq::Worker
include Sidetiq::Schedulable
recurrence { minutely(5) }
def perform
# your main method here
end
end
@johnnymo87
johnnymo87 / gist:fba71b4371fa9057c7fb
Last active August 29, 2015 14:02
js letter shifter
var str = 'argentina';
for(var i = 0; i < str.length; i++) {
if (str[i].match(/[a-y]/i)) {
console.log(String.fromCharCode(str[i].charCodeAt(0) + 1))
} else if (str[i] === 'z') {
console.log('a')
};
};
@johnnymo87
johnnymo87 / sort.js
Last active August 29, 2015 14:02
Table sorting from scratch (with Zepto)
// Uses Zepto (http://zeptojs.com/)
$().ready(function() {
var order = new (function() {
var __front = 1,
__back = -1;
this.front = function() { return __front };
this.back = function() { return __back };
this.switch = function() {
__front = -__front;
@johnnymo87
johnnymo87 / users_controller.rb
Created May 27, 2014 02:52
Proposal for UsersController
# from the discussion here: https://github.com/AgileVentures/WebsiteOne/pull/417/files#discussion_r13060679
class UsersController < ApplicationController
include Youtube
# other methods elided
def show
@user = User.friendly.find(params[:id])
@user.extend Foo
@johnnymo87
johnnymo87 / parens.rb
Last active August 29, 2015 14:01
Exercise 2: Parentheses Balancing
# https://class.coursera.org/progfun-004/assignment/view?assignment_id=4
# Exercise 2: Write a recursive function which verifies the balancing of parentheses in a string
def balance(ary, collected = [])
return collected.length.even? if ary.empty?
char = ary.shift
balance(ary, collected + char.scan(/\(|\)/))
end
require 'minitest/autorun'
@johnnymo87
johnnymo87 / gist:711e1d38e2e5707fda06
Created May 17, 2014 17:38
Finding fixed points
import math.abs
object finding_fixed_points {
val tolerance = 0.0001 //> tolerance : Double = 1.0E-4
def isCloseEnough(x: Double, y: Double) =
abs((x - y) / x) / x < tolerance //> isCloseEnough: (x: Double, y: Double)Boolean
def fixedPoint(f: Double => Double)(firstGuess: Double) = {
def iterate(guess: Double): Double = {
val next = f(guess)
if (isCloseEnough(guess, next)) next
@johnnymo87
johnnymo87 / gist:eea8f9118af338ac46e6
Last active August 29, 2015 14:01
Deconstructing the framework

Deconstructing the framework, by Gary Bernhardt

Single Responsibility Principle - A class should have one, and only one, reason to change.

A Rails controller's reasons to change:

  • Authentication
  • Authorization
  • Wrap HTTP in both directions (in: params & headers; out: status codes & headers)
  • Manipulate your Active Record models
  • Manipulate your database (user.reload)
@johnnymo87
johnnymo87 / user_reports_controller
Created May 7, 2014 17:40
Should I extract this private method into a service?
class UserReportsController < ApplicationController
layout 'full_width', :except => [:invited]
...
def invited
@resend_invitation = true
@invitations = serialize_invitations
render :template => 'user_reports/invited', :layout => 'invitation_table'
end