Skip to content

Instantly share code, notes, and snippets.

Avatar

Simon Chiang thinkerbot

  • Denver, CO
View GitHub Profile
@thinkerbot
thinkerbot / gem_env.sh
Created Nov 8, 2010
Illustrates GEM_HOME vs GEM_PATH
View gem_env.sh
# 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 / public_enc_example.sh
Created Nov 19, 2010
Public-key encryption example using OpenSSL
View public_enc_example.sh
#!/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 / run.bat
Created Aug 2, 2011
Execute a powershell script via ssh
View run.bat
# 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 Jun 7, 2012
Find and remove old git branches
View README.md

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):

@thinkerbot
thinkerbot / expect_argv
Created Nov 10, 2012
Expect - special characters without escape
View expect_argv
#!/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 '---&;`'\''"|*?~<>^()[]{}$\---'
# ---&;`'"|*?~<>^()[]{}$\---
#
View interact_example
#!/bin/bash
# works
cat > example <<SCRIPT
#!/usr/bin/env expect -f
spawn irb
interact
SCRIPT
chmod +x example
./example
@thinkerbot
thinkerbot / Gemfile
Created Jan 14, 2010
A bundler+gemspec setup for managing dependencies
View Gemfile
#############################################################################
# Dependencies in this Gemfile are managed through the gemspec. Add/remove
# depenencies there, rather than editing this file ex:
#
# Gem::Specification.new do |s|
# ...
# s.add_dependency("sinatra")
# s.add_development_dependency("rack-test")
# end
#
@thinkerbot
thinkerbot / multiple_writers
Created Sep 1, 2013
Demonstrates that multiple writers to a single fifo often get inputs interleaved, regardless of sync.
View multiple_writers
#!/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 Sep 27, 2011
syslog usage from ruby
View README.md

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.

@thinkerbot
thinkerbot / sign_requests_with_instance_profile_for_aws_es.rb
Created Aug 4, 2016
Sign requests to get access to a role-controlled AWS elasticsearch
View sign_requests_with_instance_profile_for_aws_es.rb
require 'aws-sdk'
require 'faraday_middleware'
require 'faraday_middleware/aws_signers_v4'
require 'pp'
conn = Faraday.new(url: 'http://ENDPOINT') do |faraday|
faraday.request :aws_signers_v4,
credentials: Aws::InstanceProfileCredentials.new.credentials,
service_name: 'es',
region: 'REGION'
You can’t perform that action at this time.