Skip to content

Instantly share code, notes, and snippets.

@sshaw
sshaw / skye-shaw-s-ruby-is-the-new-perl-guide-to-proc-and-lambda-s-and-some-random-shit.rb
Last active October 7, 2022 03:19
Skye Shaw's Ruby is the New Perl ™️ Guide to Procs and lambdas
View skye-shaw-s-ruby-is-the-new-perl-guide-to-proc-and-lambda-s-and-some-random-shit.rb
# coding: utf-8
# Skye Shaw's Ruby is the New Perl ™️ Guide to Procs and lambda and Some Random Shit
lambda do
p 1
p 2
p 3
end[]
lambda {
@sshaw
sshaw / export-product-metafields.sh
Created January 5, 2022 03:57
Export the metafields of all products in your Shopify store to a JSONL file
View export-product-metafields.sh
#!/bin/bash
#
# Export the metafields for products in your Shopify store to a JSONL file.
# Can be modified to output to a file per product or to text file(s).
# See Shopify Development Tools (sdt) for more infomation.
#
# By ScreenStaring (http://screenstaring.com)
#
#
@sshaw
sshaw / rle.txt
Last active April 5, 2019 12:01
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
3a3b1c1d3e
perl -E'print $2 x $1 while $ARGV[0] =~ /(\d+)(.)/g' 3a3b1c1d3e
aaabbbcdeee
@sshaw
sshaw / db.rake
Last active June 19, 2018 04:52
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
sshaw / bad.plist
Created June 15, 2018 23:07
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" "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 / 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.
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
sshaw / pick.js
Last active June 10, 2017 21:36
JavaScript function to pluck truthy properties and functions from an Array of Objects
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) {
@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
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
@sshaw
sshaw / index.html
Last active April 10, 2017 23:55 — forked from sasharevzin/slack.js
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;
}
@sshaw
sshaw / convert-phone-number.rb
Last active February 26, 2017 02:53
Convert a Vanity Phone Number With Letters to One With Numbers Only
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