This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fileSystemModule = require("file-system"); | |
var fileName = "persistedFile.json"; | |
var file = fileSystemModule.knownFolders.documents().getFile(fileName); | |
var data = [{"id": "1", "value": "NativeScript"}, ...]; | |
// write data to the file, converted to a JSON string first | |
file.writeText(JSON.stringify(data)); | |
// read data from the file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getKeys(obj) { | |
all = {}; | |
function get(obj) { | |
var keys = Object.keys(obj); | |
for (var i = 0, l= keys.length; i < l; i++) { | |
var key = keys[i]; | |
all[key] = true; | |
var value = obj[key]; | |
if (value instanceof Object) get(value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// repo is assumed to be in closure | |
var repo; | |
// commit - the hash of the current commit | |
// path - the path to the hash in the current commit | |
// callback -> the previous blob value | |
function findPrevious(commit, path, callback) { | |
var log; // The log stream | |
var currentBlob; // The current value of the blob | |
var oldBlob; // The last value of the blob |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var fs = require('fs'); | |
var cache = {}, hit = 0, missed = 0; | |
function load(name, cb) { | |
var res = cache[name]; | |
if (res) { | |
process.nextTick(function() { | |
hit++; | |
cb(null, res); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Person() { | |
// properties and validations | |
this.attr( | |
{ id: Number, unique: true, nullable: false }, | |
{ email: String, unique: true, nullable: false, min: 1, max: 55, format: '[a-b]' }, | |
{ salt: String }, | |
{ pswd: String }, | |
{ active: Boolean, init: false }, | |
{ tags: Array } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Pattern = Object.create(Object.prototype, { | |
// Implement extend for easy prototypal inheritance | |
extend: {value: function extend(obj) { | |
if (obj === undefined) return Object.create(this); | |
obj.__proto__ = this; | |
Object.freeze(obj); // Lock the prototype to enforce no changes | |
return obj; | |
}}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Person = function( name ){ this.name = name }; | |
Person.create = function(name) { return new Person(name) }; | |
Brian = new Person('brianleroux'); | |
Tim = Person.create('tim'); | |
// Lame, I would do this one of three ways depending on how it will be used | |
// If the example really was this simple and there was nothing else involved, | |
// I would use object literals. No need to overcomplicate things |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//usage: $ node wav2mp3.js file1.wav file2.wav | |
// converts to .mp3 format and deletes original .wav file | |
var fs = require('fs'); | |
var sys = require('sys'); | |
var Step = require('step'); | |
var spawn = require('child_process').spawn; | |
var exec = require('child_process').exec; | |
function convert(file, callback){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var HTTPParser = process.binding('http_parser').HTTPParser; | |
var net = require('net'); | |
var path = require('path'); | |
var sys = require('sys'); | |
var Worker = require('webworker/webworker').Worker; | |
var VHOSTS = ['foo.bar.com', 'baz.bizzle.com']; | |
var WORKERS = {}; | |
VHOSTS.forEach(function(vh) { |