Skip to content

Instantly share code, notes, and snippets.

View mecampbellsoup's full-sized avatar

Matt Campbell mecampbellsoup

View GitHub Profile
@mecampbellsoup
mecampbellsoup / ruby_lisp.md
Created January 29, 2014 17:55
Trivial Ruby implementation of Lisp, where ::cons creates the list, and ::car / ::cdr return the head and tail, respectively.
module Lisp
  def cons(x,y)
    -> (m) { m.call(x,y) }
  end

  def car(z)
    z.call(-> (p, q) { p })
  end
@mecampbellsoup
mecampbellsoup / Setup.hs
Created February 5, 2014 20:53
stackbuilders.com cabal package unable to import Paths_stackbuilders (in order to access getDataDir which is imported in that module)...
import Distribution.Simple
import Distribution.PackageDescription
import Distribution.PackageDescription.Parse (readPackageDescription)
import Distribution.Verbosity (silent)
version <- fmap (showVersion . pkgVersion . package . packageDescription)
$ readPackageDescription silent "stackbuilders.com.cabal"
@mecampbellsoup
mecampbellsoup / ad_rank_spec.rb
Created March 12, 2014 19:23
Rails model spec for FactoryGirl behavior...
describe AdRank do
describe 'Factories' do
it 'has a couple of factories that return valid instances' do
build(:ad_rank).should be_valid
end
end
end
def snail(array)
array.empty? ? [] : array.shift + snail(array.transpose.reverse)
end
@mecampbellsoup
mecampbellsoup / blog_post.md
Last active August 29, 2015 14:01
ActiveRecord `super` + Ruby `tap` = magic!

Let's say you have a books table and corresponding model with a title and author column...

Your challenge: come up with a way to present the title and author together for every book in your library. In other words, normalize the author and title data for each book.

How can we achieve this for consistent formatting for our library, without:

  • using any ActiveRecord callbacks;
  • overwriting the setter methods ActiveRecord dynamically dispatches by inspecting the schema file; or
  • making things look messy & gross (i.e one-liner if possible!)

What is SOAP?

  1. 100% XML-based protocol
  2. 100%
  3. 100% good smelling!

Let's talk about XML first

Attribute type modifier for both address blocks

@mecampbellsoup
mecampbellsoup / tree.txt
Created May 19, 2014 14:38
ZSH output running `tree` from `/usr/local/Cellar/zsh/5.0.5`
⇒ tree .
.
├── ChangeLog
├── INSTALL_RECEIPT.json
├── LICENCE
├── NEWS
├── README
├── bin
│   ├── zsh
│   └── zsh-5.0.5
#compdef git git-cvsserver git-receive-pack git-upload-archive git-upload-pack git-shell gitk tig
# Some parts of this completion's behaviour are configurable:
#
# Say you got your own git sub-commands (git will run a program `git-foo'
# when you run "git foo") and you want "git f<tab>" to complete that sub
# commands name for you. You can make that sub-command know to the completion
# via the user-command style:
#
# % zstyle ':completion:*:*:git:*' user-commands foo:'description for foo'
#compdef git gitk
# zsh completion wrapper for git
#
# Copyright (c) 2012-2013 Felipe Contreras <felipe.contreras@gmail.com>
#
# You need git's bash completion script installed somewhere, by default it
# would be the location bash-completion uses.
#
# If your script is somewhere else, you can configure it on your ~/.zshrc:
# Find all files/directories from current directory recursively down into all folders
# USE: ff filename (ex: "ff '*spec.rb'" or "ff *spec.rb"). If can't find file,
# "cd .." into directory above current one, then try this again.
function ff {
find . -name $1
}
# Like ff. Finds only files. Excludes directories.
# USE: f filename
function f {