Skip to content

Instantly share code, notes, and snippets.

@ioleo
ioleo / moment.workdays.js
Last active September 8, 2017 12:02
introduce 'workdays' mode to moment.js add/subtract methods (PL national holidays)
(function (undefined) {
/**
* moment.easter
* Source: https://github.com/zaygraveyard/moment-easter
* License: MIT
*/
moment.easter = function Easter20ops(year) {
var a = (year / 100 | 0) * 1483 - (year / 400 | 0) * 2225 + 2613;
var b = ((year % 19 * 3510 + (a / 25 | 0) * 319) / 330 | 0) % 29;
var c = 148 - b - ((year * 5 / 4 | 0) + a - b) % 7;
@gamefreak
gamefreak / binds.js
Created April 2, 2015 22:49
Class method binding
function bound(object, key, descriptor) {
let boundMethodId = Symbol('bound-method-'+key);
let theMethod = descriptor.value;
delete descriptor.value;
delete descriptor.writable;
descriptor.get = function() {
//Memoize it per instance so we can remove listeners
return this[boundMethodId] || (this[boundMethodId] = theMethod.bind(this));
};
@maximilianschmitt
maximilianschmitt / readme.md
Last active August 29, 2015 14:19
Making your io.js command line apps compatible with node.js
@aldendaniels
aldendaniels / alternative-to-higher-order-components.md
Last active October 6, 2018 09:50
Alternative to Higher-order Components

React now supports the use of ES6 classes as an alternative to React.createClass().

React's concept of Mixins, however, doesn't have a corollary when using ES6 classes. This left the community without an established pattern for code that both handles cross-cutting concerns and requires access to Component Life Cycle Methods.

In this gist, @sebmarkbage proposed an alternative pattern to React mixins: decorate components with a wrapping "higher order" component that handles whatever lifecycle methods it needs to and then invokes the wrapped component in its render() method, passing through props.

While a viable solution, this has a few drawbacks:

  1. There's no way for the child component to override functionality defined on the higher order component.
@eckardt
eckardt / exponentialBackOffScheduler.js
Created June 1, 2015 13:52
Exponential backoff scheduler to be used with RxJS's retrywhen
// https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/retrywhen.md
function exponentialBackOffScheduler(options) {
return function(errors) {
return errors.scan(options, function(currentOptions, err) {
if (currentOptions.maxRetries <= 0) {
throw err;
}
return {
maxRetries: currentOptions.maxRetries - 1,
@gaearon
gaearon / combining.js
Created June 3, 2015 18:03
Combining Stateless Stores
// ------------
// counterStore.js
// ------------
import {
INCREMENT_COUNTER,
DECREMENT_COUNTER
} from '../constants/ActionTypes';
const initialState = { counter: 0 };
@jordaaash
jordaaash / cover.styl
Last active May 23, 2017 08:10
Cross-browser object-fit: cover mixin
cover(width = inherit, height = inherit, min-width = 100%, min-height = 100%)
// Chrome, Safari
@media screen and (-webkit-min-device-pixel-ratio: 0)
object-fit cover
height height
width width
// Firefox
@-moz-document url-prefix()
&
object-fit cover
@skevy
skevy / gist:8a4ffc3cfdaf5fd68739
Last active February 4, 2017 04:59
Redux with reduced boilerplate

Note

I would recommend @acdlite's redux-actions over the methods suggested in this Gist.

The methods below can break hot-reloading and don't support Promise-based actions.

Even though 'redux-actions' still uses constants, I've come to terms with the fact that constants can be good, especially in bigger projects. You can reduce boilerplate in different places, as described in the redux docs here: http://gaearon.github.io/redux/docs/recipes/ReducingBoilerplate.html


@vjpr
vjpr / README.md
Last active February 4, 2016 21:29 — forked from skevy/gist:8a4ffc3cfdaf5fd68739
Reduce boilerplate in Redux

Reduce boilerplate in Redux

  • Create actions similar to Flummox.
  • Generate action ids.
  • Supports actions with promises, and therefore ES7 async.
@Dr-Nikson
Dr-Nikson / README.md
Last active January 14, 2019 06:35 — forked from vjpr/README.md

Reduce boilerplate in Redux

  • Create actions similar to Flummox.
  • Generate action ids.
  • Supports actions with decorators, promises, and therefore ES7 async.