Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/perl -w
use strict;
$|++;
use IO::Socket::INET qw(CRLF);
use IO::Select;
use Getopt::Long;
$SIG{__WARN__} = sub {
warn map "[".localtime()."] $_\n", (join "", @_) =~ /(.+)\n*/g;
@mrogaski
mrogaski / .vimrc
Last active December 6, 2016 20:13
My favorite .vimrc
colorscheme blue
set encoding=utf-8
" enable syntax highlighting
syntax enable
" show line numbers
set number
" set tabs to have 4 spaces
@mrogaski
mrogaski / .screenrc
Last active December 6, 2016 20:14
.screenrc
autodetach on
nethack on
deflogin on
term screen-256color
termcapinfo xterm* 'is=\E[r\E[m\E2J\E[H\E[?7h\E[?1;4;6l'
bind h hardcopy
hardcopy_append on
hardcopydir $HOME/capture
@mrogaski
mrogaski / byte_inc.lua
Last active August 29, 2015 14:04
Bytewise increment function in Lua
b = { 0, 0, 0, 0, 0, 0, 0, 0 }
function byte_inc(b)
local c = 1
for i = 1, 8 do
local new = (b[i] + c) % 0xFF
c = math.floor((b[i] + c) / 0xFF)
b[i] = new
if c == 0 then
break
@mrogaski
mrogaski / tcp_state.lua
Created May 15, 2014 17:36
Wireshark TCP session state summarization
--[[
tcp_state.lua - Find TCP HALF_OPEN and HALF_CLOSE conditions.
Copyright (C) 2014 Mark Rogaski <mrogaski@pobox.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
@mrogaski
mrogaski / getOrElseProduce.scala
Created January 19, 2014 15:18
ConcurrentHashMap getOrElseProduce()
import akka.dispatch.Future._
def getOrElseProduce(key: K, producer: => V): Future[V] = {
val f = empty[V]()
putIfAbsent(key, f) match {
case null => f completeWithResult producer
case value => value
}
}
@mrogaski
mrogaski / power.py
Created January 3, 2014 16:02
Animal Power Converter
#!/opt/bin/python
#
# $Id: power.py,v 1.1 2002/02/15 07:42:30 wendigo Exp $
#
import sys
import os
import cgi
import types
#
@mrogaski
mrogaski / turing.pl
Last active January 2, 2016 02:49
Turing Machine JAPH
#!/usr/local/bin/perl -nl
@a=map{s/##//;s/CM/,/;$_}split(",",$_);$s->[$a[0]]{$a[1]}=[@a[2..4]];}continue{
eof&&last;}$q=$i=0;@t=split(//,shift);while("!!"ne$q){($q,$t[$i],$_)=@{$s->[$q]
{$t[$i]}||die};$i+=(/R/?1:-1);if($i<0){$i++;unshift(@t,"");}}print@t;{