Skip to content

Instantly share code, notes, and snippets.

Bryan Petty tierra

Block or report user

Report or block tierra

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View sql_logger.rb
ActiveSupport::Notifications.subscribe("sql.active_record") do |_, _, _, _, details|
if details[:sql] =~ /search_path/
puts details[:sql]
puts caller.join("\n")
puts "*" * 50
end
end
View gist:09481964a29f2834e24d9d8320b6ae81
[15] pry(#<RSpec::ExampleGroups::SwitchmanActiveRecordConnectionPool>)> @conn.execute 'SELECT 1'
=> #<PG::Result:0x00000000047e2120 status=PGRES_TUPLES_OK ntuples=1 nfields=1 cmd_tuples=1>
[16] pry(#<RSpec::ExampleGroups::SwitchmanActiveRecordConnectionPool>)> @conn.active?
=> true
[17] pry(#<RSpec::ExampleGroups::SwitchmanActiveRecordConnectionPool>)> @conn.execute 'SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid = pg_backend_pid()'
ActiveRecord::StatementInvalid: PG::UnableToSend: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
: SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid = pg_backend_pid()
from /home/docker/.rvm/gems/ruby-2.3.6/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec'
View gist:d713dd6be644ac203fe004edad146ca0
[4/4] Building fresh packages...
Done in 88.38s.
> node-sass@4.5.2 install /usr/src/app/node_modules/node-sass
> node scripts/install.js
node-sass build Binary found at /usr/src/app/node_modules/node-sass/vendor/linux-x64-48/binding.node
> node-sass@4.5.2 postinstall /usr/src/app/node_modules/node-sass
> node scripts/build.js
View 0-rate-limiters.md

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

View gist:8277bcd30bfdc2a88a3f5b61c9a740be
==> Installing wxpython
==> Downloading https://homebrew.bintray.com/bottles/wxpython-3.0.2.0.sierra.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring wxpython-3.0.2.0.sierra.bottle.1.tar.gz
🍺 /usr/local/Cellar/wxpython/3.0.2.0: 1,107 files, 38.1M
bpetty-laptop:~ bpetty$ python --version
Python 2.7.12
bpetty-laptop:~ bpetty$ python
Python 2.7.12 (default, Oct 11 2016, 05:20:59)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
@tierra
tierra / .dockerignore
Last active Feb 15, 2016
Modern phpBB Docker Configuration
View .dockerignore
.dockerignore
Dockerfile
docker-compose.yml
.git
.gitignore
@tierra
tierra / gist:645a5c9d905de44f6ff0
Created Nov 1, 2015
Five days of wxWidgets 3.0.2 downloads off of GitHub
View gist:645a5c9d905de44f6ff0
bryan@ibaku:~$ ruby wx-downloads.rb
changes.txt: 3, 670 KB
README.md: 16, 110 KB
wxMSW-3.0.2-Setup.exe: 834, 37 GB
wxMSW-3.0.2_gcc471TDM_Dev.7z: 9, 350 MB
wxMSW-3.0.2_gcc471TDM_ReleaseDLL.7z: 14, 82 MB
wxMSW-3.0.2_gcc471TDM_x64_Dev.7z: 13, 660 MB
wxMSW-3.0.2_gcc471TDM_x64_ReleaseDLL.7z: 7, 75 MB
wxMSW-3.0.2_gcc481TDM_Dev.7z: 25, 960 MB
wxMSW-3.0.2_gcc481TDM_ReleaseDLL.7z: 19, 110 MB
@tierra
tierra / create_releases.sh
Created Oct 25, 2015
Script used to create and upload existing wxWidgets releases to GitHub
View create_releases.sh
#!/bin/bash
# You must generate a personal access token with public_repo
# permission, and configure that token using the following:
# export GITHUB_TOKEN="..."
GITHUB_USER="wxWidgets"
GITHUB_REPO="wxWidgets"
for directory in v*/; do
@tierra
tierra / retag-wx.sh
Created Oct 23, 2015
Script used to create v* tags for wxWidgets.
View retag-wx.sh
#!/bin/bash
for t in $(git tag -l | grep -v '@' | egrep '^(WX_[23]_[0-9]_[0-9])'); do
export GIT_COMMITTER_DATE=$(git log -1 --format=%ad $(echo $t))
VTAG=$(echo $t | sed -e 's/WX_2_4_0_CANDIDATE/WX_2_4_0-rc1/;s/2rc/2-rc/;s/_rc/-rc/;s/^WX_/v/;s/_/\./g;')
echo "Tagging $t as $VTAG with $GIT_COMMITTER_DATE"
git tag -m "Release $VTAG." $VTAG $t;
done
@tierra
tierra / gist:093183288b005eddf65e
Created Oct 22, 2015
wxWidgets original v* tags
View gist:093183288b005eddf65e
154f22b - Mon Nov 8 21:14:50 1999 +0000 - refs/tags/v2.1.11
dc3d889 - Mon Mar 20 18:41:55 2000 +0000 - refs/tags/v2.1.14
b97a2c5 - Wed May 17 16:45:01 2000 +0000 - refs/tags/v2.1.16
dc3d889 - Mon Mar 20 18:41:55 2000 +0000 - refs/tags/v2.2.0
dc3d889 - Mon Mar 20 18:41:55 2000 +0000 - refs/tags/v2.2.1
dc3d889 - Mon Mar 20 18:41:55 2000 +0000 - refs/tags/v2.2.5
dc3d889 - Mon Mar 20 18:41:55 2000 +0000 - refs/tags/v2.2.5.1
dc3d889 - Mon Mar 20 18:41:55 2000 +0000 - refs/tags/v2.2.6
dc3d889 - Mon Mar 20 18:41:55 2000 +0000 - refs/tags/v2.2.7
dc3d889 - Mon Mar 20 18:41:55 2000 +0000 - refs/tags/v2.2.8
You can’t perform that action at this time.