Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
<?php | |
function explore( $path ){ | |
$files = scandir( $path ); | |
$files = array_slice( $files, 2); | |
foreach( $files as $file ) | |
if( is_dir( $path.'/'.$file ) ) | |
explore( $path.'/'.$file ); | |
else | |
process( $path.'/'.$file ); | |
} |
{ | |
"letters": [ | |
{ | |
"title": "name_test", | |
"to": "me", | |
"date": "today" | |
}, { | |
"title": "test", | |
"to": "you", | |
"date": "today" |
/* Scaled-down Backbone.js demonstration | |
* By Jacob Oscarson (http://twitter.com/jacob414), 2010 | |
* MIT Licenced, see http://www.opensource.org/licenses/mit-license.php */ | |
$(function() { | |
window.ulog = function(msg) { $('#log').append($('<div>'+msg+'</div>')); } | |
// Faking a little bit of Backbone.sync functionallity | |
Backbone.sync = function(method, model, succeeded) { | |
ulog('<strong>'+method + ":</strong> " + model.get('label')); | |
if(typeof model.cid != 'undefined') { |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<title>Backbone example</title> | |
<script type="text/javascript" src="jquery.min.js"></script> | |
<script type="text/javascript" src="underscore.js"></script> | |
<script type="text/javascript" src="backbone.js"></script> |
var oldSync = Backbone.sync; | |
Backbone.sync = function(method, model, success, error){ | |
var newSuccess = function(resp, status, xhr){ | |
if(xhr.statusText === "CREATED"){ | |
var location = xhr.getResponseHeader('Location'); | |
return $.ajax({ | |
url: location, | |
success: success | |
}); |
#! /usr/bin/env python | |
import fileinput | |
import argparse | |
from operator import itemgetter | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--target-mb', action = 'store', dest = 'target_mb', default = 61000, type = int) | |
parser.add_argument('vmtouch_output_file', action = 'store', nargs = '+') | |
args = parser.parse_args() |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
var parser = document.createElement('a'); | |
parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
parser.protocol; // => "http:" | |
parser.hostname; // => "example.com" | |
parser.port; // => "3000" | |
parser.pathname; // => "/pathname/" | |
parser.search; // => "?search=test" | |
parser.hash; // => "#hash" | |
parser.host; // => "example.com:3000" |
$(this.input)[0].selectionStart | |
this.wordList.push($(this.input).val().split(" ", -1)); | |
// Space recorded start a new request | |
if (e.keyCode == 32){ | |
this.wordFragment = ''; | |
this.emptySuggestions(); | |
return true; | |
} |
// Creating a namespace | |
var chat = { | |
// Create this closure to contain the cached modules | |
module: function() { | |
// Internal module cache. | |
var modules = {}; | |
// Create a new module reference scaffold or load an | |
// existing module. | |
return function(name) { |