Skip to content

Instantly share code, notes, and snippets.

View hooopo's full-sized avatar
🍏
I may be slow to respond.

Hooopo hooopo

🍏
I may be slow to respond.
View GitHub Profile
@hooopo
hooopo / 0-readme.md
Created October 12, 2018 18:13 — forked from toolmantim/0-readme.md
Using rvm and node on Ubuntu with Buildkite Agent

Firstly, you'll need to install rvm as the buildkite-agent user:

sudo su buildkite-agent
curl -sSL https://get.rvm.io | bash -s stable
source /var/lib/buildkite-agent/.rvm/scripts/rvm
rvm install 2.4.0 && rvm use 2.4.0 && gem install bundler

Secondly, make rvm available to your build commands by adding the following pre-command Buildkite Agent hook:

@hooopo
hooopo / newrelic_instrumenter.rb
Created June 27, 2018 04:33 — forked from nettofarah/newrelic_instrumenter.rb
sample newrelic instrumenter for graphql-ruby
# NewRelic instrumenter for GraphQL-ruby
#
# In your controller:
# ::NewRelic::Agent.add_custom_attributes({
# user_id: @user.try(:id),
# query_string: @query_string,
# query_arguments: @query_variables
# })
#
# @document = self.class.trace_execution_scoped(["GraphQL#parse"]) do
@hooopo
hooopo / Dockerfile
Last active June 21, 2018 03:24 — forked from rtacconi/Dockerfile
Alpine Linux, jemalloc, Ruby 2.4.1 segmentation fault
FROM alpine:3.4
# skip installing gem documentation
RUN mkdir -p /usr/local/etc \
&& { \
echo 'install: --no-document'; \
echo 'update: --no-document'; \
} >> /usr/local/etc/gemrc
ENV RUBY_MAJOR 2.5
@hooopo
hooopo / postgres_queries_and_commands.sql
Created January 26, 2018 05:51 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
# speed up pluck
class ActiveRecord::Relation
class RailsDateTimeDecoder < PG::SimpleDecoder
def decode(string, tuple=nil, field=nil)
if Rails.version >= "4.2.0"
@caster ||= ActiveRecord::Type::DateTime.new
@caster.type_cast_from_database(string)
else
#!/usr/bin/env ruby
require 'open-uri'
patchset = ARGV[0]
version = ARGV[1]
raise 'Please specify a patchset' if patchset.nil?
raise 'Please specify a ruby version' if version.nil?
@hooopo
hooopo / gist:10fef815d816faeef03310724ce29cbc
Created July 14, 2016 03:44 — forked from lukas-vlcek/gist:6039115
Torturing Word Delimiter TokenFilter in ElasticSearch
#!/bin/sh
curl -X DELETE 'localhost:9200/i/'
curl -X POST 'localhost:9200/i/' -d '{
"settings" : {
"analysis" : {
"analyzer" : {
"crazy" : {
"type" : "custom",

My largest Sidekiq application had a memory leak and I was able to find and fix it in just few hours spent on analyzing Ruby's heap. In this post I'll show my profiling setup.

As you might know Ruby 2.1 introduced a few great changes to ObjectSpace, so now it's much easier to find a line of code that is allocating too many objects. Here is great post explaining how it's working.

I was too lazy to set up some seeding and run it locally, so I checked that test suite passes when profiling is enabled and pushed debugging to production. Production environment also suited me better since my jobs data can't be fully random generated.

So, in order to profile your worker, add this to your Sidekiq configuration:

if ENV["PROFILE"]
@hooopo
hooopo / elasticsearch.conf
Created November 27, 2015 07:55 — forked from crofty/elasticsearch.conf
Upstart for elasticsearch
# ElasticSearch Service
description "ElasticSearch"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
@hooopo
hooopo / nginx.conf
Created November 11, 2015 15:23 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048