Skip to content

Instantly share code, notes, and snippets.

@andrejewski
andrejewski / tagged-union.ts
Created January 6, 2018 15:51
Tagged union in TypeScript
interface Tag {
kind: string
data: any
}
interface Union {
match<T>(tag: Tag, handleMap: { [kind: string]: (data: any) => T }, catchAll?: () => T): T,
tags: { [kind: string]: (data: any) => Tag }
}
@andrejewski
andrejewski / raj.clj
Created December 29, 2017 05:39
Raj ported to Clojure/Script
(defn program [{:keys [init, update, done, view]}]
(let [state (atom nil)
running (atom true)
change (fn [dispatch [newState effect]]
(do
(if effect
(effect dispatch))
(reset! state newState)
(view @state dispatch)))
dispatch (fn dispatch [message]
@andrejewski
andrejewski / css-naming-convention.md
Last active December 22, 2017 13:50
My CSS naming convention

My convention for CSS naming is:

  • For a component, pascal-case (capitalized + camel-case) the root class name, Button
  • For any other element classes within that component, use the component name followed by a dash - and then the element'c class name in dash case icon, so Button's icon would be Button-icon.
  • For modifiers, meaning classes that override styles from a base class name, use the component name followed by two dashes -- and then the class name in dash case shopping-cart, so Button's icon style overrides for the shopping cart icon would be Button-icon--shopping-cart.

A button component with an icon and text:

<button class='Button Button--primary'>
@andrejewski
andrejewski / raj-flat-structure.js
Created December 2, 2017 20:24
Raj program husk with separated concerns
import request from './shared-request'
export function assemble (deps, {data, view, logic}) {
return {view, ...logic(data(deps))}
}
export function data (deps) {
return {
getUser (userId) {
return dispatch => {
@andrejewski
andrejewski / can-map-spec.js
Created October 23, 2017 19:18
Clojure Spec, but for CanJs
export function getNestedChecks (check) {
if (typeof check !== 'object') {
return check;
}
return (x, key) => {
const props = Object.keys(check);
for (let i = 0; i < props.length; i++) {
const prop = props[i];
const subCheck = getNestedChecks(check[prop]);
@andrejewski
andrejewski / noid.js
Created October 8, 2017 02:26
Add an annoying particle on the screen of a webpage
document.body.appendChild((function () {
var e = document.createElement('div');
e.style = 'background-color: #000; position: fixed; right: 30vw; top: 40vh; width: 2px; height: 4px';
return e;
})())
@andrejewski
andrejewski / raj-live-code.md
Created October 6, 2017 00:31
Agenda for Raj live coding

Recover Password

aka "Forgot password"

Description

We are going to add a new page /authorize#recover-password to the existing /authorize application. This page has an input for entering an email, button for submission, and a link back to the sign in page. It will make a network request to the server with the email and the response we will display to the user.

Goals

Big

@andrejewski
andrejewski / raj-marko.js
Created September 25, 2017 01:53
Marko bindings for Raj
const {program} = require('raj/runtime')
module.exports = function markoProgram (createApp) {
return class {
onInput (input, out) {
this.makeProgram(input, out)
}
onDestroy () {
this.killProgram()
@andrejewski
andrejewski / canjs-cleanup-pkg.js
Created August 3, 2017 16:07
Code mod to update CanJs package.json
var unusedDeps = [
'done-serve',
'done-cli',
'bit-docs',
'generator-donejs'
]
var unusedScripts = [
'document',
'develop',
@andrejewski
andrejewski / license-year.js
Last active August 9, 2017 17:00
Super mod: Update license year
var fs = require('fs')
var path = require('path')
module.exports = {
getOptions: function () {
return []
},
run: function (directory) {
var potentialNames = ['LICENSE', 'LICENSE.md', 'license', 'license.md']