Skip to content

Instantly share code, notes, and snippets.

ruby -e 'p ",\x05\x14\x14\x1DD&\r\x16\x10\f\x00\x05\x1DD#\x11\x1D".chars.map{|x|(x.unpack("C")[0]^100).chr}.join'
** Invoke spec (first_time)
** Invoke vendor_orgmode (first_time)
** Invoke /Users/rob/src/quarto/vendor/org/lisp (first_time, not_needed)
** Invoke vendor/org-8.0.7 (first_time, not_needed)
** Invoke vendor/org-8.0.7.tar.gz (first_time, not_needed)
** Invoke vendor (first_time, not_needed)
** Execute vendor_orgmode
** Execute spec
/Users/rob/.rvm/rubies/ruby-2.0.0-p247/bin/ruby -S rspec ./spec/quarto/build_spec.rb ./spec/quarto/pandoc_epub_spec.rb ./spec/tasks/codex_spec.rb ./spec/tasks/export_spec.rb ./spec/tasks/highlight_spec.rb ./spec/tasks/master_spec.rb ./spec/tasks/sections_spec.rb ./spec/tasks/skeleton_spec.rb -t ~org
Run options: exclude {:org=>true}
@robmiller
robmiller / gist:7562495
Created November 20, 2013 12:38
Ruby one-liner for transposing rows to columns
echo "foo\nbar\nbaz\nfoo\nbar\nbaz" | ruby -pe 'BEGIN{i=0}; $_.chomp! << "\t" unless (i += 1) % 3 == 0'
# Input:
#
# foo
# bar
# baz
# foo
# bar
# baz
<?php
function register()
{
if (!empty($_POST)) {
$msg = '';
if ($_POST['user_name']) {
if ($_POST['user_password_new']) {
if ($_POST['user_password_new'] === $_POST['user_password_repeat']) {
if (strlen($_POST['user_password_new']) > 5) {
if (strlen($_POST['user_name']) < 65 && strlen($_POST['user_name']) > 1) {
@robmiller
robmiller / unvalued_projects.rb
Last active December 26, 2015 03:19
Script for showing projects in your LiquidPlanner workspace that haven't had a contract_value added to them.
require "rubygems"
require "liquidplanner"
# Assumes a file called ~/.lprc exists that contains:
# { "email": "[email protected]", "pass": "pa55w0rd", "space": 1234 }
config = JSON.parse(IO.read(File.expand_path("~/.lprc")))
lp = LiquidPlanner::Base.new(email: config["email"], password: config["pass"])
workspace = lp.workspaces(config["space"])
@robmiller
robmiller / strtotime.rb
Last active December 24, 2015 21:49
Sometimes I want to do natural language datetime calculations from the commandline, just to work out things like "what date will it be in 60 days" or "when was 30 days ago". This helps.
#!/usr/bin/env ruby
# Requirements: Ruby and the Chronic gem
#
# Install Chronic with: `gem install chronic`
#
# Examples:
#
# $ strtotime 'in 60 days'
# 6 Dec 2013 14:55:44
@robmiller
robmiller / nscp.sh
Created October 7, 2013 13:34
I often want to copy the IP address for a hostname to my clipboard. This shell function will do that; drop it in your `.bashrc` or `.zshrc` and you can then call `nscp example.com` to copy the A record for `example.com` to your clipboard. It also outputs it, so you can verify it by eye (or pipe it into something else).
function nscp() {
nslookup $1 | sed -n 'x;$p' | cut -d' ' -f2 | tee >(pbcopy)
}
@robmiller
robmiller / sqlite-distance.rb
Last active February 3, 2021 16:33
Ruby/SQLite code for finding places within a certain distance from another place. In other words, Ruby code that adds a "DISTANCE(lat1, lon1, lat2, lon2)" to SQLite, allowing you to select records based on the distance between two points of latitude and longitude. Magic! Adapted from the ObjectiveC version here: http://daveaddey.com/?p=71
db = SQLite3::Database.new ":memory:"
# A sample SQLite table; all that's necessary is the lat and log fields
db.execute <<-SQL
CREATE TABLE users (
email VARCHAR(255),
lat FLOAT,
lon FLOAT
)
SQL
@robmiller
robmiller / .gitconfig
Created July 17, 2013 07:52
Some useful Git aliases that I use every day
#
# Working with branches
#
# Get the current branch name (not so useful in itself, but used in
# other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track
# the upstream branch
publish = "!git push -u origin $(git branch-name)"
@robmiller
robmiller / gist:6002038
Last active December 19, 2015 18:49
One-liner for finding out what usernames attackers are using when bruteforcing SSH on an OS X box
sudo bzcat /var/log/secure*.bz2 \
| perl -ne '/authentication error for( illegal user)? (\S+) from/ && print "$2\n"' \
| sort | uniq -c | sed 's/^ *//' | sort -n