Skip to content

Instantly share code, notes, and snippets.

View justinwalsh's full-sized avatar

Justin Walsh justinwalsh

View GitHub Profile
@justinwalsh
justinwalsh / jquery_rest_helper.js
Created November 18, 2011 00:01
jQuery helper for REST apis using the _method override option
// Example usage
// api.put('/people', {name: 'John'}, function(response) { console.log(response); });
var api = {
url : "http://api.example.com",
get : function(url, data, callback) {
$.getJSON(api.url + url, data, callback);
},
post : function(url, data, callback) {
data._method = 'POST';
@justinwalsh
justinwalsh / rekey_multi_array.php
Created November 4, 2011 17:28
PHP function to rekey or index a multidimensional array and preserve associative keys
<?php
function rekey_multi_array($array) {
$new = array();
$count = 0;
if (is_array($array)) {
foreach ($array as $key => $val) {
if (!is_numeric($key)) {
$new[$key] = $this -> rekey_multi_array($val);
} else {
$new[$count] = $this -> rekey_multi_array($val);