This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var state = mobx.observable({ | |
| todos : [], | |
| visibilityFilter : "ALL", | |
| addTodoItem : action(function (text, completed) { | |
| this.todos.push({text, completed}) | |
| }), | |
| setVisibilityFilter : action(function (filter) { | |
| this.visibilityFilter = filter; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 : { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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) |
OlderNewer