Skip to content

Instantly share code, notes, and snippets.

View vslinko's full-sized avatar

Viacheslav Slinko vslinko

View GitHub Profile
@vslinko
vslinko / di.coffee
Created February 20, 2013 12:29
small di written on coffeescript
class DI
constructor: ->
@container = di: @
register: (name, value) ->
@container[name] = value
fetch: (name) ->
value = @container[name]
@vslinko
vslinko / it.coffee
Created October 28, 2013 23:32
matrix iterator written for collegue
class MatrixIterator
positions: []
constructor: (@arrays) ->
@reset()
reset: ->
@hasNext = true
for i in [0...@arrays.length]
@vslinko
vslinko / react-logo-w-bg.svg
Created April 25, 2014 08:16
react.js logo for tshirt
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vslinko
vslinko / read.py
Created May 11, 2014 14:52
binary hard drive scanner for osx
import os
import math
import datetime
def format_seconds(seconds):
hours, remainder = divmod(int(seconds), 3600)
minutes, seconds = divmod(remainder, 60)
return "%03d:%02d:%02d" % (hours, minutes, seconds)
@vslinko
vslinko / onDocumentEvent.js
Created May 5, 2015 15:57
higher order component example
import React from 'react';
const mounted = {};
const listeners = {};
function startListener(eventName) {
if (!listeners[eventName]) {
listeners[eventName] = (event) => {
mounted[eventName].forEach(([c, cb]) => cb(c.child, event));
};
@vslinko
vslinko / scheduleRender.js
Created May 5, 2015 15:57
when you have many root components
import R from 'ramda';
import React from 'react';
let scheduled = [];
let loaded = false;
document.addEventListener('DOMContentLoaded', () => {
loaded = true;
scheduled.forEach(({flux, Component, selector, props}) => {
render(flux, Component, selector, props);
@vslinko
vslinko / log.js
Created May 5, 2015 17:41
my colourful logger
import R from 'ramda';
const levels = {
debug: 0,
log: 1,
info: 2,
warn: 3,
error: 4
};
@vslinko
vslinko / rx-react.js
Created May 28, 2015 09:19
tried use rx with react
import React from 'react';
import Rx from 'rx';
import R from 'ramda';
// dispatcher.js
const dispatcher = new Rx.ReplaySubject();
function dispatch(action) {
dispatcher.onNext(action);
}
@vslinko
vslinko / flux-reference.js
Last active August 20, 2016 20:15
minimal flux
/* @flow */
type State = Object
type Action = {type: string | void}
type AsyncAction = (performAction: FluxPerformFunction, state: State) => void
type ActionCreator = () => Action | AsyncAction
type StoreFunction = (state: State, action: Action) => State