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 generateUUID(){ | |
| var d = new Date().getTime(); | |
| var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
| var r = (d + Math.random()*16)%16 | 0; | |
| d = Math.floor(d/16); | |
| return (c=='x' ? r : (r&0x3|0x8)).toString(16); | |
| }); | |
| return uuid; | |
| }; |
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 str = 'A&P Grocers, Inc.'; | |
| str.replace(/\W/g, '').toLowerCase(); // apgrocersinc |
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
| // from: Eloquent JavaScript http://eloquentjavascript.net/08_error.html#p_CJKevweHV6 | |
| // Define our own error type | |
| function InputError(message) { | |
| this.message = message; | |
| this.stack = (new Error()).stack; | |
| } | |
| InputError.prototype = Object.create(Error.prototype); | |
| InputError.prototype.name = "InputError"; |
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
| /* Sample JavaScript file added with ScriptTag resource. | |
| This sample file is meant to teach best practices. | |
| Your app will load jQuery if it's not defined. | |
| Your app will load jQuery if jQuery is defined but is too old, e.g. < 1.7. | |
| Your app does not change the definition of $ or jQuery outside the app. | |
| */ | |
| (function(){ | |
| /* Load Script function we may need to load jQuery from the Google's CDN */ |
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 isInteger(num) { | |
| num === Math.round(num); | |
| } |
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
| ## parse a .raml file and then compile Handlebar templates | |
| # Import libraries | |
| fs = require('fs') | |
| appRoot = require('app-root-path') | |
| RAML = require('raml-parser') | |
| Handlebars = require('handlebars') | |
| saveTemplate = (pathToView, renderedTemplate) -> | |
| console.log 'Saving template' |
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
| // Returns a random integer between min (included) and max (excluded) | |
| function getRandomInt(min, max) { | |
| return Math.floor(Math.random() * (max - min)) + min; | |
| } |
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
| // From: http://regexone.com/ | |
| // | |
| // abc… Letters | |
| // 123… Digits | |
| // \d any Digit | |
| // . any Character | |
| // \. Period | |
| // [abc] Only a, b, or c | |
| // [^abc] Not a, b, nor c | |
| // [a-z] Characters a to z |
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
| #spinner { | |
| width: 150px;height: 150px; | |
| -webkit-animation: sweep 1s infinite linear; | |
| border-radius:75px; | |
| border-bottom:5px solid #ccc; | |
| } | |
| @-webkit-keyframes sweep { to { -webkit-transform: rotate(360deg); } } |
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
| // From: http://mir.aculo.us/2011/03/09/little-helpers-a-tweet-sized-javascript-templating-engine/ | |
| function t (s,d) { | |
| for (var p in d) | |
| s=s.replace(new RegExp('{'+p+'}','g'), d[p]); | |
| return s; | |
| } | |
| // Call it like this: | |
| // t("Hello {who}!", { who: "JavaScript" }); |