Skip to content

Instantly share code, notes, and snippets.

View toolmantim's full-sized avatar
:shipit:
🎉

Tim Lucas toolmantim

:shipit:
🎉
View GitHub Profile
@toolmantim
toolmantim / iterm_buildkite_inline_images.js
Last active May 14, 2016 19:38
Node functions for embedding images in your build output using iTerm or Buildkite
var fs = require('fs');
function artifactOutput(imagePath) {
return '\033]1338;url=artifact://' + imagePath + ';alt=' + imagePath + '\07\n';
}
function base64Output(imagePath) {
var encodedImage = fs.readFileSync(imagePath, {encoding: 'base64'});
return '\033]1337;File=name=' + imagePath + ';inline=1:' + encodedImage + '\07\n';
}
@toolmantim
toolmantim / socket_stats_logger
Created June 16, 2015 07:18
How to monitor Unicorn and Puma unix socket queues with statsd
#!/bin/bash
# Logs the queued and active stats from the application's sockets and posts to statsd
while true; do
proc_lines=`cat /proc/net/unix`
for file in /home/deploy/myapp/tmp/sockets/*.sock; do
# /proc/net/unix lines are of the format:
@toolmantim
toolmantim / gist:d9a18fc7e853f93cb052
Created April 23, 2015 13:18
Rails/Sprockets related sections of the MemoryProfiler dump
$ ruby -rmemory_profiler -I. -e 'MemoryProfiler.report { require "config/environment" }.pretty_print'
Total allocated 2057572
Total retained 390073
allocated memory by gem
-----------------------------------
activesupport-4.2.1 x 60094221
sprockets-3.0.1 x 56626099
2.2.0/lib x 28225732
rubygems x 13918784
@toolmantim
toolmantim / gist:56fd2421b2e515f7c5e9
Created April 23, 2015 13:06
Typical keys+types of Sprocket's compute_extname_map graph (via `puts [key, type].inspect`)
This file has been truncated, but you can view the full file.
["", nil]
[".coffee", "application/javascript"]
[".jst", "application/javascript"]
[".eco", "application/javascript"]
[".ejs", "application/javascript"]
[".sass", "text/css"]
[".scss", "text/css"]
[".erb", "text/plain"]
[".jsx", "application/javascript"]
[".cjsx", nil]
@toolmantim
toolmantim / Dockerfile
Created April 18, 2015 09:07
Example Docker setup for a Rails app
FROM ruby:2.2.0
# Add official postgresql apt deb source
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Update all the things
RUN apt-get update
# Generate UTF-8 locale
@toolmantim
toolmantim / docker-compose.yml
Created April 1, 2015 07:27
Example docker-compose.yml for a Rails application
app:
build: .
links:
- db:db
- redis:redis
- memcache:memcache
volumes:
- ./:/app
environment:
PGHOST: db
@toolmantim
toolmantim / gist:cc66133bc3682c89727a
Created March 31, 2015 01:33
Using allocation tracer
# via https://github.com/halostatue/mime-types/pull/93#issuecomment-87814894
require 'allocation_tracer'
require 'pretty_print'
$LOAD_PATH << "/Users/schneems/Documents/projects/mime-types/lib"
ObjectSpace::AllocationTracer.setup(%i{path line type})
r = ObjectSpace::AllocationTracer.trace do
@toolmantim
toolmantim / buildkite_lifx_build_light_apitools_middleware.lua
Last active August 29, 2015 14:16
A middleware for apitools.com to control a LIFX build light using Buildkite webhooks
return function(request, next_middleware)
local next_response = next_middleware()
-- Modify these
local lifx_access_token = "xxx"
local bulb_selector = "id:xxx"
local webhook_token = "xxx"
-- The rest is standard and doesn't need to be modified
if request.headers["X-Buildkite-Token"] ~= webhook_token then
@toolmantim
toolmantim / deploy_branch.sh
Last active May 22, 2016 07:02
An example Buildbox deploy script for automatically deploying branches of a site or application to different subdomains. So you could have always-up-to-date copies of a branches available at http://<branch>.dev.mysite.com/
#!/usr/bin/env bash
# An example Buildbox deploy script for automatically deploying branches of a
# site or application to different subdomains. So you can have an
# always-up-to-date copy of a branch being available at http://branch.dev.mysite.com/
#
# This copies the currently checked out code to /var/www/<branch name>. You'd
# then configure your web server to dynamically map subdomains to /var/www.
#
# You could just as easily push the branch to Heroku or FTP it to a remote server.
@toolmantim
toolmantim / sidetiq_schedule_time_zone_additions.rb
Last active November 30, 2016 18:59
An addition to Sidetiq to make it easier to declare the worker's schedule's timezone. Assumes ActiveRecord::TimeZone is available.
# Timezone extension to Sidetiq
Sidetiq::Schedulable::ClassMethods.class_eval do
# Sets the time zone for the recurrence rules.
#
# Example:
#
# class MyWorker
# include Sidekiq::Worker
# include Sidetiq::Schedulable
#