Skip to content

Instantly share code, notes, and snippets.

View mikekunze's full-sized avatar

Mike Kunze mikekunze

View GitHub Profile
@mikekunze
mikekunze / closureClassExampleCart.php
Created October 19, 2013 14:16
Example closure callback for asynchronous php.
<?php
// SOURCE: http://php.net/manual/en/functions.anonymous.php
// A basic shopping cart which contains a list of added products
// and the quantity of each product. Includes a method which
// calculates the total price of the items in the cart using a
// closure as a callback.
class Cart
{
const PRICE_BUTTER = 1.00;
const PRICE_MILK = 3.00;
@mikekunze
mikekunze / httpd-container-skel.js
Last active December 21, 2015 15:48
This is the compiled version of the httpd-container-skel.coffee file
(function() {
var Controller, Events, SuperClass, Web, moduleKeywords,
__indexOf = [].indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) {
if (i in this && this[i] === item)
return i;
}
return -1;
},
__hasProp = {}.hasOwnProperty,
@mikekunze
mikekunze / httpd-container-skel.coffee
Created August 24, 2013 15:34
This is a skel for containing your Express code when it is desired to isolate app routes and websockets in classical inheritance, while potentially sharing crucial web server information such as a user session and login information.
moduleKeywords = ['included', 'extended']
class SuperClass
@include: (obj) ->
throw('include(obj) requires obj') unless obj
for key, value of obj.prototype when key not in moduleKeywords
@::[key] = value
included = obj.included
included.apply(this) if included
@mikekunze
mikekunze / nagiosAlert.jade
Created August 19, 2013 22:10
This is an example jade template body for a Nagios Service Alert E-Mail.
extends layout.jade
block content
include nav-bar-email
.container-fluid
.row-fluid
.span12
.well
i.icon-warning-sign.icon-4x.pull-right
@mikekunze
mikekunze / nav-bar-email.jade
Last active December 21, 2015 07:58
This is a sample nav-bar I am using for my Nagios Alert e-mails.
.container-fluid
.navbar
.navbar-inner
a.brand(href="domain.com/") Company
ul.nav
li
a(href="domain.com/") Home
li
a(href="domain.com/projects") Projects
@mikekunze
mikekunze / layout.jade
Created August 19, 2013 22:07
This is an example layout I am using with Nagios E-Mail alerts.
doctype 5
html
head
link(rel='stylesheet', href='http://domain.com/components/bootstrap/docs/assets/css/bootstrap.css')
link(rel='stylesheet', href='http://domain.com/components/bootstrap/docs/assets/css/bootstrap-responsive.css')
link(rel='stylesheet', href='http://domain.com/components/font-awesome/css/font-awesome.min.css')
script(type="text/javascript", src="http://domain.com/components/jquery/jquery.min.js")
script(type="text/javascript", src="http://domain.com/components/bootstrap/docs/assets/js/bootstrap.js")
body
@mikekunze
mikekunze / notify-service.coffee
Created August 19, 2013 22:02
This is an example script that Nagios could use to send email notifications to contacts bound to alerts. See http://portalstack.blogspot.com/2012/07/sending-custom-nagios-notification.html for more information.
#!/usr/bin/env coffee
#
# incoming argv is order sensitive
#
# [0] - coffee
# [1] - /opt/bin/notify-service.coffee
# [2] - hostname
# [3] - service
# [4] - IP address
# [5] - notification type [ PROBLEM, RECOVERY, OK ]
@mikekunze
mikekunze / parallelTasksExample.coffee
Last active December 21, 2015 05:39
This is a sample gist of personal work I am doing on a Project Management webApp. The goal of this gist is to show how non dependent tasks can be parallelized and dependent tasks can be run after those parallel dependencies are run. eachTask iterator takes a task object and a callback. It uses the Function prototype method call to pass scope to …
_helper = require '_helper'
###
completeIssue is a great example of parallel scripting.
req
- project ObjectId
- milestone ObjectId
- issue ObjectId
mUpload = (req, res)->
file = req.files["fileForm"]
tmpPath = file.path
fileName = file.name
dest = __dirname + "/#{fileName}"
fs.readFile tmpPath, (err, data)->
fs.writeFile dest, data, (err)->
handler = ()->
document.getElementById("fileField").files
# Make sure a file is selected first
if files.length <= 0
alert('choose a file, first')
return
file = files[0]
fd = new FormData()