Skip to content

Instantly share code, notes, and snippets.

View glenjamin's full-sized avatar

Glen Mailer glenjamin

View GitHub Profile
@glenjamin
glenjamin / .kitchen.yml
Created September 28, 2015 20:48
Systemd in a container! Useful for testing services controlled by chef
---
driver:
name: docker
provision_command:
- yum -y swap -- remove systemd-container systemd-container-libs -- install systemd
- systemctl enable sshd.service
- curl -L https://www.opscode.com/chef/install.sh | bash
require_chef_omnibus: false
run_command: /usr/sbin/init
privileged: true
@glenjamin
glenjamin / cloudstack-acceptance.sh
Created September 6, 2015 22:30
Stuff to help with running cloudstack acceptance tests against https://github.com/bvbharatk/VagrantSimulator
# Testing one section
# TF_ACC=1 go test ./builtin/providers/cloudstack -v -timeout 90m -run TestAccCloudStackLoadBalancerRule 2>&1 | tee cloudstack-acceptance.txt
# Testing all sections
# TF_ACC=1 go test ./builtin/providers/cloudstack -v -timeout 90m | tee cloudstack-acceptance-full.txt
export \
CLOUDSTACK_API_URL=http://localhost:8081/client/api \
CLOUDSTACK_API_KEY=On9yoOplojrOMV1GK587hnSKP-f4K94FxkCgeAAtnGws7lEpRTvxz9UoQCylkRhcamoWlMznPuHGCBtCtCXD9g \
CLOUDSTACK_SECRET_KEY=kKOrZ0XeuMJ-YR4p4a_2pr8JdDSSTYjodQe1CoKT2MSP5libE0iyeLmSwHH4zeKI8r6M4Fu1PVVvwwqCr_3vDA \
@glenjamin
glenjamin / users.tf.rb
Last active September 4, 2015 17:54
Terrafiddle
users = %w(
abc
def
ghi
jkl
)
def autohash
Hash.new { |h, k| h[k] = autohash }
end
@glenjamin
glenjamin / server-hot-reload.js
Created July 15, 2015 16:23
Hack way to "hot reload" when server rendering via NodeJS
// assuming that the React app is inside /client/
// clear cached client modules so next server render uses new stuff
webpack.plugin('done', function() {
Object.keys(require.cache).forEach(id => {
if (/\/client\//.test(id)) {
delete require.cache[id];
}
});
});
@glenjamin
glenjamin / notes.md
Last active September 20, 2015 09:50
Standalone npm

Standalone npm

When using tools like n or nvm it's often a bit annoying to have the npm version continually reset to whichever was bundled with the release being switched to.

Here's an alternative: having an npm installed separately.

This is especially useful if you want to try out npm@3 neatly.

sudo mkdir /opt/npm3
@glenjamin
glenjamin / demo.js
Created June 26, 2015 10:31
React Capturing all links
// Helper function
function findAnchor(node) {
while (node.nodeName.toLowerCase() != 'a') {
if (!node.parentNode) return false;
node = node.parentNode;
}
return node;
}
// Capture component
@glenjamin
glenjamin / npm-deps.sh
Created March 2, 2015 22:54
What modules am I using?
# Run the following in a directory containing npm projects
# list all modules being used directly (no sub-dependencies)
ls */package.json | xargs -n1 dirname | \
xargs -n1 -I {} bash -c 'cd {} && npm ls --depth=0 2>/dev/null | grep -oiE " [A-Z0-9\-]+@"' | \
cut -d @ -f 1 | sort -u
# list all modules being used directly and which project uses them
ls */package.json | xargs -n1 dirname | \
xargs -n1 -I {} bash -c 'cd {} && npm ls --depth=0 2>/dev/null | grep -oiE " [A-Z0-9\-]+@" | sed "s/\$/ in {}/"' | \
@glenjamin
glenjamin / es5js.eslintrc
Last active September 13, 2015 15:16
Default eslint configs
{
"env": {
"node": true
},
"rules": {
"strict": 0,
"quotes": 0,
"indent": [2, 2],
"curly": [2, "multi-line"],
"no-use-before-define": [2, "nofunc"],
@glenjamin
glenjamin / generator.sch
Created January 14, 2015 18:34
scheme tinkering
(define (f yield)
(yield 1)
(yield 2)
(yield 3))
(define gen
(letrec ((pause '())
(resume '())
(yield (lambda (x)
(call/cc (lambda (k)
@glenjamin
glenjamin / darkpeak.js
Created January 5, 2015 13:47
self-censor current page
function blacken() {
var div = document.createElement('div');
var opacity = 0;
div.style.position = 'fixed';
div.style.top = 0;
div.style.bottom = 0;
div.style.left = 0;
div.style.right = 0;
div.style.opacity = opacity;
div.style.background = 'black';