Skip to content

Instantly share code, notes, and snippets.

View cookrn's full-sized avatar
👻

Ryan Cook cookrn

👻
View GitHub Profile
@cookrn
cookrn / terms_of_service.markdown
Created March 12, 2012 17:16 — forked from devver/terms_of_service.markdown
Antiqua, Ltd. Terms of Service

Terms of Service

Last revised on 03-12-2012

The Gist

Antiqua, Ltd. operates the Antiqua.IO service, which we hope you use. If you use it, please use it responsibly. If you don't, we'll have to terminate your account.

For paid accounts, you'll be charged on a monthly basis. You can cancel anytime, but there are no refunds.

@cookrn
cookrn / fix.rb
Created March 14, 2012 15:42
Ruby Script to Remove File FOREVER From Git Repo
# Make a backup first!
# Place at the root of the desired git repo
# Run w/ commit SHA as first argument e.g. ruby fix.rb 57415b9c864e4128dca805b4a8ad7b7e59281ac6
#
# All files in your list will be forever removed from the filesystem and git repo from given
# commit up to HEAD
files = %w(
you.r
list.of
@cookrn
cookrn / links.md
Created March 20, 2012 19:51
How to Create and Apply a Patch w/ Git Across Similar Repositories
@cookrn
cookrn / 00_desc.md
Created April 3, 2012 07:03
Ruby Object Constructors

What the what?!

Ruby objects can be built in a way such that they are easier to use/test/debug from the point of view that if you do not automatically run their intended functionality from the constructor, potential side-effects and bugs can be better examined.

In general, I find it helpful to consider a constructors' purpose constrained only to setting instance-level attributes based on the passed arguments or using pre-defined defaults. Anything outside of that, I would consider setting up a class-level factory method.

Consider creating semantically-named factory style class methods that create an object and then call a specific method.

I find this especially helpful for hand-rolled presenters and worker classes (e.g. for Resque).

@cookrn
cookrn / 00_usage.md
Created April 10, 2012 02:27
A Reasonable `to_map` for `ActiveRecord::Base`

to_map

A to_map function is very useful when you want to convert models to PLAIN OLD DATA. Think presenters, conductors, APIs, JSON, etc...

Installation

Add this monkey-patch to your Rails project and call it on your model instances.

Example Models

class Person
def initialize(name)
@name = name
@fiance = nil
@preferences = []
@proposals = []
end
attr_reader :name, :proposals
attr_accessor :fiance, :preferences
@cookrn
cookrn / instructions.md
Last active March 29, 2017 15:12
Named Screen -- Inspired by @ahoward

Named Screen

A utility inspired by @ahoward that allows screens to be the name of the directory they were spawned from. This is mainly helpful for Terminal/iTerm tabs.

Executing this should rejoin sessions with the same name if they already exist or otherwise create them.

Usage

  1. Place or symlink into your path (I symlink as ns)
  2. Ensure the script is executable
@cookrn
cookrn / minitest_integration.rb
Created May 18, 2012 00:31
Changes that allow the Draper MiniTest/Integration tests to pass
require 'minitest/unit'
require 'minitest/spec'
module MiniTest
class DecoratorSpec < Spec
before do
ApplicationController.new.set_current_view_context
Draper::ViewContext.current.controller.request ||= ActionController::TestRequest.new
Draper::ViewContext.current.request ||= Draper::ViewContext.current.controller.request
Draper::ViewContext.current.params ||= {}
@cookrn
cookrn / out.txt
Created June 23, 2012 05:54
RVM 1.9.3 Ubuntu 12.04 Yaml Make Error
$ cat /usr/local/rvm/log/ruby-1.9.3-p194/yaml/make.log
[2012-06-23 05:51:12] make
CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/bash /usr/local/rvm/src/yaml-0.1.4/config/missing --run aclocal-1.11
cd . && /bin/bash /usr/local/rvm/src/yaml-0.1.4/config/missing --run automake-1.11 --foreign
src/Makefile.am:2: Libtool library used but `LIBTOOL' is undefined
src/Makefile.am:2: The usual way to define `LIBTOOL' is to add `LT_INIT'
src/Makefile.am:2: to `configure.ac' and run `aclocal' and `autoconf' again.
src/Makefile.am:2: If `LT_INIT' is in `configure.ac', make sure
src/Makefile.am:2: its definition is in aclocal's search path.
make: *** [Makefile.in] Error 1
@cookrn
cookrn / _readme.md
Created June 27, 2012 04:19
Compile *.ejs Templates

EJS Compiler

This is used to generate a templates.js file where the keys are template identifiers and the values are the raw, escaped EJS templates.

Templates are semi-compiled server side. Results of compilation are memoized on the client side using Underscore.

This is useful for maintaining multiple template files server-side and compiling them into a client-side script.

This requires the use of the ejs client side library. Requires ejs to be available on window. See: https://github.com/visionmedia/ejs#client-side-support