Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Aupajo's full-sized avatar

Pete Nicholls Aupajo

  • Christchurch, New Zealand
View GitHub Profile
@Aupajo
Aupajo / vol
Created November 7, 2017 18:45
#!/usr/bin/env ruby
# Examples:
# vol Print the current sound volume
# vol 30 Set the volume to 30%
# vol mute
# vol unmute
command = case ARGV.first
when 'mute' then "set volume output muted true"
#!/usr/bin/env ruby
require "heroku_env_audit"
require "json"
pipelines = JSON.parse(`heroku pipelines --json`, symbolize_names: true)
pipelines.each do |pipeline|
info = JSON.parse(`heroku pipelines:info #{pipeline[:name]} --json`, symbolize_names: true)
@Aupajo
Aupajo / -
Created October 16, 2017 02:22
[7a184b26-829b-495d-9e5c-b3017321c8d3 28/8065] Giving up after 5 attempts
[480f4644-c203-455b-9c8f-65bc0b8d2cb5 29/8065] Giving up after 5 attempts
[d7557738-a6c1-46f6-b20d-301458d3f80e 140/8065] Giving up after 5 attempts
[d30fac1c-5ef6-40fd-ab48-7eeb7480ff3d 141/8065] Giving up after 5 attempts
[32640d50-702b-4eb0-ae9f-a86615b990cf 143/8065] Giving up after 5 attempts
[0e24188c-6121-4fd5-91e3-45a738d8dbbe 147/8065] Giving up after 5 attempts
[ac1948ce-2469-4490-8bb7-f37f0607165c 151/8065] Giving up after 5 attempts
[990fe96f-b21b-491b-9d77-cf5d695a0c0b 152/8065] Giving up after 5 attempts
[f85cf5b4-5aee-4c6a-83b6-577eceeea9de 153/8065] Giving up after 5 attempts
[7e0f77d7-754e-4f92-a2c1-ecdaf512114a 200/8065] Giving up after 5 attempts
@Aupajo
Aupajo / client.rb
Last active October 11, 2017 04:54
Rack timings
require 'socket'
socket = TCPSocket.open('localhost', 9292)
puts "Sending headers at #{Time.now.strftime('%T.%L')}"
socket.puts <<~REQUEST
POST / HTTP/1.1\r
Host: localhost:9292\r
Accept: */*\r
CREATE TABLE pancakes (
/* The order number may be NULL - the kitchen has to eat, too! */
order_number integer UNIQUE,
/* Gotta have syrup */
maple_syrup_brand text NOT NULL,
/* Require order number and maple syrup to be unique */
CONSTRAINT order_syrup UNIQUE (order_number, maple_syrup_brand)
);

box-text

Install with:

curl https://gist.githubusercontent.com/Aupajo/523845154c905355bb008646bc066f18/raw/a4d191aad9f189fbc76111f9c4ee08c3b9e08f35/box-text > /usr/local/bin/box-text && \
chmod u+x /usr/local/bin/box-text

Usage:

A better git branch

I'll often use branches to try out experiments, ideas, and to separate different trains of thought. Not every branch gets merged – in fact, it's quite common for me to make several commits on a branch, look at the end result, and throw the branch away without ever merging it (branching is cheap and ideas are cheap, but bad code is expensive). As a result, I can end up with a lot of branches. This makes the output of git branch difficult to sort through:

$ git branch
* account-org-association
  acdx-blog-posts
  add-static-resource-support
  alter-component-naming

The Story of NPM and Yarn

In the beginning there was NPM, and for a time it was good. Packages went forth and multiplied. The New Gods proclaimed the great demon Dependency Management had been slain. But The Old Gods knew better, for they had seen much and knew that the demon can never be killed, only held at bay.

The Old Gods were ignored. In the folly of a young age grew an abundance of packages and with them grew the scourge of dependency. In the depths beneath the earth, in a place beyond memory, the great demon stirred.

The first sign something was wrong was non-deterministic package version mismatches. “This is fine!” The New Gods declared. “A temporary setback, nothing more! We can fix it.” And so they introduced shrinkwrap, a lamp to combat the growing darkness.

But it proved to be too little, too late, and dusk continued to fall. The New Gods suffered their first major defeat at the [Battle of Left-pad](https://www.theregister.co.uk/2016/03/23/npm_left_

class BufferedJsonArray
ClosedError = Class.new(StandardError)
def initialize(target_buffer)
@target_buffer = target_buffer
@internal_buffer = "["
@closed = false
@first_entry = true
end
@Aupajo
Aupajo / config.ru
Last active March 15, 2017 02:09
ITTT trigger responder
require_relative 'environment'
app = Server.new do
trigger :turn_on_lightbulb do
# Make an API request...
Net::HTTP.post_form(URI('http://lightbulb.local'), 'status' => 'on')
# Response (any JSON-like data)
{ light_bulb: "on" }
end