Skip to content

Instantly share code, notes, and snippets.

View stevendaniels's full-sized avatar
👋

Steven Daniels stevendaniels

👋
View GitHub Profile
require 'sinatra/base'
module Sinatra
# module to catch Sinatra errors and send a email
module ExceptionMailer
def initialize(app)
@app = app
# set parameters here..
yield self if block_given?
end
@raggi
raggi / bm_dci_pounding.rb
Last active September 22, 2016 23:19
Show the effects of method cache damage from runtime extend, as it relates to extend vs. delegate for DCI.
require 'benchmark'
number_of_rails_methods = 300
@rails = Class.new do
number_of_rails_methods.times do |i|
class_eval <<-RUBY
def call#{"%02d" % i} # def call01
end # end
RUBY
@ryannealmes
ryannealmes / gist:9c148a6c4b35aefaf505
Last active July 5, 2017 23:08
How to managed services and dependencies ...
# adapted from
# http://adamniedzielski.github.io/blog/2014/11/25/my-take-on-services-in-rails/
class CreateUserAccount
attr_reader :user
def initialize(send_email_service: SendEmail.new, generate_token_service: GenerateToken.new)
@send_email_service = send_email_service
@generate_token_service = generate_token_service
end
@1st8
1st8 / gist:3128135
Created July 17, 2012 08:47
God process monitoring + Upstart + rbenv
description "God Process Monitoring"
author "Christoph Geschwind <christoph@mixxt.net>"
start on runlevel [2345]
stop on runlevel [!2345]
respawn # respawn the service if it dies
respawn limit 5 10 # stop respawning if it fails 5 times in 10 seconds
pre-start script
@ryanlecompte
ryanlecompte / gist:1619490
Created January 16, 2012 06:59
Experimenting with forking and unix sockets in Ruby
require 'base64'
require 'socket'
require 'fileutils'
# UnixSocketForker is an experiment of inter-process communication using
# plain unix sockets to communicate between forked processes and the
# parent process. This can also be done via IO.pipe. In this experiment,
# the jobs are simply random arrays whose sums are calculated in the forked
# worker processes.
class UnixSocketForker
@jstorimer
jstorimer / hilong.rb
Last active July 30, 2020 06:52
hilong -- A simply utility to show character counts for each line of input and highlight lines longer than 80 characters.
#!/usr/bin/env ruby
# A simply utility to show character counts for each line of input and
# highlight lines longer than 80 characters.
#
# Written as an example for http://jstorimer.com/2011/12/12/writing-ruby-scripts-that-respect-pipelines.html
#
# Examples:
#
# $ hilong Gemfile
@Emuentes
Emuentes / two_branch_cleanup_scripts.sh
Last active October 12, 2020 19:44
SCRIPT-ONE: will print the names of the branches that have been merged into develop AND master in green. Also, branches that are only merged into develop but not master are listed in red. ---- SCRIPT-TWO: will delete the fully merged branches, those listed in green when you run SCRIPT-ONE
#######################################
# SCRIPT 1 - PREVIEW BRANCH DELETIONS #
#######################################
# will print the names of the branches that have been merged into develop and master in green and branches that are only merged into develop but not master in red.
BRANCHES_IN_MASTER=`git branch -r --merged origin/master | grep -v -E '(\*|master$|develop$)' | cut -f2- -d '/' | tr '\n' ';'` && export BRANCHES_IN_MASTER && git branch -r --merged origin/develop | grep -v -E '(\*|master$|develop$)' | cut -f2- -d '/' | xargs -L1 bash -c 'if [ $(grep -o "$0" <<< "$BRANCHES_IN_MASTER" | wc -l) -gt 0 ] ; then printf "\e[0;32m $0 \e[0m\n"; else printf "\e[0;31m $0 is merged into DEVELOP but not MASTER \e[0m\n"; fi';
#################################################################################################################################
# SCRIPT 2 - DANGER -- RUN AT YOUR OWN RISK -- The following script will DELETE the branches listed in the above preview script #
###########################
@stefanobernardi
stefanobernardi / application_controller.rb
Created September 23, 2012 07:07
Multiple omniauth providers and omniauth-identity on the main user model
class ApplicationController < ActionController::Base
protect_from_forgery
protected
def current_user
@current_user ||= User.find_by_id(session[:user_id])
end
def signed_in?
@arusso
arusso / make-san-cert.rb
Last active June 1, 2021 21:20
Generating a SAN Certificate in Ruby
require 'openssl'
require 'openssl-extensions/all'
keyfile = '/tmp/mycert.key'
csrfile = '/tmp/mycert.csr'
file = File.new(keyfile,'w',0400)
key = OpenSSL::PKey::RSA.new 2048
file.write(key)
# Blocks while a client is connected, and does not time out automatically
require 'socket'
require 'etc'
Socket.unix_server_loop("/tmp/sock") do |socket|
begin
login = Etc.getpwuid(socket.getpeereid.first).name
puts "#{login} connected"
input = socket.gets.strip
puts "#{login} sent #{input}"