Skip to content

Instantly share code, notes, and snippets.

View szalansky's full-sized avatar
🎯
Focusing

szalansky

🎯
Focusing
View GitHub Profile
@lporras
lporras / people_controller.rb
Created December 12, 2011 18:01 — forked from enthal/people_controller.rb
simple rails rsepc testing that devise before_filter :authenticate_user! covers controller actions
class PeopleController < ApplicationController
before_filter :authenticate_user!, :except => [:index, :show]
...
end
@rakhmad
rakhmad / clojure.md
Created April 17, 2012 15:55
Setting Up Clojure on OS X

Setting Up Clojure on OS X

I spent a lot of time trying to find a pretty optimal (for me) setup for Clojure… at the same time I was trying to dive in and learn it. This is never optimal; you shouldn't be fighting the environment while trying to learn something.

I feel like I went through a lot of pain searching Google, StackOverflow, blogs, and other sites for random tidbits of information and instructions.

This is a comprehensive "what I learned and what I ended up doing" that will hopefully be of use to others and act as a journal for myself if I ever have to do it again. I want to be very step-by-step and explain what's happening (and why) at each step.

Step 1: Getting Clojure (1.3)

@paneq
paneq / extend.rb
Created August 6, 2012 10:15
Prevent including module if target already has some of its instance methods
module A
extend SelfishModule
def abc; end
end
module B
extend SelfishModule
def bcd; end
end
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@szalansky
szalansky / hash.rb
Created October 5, 2012 13:36 — forked from teamon/hash.rb
# Instead of:
# hash[:a].try(:[], :b).try(:[], :c).try(:[], :d)
# you can write
# hash[:a, :b, :c, :d]
class Hash
# h = {:a => {:b => {:c => 1}}}
# p h[:a] # => {:b => {:c => 1}}
# p h[:a, :b] # => {:c => 1}
# p h[:a, :b, :c] # => 1
@zedtux
zedtux / web_steps.rb
Created November 14, 2012 19:29
Capybara 2.0 web_steps.rb file to avoid "Ambiguous match, found N elements matching xpath" (Capybara::Ambiguous)
# TL;DR: YOU SHOULD DELETE THIS FILE
#
# This file was generated by Cucumber-Rails and is only here to get you a head start
# These step definitions are thin wrappers around the Capybara/Webrat API that lets you
# visit pages, interact with widgets and make assertions about page content.
#
# If you use these step definitions as basis for your features you will quickly end up
# with features that are:
#
# * Hard to maintain
@freakhill
freakhill / list_comprehension.rb
Last active December 17, 2015 06:19
having fun with "haskell like list comprehension in ruby" - https://gist.github.com/andkerosine/3356675
#!/usr/bin/env ruby-head
class VeryBasicObject < BasicObject
undef :==
undef :!=
undef :!
end
class Captured < VeryBasicObject
def method_missing meth, *args
@mpeteuil
mpeteuil / rubocop_pre_commit_hook
Created August 3, 2013 17:44
Ruby style guide git pre-commit hook using Rubocop as the style guide checker. Only runs on staged ruby files that have been added and/or modified.
#!/usr/bin/env ruby
require 'english'
require 'rubocop'
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
@the-undefined
the-undefined / attr_capcessor.rb
Created August 20, 2013 20:54
Take advantage of metaprogramming and avoid littering the logic of your code with `define_method` declarations.
module Cappy
def attr_capcessor attr
attr_reader attr.to_sym
define_method "#{attr}=" do |value|
instance_variable_set("@#{attr}", value.to_s.upcase)
end
end
end
@telent
telent / gist:9742059
Last active May 8, 2024 11:36
12 factor app configuration vs leaking environment variables
App configuration in environment variables: for and against
For (some of these as per the 12 factor principles)
1) they are are easy to change between deploys without changing any code
2) unlike config files, there is little chance of them being checked
into the code repo accidentally
3) unlike custom config files, or other config mechanisms such as Java