Skip to content

Instantly share code, notes, and snippets.

View adrianpike's full-sized avatar

Adrian Pike adrianpike

View GitHub Profile
@adrianpike
adrianpike / ioctl.c
Created January 14, 2010 22:06
Manual control of a serial port's RTS & DTR lines
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
We couldn’t find that file to show.
log_format metrics '$time_local $upstream_response_time $request_time $request_length $bytes_sent | "$request"';
access_log /var/log/nginx/traffic.log metrics;
access_log logs/access.log combined;
# Gives you stuff like this:
15/Sep/2010:15:28:35 -0400 0.087 0.087 1341 3619 | "GET /account HTTP/1.1"
15/Sep/2010:15:28:35 -0400 - 0.000 1315 158 | "GET /javascripts/jquery-1.4.1.min.js?1284497684 HTTP/1.1"
#!/bin/bash
#
# /etc/rc.d/init.d/unicorn
# unicorn: This script starts and stops a unicorn app
#
# Author: Adrian Pike
#
# Source function library.
. /etc/init.d/functions
begin
uid, gid = Process.euid, Process.egid
user, group = 'apps', 'apps'
target_uid = Etc.getpwnam(user).uid
target_gid = Etc.getgrnam(group).gid
worker.tmp.chown(target_uid, target_gid)
if uid != target_uid || gid != target_gid
Process.initgroups(user, target_gid)
Process::GID.change_privilege(target_gid)
Process::UID.change_privilege(target_uid)
> 231
---- #229 -----
From: nerd
The nerd was here.
Enter, or Q to stop reading.
> 1
---- #228 -----
From: briandemant
this seems fun ;)
could start a new era for BBS'es
@adrianpike
adrianpike / rumble_stats
Created October 21, 2010 03:52
Simple word count of Rumble resource_used stats. make it bettar!
require 'rubygems'
require 'activeresource'
class Team < ActiveResource::Base; self.site = "http://railsrumble.com/"; self.format = :json; end
teams = []
counts = Hash.new(0)
(1..6).each {|n| teams += Team.find(:all, :params => {:page => n}).collect(&:team) }
teams.collect(&:entry).collect(&:resources_used).collect(&:split).flatten.each{|rn| counts[rn] += 1 }
counts.sort {|a,b| b[1]<=>a[1]}.each {|k,v|
@adrianpike
adrianpike / HACK THE PLANET.rb
Created November 1, 2010 22:39
Cadence measuring with the rubies
SAMPLE_SIZE = 100 # set this
i = 0
matches = {}
old = " "
while i < SAMPLE_SIZE
begin
system("stty raw -echo")
@adrianpike
adrianpike / pronounceable_passwords.php
Created November 10, 2010 00:14
Pronounceable password generator
<?php
function makeRandomPassword() {
$vowels = "aeiou";
$consonants = "bcdfghjklmnpqrstvwxyz";
$numbers = "0123456789";
srand((double)microtime()*1000000);
$i = 0; // # of chars;
$j=0; // Position. 0=consonant, 1 & 2 = vowels
while ($i <= 6) {
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
require 'rack'
protected = Rack::Auth::Basic.new(Foobar::Application) do |username, password|
'secret' == password
'foodebiz' == username
end
protected.realm = 'GO AWAY PLOX'