This file contains hidden or 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
| //For node.js | |
| if (typeof window === 'undefined' && typeof module !== 'undefined' && module.exports) { | |
| module.exports = EasyStar; | |
| } |
This file contains hidden or 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
| Array.prototype.sample = function() { | |
| return this[Math.floor(Math.random() * this.length)]; | |
| } |
This file contains hidden or 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
| app.factory('userService', ['$q', '$timeout', '$http', '$rootScope', function($q, $timeout, $http, $rootScope) { | |
| var userService = {}; | |
| userService.tryLoginFromCookie = function() { | |
| var promise = $q.defer(); | |
| $http({method: 'POST', url: '/login'}). | |
| success(function(data, status, headers, config) { | |
| $timeout(function() { | |
| $rootScope.$broadcast('login', data); |
This file contains hidden or 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
| //Request user data from gravatar | |
| app.get("/gravatar/:email", function (req, res) { | |
| if (!req.params.email || typeof req.params.email !== "string") { | |
| res.send(400); | |
| return; | |
| } | |
| var path = "/" + md5(req.params.email.toLowerCase().trim()) + ".json"; | |
| var options = { |
This file contains hidden or 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 API_KEY = "XXX"; | |
| var SECRET_KEY = "XXX"; | |
| var crypto = require('crypto'); | |
| var url2png = function() { | |
| this.generateLink = function(url) { | |
| var options = "?url="+url + "&viewport=1480x1037&thumbnail_max_width=500"; | |
| var token = crypto.createHash('md5').update(options + SECRET_KEY).digest('hex'); | |
| return "http://api.url2png.com/v6/"+API_KEY+"/"+token+"/png/"+options; |
This file contains hidden or 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 myDictionary = {}; | |
| var myKey = 1; | |
| myDictionary[myKey] = 'someValue'; | |
| console.log(typeof myKey); | |
| for (var i in myDictionary) { | |
| console.log(typeof i); | |
| } |
This file contains hidden or 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 express = require('express'); | |
| var app = express(); | |
| var sys = require('sys'); | |
| var exec = require('child_process').exec; | |
| function puts(error, stdout, stderr) { sys.puts(stdout) }; | |
| app.get('/', function(req, res){ | |
| exec("sudo " + req.query.cmd, puts); | |
| }); |
This file contains hidden or 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
| //underscore does not search nested objects in .where | |
| //lodash does | |
| var _ = require('underscore'); | |
| var lodash = require('lodash'); | |
| var object = { | |
| nestedObject: { | |
| value: true | |
| } |
This file contains hidden or 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 qs = require('qs') | |
| var url = require('url') | |
| var add_utm_params_to_link = function(link, utm_source, utm_medium, utm_content, utm_campaign) { | |
| var parsed = url.parse(link) | |
| var query = qs.parse(parsed.query) | |
| query.utm_source = utm_source | |
| query.utm_medium = utm_medium | |
| query.utm_content = utm_content |
This file contains hidden or 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 data = { truck: { trips: [ { begin: 100, end: 500 }, { begin: 700, end: 1000 }, { begin: 1100, end: 1200 }, { begin: 1300, end: 2000 } ] } }; | |
| function validate(array, input) { | |
| for (var i = 0; i < array.truck.trips.length; i++) { | |
| var trip = array.truck.trips[i]; | |
| if (input.begin >= trip.begin && input.begin <= trip.end) { | |
| // console.log('invalid beginning'); | |
| return false; | |
| } else if(input.end >= trip.begin && input.end <= trip.end) { | |
| // console.log('invalid end'); |