Skip to content

Instantly share code, notes, and snippets.

Sven Riedel sriedel

View GitHub Profile
View memoize.rb
module Memoize
def memoize(method_name)
ivar_name = :"@#{method_name}"
aliased_method_name = :"__unmemoized_#{method_name}"
alias_method aliased_method_name, method_name
define_method method_name do
return instance_variable_get(ivar_name) if instance_variable_defined?(ivar_name)
instance_variable_set(ivar_name, send(aliased_method_name))
View sway log
2019-09-19 13:00:51 - [sway/main.c:152] Linux plinth 5.1.16 #1 SMP PREEMPT Fri Jul 5 21:04:54 CEST 2019 x86_64 GNU/Linux
2019-09-19 13:00:51 - [sway/main.c:168] Contents of /etc/lsb-release:
2019-09-19 13:00:51 - [sway/main.c:152] LSB_VERSION=1.4
2019-09-19 13:00:51 - [sway/main.c:152] DISTRIB_ID=Arch
2019-09-19 13:00:51 - [sway/main.c:152] DISTRIB_RELEASE=rolling
2019-09-19 13:00:51 - [sway/main.c:152] DISTRIB_DESCRIPTION="Arch Linux"
2019-09-19 13:00:51 - [sway/main.c:168] Contents of /etc/os-release:
2019-09-19 13:00:51 - [sway/main.c:152] NAME="Arch Linux"
2019-09-19 13:00:51 - [sway/main.c:152] PRETTY_NAME="Arch Linux"
2019-09-19 13:00:51 - [sway/main.c:152] ID=arch
@sriedel
sriedel / setup_vault_access
Last active Jan 9, 2019
Automate vault access
View setup_vault_access
#!/usr/bin/bash
VAULT_USER=sr
SSH_SOCKET=$HOME/.ssh/control/vault
REMOTE_HOST=app1.staging.givve.io
VAULT_HOST=vault.givve.io
export VAULT_ADDR="https://$VAULT_HOST:8200"
export VAULT_CACERT="/home/sr/src/givve/givve/config/certs/vault_cacert.pem"
@sriedel
sriedel / db_size.rb
Created Mar 19, 2017
Summarize table size and index usage for a postgres database
View db_size.rb
#!/usr/bin/env ruby
require_relative '../config/environment'
class TableStats
include ActionView::Helpers::NumberHelper
OUTPUT_HEADER = sprintf "%-32s %10s %10s %10s %10s\n", "Table name", "Tuples", "Size", "#Seq. Scans", "#Index Scans"
def initialize( attrs = {} )
@attributes = attrs
@sriedel
sriedel / rc.lua
Created Feb 11, 2014
awesome 3.5 config
View rc.lua
-- Standard awesome library
local awful = require("awful")
awful.autofocus = require("awful.autofocus")
awful.rules = require("awful.rules")
-- Theme handling library
local beautiful = require("beautiful")
local gears = require("gears")
-- Notification library
local naughty = require("naughty")
local vicious = require("vicious")
View 0. nginx_setup.sh
# Nginx+Unicorn best-practices congifuration guide. Now with SPDY!
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
#
# Deployment structure
#
# SERVER:
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#
View gist:4032070
alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --
@sriedel
sriedel / ctags.excludes
Created Nov 5, 2012
ctags update scripts for git hooks
View ctags.excludes
tmp
log
doc
coverage
app/assets/javascripts/*min.js
@sriedel
sriedel / gist:3016439
Created Jun 29, 2012
copy opt-out-urls from xml feed
View gist:3016439
file = File.readlines( "20120628T111327_1" )
hash = {}
pairs = file.grep( /extid|opt_out_url/ ).
map { |e| e.gsub( /<.*?>/, '' ) }.
map(&:strip)
pairs.shift
pairs.each_slice( 2 ) { |e| hash[e[0].to_i] = e[1] }
hash.delete(0)
@sriedel
sriedel / gist:1682210
Created Jan 26, 2012
Generate nicknames phonetically
View gist:1682210
class NicknameGenerator
# Grabbed phoneme and template list from http://www.flipcode.com/archives/misc/NameData.xml
# Based on an idea presented on http://www.flipcode.com/archives/Generating_Names_Phonetically.shtml
# by Jim Adams (jadams@copernus.com), 2000
# (sr 2012-01-26)
PHONEME_LIST = { # consonants
:affricate => %w{ch dg j},
:alveolar => %w{d l n r s t z},
:bilabial => %w{b m p},
:bilabial_stop => %w{b p},
You can’t perform that action at this time.