Skip to content

Instantly share code, notes, and snippets.

@badslug
badslug / sendOrTimeout.go
Last active August 30, 2016 06:46
Example showing a function that sends to a channel or times out
// Send an event to a channel or timeout. The channel can be buffered or not.
func Send(event []byte) {
select {
case channel <- event:
// Channel receives the event if there is room (buffered) or if a reader is ready on the channel (unbuffered)
case <- time.After(5 * time.Second):
// Timed out - event is not sent if you do nothing here
// Alternatively you can do something else with the event here
}
}

Keybase proof

I hereby claim:

  • I am badslug on github.
  • I am badslug (https://keybase.io/badslug) on keybase.
  • I have a public key whose fingerprint is B64D 14F7 34DA E9FD 3BC8 0CDA 384C 4BAF AC5C F83C

To claim this, I am signing this object:

@badslug
badslug / nodeserver.conf
Created November 21, 2012 04:28
Node.js Upstart config file running as an unprivileged user
description "node.js server"
author "Wyndham Jade - http://www.wyndhamjade.com"
# used to be: start on startup
# until we found some mounts weren't ready yet while booting:
start on started mountall
stop on shutdown
# Automatically Respawn:
respawn
@badslug
badslug / bastion.conf
Created November 21, 2012 04:24
Node.js Upstart config file running as root
description "node.js bastion server - used for services that must attach to protected ports (e.g. 80)"
author "Wyndham Jade - http://www.wyndhamjade.com"
# used to be: start on startup
# until we found some mounts weren't ready yet while booting:
start on started mountall
stop on shutdown
# Automatically Respawn:
respawn
@badslug
badslug / gist:3445426
Created August 24, 2012 04:30
Removing meteorite cache and adding underscore-string no longer working
ion $ cd ..
ion $ rm -Rf my-test-project/
ion $ mrt uninstall --system
Deleting ~/.meteorite. Note that previously installed projects will no longer work...
ion $ mrt create my-test-project
Fetching Meteor (branch: master)...
Downloading Meteor development bundle...
######################################################################## 100.0%
my-test-project: created.
@badslug
badslug / gist:1361623
Created November 13, 2011 04:59
Example Data "Step"
{
"name":"shipping",
"title":"Shipping Address",
"notes":"Used to gather shipping address information (if shipping is not billing)",
"template":"shipping_address.jade",
"fields":[
{
"name":"street1",
"label":"Street 1",
"type":"text",
@badslug
badslug / .gitignore
Created October 17, 2011 06:28
Standard git ignore file for maven-based java projects.
.classpath
*.ipr
*.iml
*.iws
.project
.idea/
.settings/
.gradle/
target/
build/