Skip to content

Instantly share code, notes, and snippets.

View druzn3k's full-sized avatar

Maurizio Del Corno druzn3k

View GitHub Profile

Controller Filters

The Rails REST implementation dictates the default seven actions for your controllers, but frequently we want to share functionality across multiple actions or even across controllers. Controller filters are the easiest way to do that.

Before, After, and Around

There are three types of filters implemented in Rails:

  • a before_filter runs before the controller action
  • an after_filter runs after the controller action
#!/usr/bin/env ruby
# This is my current blacklist when playing spotify in radio mode with "heavy metal".
blacklist = ['Nickelback', 'Scorpions', 'Watain', 'Mayhem', 'Guns N\' Roses']
# gem install ruby-dbus
require "dbus"
session_bus = DBus::SessionBus.instance
Install GHC 7.6.3:
- Download at: http://www.haskell.org/ghc/download_ghc_7_6_3
- Extract and go in extract folder
- in terminal use: ./configure
if error:
"checking for path to top of build tree... utils/ghc-pwd/dist/build/tmp/ghc-pwd: error while loading shared libraries: libgmp.so.3: cannot open shared object file: No such file or directory
configure: error: cannot determine current directory"
use:
- in terminal: sudo apt-get install libgmp3c2
- in terminal: sudo ln -s /usr/lib/x86_64-linux-gnu/libgmp.so.10.0.5 /usr/lib/libgmp.so.3
#!/usr/bin/env ruby
require "openssl"
require 'digest/sha2'
require 'base64'
# We use the AES 256 bit cipher-block chaining symetric encryption
alg = "AES-256-CBC"
# We want a 256 bit key symetric key based on some passphrase
digest = Digest::SHA256.new
@druzn3k
druzn3k / gist:6763209
Created September 30, 2013 12:39 — forked from mtigas/gist:952344

Client-side SSL

For excessively paranoid client authentication.

Using self-signed certificate.

Create a Certificate Authority root (which represents this server)

Organization & Common Name: Some human identifier for this server CA.

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
#!/usr/bin/python
import ast, _ast, os
for root, dirs, files in os.walk('.'):
for name in files:
if name.endswith('.py'):
full = os.path.join(root, name)
t = ast.parse(open(full).read())
for n in ast.walk(t):
if isinstance(n, _ast.Str) and not isinstance(n.s, unicode):
package main
import (
"database/sql"
"errors"
"fmt"
_ "github.com/bmizerany/pq"
"os"
"regexp"
"strings"