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 parser = document.createElement('a'); | |
| parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
| parser.protocol; // => "http:" | |
| parser.hostname; // => "example.com" | |
| parser.port; // => "3000" | |
| parser.pathname; // => "/pathname/" | |
| parser.search; // => "?search=test" | |
| parser.hash; // => "#hash" | |
| parser.host; // => "example.com:3000" |
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
| //equivalent of "select count (distinct fieldName) from someTable" | |
| db.someCollection.aggregate([{ $group: { _id: "$fieldName"} },{ $group: { _id: 1, count: { $sum: 1 } } } ]) |
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
| RED="\[\033[0;31m\]" | |
| YELLOW="\[\033[0;33m\]" | |
| L_YELLOW="\[\033[1;33m\]" | |
| GREEN="\[\033[0;32m\]" | |
| BLUE="\[\033[1;34m\]" | |
| NO_COLOUR="\[\033[0m\]" | |
| CYAN="\[\033[0;36m\]" | |
| PURPLE="\[\033[0;35m\]" | |
| # Determine active Python virtualenv details. |
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'), | |
| httpProxy = require('http-proxy'), | |
| app = express(); | |
| var proxy = new httpProxy.RoutingProxy(); | |
| function apiProxy(host, port) { | |
| return function(req, res, next) { | |
| if(req.url.match(new RegExp('^\/api\/'))) { | |
| proxy.proxyRequest(req, res, {host: host, port: port}); |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Tournament Bracket Generator</title> | |
| <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> | |
| <script src="http://underscorejs.org/underscore-min.js"></script> | |
| <script> | |
| $(document).on('ready', function() { | |
| var knownBrackets = [2,4,8,16,32], // brackets with "perfect" proportions (full fields, no byes) |
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
| function go() { | |
| var userId = prompt('Username?', 'Guest'); | |
| checkIfUserExists(userId); | |
| } | |
| var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.com/users'; | |
| function userExistsCallback(userId, exists) { | |
| if (exists) { | |
| alert('user ' + userId + ' exists!'); |
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
| function go() { | |
| var userId = prompt('Username?', 'Guest'); | |
| var userData = { name: userId }; | |
| tryCreateUser(userId, userData); | |
| } | |
| var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.com/users'; | |
| function userCreated(userId, success) { | |
| if (!success) { |
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
| /* | |
| limitLoop.js - limit the frame-rate when using requestAnimation frame | |
| Released under an MIT license. | |
| When to use it? | |
| ---------------- | |
| A consistent frame-rate can be better than a janky experience only | |
| occasionally hitting 60fps. Use this trick to target a specific frame- | |
| rate (e.g 30fps, 48fps) until browsers better tackle this problem |
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
| /* | |
| * There's a bug in Chrome/Safari using overflow:hidden with border-radius. This mask fixes it. | |
| * Solution: http://stackoverflow.com/questions/5736503/how-to-make-css3-rounded-corners-hide-overflow-in-chrome-opera/10296258#10296258 | |
| */ | |
| .masked { | |
| position: absolute; | |
| border-radius: 10px; | |
| overflow: hidden; | |
| /* this fixes the overflow:hidden in Chrome */ | |
| -webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC); |
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
| /** | |
| * Get siblings of an element | |
| * @param {Element} elem | |
| * @return {Object} | |
| */ | |
| var getSiblings = function (elem) { | |
| var siblings = []; | |
| var sibling = elem.parentNode.firstChild; | |
| var skipMe = elem; | |
| for ( ; sibling; sibling = sibling.nextSibling ) |