Skip to content

Instantly share code, notes, and snippets.

View thwarted's full-sized avatar
🥓
increasingly at large

Andy Bakun thwarted

🥓
increasingly at large
View GitHub Profile
@thwarted
thwarted / inet-server-iterator.perl
Created September 30, 2009 07:35
quick comparison of using an iterator to accept network connections
#!/usr/bin/perl
use strict;
use warnings;
package ReceiveConnection;
use IO::Socket::INET;
sub TIEARRAY {
@thwarted
thwarted / perlthreadsperf.pl
Created December 16, 2009 17:56
perl threads perf
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use threads;
use threads::shared;
use Thread::Queue;
function sprintf() {
if (!arguments || arguments.length < 1 || !RegExp) { return; }
var str = arguments[0];
var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
var b = [], numSubstitutions = 0, numMatches = 0;
while (1) {
var a = re.exec(str);
if (!a) { break; }
var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
var pPrecision = a[5], pType = a[6], rightPart = a[7];
@thwarted
thwarted / screen-swap-x.diff
Created August 10, 2010 07:36
simplistic screen swap-x patch
diff -ur screen-4.0.3/display.c screen-4.0.3-swap-x/display.c
--- screen-4.0.3/display.c 2003-12-05 05:45:41.000000000 -0800
+++ screen-4.0.3-swap-x/display.c 2010-08-09 23:59:07.465303854 -0700
@@ -33,6 +33,8 @@
#include "extern.h"
#include "braille.h"
+int swap_x = 1;
+
static int CountChars __P((int));
@thwarted
thwarted / agentscreen
Created March 28, 2011 08:33
the script I use to restore my ssh-agent settings to running screen sessions
#!/bin/bash
if [ "$TERM" != "screen" ]; then
# if the auth socket variable is empty, don't do anything
if [ ! -z "$SSH_AUTH_SOCK" ]; then
# include USER to protect against shared HOME directories (rare)
NEWSOCK=$HOME/.agent-sshscreen-$USER.sock
if [ "$SSH_AUTH_SOCK" != "$NEWSOCK" ]; then
# test if the auth sock we have is actually working
# don't link to a dead socket
@thwarted
thwarted / gist:903028
Created April 5, 2011 04:21
migrating to a newly acquired computer
# install operating system onto new drive
# previous computer's drive is mounted in /mnt/oldinstall
# install all software my previous machine had installed
# - might want to trim off distribution and arch if going to a new release
# - or just skip this if going to a new release
yum install $( diff <( chroot /mnt/oldinstall rpm -qa | sort ) <( rpm -qa | sort) | grep \< | cut -c3- )
# or apt-get if you have it
# copy home directories
@thwarted
thwarted / nodejs.spec
Created June 7, 2011 05:20 — forked from charles-dyfis-net/nodejs.spec
node.js spec for Fedora 14
#node is an already known package. node.js have dot in name, so "nodejs"
#is a better name
#some ideas are taken from
#http://blog.fpmurphy.com/2010/12/node-js-and-npm-on-fedora-14.html
Name: nodejs
Version: 0.4.8
Release: 0%{?dist}
Summary: JavaScript server-side network application development
Group: Development/Languages/Other
License: MIT
@thwarted
thwarted / footguy.c
Created June 22, 2011 06:40
footguy - he's very impatient
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <unistd.h>
void uxsleep(int time)
{
sleep(time);
}
@thwarted
thwarted / lsswap
Created October 14, 2011 22:37
really rough process list that includes swap and memory usage
#!/bin/bash
# print a ps listing that includes the used swap space
# inspired by Erik Ljungstrom 27/05/2011
maxwidth=$( stty -a | tr ';' '\n' | grep columns | awk '{ print $2 }' )
maxwidth=$(( maxwidth - 10 ))
pscols=vsz:10,rss:10,pid,user,pri,stime,time:12,cmd
paste <( echo SWAP ) <( ps -p $$ -o $pscols | head -1 )
for procdir in /proc/[0-9]* ; do
PID=$( basename $procdir )
@thwarted
thwarted / rinse.spec
Created November 29, 2011 09:47
RPM spec file for rinse
Name: rinse
Version: 1.9.1
Release: 0%{?dist}
Summary: Carry out the installation of a new RPM-based distribution.
Group: Development/Tools
License: Artistic
URL: http://www.steve.org.uk/Software/rinse/
Source: http://www.steve.org.uk/Software/rinse/rinse-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: make