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
# $> gem install octokit
# $> irb
require 'octokit'
client = Octokit::Client.new(login: 'whoami', password: 'whatamidoinghere')
client.pull_requests('user/repo_name', state: 'all', per_page: 100).each {|pr| p [pr.title, pr.body, pr.user.login].join("\n")};nil
# more pages?
# client.pull_requests('user/repo_name', state: 'all', per_page: 100, page: 2).each {|pr| p [pr.title, pr.body, pr.user.login].join("\n")};nil
@dgilperez
dgilperez / delayed_job
Created July 3, 2012 18:27
Delayed_job init script for linux
#!/bin/sh
set_path="cd /home/rails/my_app/current"
case "$1" in
start)
echo -n "Starting delayed_job: "
su - rails -c "$set_path; RAILS_ENV=production script/delayed_job start" >> log/delayed_job.log 2>&1
echo "done."
;;
stop)

(my response to https://twitter.com/apotonick/status/717105889845624832)

I haven't yet came across readily available resources for large-scale application architecture for Elixir apps. I found Programming Phoenix to be a good start for that though. And there's ~30 years of knowledge in the Erlang land :)

For web apps, I found the abstractions that Elixir/Phoenix provides to be really helpful. Indeed, the list below is somewhat ORM focused.

In the small, Ecto.Schema, Ecto.Query, Ecto.Changeset, and Phoenix.View allow me to build highly composable and side-effect free modules. I can have many schemas, changesets and queries all interacting with the same underlying DB table(s) if I want to. Most of the side-effects (through Ecto.Repo for DBs) are usually in the Phoenix.Controller (or other Plugs).

@dgilperez
dgilperez / gist:e41da50eec00fd00448f1336e9828c87
Created May 7, 2017 22:13 — forked from sebboh/gist:f1dfe4f096746c45f3e9ea06a09743a0
Installing a Gem on Heroku from a Private GitHub Repo

Installing a Gem on Heroku from a Private GitHub Repo

Sometimes you want to use a gem on Heroku that is in a private repository on GitHub.

Using git over http you can authenticate to GitHub using basic authentication. However, we don't want to embed usernames and passwords in Gemfiles. Instead, we can use authentication tokens.

This method does not add your OAuth token to Gemfile.lock. It uses bundle config to store your credentials, and allows you to configure Heroku to use environment variables when deploying.

  1. Generate an OAuth token from GitHub
@dgilperez
dgilperez / trello-import.rb
Last active April 18, 2017 13:26
Taiga to Trello - ruby script to import Taiga cards into Trello
require 'trello'
# Trello.open_public_key_url # copy your public key
# Trello.open_authorization_url key: 'yourpublickey' # copy your member token
Trello.configure do |config|
config.developer_public_key = 'your_public_key' # The "key" from step 1
config.member_token = 'your_member_token' # The token from step 3.
end
@dgilperez
dgilperez / stackleveltoodeep_tracer.rb
Created November 14, 2016 16:37
StackLevelTooDeep tracer
$enable_tracing = false
$trace_out = open('trace.txt', 'w')
set_trace_func proc { |event, file, line, id, binding, classname|
if $enable_tracing && event == 'call'
$trace_out.puts "#{file}:#{line} #{classname}##{id}"
end
}
$enable_tracing = true
@dgilperez
dgilperez / gource.sh
Last active November 11, 2016 10:05 — forked from XueshiQiao/gource.sh
Generate a MP4 Video for your Git project commits using Gource!
# 1.install gource using HomeBrew
brew install gource
# 2.install avconv
git clone git://git.libav.org/libav.git
cd libav
# it will take 3-5 minutes to complie, be patient.
./configure --disable-yasm
make && make install
@dgilperez
dgilperez / gist:8921033
Last active November 4, 2016 22:08
Setting up a spinner for every AJAX call, globally
// One solution might be to have an AJAX spinner in a standard location that gets shown when AJAX requests start and hidden when AJAX requests complete. To do this globally in jQuery:
// http://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
jQuery.ajaxSetup({
beforeSend: function(xhr) {
$('#spinner').show();
},
// runs after AJAX requests complete, successfully or not
complete: function(xhr, status){
$('#spinner').hide();
@dgilperez
dgilperez / example.rb
Created October 14, 2016 19:32 — forked from nthj/example.rb
Methods I like to monkey-patch onto the Object class in Ruby
# Say you want to look up the attrs of a Stripe Event for logging to your internal database.
attrs = begin
retriable(Stripe::APIConnectionError, Stripe::APIError, max: 25) do
# ... retrieve attrs from the Stripe event here...
end
rescue Stripe::APIConnectionError, Stripe::APIError
# We're inside an SQS queue block
throw :skip_delete # we'll just have to wait on this event, come back later
rescue Stripe::Error
notify $!
@dgilperez
dgilperez / deploy.rb
Created April 14, 2016 19:24 — forked from andrey-skat/deploy.rb
Local assets precompilation on Rails 4 using Capistrano 3
# also you need to uncomment next line in Capfile
# require 'capistrano/rails/assets'
namespace :deploy do
namespace :assets do
Rake::Task['deploy:assets:precompile'].clear_actions
desc 'Precompile assets locally and upload to servers'
task :precompile do