Skip to content

Instantly share code, notes, and snippets.

View duggan's full-sized avatar

Ross Duggan duggan

View GitHub Profile
@duggan
duggan / gist:1b42cddf34c419db824d
Created August 2, 2014 21:47
RethinkDB: is it possible to supply ["foo", "def"] to a query on this table and return just the third document?
{
id: 1,
title: "Foo post",
tags: ["foo", "bar", "baz"]
},
{
id: 2,
title: "Bar post",
tags: ["abc", "def", "ghi"]
},
@duggan
duggan / check.php
Last active July 24, 2017 07:16
Get latest versions of a list of PHP PECL extensions
<?php
/*
* Usage:
* $ php check.php --extensions="apc memcached redis"
* apc: 3.1.13
* memcached: 2.2.0
* redis: 2.2.5
*/
class PHPExtensionUpdates {

Keybase proof

I hereby claim:

  • I am duggan on github.
  • I am duggan (https://keybase.io/duggan) on keybase.
  • I have a public key whose fingerprint is 9D02 FCF7 E7C1 1D58 826B 7E69 9271 ADA5 309F A120

To claim this, I am signing this object:

@duggan
duggan / import-keypair
Last active December 23, 2015 23:49
Import public key to all EC2 regions. Required ec2-tools. Dedicated to @whiteley
#!/bin/sh
#
# Imports a public key to all EC2 regions.
#
# Usage:
# sh import-keypair <name> <path>
#
# Example:
# sh import-keypair foo ~/.ssh/foo.pub
#
@duggan
duggan / Vagrantfile
Last active December 18, 2015 11:09 — forked from wizardishungry/Gemfile
Vagrant (v1.1+) snippet to set VirtualBox guest CPU count to the number of host cores on Linux or OS X
# -*- mode: ruby -*-
# vi: set ft=ruby :
if not RUBY_PLATFORM.downcase.include?("mswin")
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--cpus",
`awk "/^processor/ {++n} END {print n}" /proc/cpuinfo 2> /dev/null || sh -c 'sysctl hw.logicalcpu 2> /dev/null || echo ": 2"' | awk \'{print \$2}\' | cut -d' ' -f2 `.chomp ]
end
end
@duggan
duggan / replace.sh
Last active August 11, 2024 13:48
Using sed to to find/replace in a file in a portable way.
#!/bin/sh
# Usage: replace "foo" "bar" "/etc/omg.conf"
replace() {
local pattern=$1
local replacement=$2
local file=$3
local tempfile="$(mktemp -t temp.XXXXX)"
sed "s/$pattern/$replacement/" ${file} > ${tempfile} && mv ${tempfile} ${file}
@duggan
duggan / nginx-setup.sh
Last active December 18, 2015 09:49
Add nginx official deb sources
apt-get install -y curl
# Install nginx
if [ "xx" = "x$(grep 'nginx' /etc/apt/sources.list )x" ] ; then
echo 'Installing nginx...'
echo '
# Repositories for up to date nginx packages
deb http://nginx.org/packages/mainline/ubuntu/ precise nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ precise nginx' >> /etc/apt/sources.list
curl -s http://nginx.org/keys/nginx_signing.key | apt-key add -
apt-get update > /dev/null
@duggan
duggan / gist:5629873
Created May 22, 2013 18:40
/usr/local/bin/composer
#!/bin/sh
/usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off /data/homedirs/deploy/build/composer.phar $*
@duggan
duggan / envclean.sh
Last active December 16, 2015 21:48
Envclean helps nuke and reseed a ruby environment for development purposes using rbenv and bundler. Add it to your PATH.
#!/bin/sh
set -o nounset
set -o errexit
help() {
printf "envclean - managing ruby environments
envclean list list available ruby versions (uses rbenv).
envclean for RUBY_VERSION cleans and initializes a specific ruby version.
@duggan
duggan / removegems.sh
Created April 9, 2013 18:31
Remove all gems
gem list | cut -d" " -f1 | xargs gem uninstall -aIx