Skip to content

Instantly share code, notes, and snippets.

View vitalipe's full-sized avatar

Vitali Perchonok vitalipe

View GitHub Profile
class SimpleAssetManager {
// loader is the function that will actually do the fetching & return a promise...
constructor(loader, options = {}) {
this._cache = {};
this._cacheLimit = (options.cacheLimit || 1000);
this._cacheTTL = (options.cacheTTL || 10*1000); // ms
this._taskLimit = (options.tasks || 4);
this._loader = loader;
@vitalipe
vitalipe / get-in.js
Created October 11, 2016 01:13
get-in form clojure in JS
// returns the value in a nested associative structure,
// just like (get-in) in clojure
var getIn = function (obj, path) {
if (!_(path).isArray()) // normalize
path = _(arguments).toArray().rest().value();
if (path.length === 0)
return obj;
if (!_(obj).has(_.first(path)))
@vitalipe
vitalipe / Router.js
Created March 17, 2017 09:43
the-only-router-I-ever-needed
const _ = require("lodash");
const Navigo = require("navigo");
class Router {
constructor(routes, config) {
let handler = config.handler || (() => null);
let before = config.before || ((d) => d());
let router = new Navigo(null, true);
_(routes).each(
// calling this version of bind inside .render() should only create each bound function once
// WARNING: I didn't even ran this code :P so I'm not sure if it works
const _cache = new WeakMap();
const _cmpArray = (arr1, arr2) => (arr1.length === arr2.length) &&
(arr1.every((v,i)=> (v === arr2[i])));
function bind(fn, context, ...args) {
var state = mobx.observable({
todos : [],
visibilityFilter : "ALL",
addTodoItem : action(function (text, completed) {
this.todos.push({text, completed})
}),
setVisibilityFilter : action(function (filter) {
this.visibilityFilter = filter;
@vitalipe
vitalipe / dummy-greet.js
Created July 23, 2017 09:49
TS-vs-ES-with-React
// this is how I write React with JS..
//
// "View" is a simple wrapper around React's API similar to this one:
// https://github.com/vitalipe/react-hut#createhutview---component-api
//
// "Type" is based on React.PropTypes with a few simple extentions...
const UserComponent = View.define({
props : {
@vitalipe
vitalipe / StoreAtom.js
Last active August 19, 2017 19:57
mobx+immutable-basic-todo-mvc
// StoreAtom is a mutable ref that holds the immuable data, it's basically a shitty
// version of reagent/atom.. but becuase mobx is awesome it works :)
export defualt function StoreAtom(schema) {
const _state = mobx.observable(schema);
// expose schema as getter
Object.defineProperties(this,
_(schema)
.reduce((props, v, k) => _.extend(
@vitalipe
vitalipe / _hook.js
Last active December 11, 2017 13:35
just goofing around with stateful function components
// implementation details here, you want to look at the other files first
function init(React) {
let createElement = React.createElement;
let _cache = new WeakMap(); // can also be a regular map..
let _currentElement = null; // this is where updateState will lookup the current state
let createWrapper = (fn) =>
class StateWrapper extends React.Component {
constructor(props) {
@vitalipe
vitalipe / config-log.js
Created January 4, 2018 20:31
CoolAutomation logger setup
/**
* Built-in Log Configuration
* (sails.config.log)
*
* Configure the log level for your app, as well as the transport
* (Underneath the covers, Sails uses Winston for logging, which
* allows for some pretty neat custom transports/adapters for log messages)
*
* For more information on the Sails logger, check out:
* http://sailsjs.org/#/documentation/concepts/Logging
(ns adventofcode.playground.d4
(:require [clojure.string :as s]))
(defn line->date+event [line]
(let [[_ date-string event-string] (s/split line #"\[(.*?)\]")]
{:date (.getTime (doto (new js/Date date-string)
(.setSeconds 0)
(.setMilliseconds 0)))
:event (case (s/trim event-string)