Skip to content

Instantly share code, notes, and snippets.

View flipjs's full-sized avatar
:octocat:
hjkl

Felipe Apostol flipjs

:octocat:
hjkl
View GitHub Profile
@flipjs
flipjs / mac.sh
Created August 15, 2014 00:14
Make Your Keyboard Keys Repeat Properly When Held Down in Mac OS X
defaults write -g ApplePressAndHoldEnabled -bool false
@flipjs
flipjs / gplus-alt.js
Last active August 29, 2015 14:05
Google+ Photos API (using request module)
var request = require('request')
var url = 'http://picasaweb.google.com'
+ '/data/feed/api/user/102873175118305865375/'
+ 'albumid/5646665615382099025'
+ '?alt=json'
request.get(url, function(err, res, body) {
var gplus = JSON.parse(body)
var len = gplus.feed.entry.length
@flipjs
flipjs / gplus.js
Last active August 29, 2015 14:05
Google+ Photos API
#!/usr/bin/env node
var http = require('http')
// Google Plus Photos API
// Sample data from Felipe Apostol's Street Photography album
// userId is 102873175118305865375
// albumId is 5646665615382099025
var options = {
@flipjs
flipjs / this.js
Created August 6, 2014 22:42
The Contextual This
var obj = {
name: 'flip',
printMe: function() {
// solution: pass this as closure
var self = this
console.log('1. ' + this.name)
var x = (function() {
// console.log('2. ' + this.name)
console.log('2. ' + self.name)
var y = (function() {
@flipjs
flipjs / iterator_async.js
Created August 6, 2014 22:36
Async Iterator Snippet
var arr = [1, 2, 3, 4, 5, 6, 7]
, results = []
, len = arr.length
;(function iterator(i) {
if (i >= len) {
callback(null, results)
} else {
async_work(function(err, res) {
if (err) {
@flipjs
flipjs / node_mgd_conn.js
Created August 6, 2014 09:37
MongoDB and NodeJS
var mongo = require('mongodb')
var Server = mongo.Server
, Db = mongo.Db
, BSON = mongo.BSONPure
var server = new Server('localhost', 27017, {auto_reconnect: true})
, db = new Db('dbName', server)
db.open(function(err, db) {
@flipjs
flipjs / waldo.js
Created August 4, 2014 08:28
Waldo by Angus Croll
(function(){
var traverse = function(util, searchTerm, options) {
var options = options || {};
var obj = options.obj || window;
var path = options.path || ((obj==window) ? "window" : "");
var props = Object.keys(obj);
props.forEach(function(prop) {
if ((tests[util] || util)(searchTerm, obj, prop)){
console.log([path, ".", prop].join(""), "->",["(", typeof obj[prop], ")"].join(""), obj[prop]);
}
@flipjs
flipjs / to-type.js
Last active August 29, 2015 14:04
toType() by Angus Croll
var toType = function(obj) {
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
}
toType({a: 4}); //"object"
toType([1, 2, 3]); //"array"
(function() {console.log(toType(arguments))})(); //arguments
toType(new ReferenceError); //"error"
toType(new Date); //"date"
toType(/a-z/); //"regexp"
@flipjs
flipjs / truthey-tester.js
Created August 3, 2014 20:53
Truthey Tester by Angus Croll
var trutheyTester = function(expr) {
return expr ? "truthey" : "falsey";
}
trutheyTester({}); //truthey (an object is always true)
trutheyTester(false); //falsey
trutheyTester(new Boolean(false)); //truthey (an object!)
trutheyTester(""); //falsey
@flipjs
flipjs / observe.js
Created August 3, 2014 00:40
Object.observe()
var myObject = { name : 'flipjs' }
console.log('Start observing...')
Object.observe(myObject, function(changes) {
changes.forEach(function(change) {
console.log(change.name
+ " was "
+ change.type
+ " and is now "