Skip to content

Instantly share code, notes, and snippets.

View thinkerbot's full-sized avatar

Simon Chiang thinkerbot

View GitHub Profile
@thinkerbot
thinkerbot / public_enc_example.sh
Created November 19, 2010 04:56
Public-key encryption example using OpenSSL
#!/bin/bash
#
# Public-Key Encryption and Decryption
# * http://www.openssl.org/
# * http://barelyenough.org/blog/2008/04/fun-with-public-keys/
#
# Mac OS X 10.6.4
# OpenSSL 0.9.8l 5 Nov 2009
# Generate keys
@thinkerbot
thinkerbot / gem_env.sh
Created November 8, 2010 18:28
Illustrates GEM_HOME vs GEM_PATH
# Two ENV variables control the 'gem' command:
#
# GEM_HOME: the single path to a gem dir where gems are installed
# GEM_PATH: a standard PATH to gem dirs where gems are found
#
# A gem directory is a directory that holds gems. The 'gem' command will lay
# out and utilize the following structure:
#
# bin # installed bin scripts
# cache # .gem files ex: cache/gem_name.gem
@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 / multiple_writers
Created September 1, 2013 18:39
Demonstrates that multiple writers to a single fifo often get inputs interleaved, regardless of sync.
#!/bin/bash
# 8... always?
mkfifo fifo
ruby -e '100000.times {|i| puts "a"}' > fifo &
ruby -e '100000.times {|i| puts "b"}' > fifo &
ruby -e '100000.times {|i| puts "c"}' > fifo &
ruby -e '100000.times {|i| puts "d"}' > fifo &
ruby -e '100000.times {|i| puts "e"}' > fifo &
ruby -e '100000.times {|i| puts "f"}' > fifo &
ruby -e '100000.times {|i| puts "g"}' > fifo &
@thinkerbot
thinkerbot / README.md
Created October 19, 2012 04:41
Hex-escape sensitive command line characters

Description

Hex-escape sensitive tcl/shell characters

Usage

printf $(printf "\x26\x3b\x60\x27\x22\x7c\x2a\x3f\x7e\x3c\x3e\x5e\x28\x29\x5b\x5d\x7b\x7d\x24\x5c\n" | ./escape)

&;`'"|*?~<>^()[]{}$\

@thinkerbot
thinkerbot / expect_argv
Created November 10, 2012 16:51
Expect - special characters without escape
#!/usr/bin/expect -f
#############################################################################
#
# Arguments passed on the command line end up as a list of escaped strings.
# Hence you can eval them to get the literal values properly entered into
# an expect command.
#
# ./expect_argv '---&;`'\''"|*?~<>^()[]{}$\---'
# ---&;`'"|*?~<>^()[]{}$\---
#
@thinkerbot
thinkerbot / fetch.rb
Created May 30, 2011 17:43
fetch + format craigslist data into csv
require 'rubygems'
require 'rest_client'
request = 'http://denver.craigslist.org/search/cta?query=accord&srchType=T&minAsk=8000&maxAsk=20000&hasPic=1&s=%s'
page_min, page_max = ARGV
(page_min.to_i...page_max.to_i).each do |page|
puts RestClient.get(request % page)
end
@thinkerbot
thinkerbot / interact_example
Created October 25, 2012 03:06
Expect examples
#!/bin/bash
# works
cat > example <<SCRIPT
#!/usr/bin/env expect -f
spawn irb
interact
SCRIPT
chmod +x example
./example
@thinkerbot
thinkerbot / run.bat
Created August 2, 2011 20:21
Execute a powershell script via ssh
# Notes:
# 1) The input format must be specified to prevent ssh from hanging
# 2) The full path to the script is required
# 3) An SSH server must be running on the Windows box, naturally. WinSSHD
# is free for personal, non-commercial use and worked for this example.
# See http://www.bitvise.com/winsshd
#
# You have to set the execution policy for scripts so that powershell has
# permissions to run the script. To do so, search for 'Powershell' under
# the Start menu. Then right-click and 'Run as administrator' so that you
@thinkerbot
thinkerbot / README.md
Created June 7, 2012 21:03
Find and remove old git branches

Description

Find and delete old git branches that are no longer needed.

Usage

Clone the repo and add to your path (just for ease of use):