This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####################################### | |
# 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 # | |
########################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
protect_from_forgery | |
protected | |
def current_user | |
@current_user ||= User.find_by_id(session[:user_id]) | |
end | |
def signed_in? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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}" |
OlderNewer