Skip to content

Instantly share code, notes, and snippets.

View gerhard's full-sized avatar

Gerhard Lazu gerhard

View GitHub Profile
@gerhard
gerhard / nginx.conf
Last active August 29, 2015 14:10 — forked from plentz/nginx.conf
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
---
- name: Register New Relic repository.
get_url: url=http://download.newrelic.com/debian/newrelic.list
dest=/etc/apt/sources.list.d/newrelic.list
- name: Download repo key.
apt_key: url=http://download.newrelic.com/548C16BF.gpg
- name: Install New Relic.
apt: pkg=newrelic-sysmond update_cache=yes
class Thing
def execute
stubbed_method
end
end
MyException = Class.new(StandardError)
describe Thing do
subject(:thing) { Thing.new }
if [ $(ls | grep -c "backup.*tgz") > 0 ]
then
unless folder _purge exists; do
mkdir _purge
done
mv backup*tgz _purge
mv backup*md5 _purge
fi
@gerhard
gerhard / aa_instructions.md
Created May 23, 2012 10:38 — forked from NZKoz/aa_instructions.md
Back Up All Your Gmail
  • Install getmail (aptitude install getmail4)
  • Set Up Your Imap Server (tl;dr)
  • getmail
  • ruby date_based_archive.rb ~/Maildir/.Archive
@gerhard
gerhard / gist:2517250
Created April 28, 2012 08:43 — forked from kyledrake/gist:2120107
Rainbows! config file for use with EventMachine
# This is a configuration script for using Rainbows with EventMachine. I'm providing it incase somebody finds it useful. But honestly, you
# should stop using EventMachine and use threads instead. The ThreadPool version of this is also in my gist list, and I recommend taking a look at that instead.
# NO, SERIOUSLY, STOP USING EVENTMACHINE.
Rainbows! do
name = 'yourappname'
use :EventMachine
client_max_body_size nil # This is set in nginx
# keepalive_timeout 1

Fibur

Fibur is a library that allows concurrency during Ruby I/O operations without needing to make use of callback systems. Traditionally in Ruby, to achieve concurrency during blocking I/O operations, programmers would make use of Fibers and callbacks. Fibur eliminates the need for wrapping your I/O calls with Fibers and a callback. It allows you to write your blocking I/O calls the way you normally would, and still have concurrent execution during those I/O calls.

Example

Say you have a method that fetches data from a network resource:

@gerhard
gerhard / command.sh
Created November 6, 2011 22:56 — forked from felixge/command.sh
Bash stuff for fighting a weak DOS attack
# Here a few bash one-liners that helped me analyze / fight a weak DOS attack against debuggable.com. Mostly for future reference.
# The attacker was opening lots of tcp connections without sending data, I believe it's called a SYN flood, see: http://tools.ietf.org/html/rfc4987#section-3.2
# Step 0: Check what is going on at port 80
$ netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c
# Step 1: Increase the number of available fds
$ ulimit -n 32000
# Step 2: Restart your webserver, for me:
@gerhard
gerhard / twilio_goliath.rb
Created September 15, 2011 23:01 — forked from subelsky/twilio_goliath.rb
Using Goliath as an API Proxy
require 'goliath'
require 'em-synchrony/em-http'
class TwilioResponse < Goliath::API
use Goliath::Rack::Params
use Goliath::Rack::JSONP
HEADERS = { authorization: ENV.values_at("TWILIO_SID","TWILIO_AUTH_TOKEN") }
BASE_URL = "https://api.twilio.com/2010-04-01/Accounts/#{ENV['TWILIO_SID']}/AvailablePhoneNumbers/US"
@gerhard
gerhard / app.rb
Created June 14, 2011 15:58 — forked from hakanensari/app.rb
non-blocking redis pub/sub in sinatra
require "fiber"
require "rack/fiber_pool"
require "sinatra/base"
require "redis"
require "redis/connection/synchrony"
class App < Sinatra::Base
use Rack::FiberPool