Skip to content

Instantly share code, notes, and snippets.

View mru2's full-sized avatar

David Ruyer mru2

View GitHub Profile
### Keybase proof
I hereby claim:
* I am mru2 on github.
* I am mru2 (https://keybase.io/mru2) on keybase.
* I have a public key ASD3Ty-eaUw6HF7D1I3BHFuPjAw5ibLcu4wwUmUPjZ3zWAo
To claim this, I am signing this object:
@mru2
mru2 / restore
Last active May 13, 2019 00:12 — forked from jgillman/restore.sh
pg_restore a local db dump into Docker
# Create and download backup
heroku pg:backups:capture
heroku pg:backups:download
# Assumes the database container is named 'db'
DOCKER_DB_NAME="$(docker-compose ps -q db)"
DB_HOSTNAME=db
DB_USER=postgres
LOCAL_DUMP_PATH="path/to/local.dump"
# string => unique
def transaction_id(reference)
"#{Time.now.to_i}#{Random.rand(1000)}|#{reference}"
end
# unique => string
def reference(transaction_id)
transaction_id.match(/\d+|(.*)/)[1]
end
@mru2
mru2 / gist:9975136
Last active August 29, 2015 13:58
Webservice proxy
# =============
# Without proxy
# =============
require 'soap_client'
class Webservice
def initialize()
@client = SoapClient.new('http://my.api.com/endpoint')
@mru2
mru2 / gist:8517209
Created January 20, 2014 09:12
How to return a Rack::Response in a Rails controller
def show
rack_response = Rack::Response.new(["Hello!"], 200, {'Content-Type' => 'test/plain'})
self.response = ActionDispatch::Response.new(*rack_response.to_a)
self.response.close
return
end
@mru2
mru2 / gist:7947486
Created December 13, 2013 17:01
Grouping and 2D projection for multi-dimensional analytics data
require 'rspec'
#######
# SPECS
#######
describe "blob projection" do
@mru2
mru2 / crawler
Last active December 22, 2015 22:18
Simple ruby crawler for checking HTTP status codes
#!/usr/bin/env ruby
require 'rubygems'
require 'anemone'
require 'colorize'
entry = ARGV[0]
unless entry
puts "Please precise a point to start the crawl"