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 Words(str) { | |
| this._str = str; | |
| } | |
| Words.prototype[Symbol.iterator] = function() { | |
| var re = /\S+/g; | |
| var str = this._str; | |
| return { | |
| next: function() { |
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
| // register the service worker | |
| navigator.serviceWorker.register('/worker.js').then( | |
| function(reg) { console.log('Installed successfully', reg) }, | |
| function(err) { console.log('Worker installation failed', err) } | |
| ); | |
| // ... worker.js | |
| self.addEventListener('fetch', function(event) { | |
| var requestURL = new URL(event.request); |
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
| Sinatra::Application.routes["GET"].each do |route| | |
| before do | |
| // All the things | |
| end | |
| end |
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(angular) { | |
| angular.module('analytics', ['ng']).service('analytics', [ | |
| '$rootScope', '$window', '$location', function($rootScope, $window, $location) { | |
| var track = function() { | |
| $window._gaq.push(['_trackPageview', $location.path()]); | |
| }; | |
| $rootScope.$on('$viewContentLoaded', track); | |
| } | |
| ]); |
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> | |
| <title>Animations</title> | |
| <body> | |
| <script> | |
| function createAndAnimate(part) { | |
| var element = document.createElement('pre'); | |
| element.textContent = part; | |
| document.body.appendChild(element); | |
| element.animate( |
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
| // dollar selector | |
| function $(C, P) { | |
| P = P || document; | |
| return /:first$/.test(C) ? (P = P.querySelector(C.slice(0, -6))) ? [P] : [] : [].slice.call(P.querySelectorAll(C)) | |
| } | |
| // simple utility to add an event listener | |
| $.on = function (CSS, parentNode, type, handler, capture) { | |
| // in case parentNode is missing | |
| if (typeof type !== 'string') { |
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
| // Open Dev Tools console and enter | |
| !(function a(){ debugger; }()); | |
| // Then you should see the wrapping | |
| with ((console && console._commandLineAPI) || {}) { | |
| !(function a(){ debugger;}()) | |
| } |
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 base64 = exports; | |
| base64.encode = function (unencoded) { | |
| return new Buffer(unencoded || '').toString('base64'); | |
| }; | |
| base64.decode = function (encoded) { | |
| return new Buffer(encoded || '', 'base64').toString('utf8'); | |
| }; |
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 content from a URL (e.g. JavaScript) using RSVP promises | |
| */ | |
| var getUrl = function (url) { | |
| var xhr = new XMLHttpRequest(); | |
| // @see https://github.com/tildeio/rsvp.js | |
| var promise = new RSVP.Promise(); | |
| xhr.open('GET', url); |
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 app = express.createServer( | |
| (function(req, res, next) { | |
| if(req.url.indexOf("/stylesheets/") === 0) { | |
| res.setHeader("Cache-Control", "public, max-age=345600"); // 4 days | |
| res.setHeader("Expires", new Date(Date.now() + 345600000).toUTCString()); | |
| } | |
| return next(); | |
| }), | |
| express.static(__dirname + '/static') | |
| ); |