(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| Function::define = (prop, desc) -> | |
| Object.defineProperty this.prototype, prop, desc | |
| class GetterSetterTest | |
| constructor: (@_obj = {}) -> | |
| # 'obj' is defined via the prototype, the definition proxied through | |
| # to 'Object.defineProperty' via a function called 'define' providing | |
| # some nice syntactic sugar. Remember, the value of '@' is | |
| # GetterSetterTest itself when used in the body of it's class definition. |
| // Original - @Gozola. This is a reimplemented version (with a few bug fixes). | |
| window.WeakMap = window.WeakMap || (function () { | |
| var privates = Name() | |
| return { | |
| get: function (key, fallback) { | |
| var store = privates(key) | |
| return store.hasOwnProperty("value") ? | |
| store.value : fallback | |
| }, |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
| <title>sorting lists</title> | |
| <script src="jquery-1.7.2.min.js"></script> | |
| <script src="jquery.sortChildren.js"></script> | |
| <script> |
| /* | |
| * Observable | |
| */ | |
| var xs = Rx.Observable.range(0, 3) | |
| xs.subscribe(log) | |
| //=> 0 | |
| //=> 1 | |
| //=> 2 |
| /*jshint asi:true */ | |
| ;(function(global) { | |
| 'use strict' | |
| const parser = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, | |
| queryKeyParser = /(?:^|&)([^&=]*)=?([^&]*)/g, | |
| keys = "href protocol authority userInfo user password host port relative path directory file query anchor".split(" "); | |
| /** |
| (function($) { | |
| $.fn.batch = function(method, args) { | |
| var func = $.fn[method], results = []; | |
| this.each(function() { | |
| results.push(func.apply(this, args)); | |
| }); | |
| return results; | |
| }; | |
| var funcs = "attr css=styles prop html text val offset width height".split(" "); |
| /** | |
| * Allows you to specify named groups in regular expressions like in Perl/Python/.NET/etc. You have to | |
| * use a string to specify the regex, and the function returns an object that has `exec` and `replace` | |
| * functions like a normal RegExp object, but matches they generate have keys for the values of the named | |
| * groups. | |
| * | |
| * n = NamedRegExp("(?<protocol>http|ftp)://(?<host>[\\w-]+\\.com)(?<path>/.+\\.html)?$"); | |
| * res = n.exec("http://foobar.com"); -> res.protocol = http, res.host = foobar.com res.path = undefined | |
| * res = n.exec("http://foobar.com/"); -> res.protocol = http, res.host = foobar.com res.path = / |
| // Credits: Adam's answer in http://stackoverflow.com/a/20786262/69362 | |
| // Paste this in browser's console | |
| var $rootScope = angular.element(document.querySelectorAll("[ui-view]")[0]).injector().get('$rootScope'); | |
| $rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){ | |
| console.log('$stateChangeStart to '+toState.to+'- fired when the transition begins. toState,toParams : \n',toState, toParams); | |
| }); | |
| $rootScope.$on('$stateChangeError',function(event, toState, toParams, fromState, fromParams){ | |
| console.log('$stateChangeError - fired when an error occurs during transition.'); |
| // ==UserScript== | |
| // @name GM_download emulation | |
| // @namespace http://tampermonkey.net/ | |
| // @version 0.1 | |
| // @description emulate GM_download functionality | |
| // @require https://github.com/eligrey/FileSaver.js/raw/master/FileSaver.js | |
| // @match http://tampermonkey.net/empty.html | |
| // @grant GM_xmlhttpRequest | |
| // @copyright 2014, Jan Biniok | |
| // ==/UserScript== |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.