Skip to content

Instantly share code, notes, and snippets.

View therealklanni's full-sized avatar
👨‍💻
Learning Rust

Kevin Lanni therealklanni

👨‍💻
Learning Rust
View GitHub Profile
@therealklanni
therealklanni / proxy.php
Created November 22, 2011 04:53
Stupidly simple PHP proxy
<?php
// Stupidly simple PHP proxy for AJAX (HTTP GET) requests. Written by Kevin Lanni.
$dest = ''; // Set to the remote script URL (i.e. http://remotehost.com/some.php)
$a = array();
foreach ($_GET as $k=>$v) {
$a[] = "{$k}={$v}";
}
@therealklanni
therealklanni / JSONP_Example.php
Created November 23, 2011 23:42
Simple public Web API in PHP using JSONP
<?php
/* JSONP_Example.php
* Author: Kevin Lanni
* Description: Demonstrates how to create a simple public Web API using JSONP responses
* This is useful for opening Web APIs for public use without the need for proxying or other SOP work-arounds.
* This example does not demonstrate API keys or any other method of authentication.
*/
// Supply a header to set the proper expectation for the client browser
header('Content-Type: application/json');
@therealklanni
therealklanni / json2html.js
Created November 29, 2011 23:44
Converts a JSON object into a visual HTML representation. This was originally meant to be part of a side-project I was working on and later abandoned. I might end up recycling this code for something in the future.
json2html = function(o, e) {
var ret, obj, n, t = '<ul/>';
if (!e && $('#json_root').length === 0) {
e = $(t,{
"id": "json_root",
"class": "array"
}).appendTo('body')
} else if (!e) {
e = $('#json_root');
@therealklanni
therealklanni / xml2json.js
Created November 29, 2011 23:54
A simple XML to JSON converter. Originally based on http://goo.gl/xfG0l and simplified.
xml2json = function(xml, extended) {
var root, out,
jsVar = function(s) {
return String(s || "").replace(/-/g,"_");
},
isNum = function(s) {
return (typeof s === "number") || String((s && typeof s === "string") ? s : "").test(/^((-)?([0-9]*)((\.{0,1})([0-9]+))?$)/);
},
myArr = function(o) {
if (!o.length) {
@therealklanni
therealklanni / json2xml.js
Created November 29, 2011 23:57
A simple JSON to XML converter with namespace support.
json2xml = function(o, ns, tab) {
if (!Array.prototype.j) Array.prototype.j = function (a) { return this.join(a||"") };
var ns = ns+":"||"", m, xml = '',
toXml = function(v, name, ind) {
var i, n, m, s, hasChild, xml = "";
if (v instanceof Array) {
for (i = 0, n = v.length; i < n; i++) {
xml += [ind,toXml(v[i], name, ind + '\t'),'\n'].j();
}
@therealklanni
therealklanni / RESTRequest.php
Created August 23, 2012 18:45
RESTRequest is a PHP class for handling cURL requests, specifically for use with RESTful web services. Supports session states.
<?php
class RESTRequest
{
public $response;
public $code;
private $handle;
private $session;
private $curlopts;
@therealklanni
therealklanni / dabblet.css
Created December 27, 2012 21:12
Simple CSS3 Tooltip
/**
* Simple CSS3 Tooltip
*/
.tooltip{
display: inline;
position: relative;
}
.tooltip:hover:after{

stopBefore.js

2min screencast

Examples

stopBefore(document, 'getElementById')
stopBefore('document.getElementById') // the same as the previous
stopBefore(Element.prototype, 'removeChild')
/*global document*/
//a function to get DOM nodes by nodeType property.
//If you do not supply a value I will give you every DOM node.
//
//example:
// var allComments = document.getNodesByType(8);
// or
// var allComments = document.getNodesByType("COMMENT_NODE");
//
//The accepted string values are the actual node type names, so that the
@therealklanni
therealklanni / distill.js
Created March 29, 2014 04:13
Array of Objects distiller
// Found myself needing to do this the other day...
//
// Map an array of objects down to a single object in one pass
function distill (a, b) {
a[b.name] = b.value;
return a;
}
// Say you have objects that follow this format
var obj1 = {