Skip to content

Instantly share code, notes, and snippets.

@jcready
jcready / timestamp.log.js
Created April 24, 2014 17:34
Timestamps for console.log()
(function(){
var log = console.log;
console.log = function(){
var timestamp = '['+new Date().toJSON().slice(14,-1)+']';
if (arguments.length) {
if (typeof arguments[0] === "string") {
var args = Array.prototype.slice.call(arguments, 0);
args[0] = "%s " + arguments[0];
args.splice(1, 0, timestamp);
return log.apply(console, args);
function MasterStore() {
this.datastore = {};
}
MasterStore.prototype.has = function(key, value){
if (value == null) return this.datastore.hasOwnProperty(key);
if (Array.isArray(value)) {
for (var i = 0; i < value.length; i++) {
if (this.datastore[key].indexOf(value[i]) < 0) {
return false;
  • a task list item
  • list syntax required
  • normal formatting, @mentions, #1234 refs
  • incomplete
  • completed
/* jshint newcap: false */
var B = require("bluebird/js/main/promise")();
var Bproto = B.prototype;
var deferredPrototype = B.pending().constructor.prototype;
deferredPrototype.makeNodeResolver = function() {
return this.asCallback;
};
var B = require("bluebird/js/main/promise")();
var Bproto = B.prototype;
var deferredPrototype = B.pending().constructor.prototype;
deferredPrototype.makeNodeResolver = function() {
return this.asCallback;
};
function bind(fn, ctx) {
(function (navigator) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(location) {
var lat = location.coords.latitude,
lon = location.coords.longitude,
url = 'https://maps.google.com/maps?q='+lat+','+lon;
console.log('Latitude: %s | Longitude: %s \n%o', lat, lon, url);
var map = window.open(url, "GAMap", "width=1200,height=800");
});
}
function Model(props) {
var obj = { 'props': props };
for (o in obj.props) {
if (obj.props.hasOwnProperty(o)) {
this[o] = new Function("value", "if (!arguments.length) return typeof this.props['" + o.toString() +
"'] == 'function' ? this.props['" + o.toString() + "'].call(this) : this.props['" + o.toString() + "'];" +
"this.props['" + o.toString() + "'] = (typeof value == 'function' ? value.call(this) : value); return this")
}
}
@jcready
jcready / _.map.js
Last active December 10, 2015 08:38
function map(collection, callback, thisArg) {
var index = -1,
length = collection ? collection.length : 0,
result = isArray(collection) ? Array(length) : {};
callback = createCallback(callback, thisArg);
if (isArray(result)) {
while (++index < length) {
result[index] = callback(collection[index], index, collection);
}
function parsePls(pls) {
//get number of entries
var matched = pls.match(/numberofentries=\d+/i);
matched = matched[0].split("=");
var numberOfEntries = matched[1];
var i = 1;
var files = [], file, title, length;
while (i <= numberOfEntries) {
var fileRegex = new RegExp('File'+i+'=\\S+');
@jcready
jcready / globals.js
Last active December 13, 2015 20:39
Detect Global Variables
(function(){
var differences = {},
ignoreList = (prompt('Ignore filter (comma sep)?', 'jQuery, Backbone, _, $').split(/,\s?/) || []),
iframe = document.createElement('iframe'),
count = 0; ignoreList.push('prop');
for (prop in window) {
differences[prop] = {
type: typeof window[prop],
val: window[prop]