Skip to content

Instantly share code, notes, and snippets.

View DavidWittman's full-sized avatar

David Wittman DavidWittman

View GitHub Profile
@bfg
bfg / apache-2.2-mod_remoteip.c
Created June 23, 2011 09:32
Working backport (doesn't crash when using Allow/Deny ACLs) of Apache 2.3 module mod_remoteip to Apache 2.2.x
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@spicycode
spicycode / tmux.conf
Created September 20, 2011 16:43
The best and greatest tmux.conf ever
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000
@rubiojr
rubiojr / fog_kvm_create_from_template.rb
Created November 29, 2011 17:15
Create KVM guest using fog/libvirt and a QCOW2 template
require 'fog'
require 'net/ssh'
require 'net/scp'
def upload_file(host, user, password, source, dest, print_progress = true)
Net::SSH.start(host, user, :password => password) do |ssh|
puts "Uploading file... (#{File.basename(source)})"
ssh.scp.upload!(source, dest) do |ch, name, sent, total|
if print_progress
@events =
events: {}
on: (topic, handler, context = this) ->
(@events[topic] or= []).push {handler, context}
trigger: (topic, args...) ->
return unless @events[topic]?
handler.apply(context, args) for {handler, context} in @events[topic]
@nijikokun
nijikokun / example-user.js
Created May 3, 2012 20:46
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9_-]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active April 23, 2024 19:14
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@sturadnidge
sturadnidge / tmux-1.8-on-CentOS-6.x.txt
Last active May 10, 2021 18:31
Install tmux 1.8 on CentOS 6.x minimal (64bit)
# download latest libevent2 and tmux sources, and extract them somewhere
# (thx bluejedi for tip on latest tmux URL)
#
# at the time of writing:
# https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
# http://sourceforge.net/projects/tmux/files/latest/download?source=files
#
# install deps
yum install gcc kernel-devel make ncurses-devel
@DavidWittman
DavidWittman / tokenreaper.sql
Last active December 14, 2015 09:08
MySQL scheduled event to remove Keystone authentication tokens expired for over one week.
USE keystone
-- This needs to be set in the my.cnf to persist
SET GLOBAL event_scheduler = 1;
DELIMITER $$
CREATE EVENT tokenreaper
ON SCHEDULE EVERY 1 WEEK
DO BEGIN
DELETE FROM `token` WHERE expires <= DATE_SUB(NOW(), INTERVAL 1 WEEK);
END $$
DELIMITER ;
@lorin
lorin / preseed-fragment.seed
Last active November 30, 2022 04:04
Automated partitioning with Ubuntu preseed
# Use LVM for partitioning
d-i partman-auto/method string lvm
# If one of the disks that are going to be automatically partitioned
# contains an old LVM configuration, the user will normally receive a
# warning. Preseed this away
d-i partman-lvm/device_remove_lvm boolean true
# And the same goes for the confirmation to write the lvm partitions.
d-i partman-lvm/confirm boolean true