Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sshaw
sshaw / bad.plist
Created June 15, 2018 23:07
Example of Apple Property List (Plist) DTD Validation With xmllint
<?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>
@sshaw
sshaw / greeting.liquid
Last active October 3, 2019 09:37
"Random" Greeting in a Shopify Liquid Template
{% assign name = "sshaw" %}
{% assign greetings = "Hi %s!|Oi %s!|¡Hola %s!" | split: "|" %}
{% assign index = "now" | date: "%s" | modulo: greetings.size %}
{{ greetings[index] | replace_first: '%s', name }}
@sshaw
sshaw / rle.txt
Last active April 5, 2019 12:01
Run-length encoding in Perl. Does not support integers :)
perl -E'print $+[1]-$l,$& and $l=$+[1] while $ARGV[0] =~ /(.)(?!\1)/g' aaabbbcdeee
3a3b1c1d3e
perl -E'print $2 x $1 while $ARGV[0] =~ /(\d+)(.)/g' 3a3b1c1d3e
aaabbbcdeee
@sshaw
sshaw / page_number.gemspec
Last active September 14, 2018 10:29
Ruby utility methods for pagination page and per page that make sure you'll always have a valid number. Use them your controllers or model or anywhere where you process page info. Moved to https://github.com/sshaw/page_number.git
Gem::Specification.new do |s|
s.name = "page_number"
s.version = "0.0.2"
s.date = "2016-09-19"
s.summary = "Utility methods for pagination page and per page that make sure you'll always have a valid number."
s.description =<<-DESC
Utility methods for pagination page and per page that make sure you'll always have a valid number.
Use them your controllers or model or anywhere where you process page info.
DESC
s.authors = ["Skye Shaw"]
@sshaw
sshaw / db.rake
Last active June 19, 2018 04:52
Remove MySQL AUTO_INCREMENT From Rails db:structure:dump
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
sshaw / app-service-view-examples.rb
Last active November 11, 2017 23:12
Examples on the ways to separate an ActiveRecord domain model from UI layer in Rails/Ruby.
module PropertyManagement
class OnBoarding
#
# **********
# Setup
# **********
#
# ActiveRecord: None
# ActiveModel+freeze: None
# Hash: None, but param massaging may be necessary unless everything matches ActiveRecord
@sshaw
sshaw / rusage.rb
Last active October 19, 2017 13:55 — forked from itsderek23/rusage.rb
require 'get_process_mem'
require 'rusage' # gem install rusage
require 'benchmark'
n = 2000
gpm = GetProcessMem.new
Benchmark.bm(10) do |x|
x.report("status:") { n.times do gpm.linux_status_memory end }
# In sshaw version
@sshaw
sshaw / form_fields.rb
Last active August 6, 2017 19:26
Ruby module to help create classes for form parameters (or other things). Also see Class2: https://github.com/sshaw/class2
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
@sshaw
sshaw / pick.js
Last active June 10, 2017 21:36
JavaScript function to pluck truthy properties and functions from an Array of Objects
// 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) {
@sshaw
sshaw / index.html
Last active April 10, 2017 23:55 — forked from sasharevzin/slack.js
<!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;
}