Skip to content

Instantly share code, notes, and snippets.

View benoittgt's full-sized avatar
🏴

Benoit Tigeot benoittgt

🏴
View GitHub Profile
@DevL
DevL / sequel_migrations.rake
Created December 12, 2012 10:11
Sequel migration rake tasks based on https://gist.github.com/1409152
namespace :db do
require 'sequel'
namespace :migrate do
Sequel.extension :migration
task :connect do
if ENV['DATABASE_URL']
DB = Sequel.connect(ENV['DATABASE_URL'])
else
puts 'ABORTING: You must set the DATABASE_URL environment variable!'
@stevenharman
stevenharman / select_from_subquery.sql
Created January 21, 2013 20:44
Using Arel/ActiveRecord to execute a subquery, including a SUM.
select fund_sums.total, fund_products.name
from (
select sum(allocation_amount) total, fund_product_id
from transactions
where transactions.investor_id = 490
group by fund_product_id
) fund_sums
left join fund_products on fund_sums.fund_product_id = fund_products.id
@mmasashi
mmasashi / launch_redshift.rb
Created March 13, 2013 00:10
Launch an Amazon Redshift Cluster with aws-sdk for ruby. Ref -> http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/Redshift/Client.html
require 'aws-sdk'
ACCESS_KEY_ID=ENV['AWS_KEY_ID']
SECRET_ACCESS_KEY=ENV['AWS_SEC_KEY']
CLUSTER_IDENTIFIER='test-instance'
DB_NAME='testdb'
PORT_NUMBER=5439
MASTER_USERNAME='test_admin'
MASTER_USER_PASSWORD=ENV['MASTER_USER_PASSWORD']
@benweint
benweint / gdb-stuck-ruby.txt
Created April 16, 2013 14:55
An example of how to gather C and Ruby backtraces from a stuck Ruby process using gdb.
# Here's the script I'll use to demonstrate - it just loops forever:
$ cat test.rb
#!/usr/bin/env ruby
loop do
sleep 1
end
# Now, I'll start the script in the background, and redirect stdout and stderr
@mfilej
mfilej / Readme.md
Last active November 5, 2021 09:16
RSpec hook to show current spec in process name

Our suite would sometimes randomly hang when running a certain spec, but we weren't able to tell which one. With the below RSpec around filter you can see the spec that is currently running by inspecting the process name.

$ rspec spec_spec.rb &
[2] 64968
$ ps | grep rspec
64968 ttys005    0:00.24 rspec /Users/miha/spec_spec.rb:10 "Dummy spec waits for 100 seconds"
@jamesgary
jamesgary / gist:5504200
Last active February 27, 2017 12:46
How to Talk to Developers - Ben Orenstein (@r00k) - RailsConf 2013

How to Talk to Developers

Ben Orenstein (@r00k)

Obey Law of Demeter

  • Reduces coupling
  • Enables refactoring

Throw something weird at people to keep their attention. Bored people don't learn anything, so focus on entertainment over being informative.

Write like a newspaper

@jonasschmidt
jonasschmidt / pre-commit
Last active September 6, 2024 15:32
git pre-commit hook checking for RSpec :focus tags that were unintentionally left in the specs
#!/usr/bin/env ruby
if `git diff --cached spec` =~ /,\s?(:focus|focus:\s?true|:focus\s?=>\s?true)/
puts "\e[31mPlease focus and remove your :focus tags before committing :)"
exit 1
end
@patshaughnessy
patshaughnessy / gist:7104128
Last active February 3, 2025 17:36
Resources for learning about MRI Ruby's internal C source code
Recently someone asked me for online resources about MRI's internal C source
code. Here are a few - if there are more to add please leave a comment! - pat
1. Ruby Hacking Guide - The definitive resource for people who want to learn
the C programming details of how Ruby works internally. Intended for C hackers.
It was just recently translated into English from the original Japanese.
http://ruby-hacking-guide.github.io
2. Various presentations by Koichi Sasada - he often does public presentations
on Ruby internals and they're always fascinating and full of technical details.
@ngpestelos
ngpestelos / postgresql-osx.md
Last active July 11, 2023 18:55
How to compile and run PostgreSQL on Mac OS X
@stereoscott
stereoscott / copy_attachments.rb
Created April 6, 2014 21:56
Paperclip Copy Attachments
module Paperclip
module CopyAttachments
def copy_attachments_from(source_obj, source_bucket = nil, destination_bucket = nil)
self.class.attachment_definitions.keys.each do |attachment_name|
source_attachment = source_obj.send(attachment_name)
next if source_attachment.blank?
destination_attachment = self.send(attachment_name)
connection = destination_attachment.send(:connection)