Skip to content

Instantly share code, notes, and snippets.

View vslinko's full-sized avatar

Viacheslav Slinko vslinko

View GitHub Profile
@vslinko
vslinko / .gitignore
Last active August 29, 2015 14:23
npm package template
/lib/
/node_modules/
/npm-debug.log
@vslinko
vslinko / 01_test.js
Last active August 29, 2015 14:22
es6 template literals example
import pgquery from 'pgquery'
const role = 'admin'
const likes = 5
console.log(pgquery`
SELECT * FROM users WHERE role = ${role} AND likes > ${likes}
`)
/*
{ queryString: '\n SELECT * FROM users WHERE role = $1::varchar AND likes > $2::int\n',
@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
@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 / 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 / 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 / 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 / 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 / react-logo-w-bg.svg
Created April 25, 2014 08:16
react.js logo for tshirt
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.