This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I submitted a bug report https://github.com/rails/rails/issues/34244 | |
# b/c Rails was not honouring my `rescue_from` block which was causing my API to | |
# be inconsistent. I was told this is expected behaviour. I think it's probably | |
# fine for an HTML app where you control the form inputs. But for an API app, | |
# the API is public facing and very important, so Rails shouldn't have its own | |
# special errors that bypass my app's configuration and make my API inconsistent. | |
# | |
# Decided it shouldn't be too difficult to handle this myself. So, here is my | |
# solution. It contains most of the important lessons I've learned about how to | |
# get a Rails API app setup. It removes Rails' params parsing and adds its own. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Helpers to make the code below easier to read | |
class Array | |
def keywords?() = Hash.ruby2_keywords_hash?(self[-1]) | |
def to_keywords!() = (self[-1] = Hash.ruby2_keywords_hash(self[-1])) | |
end | |
# Code to facilitate the examples below | |
def record_args(*args) = args | |
def call_this(val:) = val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts Solution.new('1. Fizz Buzz', <<SOLUTION) | |
def fizzbuzz(n)(n%15==0?'FizzBuzz':n%3==0?'Fizz':n%5==0?'Buzz':n).to_s end | |
SOLUTION | |
.test { fizzbuzz 3 }.expect { |result| result == "Fizz" } | |
.test { fizzbuzz 10 }.expect { |result| result == "Buzz" } | |
.test { fizzbuzz 45 }.expect { |result| result == "FizzBuzz" } | |
.test { fizzbuzz 31 }.expect { |result| result == "31" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* touch -- change modification and access times of files | |
Copyright (C) 1987, 1989-1991, 1995-2005, 2007-2011 Free Software | |
Foundation, Inc. | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pg' | |
db = PG.connect dbname: 'josh_testing' | |
db.exec 'begin' | |
def db.exec(*) | |
super.to_a | |
rescue | |
$!.set_backtrace caller.drop(1) | |
raise | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -s 'https://sciplypandora.github.io/static/json/configs/CT36.json' | | |
ruby -r json -e ' | |
puts JSON.parse($stdin.read, symbolize_names: true) | |
.[](:tiles) | |
.reject { |code, tile| tile[:tile_type] == "regular" } | |
.map { |code, tile| | |
tile_type = tile[:tile_type] | |
game_type = tile[:game_type].sub("least_cash", "lc").sub("least_tiers", "lt") | |
boss = tile[:boss] || " " | |
relic = tile[:relic] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# these are reconstructed from a shell session without runnig them, so make | |
# sure you check that it's a sane thing to do before running it, I make no | |
# guarantees of fitness, and accept no liability. Run at your own risk. | |
sudo launchctl remove com.snap.SnapCameraRemover | |
rm -r ~/Library/Caches/Snap/ | |
rm -r ~/Library/Caches/com.snap.SnapCamera/ | |
rm -r ~/Library/Preferences/Snap/ | |
rm ~/Library/Preferences/com.snap.SnapCamera.plist | |
rm ~/Library/Preferences/com.snap.Snap\ Camera.plist | |
sudo rm -rf /Applications/Snap\ Camera.app/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WOFF spec https://www.w3.org/TR/2012/REC-WOFF-20121213/ | |
# OTF spec https://www.microsoft.com/en-us/Typography/OpenTypeSpecification.aspx | |
# Really nice inspector https://opentype.js.org/font-inspector.html | |
# unpack instructions http://www.rubydoc.info/stdlib/core/String#unpack-instance_method | |
# Font programming instruction definitions https://developer.apple.com/fonts/TrueType-Reference-Manual/RM05/Chap5.html#WS | |
# Font forge has some useful info, too, get it with homebrew cask | |
FONT_FILE = '/Users/xjxc322/gamut/bots/pxgamut_regular.woff' | |
require 'zlib' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Values found with `stty -g` | |
# Turns out you can do `stty -a` to get human readable values | |
# Context is at https://github.com/pry/pry/issues/1290#issuecomment-55916557 | |
configs = [ | |
[:broken_pry, "gfmt1:cflag=4b00:iflag=2b02:lflag=200005cf:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=38400:ospeed=38400"], # => [:broken_pry, "gfmt1:cflag=4b00:iflag=2b02:lflag=200005cf:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=38400:ospeed=38400"] | |
[:good_term, "gfmt1:cflag=4b00:iflag=6902:lflag=200005cf:oflag=3:discard=f:dsusp=19:eof=4:eol=ff:eol2=ff:erase=7f:intr=3:kill=15:lnext=16:min=1:quit=1c:reprint=12:start=11:status=14:stop=13:susp=1a:time=0:werase=17:ispeed=38400:ospeed=38400"], # => [:good_term, "gfmt1:cflag=4b00:iflag=6902:lflag=200005cf:oflag=3:discard=f:dsusp=19:eof=4:eol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-> { a = case when true then return end } # this is allowed | |
-> { a = if true then return end } # this is not | |
-> { a = if true then return; 2 end } # this is | |
-> { a = (true && return) } # this is allowed | |
-> { a = (return && true) } # this is not | |
-> { a = begin; return | |
rescue; return | |
ensure; return |
NewerOlder