Skip to content

Instantly share code, notes, and snippets.

View ksafranski's full-sized avatar

Kent Safranski ksafranski

View GitHub Profile
@ksafranski
ksafranski / grunt-templates.js
Last active December 19, 2015 19:09
Grunt multitask for compiling tpl files into one source.
/*
Usage:
... grunt config ...
templates: {
main: {
header: '\n<!-- {{tplbasename}} -->\n<div data-tpl="{{tplbasename}}">\n',
footer: '\n</div>\n',
@ksafranski
ksafranski / PortProxyApache2
Created June 19, 2013 13:15
Port-based Apache proxy (good for nodejs apps) via VirtualHost
1. Run the following commands:
a2enmod proxy
a2enmod proxy_http
2. Setup a VirtualHost in /etc/apache2/sites-available/
<VirtualHost *:80>
ServerName something.mydomain.com
ProxyPass / http://something.mydomain.com:9999
#!/bin/bash
# Script to easily create VHosts
echo "Enter URL [ENTER]:"
read url
echo "Enter folder path [ENTER]:"
read path
@ksafranski
ksafranski / tester.sh
Created April 14, 2013 14:15
Script for easily testing Git pull requests.
#!/bin/bash
# Script to easily (re)create folder and pull repo for testing
echo "Enter folder name [ENTER]:"
read folder
echo "Enter git repo (space) branch [ENTER]:"
read repo
@ksafranski
ksafranski / REST-Tester.js
Last active December 16, 2015 02:09
Small script for testing RESTful ajax calls in dev environment using Node Restify. Includes static content server.
/**
*
* Dev NodeJS Script for testing basic REST calls - GET, POST, PUT, DELETE
*
* Place in root of site, create data.json in root with following format:
* [
* {
* id: "1",
* ...additional params...
* },
@ksafranski
ksafranski / combocode.js
Last active December 14, 2015 17:19
Simple, plain-english keycode combo handler
/**
*
* Simple Plain-English Key Combo Listener
*
* Usage / Example:
* ======================================
* var konami = new combo({
* code: 'up up down down left right left right b a',
* timeout: 5000,
* callback: function(){
@ksafranski
ksafranski / ajax.js
Last active December 14, 2015 11:50
A simple, library-independent ajax function
/**
* Library-Independent AJAX Function
*
* Usage:
* --------------------------------
*
* ajax(url, { ...properties... });
* -or-
* ajax({ ...properties... });
*
@ksafranski
ksafranski / httpserver.js
Last active December 14, 2015 03:59
Simple Node HTTP Server with logging
var http = require('http'),
fs = require('fs'),
path = require('path'),
port = 8080,
default_file = 'index.html';
http.createServer(function (request, response) {
// Params
var contentType,
@ksafranski
ksafranski / each.js
Created February 6, 2013 21:26
Roll your own 'each' function
function each(obj,callback){
// Ensure callback is a function
if (!callback || typeof(callback) !== "function") {
throw new Error("Callback is not a function.");
return false;
}
// If obj is an array
if(obj.constructor === Array){
for (var i=0, z=obj.length; i<z; i++){
@ksafranski
ksafranski / SimpleStore.js
Last active July 2, 2022 15:25
Simple localStorage function with Cookie fallback for older browsers.
/**
* Simple localStorage with Cookie Fallback
* v.1.0.0
*
* USAGE:
* ----------------------------------------
* Set New / Modify:
* store('my_key', 'some_value');
*
* Retrieve: