Skip to content

Instantly share code, notes, and snippets.

Simon Chiang thinkerbot

  • Denver, CO
Block or report user

Report or block thinkerbot

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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 / 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 / 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 / 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'
@thinkerbot
thinkerbot / README.md
Created May 7, 2012
A shell script transpiler
View README.md

Provides a mechanism to write portable shell scripts in a higher-level language.

Ruby may be used to describe shell scripts in code. For example shell commands may be represented as methods and command pipelines as method chains. The method calls are translated into shell script. Zero or more script files may be generated in this process.

Cursor objects can be used to mark the locations in the final script where a given shell expression is to be added. For example one cursor could mark where options are defined in a 'getopts' command, another could mark where the option

View fix_timestamps.sh
#!/bin/bash
# Google Uploader looks at a file timestamp not the video metadata. Run
# this to get the right timestamp to appear on the video. Requires
# exiftool. https://productforums.google.com/forum/#!topic/photos/oj96JZK14Fs
#
# brew install exiftool
# ./fix_timestamps.sh
#
cd "DIR_WITH_THE_m4v_VIDEO_FILES"
ruby -rtime -ryaml -rshellwords -e '
You can’t perform that action at this time.