Skip to content

Instantly share code, notes, and snippets.

View freidamachoi's full-sized avatar

Bo freidamachoi

View GitHub Profile
function readDir(start, callback) {
// Use lstat to resolve symlink if we are passed a symlink
fs.lstat(start, function(err, stat) {
if(err) {
return callback(err);
}
var found = {dirs: [], files: []},
total = 0,
processed = 0;
function isDir(abspath) {
@freidamachoi
freidamachoi / dirTree.js
Created November 22, 2013 20:13
another directory traversal method
var fs = require('fs'),
path = require('path');
function dirTree(filename) {
var stats = fs.lstatSync(filename),
info = {
path: filename,
name: path.basename(filename)
};
/**
* Module dependencies
*/
var express = require('express');
var fs = require('fs');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// img path
@freidamachoi
freidamachoi / Mongoose GridFS
Created December 5, 2013 22:23 — forked from richzw/Mongoose GridFS
GridStore ( File upload Mongoose)
mongoose = require('mongoose');
var GridStore = mongoose.mongo.GridStore,
Grid = mongoose.mongo.Grid,
ObjectID = mongoose.mongo.BSONPure.ObjectID;
exports.getGridFile = function(id, fn) {
var db = mongoose.connection.db,
id = new ObjectID(id),
// The .config() part is the relevant part, 'SomeModule' is arbitrary name,
// but this config() call goes on your main ng-app="YourAppModule"
// The PHP $_POST expects data w/ a form content type, not a JSON payload
angular.module("YourAppModule", ["SomeModule"]).config(function($httpProvider) {
$httpProvider.defaults.headers.put['Content-Type'] =
'application/x-www-form-urlencoded';
$httpProvider.defaults.headers.post['Content-Type'] =
'application/x-www-form-urlencoded';
});
@freidamachoi
freidamachoi / gist:8735974
Created January 31, 2014 16:46 — forked from justinwinslow/gist:7994944
Breadcrumb Directive
// State example:
//
// $stateProvider
// .state('state', {
// url: 'state/:id',
// template: stateTemplate,
// controller: stateController,
// // Expose parameters in display names using {:param} syntax
// displayName: 'State ({:id})'
// });
@freidamachoi
freidamachoi / multi-collections.js
Created February 25, 2014 17:33 — forked from aheckmann/multi-collections.js
MongooseJs/Mongo Multitenant
var mongoose = require('mongoose');
mongoose.connect('localhost', 'testing_multiTenant');
/**
* User schema.
*/
var UserSchema = new mongoose.Schema({
name: String
, prefix: { type: String, required: true }
'use strict';
/**
* This module monitors angularFire's authentication and performs actions based on authentication state.
* directives/directive.ngcloakauth.js depends on this file
*
* Modify ng-cloak to hide content until FirebaseSimpleLogin resolves. Also
* provides ng-show-auth methods for displaying content only when certain login
* states are active.
*
@freidamachoi
freidamachoi / Procfile
Created April 1, 2014 19:17 — forked from mojodna/Procfile
Heroku Worker/Queue
web: node app.js
worker: node consumer.js
@freidamachoi
freidamachoi / jwtparser.js
Created April 4, 2014 23:07 — forked from katowulf/jwtparser.js
Jwt Parser
// Helper function to extract claims from a JWT. Does *not* verify the
// validity of the token.
// credits: https://github.com/firebase/angularFire/blob/master/angularFire.js#L370
// polyfill window.atob() for IE8: https://github.com/davidchambers/Base64.js
// or really fast Base64 by Fred Palmer: https://code.google.com/p/javascriptbase64/
function deconstructJWT(token) {
var segments = token.split(".");
if (!segments instanceof Array || segments.length !== 3) {
throw new Error("Invalid JWT");
}