Skip to content

Instantly share code, notes, and snippets.

View DobrinGanev's full-sized avatar
🏠
Working from home

Dobrin Ganev DobrinGanev

🏠
Working from home
View GitHub Profile
@DobrinGanev
DobrinGanev / connect.js
Created August 20, 2017 03:40 — forked from gaearon/connect.js
connect.js explained
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
@DobrinGanev
DobrinGanev / redux-rx.js
Last active September 15, 2017 16:10
Redux pattern with RxJS
const Rx = require('rx')
const action$ = new Rx.Subject()
const initState = 0
const reducer = (state, action) => {
switch (action.type) {
case 'INC':
return state + action.payload
default:
return state
@DobrinGanev
DobrinGanev / thunks.js
Last active September 15, 2017 04:21
thunks and redux
import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk';
function reducer(state, action) {
if (typeof state === 'undefined') {
return 0
}
switch (action.type) {
case 'INCREMENT':
@DobrinGanev
DobrinGanev / lastAction.js
Created September 1, 2017 04:33
redux last Action
const reducer = ((state = 0, action) => {
switch (action.type) {
case 'INCREMENT': return state + 1
case 'DECREMENT': return state - 1
default: return state
}
})
const initialState = {
count: 0
@DobrinGanev
DobrinGanev / observable.js
Created September 14, 2017 20:00
redux createStore returns [$$observable]: observable
/**
this is from the Redux createStore()
/**
* Interoperability point for observable/reactive libraries.
* @returns {observable} A minimal observable of state changes.
* For more information, see the observable proposal:
* https://github.com/tc39/proposal-observable
*/
function observable() {
const outerSubscribe = subscribe
@DobrinGanev
DobrinGanev / merkleTree.md
Last active September 29, 2017 16:16
merkleTree
import hashlib
# Hash pairs of items recursively until a single value is obtained
def merkle(hashList):
namespace Sagas
{
using System;
using System.Collections.Generic;
class Program
{
static ActivityHost[] processes;
@DobrinGanev
DobrinGanev / lxc.sh
Created December 13, 2017 23:20 — forked from reqshark/lxc.sh
set up linux containers with node.js
# update the host
apt-get update && apt-get upgrade -y # && apt-get dist-upgrade -y && apt-get autoremove --purge -y && apt-get autoclean -y
# https://www.stgraber.org/
# install linux containers
sudo apt-get install lxc
# list all containers and view their current status
sudo lxc-ls -f
@DobrinGanev
DobrinGanev / echo_server.js
Created December 14, 2017 17:05 — forked from liamgriffiths/echo_server.js
simple node.js net tcp/unix socket echo server
/**
* echo server
*
*/
var net = require('net'),
port = 5000,
unixsocket = '/tmp/echo.sock';
var log = function(who, what) {
@DobrinGanev
DobrinGanev / difference.js
Created January 25, 2018 05:43 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function(result, value, key) {
if (!_.isEqual(value, base[key])) {