Skip to content

Instantly share code, notes, and snippets.

@markhuge
markhuge / gist:4669438
Created January 30, 2013 00:24
Bulk Jenkins git repo configuration through Groovy interface.
// Loop through Jenkins projects, adding a git repo for any project without a repo defined.
def projects = hudson.model.Hudson.instance;
projects.getItems(hudson.model.Project).each {
proj ->
if (proj.getScm().type == "hudson.scm.NullSCM") {
proj.scm = new hudson.plugins.git.GitSCM("git://path/to/your/repo.git");
println("Project: " + proj.displayName + " SCM: " + proj.getScm().type);
}
}
@markhuge
markhuge / gist:4724990
Last active February 14, 2019 07:11
Using regex capture groups in Sublime Text 2 search and replace

I copied my .csshrc to a new machine, and needed to add a domain suffix to the hostnames of 20+ VMs in my cluster config. All of my hostnames end in at least 2 digits (foo-bar-baz-01), so I:

  1. Search for instances of 2 digits followed by whitespace.
  2. Preserve the digits in a capture group.
  3. Append the suffix to the capture group (\1)

Append domain suffix where none exists:

Search: ([0-9]{2})\s Replace: \1.my.domain.suffix

@markhuge
markhuge / bottle-jsonp.py
Created March 2, 2013 21:56
Dynamically Serving JSONP with bottle.py
# This will return either JSON or JSONP depending on the existence of a callback.
def jsonp(request, dictionary):
if (request.query.callback):
return "%s(%s)" % (request.query.callback, dictionary)
return dictionary
@route('/something')
def something():
return jsonp(dict(success="It worked"))
@markhuge
markhuge / gist:6038456
Created July 19, 2013 11:22
Handlebars Helper - Time Since <date>
Handlebars.registerHelper 'timesince', (date) ->
seconds = Math.floor((new Date() - new Date(date)) / 1000)
interval = Math.floor seconds / 31536000
if interval > 1
return new Handlebars.SafeString interval + " years"
interval = Math.floor seconds / 2592000
if interval > 1
return new Handlebars.SafeString interval + " months"
@markhuge
markhuge / README.md
Last active March 25, 2016 12:57
Fix failing node deployments on AWS Elastic Beanstalk

Fix failing node deployments on AWS Elastic Beanstalk

Elastic beanstalk runs npm install with a system user that has no homedir. During the npm install step, it's expecting a $HOME env variable for the npm cache (which doesn't exist). add this file to your project's .ebextensions directory to have it use root's homedir as a temporary path.

This workaround was provided by AWS support, but it doesn't appear to be documented anywhere. Determining root cause on this was a massive pain in the ass. Sharing this so others don't need to feel the pain.

Keybase proof

I hereby claim:

  • I am markhuge on github.
  • I am markhuge (https://keybase.io/markhuge) on keybase.
  • I have a public key whose fingerprint is 6450 7421 25CF B80C C9EA 6BB6 8EA2 79E6 5667 3B23

To claim this, I am signing this object:

@markhuge
markhuge / class.js
Last active August 29, 2015 14:04
Javascript prototypal pitfalls
// Pseudoclassical class pattern
// Constructor
function myThing() {
// under the hood 'this' is mapped to a new object
// created from myThing's prototype and NOT to myThing
this.name = "myThing";
}
@markhuge
markhuge / chef.template.erb
Last active August 29, 2015 14:07
Node.js app Upstart Script example
# <%= @app_name %>.conf
# This file is generated by Chef for <%= node[:fqdn] %>
description "<%= @app_name %>"
start on filesystem or runlevel [2345]
stop on runlevel [06]
expect fork
respawn
  • When this app is started with node index, a SIGINT (Ctrl+c) is caught by the app and it continues running.
  • When this app is started with npm start, a SIGINT causes npm to exit, detaching the still running node process from the foreground.
@markhuge
markhuge / travis.yml
Last active August 29, 2015 14:09 — forked from tgrrtt/travis.yml
# Set up notification options
notifications:
email:
recipients:
- one@example.com
- other@example.com
# change is when the repo status goes from pass to fail or vice versa
on_success: change
on_failure: always