Skip to content

Instantly share code, notes, and snippets.

View ernie's full-sized avatar

Ernie Miller ernie

View GitHub Profile
@ernie
ernie / sanity-score
Last active July 18, 2020 10:28
Here's a little something to run in your Rails app's directory
#!/bin/sh
echo $(
find app/controllers -path app/controllers/concerns -prune -o -type f | wc -l
) / $((
$(egrep -r -l '<\s*ActiveRecord::Base' app/models | wc -l)
+ $(
(
[ -d app/models/concerns ] &&
find app/models/concerns -type f | wc -l
@ernie
ernie / serialization.rb
Created May 29, 2015 12:50
Serialization issue with Rails and jsonb
#!/usr/bin/env ruby
gem 'activerecord'
gem 'minitest'
require 'active_record'
require 'minitest/autorun'
ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
database: 'playground'
@ernie
ernie / GoDaddy CLI
Created April 6, 2011 15:45
If GoDaddy did CLI domain registration...
$ godaddy buy wynn.fm
-- Reading CC Info from .godaddy...
-- THANK YOU FOR PURCHASING YOUR DOMAIN WITH GODADDY!
-- WHILE OUR SERVERS THINK ABOUT REGISTERING YOUR DOMAIN
-- NAME, PLEASE GIVE CAREFUL CONSIDERATION TO THE
-- FOLLOWING SPECIAL OFFERS!!!
Would you like to also register the following and SAVE 64%?
wynn.net
@ernie
ernie / delegate.rb
Last active May 31, 2016 10:39
An alternate take on the delegation class macro provided by ActiveSupport. Updated with Ruby 2.0's caller_locations.
#!/usr/bin/env ruby
class Module
private
def delegate(*args)
dest, prefix = _extract_valid_delegation_options(args.pop)
_define_delegators(caller_locations.first, prefix, dest, args)
end
@ernie
ernie / venture.conf
Created April 21, 2016 13:29
Sample nginx config for a Venture (https://github.com/ernie/venture) server
server {
listen 80;
server_name venture.mydomain.com;
return 301 https://venture.mydomain.com$request_uri;
}
server {
listen 443 ssl;
server_name venture.mydomain.com;
#!/bin/bash
# ... some resources regarding escape sequences ...
# man console_codes
# http://en.wikipedia.org/wiki/ANSI_escape_code
# http://rtfm.etla.org/xterm/ctlseq.html
# http://linuxgazette.net/137/anonymous.html
# http://wiki.archlinux.org/index.php/Color_Bash_Prompt
# http://www.comptechdoc.org/os/linux/howlinuxworks/linux_hlvt100.html
# http://pushpopnil.info/post/804629866/zsh-cursor-color-vi-mode
@ernie
ernie / reorder.rb
Created September 6, 2013 19:20
So, I was in the process of writing this code today, and went on a wild goose chase due to this weird error message. I'd expected to see the nil come back from String#index, and give a different error, but no NilClass to be found in this error. String isn't even a type that String#index can return. It should only return a Fixnum or nil. Instead:…
#!/usr/bin/env ruby
require 'minitest/autorun'
class Reorder
SINGLE_CHAR = /./
def initialize(word, order)
@word, @order = word, order
end
@ernie
ernie / dot_context.rb
Created May 14, 2013 18:22
Multistache! A multipass rendering example for Mustache.
class DotContext < String
def initialize(val = '.')
val = '.' # Ensure we're always a dot
super
freeze
end
def to_s
self
@ernie
ernie / dance.rb
Created September 23, 2012 19:59
Dependency Injection
#!/usr/bin/env ruby
require './dancer'
require './gangnam_style'
dancer = Dancer.new('PSY', GangnamStyle.new)
dancer.dance!
@ernie
ernie / call_tracker.rb
Created September 23, 2012 19:57
Injection.rb
#!/usr/bin/env ruby
require './injection'
require 'pry'
class CallTracker < BasicObject
attr_reader :tracked_calls
def initialize
@tracked_calls = ::Hash.new { |h, k| h[k] = 0 }