Skip to content

Instantly share code, notes, and snippets.

View nmarley's full-sized avatar
🦀
我想吃一點點東西。

Nathan Marley nmarley

🦀
我想吃一點點東西。
View GitHub Profile
@nmarley
nmarley / copy.rb
Created April 14, 2013 16:28
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.
#!/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 April 15, 2013 02:13
Ruby function which runs a command and WAITS for it to finish before continuing processing.
#!/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 April 25, 2013 17:27
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…
#! /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 21:54
Example of how Btce::TradeAPI could be initialized
#<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 July 18, 2013 01:43
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.
#! /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)
@nmarley
nmarley / openssl_output.txt
Created October 6, 2013 20:17
Output of the openssl command for the issue https://github.com/rubygems/rubygems/issues/665
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 January 1, 2016 10:09
Ideal implementation of TradeAPI - factors out details of retrieving key/secret
#! /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 August 29, 2015 14:19
WorldCoinIndex parser
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 August 29, 2015 14:20
Analyse Tarsnap Usage
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 August 29, 2015 14:21
Domain Expiration Checker
#! /usr/bin/env ruby
require 'whois'
require 'date'
require 'time'
require 'pp'
require 'awesome_print'
class Chequer
def initialize