Skip to content

Instantly share code, notes, and snippets.

View hugooliveirad's full-sized avatar

Hugo de Oliveira hugooliveirad

View GitHub Profile
import { createMachine, assign } from "xstate";
type MachineContext = {
lives: number;
};
type MachineEvent =
| { type: "IDLE" }
| { type: "WALK" }
| { type: "RUN" }
<?xml version="1.0" encoding="UTF-8"?>
<!-- TeXML files must contain the Response element -->
<Response>
<!-- Say and Dial are Verbs -->
<Say>Thank you for calling Telnyx.</Say>
<Dial>
<Sip>sip:gencredhoj84HXAATNAXTfLJBkZBFv0sr@sip.telnyx.com</Sip>
</Dial>
</Response>
(defn button [props _]
(om/component
(dom/button nil (:children props))))
(def render-out (om/render-to-object button {:children "text"}))
(is (= "text" (:children render-out))
@hugooliveirad
hugooliveirad / connect-cljs.repl.md
Created October 8, 2015 13:01
Connect to ClojureScript Node nREPL

jack-in into normal Clojure nREPL. Run:

(require '[cljs.repl :as repl] '[cljs.repl.node :as node])

(compile 'cljs.repl.node)

(cemerick.piggieback/cljs-repl (cljs.repl.node/repl-env))
@hugooliveirad
hugooliveirad / angles-fun.js
Created September 16, 2015 16:53
Angles fun
// radians->degrees
function degrees(radians) {
return radians * 180 / Math.PI;
}
// gets two positions { x: Number, y: Number } and return
// angle between them in radians
function getAngle(pos1, pos2 = {x: 0, y: 0}) {
let [dx, dy] = [pos1.x - pos2.x, (pos1.y - pos2.y) * -1]
return Math.atan2(dy, dx);
function createReducer(handlers, initialState) {
return function reducer(state = initialState, action) {
return handlers[action.type] ?
handlers[action.type](state, action)
: state
}
}
const math = createReducer({
INCREMENT: (state) => state + 1,
@hugooliveirad
hugooliveirad / a.sh
Created June 24, 2015 11:30
Run Node REPL with require support
node -e "require('repl').start({ignoreUndefined: true})"
@hugooliveirad
hugooliveirad / comp.md
Last active June 2, 2017 11:44
Composing styles

Composing styles

CSS Wizardry recently wrote a great post about styling: Contextual Styling: UI Components, Nesting, and Implementation Detail. He showed three ways to solve the problem of implementation details in a component's styles. I want to propose another way to solve this problem, one that uses composition.

The original styles of a .nav-primary component are:

.nav-primary {
  /* This is how the nav should always look: */
 margin: 0;
@hugooliveirad
hugooliveirad / om.cljs
Created May 24, 2015 07:00
My first 100 lines of ClojureScript
(ns ^:figwheel-always om-tut.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[cljs.core.async :refer [put! chan <!]]
[clojure.data :as data]
[clojure.string :as string]))
(enable-console-print!)
@hugooliveirad
hugooliveirad / readme.md
Created May 18, 2015 18:30
Diff two command outputs (stdout) without using files