Skip to content

Instantly share code, notes, and snippets.

@ryangreenberg
ryangreenberg / git.sh
Created April 13, 2022 14:10
Git aliases that support master or main
# main or master?
alias morm='(git rev-parse --quiet --verify origin/main && echo "main") || echo "master"'
alias gmom='git merge origin/$(morm)'
alias gdom='git diff origin/$(morm)'
alias grom='git rebase --autosquash origin/$(morm)'
alias gromi='git rebase --autosquash -i origin/$(morm)'
alias gfom='git fetch origin $(morm)'
alias gpom='git pull origin $(morm)'
@ryangreenberg
ryangreenberg / aws_ip_ranges.rb
Created February 11, 2022 21:20
Check IP addresses against AWS's published ip ranges
#!/usr/bin/env ruby
require 'ipaddr'
require 'json'
require 'open-uri'
# From https://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html#aws-ip-download
source_url = 'https://ip-ranges.amazonaws.com/ip-ranges.json'
file = File.join(__dir__, 'ip-ranges.json')
use namespace HH\Lib\C;
<<__EntryPoint>>
function example(): void {
takes_varray(varray[""]); // works for non-empty varray
takes_varray(varray[]); // runtime exception for empty varray
}
function takes_varray(?varray<string> $v): void {
// This truthy check does not pass for an empty varray, but the typechecker doesn't
@ryangreenberg
ryangreenberg / launch-topic.rb
Last active September 3, 2020 20:07
Slack Launch Topic
#!/usr/bin/env ruby
# set the channel topic: ▓░░░░░░░░░░░░░░░░░░░ 1%
# set the channel topic: ▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░ 50%
# set the channel topic: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 100%
blocks = 20
percent = ARGV[0]
abort "#{$PROGRAM_NAME} <0-100>" unless percent
@ryangreenberg
ryangreenberg / Notes on The Rise of Skywalker.md
Created April 9, 2020 04:14
Notes on The Rise of Skywalker

Notes on The Rise of Skywalker (SPOILERS)

  • How have the rules of hyperspace changed so dramatically in the last 5 years?
  • Those black uniforms must be hot as hell in the desert
  • You know Darth Vader wore that helmet for medical reasons, it wasn’t a fashion statement.
  • Does the force increase in power relative to the release year of these movies? Stopping an entire ship with the force?
  • C-3P0’s inability to translate feels like DRM to me
  • Is spice a nod to Dune?
  • What is this quantum tunneling force stuff? Is this like third-gen Force powers?
  • Shouldn’t adults get to know their own history and origins? Why does everyone work to hide people’s actual parentage?
@ryangreenberg
ryangreenberg / index.hack
Created November 7, 2019 16:47
Simple HHVM server
function main(): noreturn {
$rsp = dict[
'$_SERVER' => $_SERVER,
'$_GET' => $_GET,
'$_POST' => $_POST,
'$_REQUEST' => $_REQUEST,
'getallheaders' => getallheaders(),
'body' => file_get_contents('php://input'),
];
@ryangreenberg
ryangreenberg / redirect_markdown.rb
Created September 3, 2019 16:35
Create markdown files to redirect a batch of documents in a repository
#!/usr/bin/env ruby
require 'fileutils'
require 'pathname'
USAGE = "#{$PROGRAM_NAME} <src dir> <dest dir>"
abort USAGE unless ARGV.size == 2
src = ARGV[0]
{
"roots": [
"vendor/"
],
"builtinLinters": "none",
"overrides": [
{
"patterns": [
"*"
],
@ryangreenberg
ryangreenberg / prn.rb
Created August 6, 2019 15:34
prn.rb - Pull request notes
#!/usr/bin/env ruby
# prn = pull request notes
# TODO: Better name
# PRN is an abbreviation for the Latin term, "pro re nata" which loosely translates to "as needed."
#
# This tool opens notes for the current pull request in a text file named for the current branch.
require 'fileutils'