Skip to content

Instantly share code, notes, and snippets.

Skye Shaw sshaw

Block or report user

Report or block sshaw

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
sshaw / rle.txt
Last active Apr 5, 2019
Run-length encoding in Perl. Does not support integers :)
View rle.txt
perl -E'print $+[1]-$l,$& and $l=$+[1] while $ARGV[0] =~ /(.)(?!\1)/g' aaabbbcdeee
perl -E'print $2 x $1 while $ARGV[0] =~ /(\d+)(.)/g' 3a3b1c1d3e
sshaw / db.rake
Last active Jun 19, 2018
Remove MySQL AUTO_INCREMENT From Rails db:structure:dump
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|
sshaw / bad.plist
Created Jun 15, 2018
Example of Apple Property List (Plist) DTD Validation With xmllint
View bad.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
sshaw / app-service-view-examples.rb
Last active Nov 11, 2017
Examples on the ways to separate an ActiveRecord domain model from UI layer in Rails/Ruby.
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
sshaw / pick.js
Last active Jun 10, 2017
JavaScript function to pluck truthy properties and functions from an Array of Objects
View pick.js
// 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) {
sshaw / form_fields.rb
Last active Aug 6, 2017
Ruby module to help create classes for form parameters (or other things). Also see Class2:
View form_fields.rb
module FormFields
def self.included(klass)
klass.class_eval do
def self.fields(*args)
@@fields =
View index.html
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>Slack Message to Emoji</title>
<script src="slack.js"></script>
h1 {
text-align: center;
sshaw / convert-phone-number.rb
Last active Feb 26, 2017
Convert a Vanity Phone Number With Letters to One With Numbers Only
View convert-phone-number.rb
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
sshaw / template.rb
Created Nov 17, 2016
Class for rendering ERB templates using "local variable style" in templates
View template.rb
require "erb"
class Template
def initialize(template)
@__template =, nil, "-")
def render(__vars = {})
__b = binding
__names = []
sshaw / to_pluralizer.rb
Last active Sep 10, 2016
String#to_pluralizer: Create a pluralization Proc from a String
View to_pluralizer.rb
require "active_support/core_ext/string/inflections"
class String
def to_pluralizer
->(*a) { pluralize(*a) }
CUSTOMER = "customer".to_pluralizer
You can’t perform that action at this time.