Skip to content

Instantly share code, notes, and snippets.

@ksafranski
ksafranski / modal.js
Created October 11, 2012 20:01
Modal
/*
* HTML:
* <div id="modal-overlay"></div>
* <div id="modal"><a id="modal-close">x</a><div id="modal-content"></div></div>
*
* CSS:
* #modal-overlay {
* display: none;
* position: fixed;
* top: 0;
@ksafranski
ksafranski / api.php
Created November 6, 2012 19:31
PHP API Framework
<?php
// HTACCESS:
// ----------------------------------
// Options +FollowSymLinks
// RewriteEngine On
// RewriteCond %{REQUEST_FILENAME} !-f
// RewriteCond %{REQUEST_FILENAME} !-d
// RewriteRule ^ api.php [QSA,L]
@ksafranski
ksafranski / jquery.tinypubsub.js
Created December 15, 2012 20:40
Really small jQuery pub/sub script
// See example at http://jsfiddle.net/fluidbyte/AhBKq/
var broadcast = {
speak: function (name, message) {
$(document).trigger(name, message);
},
listen: function (name, callback) {
$(document).bind(name, function (e, message) {
@ksafranski
ksafranski / SimpleStore.js
Last active February 26, 2026 06:14
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:
@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 / 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 / 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 / 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 / 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 / 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