Skip to content

Instantly share code, notes, and snippets.

View vitalipe's full-sized avatar

Vitali Perchonok vitalipe

View GitHub Profile
@vitalipe
vitalipe / async.cljc
Last active June 28, 2023 20:27
async/await cljs macros
(ns alpakit.async
(:require [cljs.core.async]
[cljs.core.async.interop :refer-macros [<p!]]))
(defn promise? [obj]
#?(:clj false)
#?(:cljs (= js/Promise (type obj))))
@vitalipe
vitalipe / cleaner.java
Last active June 27, 2023 11:34
"Clean Code" is dog shit.
// https://qntm.org/clean
package fitnesse.html;
import fitnesse.responders.run.SuiteResponder;
import fitnesse.wiki.*;
public class SetupTeardownIncluder {
public static String render(PageData pageData) throws Exception {
(unpack
;; data
{:parent {:nested [{:name "banana" :price 1}
{:name "banana2" :price 2}]}}
;; query:
{:all-names [:parent :nested [[:name]]]
:all-names-in-caps [:parent :nested [[:name to-upper]]]
:max-price [:parent :nested [[:price] *|> max]]
:same+1-to-price {:parent [:parent {:nested [:nested [[{:name :name
:price [:price inc]}]]]}]}})
;; this macro will send paint instructions to hudini paint worklet and will setup
;; custom css keys so that we can pass params (color in this example)
(defpaint color-circle [{:keys [color]} {:keys [width height ctx]}]
(doto ctx ;; <-- need to make a nicer paint API, for now it's almost 1:1 with the js api
(.arc (/ width 2) (/ height 2))
(.fillColor color)
(.fill)))
(def player (ref {:health 500 :attack 10 :items #{}}))
(def mob1 (ref {:health 100 :attack 2 :items #{"big-banana"}}))
(def mob2 (ref {:health 100 :attack 4 :items #{"banana"}}))
(defn attack! [attacker enemy]
(dosync
(let [attacker-value (:attack @attacker)
enemy-value (:attack @enemy)]
(alter enemy update :health - attacker-value)
(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)
@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
@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 / 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 / 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 : {