Skip to content

Instantly share code, notes, and snippets.

@mattriley
mattriley / run-gist.sh
Last active March 14, 2020 01:36
Clones and runs a script from a GitHub gist.
# Usage: ./run-gist.sh <GIST ID> <SCRIPT NAME> <SCRIPT ARGS>
# Extract args
gist_id="$1"
script_name="$2"
script_args="${@:3}"
# Clone gist
remote="https://gist.github.com/$gist_id.git"
gist_dir=".gist/$gist_id"
@mattriley
mattriley / nvmrc-latest-lts.sh
Last active March 14, 2020 01:26
Writes a .nvmrc file containing the current Node LTS version. Requires nvm.
# Usage: ./nvmrc-latest-lts.sh
# Load NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Find latest Node LTS version
last_line=$(nvm ls-remote --lts --no-colors | tail -n 1)
# Match the version number
@mattriley
mattriley / post_xml.rb
Created January 25, 2012 22:39
Ruby HTTP POST request containing XML content
require 'net/http'
def post_xml url_string, xml_string
uri = URI.parse url_string
request = Net::HTTP::Post.new uri.path
request.body = xml_string
request.content_type = 'text/xml'
response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }
response.body
end