Skip to content

Instantly share code, notes, and snippets.

View thinkerbot's full-sized avatar

Simon Chiang thinkerbot

View GitHub Profile
@thinkerbot
thinkerbot / Gemfile
Created January 14, 2010 17:58
A bundler+gemspec setup for managing dependencies
#############################################################################
# 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 / 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.

@thinkerbot
thinkerbot / sign_requests_with_instance_profile_for_aws_es.rb
Created August 4, 2016 20:03
Sign requests to get access to a role-controlled AWS elasticsearch
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 02:06
A shell script transpiler

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

@thinkerbot
thinkerbot / fix_timestamps.sh
Created November 24, 2016 20:24
Google Uploader
#!/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 '
@thinkerbot
thinkerbot / context.yml
Created December 20, 2010 00:51
ERB vs Erubis Shootout
list:
- name: Adobe Systems
name2: Adobe Systems Inc.
url: http://www.adobe.com
symbol: ADBE
price: 39.26
change: 0.13
ratio: 0.33
- name: Advanced Micro Devices
name2: Advanced Micro Devices Inc.
@thinkerbot
thinkerbot / example.sh
Last active October 29, 2016 03:47
Stream compress, encrypt, decrypt, uncompress
#!/bin/bash
# http://unix.stackexchange.com/questions/79525/openssl-buffering-problem
# http://stackoverflow.com/questions/570984/how-can-i-gzip-standard-in-to-a-file-and-also-print-standard-in-to-standard-out
time (
ruby -e "STDOUT.sync=true; 100000.times {|i| puts(i.to_s + ' knowledge is power') }" |
gzip --stdout |
openssl enc -aes-128-cfb -pass pass:test -bufsize 256 |
openssl enc -base64 -bufsize 256 |
openssl enc -base64 -d -bufsize 256 |
@thinkerbot
thinkerbot / madlib_example.sql
Last active October 5, 2016 19:01
MADlib install on ubuntu (partial)
create temporary sequence predictor_seq;
CREATE temporary TABLE linear_systems_test_data( id INTEGER NOT NULL, lhs DOUBLE PRECISION[], rhs DOUBLE PRECISION);
insert into linear_systems_test_data values (nextval('predictor_seq'), '{352137.0,84.7067061967771,-150.185137392799,122.050417659229,-74.0884874537119,99.7911494563722,-3.7907455558484,181224.690513009,106938.029173016,69336.1362009346,18335.0,12.7007088793537,-250.440511627437,-62.5561474971013,-292.703374755409,-167.012940969203,-78.511449979818,9451.24681999999,5585.85191537643,3628.50938401}'::float[], 88920344.0 );
insert into linear_systems_test_data values (nextval('predictor_seq'), '{84.7067061967771,176105.544243727,61.0252088296143,-73.1971959184637,7.54222162981446,-48.6063990056131,-37.7170700467655,-11006.0678697046,-11871.4874441653,-10787.6157862104,12.7007088793537,9313.85168737771,-31.2780737485506,-85.9645308238089,-89.8568249242787,-78.6462830692247,10.8622991388217,-566.613529886409,-617.49619500345,-565.289335368564}'::float[]
@thinkerbot
thinkerbot / commands.sh
Created July 20, 2011 20:10
IP cheats
# determine interfaces in promiscuous mode (ie sniffing)
ifconfig | grep PROMISC
# DNS lookup, reverse lookup
nslookup
# List all processes, for all users
# UID PID PPID C STIME TTY TIME CMD
ps -afx
@thinkerbot
thinkerbot / thisiswhatyouget.rb
Created October 28, 2013 17:42
Positive match for files not matching '.*\.example'
[
"abc",
"abc.s",
"abc.ex",
"abc.exs",
"abc.exa",
"abc.exas",
"abc.exam",
"abc.exams",
"abc.examp",