Skip to content

Instantly share code, notes, and snippets.

View thinkerbot's full-sized avatar

Simon Chiang thinkerbot

View GitHub Profile
@thinkerbot
thinkerbot / dashboard.xml
Created November 8, 2011 18:04
Splunk examples
<?xml version="1.0"?>
<form>
<label>The Battle Overview</label>
<searchTemplate><![CDATA[
index=thebattle | rex field=uri "/battle/(?<thing>[^?]+)(\?color=(?<color>\w+))?" | eval color=if(isnull(color), "", color) | eval strategy=color.thing | stats count by date_hour, bytes, clientip, strategy
]]>
</searchTemplate>
<fieldset>
<input type="time">
<label/>
@thinkerbot
thinkerbot / black_magic.rb
Created November 5, 2011 22:08
Access included modules on a BasicObject
class Basic < BasicObject
def _included_modules_
class << self
SINGLETON_CLASS = self
def _included_modules_
SINGLETON_CLASS.included_modules
end
end
_included_modules_
end
helpers 'linecook/shell'
############################################################
shebang '/bin/bash', :one, :two, [:three], %{
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation
}, %{
-a=A [one] : option with default and external var
-b=b : option
-c : flag
@thinkerbot
thinkerbot / prompt.sh
Created October 31, 2011 21:03
Shell prompt example
stty -echo
attempt=0
while [ "$attempt" -lt 3 ]; do
printf "Do you wish to continue? [y/n]: "
read answer
case $answer in
y ) printf "\nOk!\n"; break;;
n ) printf "\nToo bad.\n"; break;;
* ) printf "\nPlease answer y or n.\n";;
esac
@thinkerbot
thinkerbot / example.rb
Created October 25, 2011 14:31
Shell timeout test for PTY exits
require 'pty'
#
# To add to results:
#
# echo "# OS" >> results.txt
# ruby example.rb | tee -a results.txt
#
shells = ARGV
@thinkerbot
thinkerbot / README.md
Created October 14, 2011 03:04
Sporadic missing EOF for pty shell

Demonstrates a pecuilar problem whereby it appears a shell session occasionally does not produce an EOF on the pty slave after exit. I'm not sure this is an issue with the implementation of PTY or an OS X issue. It does not appear to be a shell issue per-se as I can produce the failure with bash, zsh, ksh, csh, and tcsh.

Example failures:

thinkerbot:~/Documents/Gems/shell_test> ruby --version
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.4.0]

thinkerbot:~/Documents/Gems/shell_test> time ruby pty_fail.rb 10000 /bin/bash
pty_fail.rb:19:in `block (2 levels) in <main>': timeout waiting for slave EOF (i:425 pid:13569) (RuntimeError)

"exit 8\r\n$ exit 8\r\nexit\r\n"

@thinkerbot
thinkerbot / example.exp
Created October 14, 2011 01:56
Expect example
##############################################
# env PS1='$ ' PS2='> ' expect -f script.txt
spawn /bin/sh
expect "$ " ; send "printf \"abc\\rxyz\\n\"\n"
expect "$ " ; send "printf \"abc\\fxyz\\n\"\n"
expect "$ " ; send "for n in one two; do\n"
expect "> " ; send " echo \$n\n"
expect "> " ; send "done\n"
expect "$ " ; send "exit \$?\n"
expect eof
@thinkerbot
thinkerbot / hex_to_decimal.sh
Created October 5, 2011 14:23
shell tricks
h2d () {
for hex in $*; do
HEX=$(echo "$hex" | tr [:lower:] [:upper:])
echo "ibase=16;$HEX" | bc
done;
}
d2h () {
for DEC in $*; do
echo "obase=16;$DEC" | bc
@thinkerbot
thinkerbot / redirect_at_pipe_end.sh
Created October 4, 2011 19:52
linecook considerations
cat > input.csv <<DOC
1,a
2,a
3,b
4,c
5,a
6,b
DOC
cut -d ',' -f 2 < input.csv | uniq -c
# 2 a
@thinkerbot
thinkerbot / README.md
Created September 27, 2011 21:54
syslog usage from ruby

Setup

This gist tests various aspects of syslog from Ruby. In order to do so you have to setup syslog first.

Setting up syslog is system-specific and quite variable because of variations like rsyslogd or syslogd-ng. OSX, for example, uses a custom system logger (the apple system logger) that supports the syslog API, but also adds additional stuff like the 'syslog' command line application.