Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Marley nmarley

View GitHub Profile
@nmarley
nmarley / copy.rb
Created Apr 14, 2013
Ruby script that uses sequel to populate my new Rails database with data from my old (non-Rails) DB. Used a script instead of a standard Postgres copy to prevent gaps in auto-increment fields.
View copy.rb
#!/usr/bin/env ruby
require 'sequel'
require 'pp'
# script to copy data from my old, non-Rails postgres DB to my new rails DB.
#
# The DB has users, which have a number of Lists.
# And Lists, which have a number of Items.
#
@nmarley
nmarley / runcmd.rb
Created Apr 15, 2013
Ruby function which runs a command and WAITS for it to finish before continuing processing.
View runcmd.rb
#!/usr/bin/env ruby
def runcmd(cmd)
pid = Process.spawn(cmd)
Process.wait(pid)
unless ( $?.exited? && $?.exitstatus == 0 )
raise "oh noes"
end
$?.exitstatus
end
@nmarley
nmarley / git-start.rb
Created Apr 25, 2013
Quick-and-dirty utility to: 1) initialize a new git repo in the current directory (git init) 2) add all existing files, and: (git add .) 3) make an initial commit with message 'Initial commit' (git commit -m 'Initial commit') It won't run the commands if a git repo already exists. It checks the current directory only (does not accept a dir as an…
View git-start.rb
#! /usr/bin/env ruby
#
# git-start.rb
#
# Quick-and-dirty utility to initialize a new git repo in the current
# directory, add all existing files and make an initial commit with message
# 'Initial commit'.
#
# Saves a few seconds here and there.
#
@nmarley
nmarley / output
Created May 24, 2013
Example of how Btce::TradeAPI could be initialized
View output
#<TradeAPI:0x007fd9143fc6c8 @key="YOUR-API-KEY", @secret="YOUR-SECRET-KEY">
#<TradeAPI:0x007fd9144134e0 @key="MY-OTHER-API-KEY", @secret="MY-OTHER-SECRET-KEY">
#<TradeAPI:0x007fd9144129a0 @key="Master key!", @secret="Super S33krit">
@nmarley
nmarley / kapture.sh
Created Jul 18, 2013
OSX can capture WiFi packets using only tcpdump (and without needing a clunky interface such as KisMAC). Used for testing security strength of home WiFi setup.
View kapture.sh
#! /bin/bash
# This is for Mac OSX only.
# =============================================
# explanation of arguments used with 'tcpdump':
# =============================================
# -y IEEE802_11_RADIO => makes it capture __WIFI__ packets, turns resultant file
# into a dump which can be read by aircrack-ng, etc.
#
# -I => puts interface into monitor mode (required to capture packets)
View openssl_output.txt
depth=1 /C=US/O=GeoTrust, Inc./CN=RapidSSL CA
verify error:num=20:unable to get local issuer certificate
verify return:0
CONNECTED(00000003)
OCSP response: no response sent
---
Certificate chain
0 s:/serialNumber=RRAXldgzDrRZWQpGo6FHdTHV3qwvwXtD/OU=GT35895174/OU=See www.rapidssl.com/resources/cps (c)13/OU=Domain Control Validated - RapidSSL(R)/CN=*.rubygems.org
i:/C=US/O=GeoTrust, Inc./CN=RapidSSL CA
-----BEGIN CERTIFICATE-----
@nmarley
nmarley / tapi2.rb
Last active Jan 1, 2016
Ideal implementation of TradeAPI - factors out details of retrieving key/secret
View tapi2.rb
#! /usr/bin/env ruby
class TradeAPI
attr_accessor :key
attr_accessor :secret
def initialize(key, secret)
@key = key
@secret = secret
@nmarley
nmarley / parse_wci.rb
Last active Aug 29, 2015
WorldCoinIndex parser
View parse_wci.rb
require 'nokogiri'
require 'bigdecimal'
require 'bigdecimal/util'
require 'ap'
require 'pp'
def text_to_number(text)
val = text.dup
val.gsub!(/\s+/, '')
@nmarley
nmarley / analyze-tarsnap-usage.rb
Last active Aug 29, 2015
Analyse Tarsnap Usage
View analyze-tarsnap-usage.rb
require 'open3'
require 'pp'
def get_stats(archive_name)
cmd = "sudo tarsnap --print-stats -f #{archive_name}"
stats = run_cmd(cmd)[3,4]
end
def get_uniq_comp_size(stats)
stats.last.split(/\s+/)[-1]
@nmarley
nmarley / check.rb
Last active Aug 29, 2015
Domain Expiration Checker
View check.rb
#! /usr/bin/env ruby
require 'whois'
require 'date'
require 'time'
require 'pp'
require 'awesome_print'
class Chequer
def initialize