Skip to content

Instantly share code, notes, and snippets.

@robmiller
robmiller / wait-rs-server.rb
Last active May 10, 2016 05:53
Wait for a Rackspace cloud server to build
#!/usr/bin/env ruby
require "fog"
hostname = ARGV.fetch(0)
compute = Fog::Compute.new(
provider: "Rackspace",
rackspace_api_key: ENV.fetch("RACKSPACE_API_KEY"),
rackspace_username: ENV.fetch("RACKSPACE_USERNAME"),
@robmiller
robmiller / enable-rs-db-root.rb
Created February 4, 2016 21:34
A script for easily enabling the root account on a Rackspace cloud database instance, something that's inexplicably impossible to do via the GUI
#!/usr/bin/env ruby
#
# enable-rs-db-root
#
# Enables the root account on a Rackspace cloud database instance.
#
# Usage:
#
# enable-rs-db-root name.of.your.instance.example.com
#
@robmiller
robmiller / childish.sh
Last active December 11, 2015 16:32
childish fun
#!/bin/bash
# Uses text to speech to say MESSAGE 1,000 times, ensuring that sound
# is unmuted and the audio device is set to the internal speakers
#
# Usage: childish MESSAGE
#
# Requires audiodevice:
# http://whoshacks.blogspot.co.uk/2009/01/change-audio-devices-via-shell-script.html
for i in `seq 1 1000`
@robmiller
robmiller / archive-github.rb
Created October 27, 2015 12:43
Clones a GitHub repository locally, and then deletes it from GitHub. Useful for cleaning up no-longer-needed private repos. Usage: archive-github OWNER REPO_NAME
#!/usr/bin/env ruby
#
# archive-github
#
# Author: Rob Miller <r@robm.me.uk>
#
# Clones a GitHub repository locally, and then deletes it from GitHub.
# Useful for cleaning up no-longer-needed private repos.
#
# Assumes you have an OAuth token stored in an environment variable
extern crate plist;
use std::process::Command;
use std::io::{Read,Seek,SeekFrom,Cursor};
use plist::StreamingParser;
fn main() {
println!("Profiling system.");
let profiler = Command::new("system_profiler")
@robmiller
robmiller / cleanup-users.zsh
Created September 21, 2015 11:58
Delete unwanted users from your system (prompts before each one)
for user in $(cat /etc/passwd | cut -d: -f1); do; read "DELETE?Delete $user? "; [[ "$DELETE" =~ ^[Yy]$ ]] && echo "Removing $user"; done
@robmiller
robmiller / 404s.sh
Last active August 27, 2016 11:08
Use wget to spider a site and output which URLs (of pages or resources within those pages, such as stylesheets or images) returned a 404 status.
#!/bin/zsh
#
# 404s
#
# Usage:
# 1. Download, rename to 404s, put in path (~/bin is a good place)
# 2. Run the script:
#
# $ 404s http://example.com
#
@robmiller
robmiller / wp-audit
Last active June 26, 2017 23:33
wp-audit — a script that searches for WordPress installs on disk, and tells you: whether WordPress is out-of-date; whether any of the plugins you're using are out-of-date; and whether any of the core WordPress files have been tampered with. Requires Ruby 2.0+
#!/usr/bin/env ruby
# Usage: wp-audit [options]
# -a, --all-plugins Show all plugins, not just outdated ones
# -c, --[no-]color Highlight outdated versions in colour
# -f, --format [format] Specify output format. Accepted values: html, term (Terminal output and colours), md (Markdown, no colours). term is default.
#
# Requires: Ruby >= 2.0; a Unix-like operating system (one that ships
# with `find`, `less`, and `diff`)
#
# Installation:
@robmiller
robmiller / gist:ce072c37df914adec0ac
Last active August 29, 2015 14:19
Ruby one-liner to replace URLs in a CSV with their bitly-shortened versions. Assumes you have a bit.ly account
$ gem install bitly
$ export BITLY_USERNAME="your bit.ly username" BITLY_API_KEY="your bit.ly API key"
$ ruby -rcsv -rbitly -e 'b = Bitly.new(ENV["BITLY_USERNAME"], ENV["BITLY_API_KEY"]); CSV.filter { |r| r.each { |f| f.replace b.shorten(f).short_url if f =~ /^https?:/ } }' urls.csv > urls.shortened.csv
@robmiller
robmiller / Guardfile
Last active August 29, 2015 14:12 — forked from Integralist/Guardfile
require "terminal-notifier-guard"
guard :shell do
watch(/src\/(.*\/)?(.*)\.rs$/) do |path, folder, file|
p "Path: #{path}"
p "Folder: #{folder}"
p "File: #{file}"
binary_name = File.read("Cargo.toml")[/name = "(.*)"/, 1]