Instantly share code, notes, and snippets.

View db.rake
namespace :db do
namespace :structure do
task :dump => :environment do
# Can add more dump options to ~/.my.cnf:
#
# [mysqldump]
# skip-comments
#
command = %q{perl -i -pe's/AUTO_INCREMENT=\d+\s//' %s} % Rails.root.join("db/structure.sql")
sh command, :verbose => false do |ok, res|
View bad.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>A</key>
<key>B</key>
<string>sshaw</string>
<string>DDEX</string>
</dict>
</plist>
View app-service-view-examples.rb
module PropertyManagement
class OnBoarding
#
# **********
# Setup
# **********
#
# ActiveRecord: None
# ActiveModel+freeze: None
# Hash: None, but param massaging may be necessary unless everything matches ActiveRecord
View pick.js
// https://gist.github.com/sshaw/e21c9a7c82aff15359804e90ea7042a3
// Pluck truthy properties and functions from an Array of Objects
//
// var a = [ {id: 123}, {id: 0}, {id: false}, {id: function() { return 'foo' }} ]
// pick('id', a) returns [123, 'foo']
// var f = pick('id')
// f(a)
var pick = function(property, array) {
var picker = function(_array) {
return _array.reduce(function(acc, v) {
View form_fields.rb
module FormFields
def self.included(klass)
klass.class_eval do
def self.fields(*args)
args.flatten!
attr_accessor(*args)
@@fields = args.map(&:to_sym)
end
end
end
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Slack Message to Emoji</title>
<script src="slack.js"></script>
<style>
h1 {
text-align: center;
}
View convert-phone-number.rb
# https://gist.github.com/sshaw/29d6f7379771e3b4596e228b626bcf9a
def convert(chr)
chr = chr.upcase
# subtract "A"
n = (chr.ord - 65) / 3
# account for #7 & #9 which have 4 chars
n -= 1 if chr == "S".freeze || chr == "V".freeze || chr >= "Y".freeze
(n + 2).to_s
end
View template.rb
require "erb"
class Template
def initialize(template)
@__template = ::ERB.new(template, nil, "-")
end
def render(__vars = {})
__b = binding
__names = []
View to_pluralizer.rb
require "active_support/core_ext/string/inflections"
class String
def to_pluralizer
->(*a) { pluralize(*a) }
end
end
__END__
CUSTOMER = "customer".to_pluralizer
View refills_flash.rb
# Helper to render Bourbon/Neat Refills style flash messages
# https://gist.github.com/sshaw/bc27941c20f0adbfa5b5c9c57da095d7
module RefillsFlash
FLASH_KEYS = [:success, :notice, :error, :alert]
def flash_messages
FLASH_KEYS.inject("") do |html, name|
if flash[name]
html << content_tag(:div, :class => "flash-#{name}") {
content_tag :span, flash[name]