Skip to content

Instantly share code, notes, and snippets.

View ladas-larry's full-sized avatar

Ladislav M. ladas-larry

View GitHub Profile
@berzniz
berzniz / bind-unbind.js
Last active August 29, 2015 13:58
Backbone tips & rules
// Ok:
this.stateModel.on('change:readMore', this.renderReadMore, this);
// Awesome:
this.listenTo(this.stateModel, 'change:readMore', this.renderReadMore);
@ladas-larry
ladas-larry / parseQuery.js
Last active August 13, 2017 09:50
Parse query string
function parseQuery(locationSearch) {
locationSearch = locationSearch.substring(1); // remove "?" at the beginning
var values = locationSearch.split('&');
var queryObj = values.reduce(function (result, item) {
var parts = item.split('=');
result[decodeURIComponent(parts[0])] = parts[1];
return result;
}, {});
return queryObj;
}
@mvbattan
mvbattan / reducer.js
Last active June 4, 2018 15:29
Reducer description
const reducerDescription = {
[actions.GET_MATCHES]: (state, action) => ({ ...state, matchesLoading: true }),
[actions.GET_MATCHES_SUCCESS]: (state, action) => ({
...state,
matchesLoading: false,
matchesError: null,
matches: action.payload
}),
[actions.GET_MATCHES_FAILURE]: (state, action) => ({
...state,
@ustun
ustun / reducer_as_immutable_class.js
Created February 6, 2017 09:56
redux reducer from immutable class
var camelCase = require('lodash.camelcase');
const {Map, Record, List} = require('immutable');
class Todo extends Record({ description: null, completed: false }) {
toggle() {
return this.set('completed', !this.completed);
}
}
const InitialTodoApp = Record({
@jiayihu
jiayihu / actionCreator.ts
Last active September 20, 2019 13:10
Minimal action creator factory for redux-observable and redux-saga
import { IAction } from '../types/redux.types';
import { actionTypes as errorTypes, showError } from './errors.actions';
interface IPayloadCreators {
request(...args: any[]): any;
success(...args: any[]): any;
failure?(errorMsg: string): any;
}
interface IActionCreator {
@jmarceli
jmarceli / README.md
Last active October 31, 2019 09:46
React errors explained

1

You will get one of these:

Uncaught (in promise) TypeError: Cannot read property 'toUpperCase' of undefined(…)

ReactCompositeComponent.js:870 Uncaught TypeError: Cannot read property 'displayName' of undefined

if you try to:

@ericelliott
ericelliott / dependency-injection.js
Created October 2, 2016 01:02
Dependency Injection
const consumer = dependency => dependency.doSomething();
const realDependency = {
doSomething () {
console.log('did something!');
}
};
consumer(realDependency);
const original = [0,1,2,3];
const copy = Object.assign([], original, { 2: 42 }); // [0,1,42,3]
console.log(original);
// [ 0, 1, 2, 3 ]
console.log(copy);
// [ 0, 1, 42, 3 ]
@gf3
gf3 / gist:306785
Created February 17, 2010 16:38
Sexy bash prompt
Moved to: http://github.com/gf3/dotfiles/blob/master/bash_prompt
@davidmatas
davidmatas / mou.html
Last active March 1, 2023 16:42
highlight syntax for Mou.app
<!-- Highlight syntax for Mou.app, insert at the bottom of the markdown document -->
<script src="http://yandex.st/highlightjs/7.3/highlight.min.js"></script>
<link rel="stylesheet" href="http://yandex.st/highlightjs/7.3/styles/github.min.css">
<script>
hljs.initHighlightingOnLoad();
</script>