Skip to content

Instantly share code, notes, and snippets.

View ampedandwired's full-sized avatar

Charles Blaxland ampedandwired

  • Sydney, Australia
View GitHub Profile
@ampedandwired
ampedandwired / README.md
Last active October 6, 2022 06:40
webpack-dev-server with html-webpack-plugin
$ npm install
$ ./node_modules/.bin/webpack-dev-server
$ open http://localhost:8080/webpack-dev-server/

Notes:

  • Note the trailing slash on the URL is significant. Without it webpack-dev-server shows a file listing page.
  • You need 1.0.11 or later of webpack-dev-middleware for this URL to work. With earlier versions you need to specify the full URL like this: http://localhost:8080/webpack-dev-server/index.html.
  • To get a non-autoreloading version of the page use http://localhost:8080/index.html.
@ampedandwired
ampedandwired / template.rb
Last active August 26, 2020 03:43
Splitting cfndsl templates into multiple files
require_relative "subtemplate.rb"
CloudFormation {
instance_type = external_parameters.fetch(:instance_type, "t2.micro")
my_instance(instance_type)
}
@ampedandwired
ampedandwired / Vagrantfile
Created January 14, 2015 05:09
Configure a Vagrant VM to piggyback off CNTLM running on the host
def get_proxy_url
# Doesn't support different proxies for different protocols at present
host_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] || ENV['https_proxy'] || ENV["HTTPS_PROXY"]
if host_proxy
uri = URI(host_proxy)
if ['localhost', '127.0.0.1'].include? uri.host
# 10.0.2.2 is the default vagrant gateway and should connect to the host OS.
# Confirm this by running 'netstat -r' in the guest.
host_proxy = host_proxy.sub(uri.host, '10.0.2.2')
end
@ampedandwired
ampedandwired / gist:3385002
Last active October 8, 2017 11:53
Zip a directory to memory in Ruby. The rubyzip library is pretty hard to use. I tried for ages to figure out how to zip a directory to a string in memory. So here's an example that zips the given directory to a Ruby StringIO object using rubyzip.
require 'zip/zip'
def zip(dir)
Zip::ZipOutputStream::write_buffer do |zos|
Dir["#{dir}/**/**"].each do |file|
path_for_file_in_zip = file.sub(/\A#{dir}\//, '')
if !File.directory?(file)
zip_entry = zos.put_next_entry(path_for_file_in_zip)
zos << IO.read(file)
end
@ampedandwired
ampedandwired / docker-cleanup.sh
Created February 12, 2017 22:33
Docker cleanup
#!/bin/bash
# Remove exited containers
docker rm $(docker ps -qa --no-trunc --filter "status=exited")
# Remove dangling containers
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
# Remove unused images (https://github.com/docker/docker/issues/9054#issuecomment-184246090)
docker rmi $(grep -xvf <(docker ps -a --format '{{.Image}}') <(docker images | tail -n +2 | grep -v '<none>' | awk '{ print $1":"$2 }'))
@ampedandwired
ampedandwired / trello-bz.js
Created October 27, 2016 07:24
A TamperMonkey script that turns bugzilla bug references in Trello into clickable links. Handles formats like "BZ123", "BZ-123", "BZ 123" or "BZ#123"
// ==UserScript==
// @name Trello Bugzilla Linker
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Links Trello issues to Bugzilla
// @author Charles Blaxland
// @match https://trello.com/*
// @grant none
// ==/UserScript==
@ampedandwired
ampedandwired / trello-bz.js
Created October 27, 2016 07:24
A TamperMonkey script that turns bugzilla bug references in Trello into clickable links. Handles formats
// ==UserScript==
// @name Trello Bugzilla Linker
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Links Trello issues to Bugzilla
// @author Charles Blaxland
// @match https://trello.com/*
// @grant none
// ==/UserScript==
@ampedandwired
ampedandwired / trello-bz.js
Created October 27, 2016 07:24
A TamperMonkey script that turns bugzilla bug references in Trello into clickable links. Handles formats
// ==UserScript==
// @name Trello Bugzilla Linker
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Links Trello issues to Bugzilla
// @author Charles Blaxland
// @match https://trello.com/*
// @grant none
// ==/UserScript==
@ampedandwired
ampedandwired / jenkins.conf
Created September 25, 2013 06:35
Configuring nginx as a Jenkins proxy with SSL
upstream app_server {
server 127.0.0.1:8080 fail_timeout=0;
}
server {
listen 80 default;
rewrite ^ https://$host$request_uri? permanent;
}
server {
@ampedandwired
ampedandwired / gist:3682627
Created September 9, 2012 04:39
A simple command line client for JSON (Rails) APIs - basically a curl wrapper
#!/bin/bash
baseurl='http://localhost:3000'
output_file=zb.out
rm $output_file
action=`echo $1 | tr '[a-z]' '[A-Z]'`
shift
url=$1.json
shift