Skip to content

Instantly share code, notes, and snippets.

@Exegetech
Exegetech / pretty_date
Created August 5, 2014 02:22
Pretty Date by John Resig
function prettyDate(time) {
var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")),
diff = (((new Date()).getTime() - date.getTime()) / 1000),
day_diff = Math.floor(diff / 86400);
if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 ){
return;
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
var Pocket = require('./lib/pocket-auth.js');
var express = require('express');
var request = require('request');
var router = express.Router();
var auth = require('../../auth/auth.service');
var consumer_key = process.env.POCKET_KEY;
var redirect_uri = process.env.DOMAIN + '/pocket/redirect';
var pocket = new Pocket({
@Exegetech
Exegetech / imageUploadService.js
Created November 11, 2015 18:24 — forked from calendee/imageUploadService.js
Cloudinary / Ionic Image Upload Service
```
(function() {
/**
* @ngInject
*/
function ius($q, $ionicLoading, $cordovaFile, $translate, CLOUDINARY_CONFIGS) {
var service = {};
var ghost = require( 'ghost' )
function processBuffer( buffer, app ){
while( buffer.length ){
var request = buffer.pop()
app( request[0], request[1] )
}
}
function makeGhostMiddleware( options ){
@Exegetech
Exegetech / aggregate.js
Created January 3, 2016 21:30
Aggregate data from MongoDB with Node.js and mongoose
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
//Database connection
var uristring = 'mongodb://localhost/test';
var mongoOptions = { };
mongoose.connect(uristring, mongoOptions, function (err, res) {
if (err) {
console.log('Error when connecting to: ' + uristring + '. ' + err);
@Exegetech
Exegetech / gist:62e60eb3bff12d654fe4
Last active January 27, 2016 15:15
JavaScript Regex to replace string that has code in it
/**
* This function assumes string as a argument and
* replaces everything between "START" and "END"
* with "START";var __REPLACED = console.log('replaced');"END"
* @param input string
* @author Georgi Naumov
* gonaumov@gmail.com for contacts and
* suggestions.
*/
function replaceString(input) {
@Exegetech
Exegetech / div-maintain-aspect-ratio-without-content-inside.html
Created February 23, 2016 01:25
Magically sets a div that maintains its aspect ratio without a content inside. Great trick for containing iFrames
<!doctype html>
<html>
<head>
<style>
/* container which maintains the ratio */
/* padding-bottom is the magic rule to set the aspect ration */
/* in this case below, this is a trick, to add padding bottom 50% but height 0 to compensate for the height created */
/* this will make the height of this container div always 50% of the width */
.container {
@Exegetech
Exegetech / mathEvaluator
Last active June 17, 2016 19:52
Interview with Neosavvy
/**
* Evaluate a basic mathematical expression
*
* This is my 2nd attempt at this problem.
* For the 1st attempt, please look at the code
* commented at the bottom.
*
* Did some research on how to tackle this problem,
* came up to using Reverse Polish Notation.
*
@Exegetech
Exegetech / neosavvyInterview.js
Created September 14, 2016 14:07
2nd interview with Neosavvy
/* You are given an n x n array P[i,j] with i and j indices that range from 0 to n-1. There is a number in each location of P[i,j] that can be negative or positive. You start with the index pair [n-1, n-1] and are free to traverse any path(according to the following two rules) that ends at [0,0].
**Rule 1:** At any location [i,j] you can decrement either one of the indices or both. So from [i,j] you can go to [i-1, j] or [i,j-1] or [i-1,j-1]. However no index is allowed to go below 0(obviously).
**Rule 2:** When an index reaches 0, it stays at 0.
Again, there is a number stored at each location of P[i,j]. The value of a path is the sum of the P[i,j] values for the indices used by the path.
Present a recursive solution that solves for the greatest possible value path among all such paths. In other words find **Best(i, j)** which is the value of the best**(maximum sum)** path from location (i,j) to (0,0).