Skip to content

Instantly share code, notes, and snippets.

View brandur's full-sized avatar

Brandur Leach brandur

View GitHub Profile
@brandur
brandur / README.md
Last active August 29, 2015 14:01
gojsonschema issue #14 reproduction

gojsonschema issue #14 repro

Clone into $GOPATH and run:

git clone https://gist.github.com/fb3eb8e804cfbf9e1b7d.git repro
cd repro
go build
./repro
@brandur
brandur / force-reset.md
Last active January 3, 2022 16:07
Force pull request's diff to reset itself against target branch

Force pull request's diff to reset itself against target branch

git checkout feature-branch
# empty commit; don't worry, this will not show up in the final pull
git commit --allow-empty -m "Empty commit"
git push origin feature-branch
# hard reset to before empty commit
git reset --hard HEAD~
git push -f origin feature-branch
@brandur
brandur / releases.rb
Created December 27, 2013 21:17
Heroku app releases this year
require "json"
require "time"
#
# usage: releases.rb <app>
#
def get_releases(app)
# use curl for -n
JSON.parse(`curl --silent -n -H "Accept: application/vnd.heroku+json; version=3" -H "Range: seq ..; order=desc, max=1000" https://api.heroku.com/apps/#{app}/releases`)

Fenced code blocks inside ordered and unordered lists

  1. This is a numbered list.

  2. I'm going to include a fenced code block as part of this bullet:

    Code
    More Code
    
@brandur
brandur / api-update-with-notes.md
Last active December 22, 2015 16:29
API Update

Current Projects

V3 GA

  • Blocked on security in releases
  • Need to finish up some client libraries -- JSON schema designed, and doc.json is being ported over

Orgs

  • Product is being shipped
@brandur
brandur / sf-traffic-rules.md
Last active December 22, 2015 06:39
SF Traffic Rules

SF Traffic Rules

  1. Don't run red lights by more than 5 seconds. 20 seconds if you're in a bus or large truck.
  2. Rule 1 doesn't apply during high traffic situations. If your green is ending and traffic hasn't moved on the other side of the light, it's okay to block the intersection as long as you're not doing it by more than four or five cars deep. Remember, pedestrian walks are a nice place to come to rest as you won't be blocking cross traffic.
  3. Know the SF intersections controlled by red light cameras, and be careful with rules 2 and 3 in them. Red light cameras are blatant revenue-generating scams cooked up by malicious and profiteering governments, but receiving a ticket from one may mean that you'll have to inconviently attend court before it can be properly thrown out.
  4. If you didn't see that your light was changing, it's fine to park on top of the near pedestrian walk. In these cases pedestrians must go around you, even if it means edging into oncoming traffic. Remember, you're in a car and
@brandur
brandur / readability-oauth.md
Last active December 21, 2015 05:39
Acquire Readability OAuth token
gem install oauth
irb
consumer = ::OAuth::Consumer.new(
  "OAUTH_KEY", 
  "OAUTH_SECRET", 
 :site=&gt;"https://www.readability.com/",
@brandur
brandur / heroku-api-stub.md
Last active December 20, 2015 22:09
Engineering API-driven Applications Using Service Stubs

Engineering API-driven Applications Using Service Stubs

Developing applications against foreign services like the Heroku Platform API can unlock a powerful set of otherwise unavailable features, but can come with drawbacks: development must occur online, valid credentials are required, calls your code makes will reveal and manipulate real data, and API calls in tests have to stubbed out individually.

This article will offer a short overview on how these pain points can be

@brandur
brandur / twitter-auth.md
Last active February 13, 2020 22:13
Twitter auth

Easy Twitter API OAuth 2 Access

  1. Go to your applications. Create a new one, and find the values in the Consumer Key and Consumer Secret fields.

  2. Use OAuth client information to produce an OAuth 2 access token:

    curl -i --user <consumer_key>:<consumer_secret> -X POST https://api.twitter.com/oauth2/token -d "grant_type=client_credentials"
    
    {"access_token":"<oauth2_token>","token_type":"bearer"}% 
    
@brandur
brandur / activerecord-2
Created June 5, 2013 05:49
Moving a non-trivial app from ActiveRecord 2.3.17 to ActiveRecord 3.2.13
# ab -n 1000 -c 10 -A :xxx https://api.brandur.herokudev.com/apps
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking api.brandur.herokudev.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests