Skip to content

Instantly share code, notes, and snippets.

View dgilperez's full-sized avatar
🌊
Build that!

David Gil dgilperez

🌊
Build that!
View GitHub Profile
@djo
djo / deploy.rb
Last active December 21, 2023 07:08
Rails, Nginx, XSendfile, and X-Accel-Mapping
# Symlink the shared protected folder
run "ln -nfs #{shared_path}/protected #{latest_release}/protected"
@mbostock
mbostock / .block
Last active December 17, 2023 21:17
Save SVG as PNG
license: gpl-3.0
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@magnetikonline
magnetikonline / README.md
Last active November 27, 2023 21:12
Setting Nginx FastCGI response buffer sizes.
@krasnoukhov
krasnoukhov / 2013-01-07-profiling-memory-leaky-sidekiq-applications-with-ruby-2.1.md
Last active October 4, 2023 21:53
Profiling memory leaky Sidekiq applications with Ruby 2.1

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"]
@tenderlove
tenderlove / h2_puma.rb
Last active September 4, 2023 17:30
Demo HTTP/2 server with Puma
require 'socket'
require 'openssl'
require 'puma/server'
require 'ds9'
class Server < DS9::Server
def initialize socket, app
@app = app
@read_streams = {}
@write_streams = {}
@ebeigarts
ebeigarts / gist:970898
Created May 13, 2011 17:04
html2haml recursive
for f in `find . -regex '.*\.html\.erb'`; do echo "Converting $f" && html2haml $f > "${f%.erb}.haml" && rm $f; done
@afeld
afeld / gist:1254889
Created September 30, 2011 20:28
YouTube video ID regex
# Parses YouTube URLs directly or from iframe code. Handles:
# * Address bar on YouTube url (ex: http://www.youtube.com/watch?v=ZFqlHhCNBOI)
# * Direct http://youtu.be/ url (ex: http://youtu.be/ZFqlHhCNBOI)
# * Full iframe embed code (ex: <iframe src="http://www.youtube.com/embed/ZFqlHhCNBOI">)
# * Old <object> tag embed code (ex: <object><param name="movie" value="http://www.youtube.com/v/ZFqlHhCNBOI">...)
/(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)/
$5 #=> the video ID
# test it on Rubular: http://rubular.com/r/eaJeSMkJvo
@nathancolgate
nathancolgate / Gemfile
Last active January 31, 2023 01:44
How I built a rails interface on top of the amazing IceCube ruby gem. Video of final product: http://youtu.be/F6t-USuWPag
# Add these two gems
gem 'ice_cube', '0.9.3'
gem 'squeel', '1.0.16'
@tlowrimore
tlowrimore / union_scope.rb
Last active January 13, 2023 21:12
Unions multiple scopes on a model, and returns an instance of ActiveRecord::Relation.
module ActiveRecord::UnionScope
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
def union_scope(*scopes)
id_column = "#{table_name}.#{primary_key}"
sub_query = scopes.map { |s| s.select(id_column).to_sql }.join(" UNION ")
where "#{id_column} IN (#{sub_query})"