Skip to content

Instantly share code, notes, and snippets.

View spiralx's full-sized avatar

James Skinner spiralx

View GitHub Profile
@Avaq
Avaq / combinators.js
Last active May 1, 2024 09:38
Common combinators in JavaScript
const I = x => x
const K = x => y => x
const A = f => x => f (x)
const T = x => f => f (x)
const W = f => x => f (x) (x)
const C = f => y => x => f (x) (y)
const B = f => g => x => f (g (x))
const S = f => g => x => f (x) (g (x))
const S_ = f => g => x => f (g (x)) (x)
const S2 = f => g => h => x => f (g (x)) (h (x))
@staltz
staltz / introrx.md
Last active April 29, 2024 09:25
The introduction to Reactive Programming you've been missing
// ==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==
@btroncone
btroncone / ngrxintro.md
Last active February 9, 2024 15:37
A Comprehensive Introduction to @ngrx/store - Companion to Egghead.io Series

Comprehensive Introduction to @ngrx/store

By: @BTroncone

Also check out my lesson @ngrx/store in 10 minutes on egghead.io!

Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!

Table of Contents

// Primitive hash function that for a string returns a positive 32 bit int
// Do not use in production, use murmur3 or fnv1
// You can improve this by changing 5 to 31
Object.defineProperty(String.prototype, 'hashCode', {
value: function() {
var hash = 0, i, chr;
for (i = 0; i < this.length; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
@endeepak
endeepak / debug_angular_ui_router.js
Last active February 21, 2021 19:28
Debugging angula ui router
// 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.');
@Raynos
Raynos / weak-map.js
Last active September 18, 2019 07:49 — forked from Gozala/weak-map.js
Harmony WeakMap shim for ES5
// 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
},
@alexaivars
alexaivars / setter_pattern.coffee
Created January 12, 2012 08:41
Getter Setter patter for Coffeescript
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.
@ekantola
ekantola / RxJS-intro.js
Last active June 1, 2017 11:19
RxJS intro snippets
/*
* Observable
*/
var xs = Rx.Observable.range(0, 3)
xs.subscribe(log)
//=> 0
//=> 1
//=> 2
@spiralx
spiralx / all-colours.js
Last active April 7, 2017 07:58
Collected DevTool snippets
// allcolors.js
// https://github.com/bgrins/devtools-snippets
// Print out CSS colors used in elements on the page.
(function() {
'use strict'
const BOLD = 'font-weight: bold;'
const LINK = 'text-decoration: underline; color: #05f'
const NORMAL = 'font-weight: normal; text-decoration: none; color: black; background-color: white; display: inline'