Skip to content

Instantly share code, notes, and snippets.

View jaydorsey's full-sized avatar
💊
Ruby on Rails

Jay Dorsey jaydorsey

💊
Ruby on Rails
View GitHub Profile
@jaydorsey
jaydorsey / gist:6221c3e93f6ce114db772bcc3bdc628b
Created August 18, 2019 03:28
Generate rdoc documentation for local gems
# Generates docs
gem list | awk '{ print $1 }' | xargs gem rdoc
# Starts server
gem server
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"attributes": {
"additionalProperties": false,
"description": "Members of the attributes object (\"attributes\") represent information about the resource object in which it's defined.",
"patternProperties": {
"^(?!relationships$|links$)\\w[\\w_-]*$": {
"description": "Attributes may contain any valid JSON value."
}
@jaydorsey
jaydorsey / bug_report.rb
Last active July 26, 2019 17:59
jsonapi-resources bug report
begin
require 'bundler/inline'
require 'bundler'
require 'pry'
require 'pry-byebug'
rescue LoadError => e
STDERR.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
@jaydorsey
jaydorsey / tmux-cheatsheet.markdown
Last active May 20, 2019 14:24 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@jaydorsey
jaydorsey / remove.js
Created November 19, 2018 03:13
Scummy facebook advertisers
// Automatically clicks the "Remove" button for all the advertisers
// that are showing from this page: https://www.facebook.com/ads/preferences/?entry_product=ad_settings_screen
// under the "Advertisers who you've interacted with" (who I actually have never
// interacted with), "Who use a contact list added to facebook" (that they likely
// bought 2nd hand because I've never done business with them)
//
// Click the "More" button multiple times to display them all, then run this script
var buttons = document.querySelectorAll("[data-tooltip-content='Remove']");for (i = 0; i< buttons.length; i++) { buttons[i].click();};
@jaydorsey
jaydorsey / post-receive
Created November 2, 2018 20:29
Notify of file changed after git pull
#!/bin/sh -eu
# This file goes in .git/hooks/post-receive
if git diff-tree --name-status -t -r --root HEAD | grep -q 'development.sql'
then
echo "Your db/data/development.sql file changed. You may want to run rails gs:load"
fi
@jaydorsey
jaydorsey / update_gems.sh
Created July 12, 2018 20:09
Update all your local gems
# Don't run this unless you know why you're running this
gem outdated | awk '{print $1}' | xargs gem update $1
@jaydorsey
jaydorsey / fib.rb
Last active July 5, 2018 18:47
Fibonacci enumerator
fib = -> { Enumerator.new { |y| a = b = 1; loop { y << a; a, b = b, a + b } } }
puts fib.call.take(20)
x = fib.call
x.next => 1
x.next => 1
x.next => 2
...
x.next => 13
@jaydorsey
jaydorsey / .zshrc
Created June 5, 2018 18:27
Guard for exercism
# Append this alias to your .zshrc or .bashrc
#
# Run `guardme` from any exercise directory to start guard
# with your custom Guardfile
alias guardme="guard --guardfile ~/exercism/ruby/Guardfile"
@jaydorsey
jaydorsey / run_length.rb
Last active June 19, 2018 15:29
Run length encoding in Ruby
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW".
chars.
chunk_while { |before, after| before == after }.
reduce(String.new) { |memo, group| memo << "#{group.size}#{group.first}" }
rle = -> (str) { str.chars.chunk_while{ |b, a| b == a }.reduce(""){ |m, g| m << g.length.to_s << g.first } }
rle.call("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW")