Skip to content

Instantly share code, notes, and snippets.

@hellerve
hellerve / capitalize-string.carp
Last active Jan 19, 2020
Our solutions to the puzzles from the Clojure Berlin Meetup in January, in Carp
View capitalize-string.carp
; as an introduction, we tried to do string capitalization by hand,
; using as many different interesting idioms as possible
(defn capitalize-char [c]
(if (Char.lower-case? c)
(=> c
(to-int)
(- 32)
(from-int))
c))
@sebmarkbage
sebmarkbage / WhyReact.md
Created Sep 4, 2019
Why is React doing this?
View WhyReact.md

I heard some points of criticism to how React deals with reactivity and it's focus on "purity". It's interesting because there are really two approaches evolving. There's a mutable + change tracking approach and there's an immutability + referential equality testing approach. It's difficult to mix and match them when you build new features on top. So that's why React has been pushing a bit harder on immutability lately to be able to build on top of it. Both have various tradeoffs but others are doing good research in other areas, so we've decided to focus on this direction and see where it leads us.

I did want to address a few points that I didn't see get enough consideration around the tradeoffs. So here's a small brain dump.

"Compiled output results in smaller apps" - E.g. Svelte apps start smaller but the compiler output is 3-4x larger per component than the equivalent VDOM approach. This is mostly due to the code that is usually shared in the VDOM "VM" needs to be inlined into each component. The tr

View gist:c121191c61453bec850a61cc428a109e
clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "c6b0b7cb0a30e2edbf7050c0119ef038cf0f0ac2"}}}' -m friendly
user=> (let [:x 5] x)
Call to clojure.core/let did not conform to spec:
-- Spec failed --------------------
([:x 5] x)
^^
should satisfy
@mk
mk / dependency.clj
Created Jul 5, 2018
Figwheel selective build
View dependency.clj
(ns com.nextjournal.build-tools.figwheel.dependency
(:require [clojure.tools.namespace.track :as ctn.track]
[clojure.tools.namespace.dir :as ctn.dir]
[clojure.tools.namespace.file :as ctn.file]
[clojure.tools.namespace.dependency :as ctn.dep]
[clojure.tools.namespace.parse :as ctn.parse]
[clojure.tools.namespace.find :as ctn.find]
[clojure.java.io :as io]
[clojure.tools.reader :as reader])
(:import java.io.PushbackReader))
@bhb
bhb / README.md
Last active May 3, 2021
Clojure friendly mode, inspired by https://github.com/slipset/friendly
View README.md
@OliverJAsh
OliverJAsh / foo.ts
Last active Oct 27, 2021
Records and dictionaries in TypeScript
View foo.ts
/*
In JavaScript, objects can be used to serve various purposes.
To maximise our usage of the type system, we should assign different types to our objects depending
on the desired purpose.
In this blog post I will clarify two common purposes for objects known as records and dictionaries
(aka maps), and how they can both be used with regards to the type system.
View faster-js->clj.cljs
(def kw-cache #js{})
(defn cached-kw [fqn]
(if-some [kw (unchecked-get kw-cache fqn)]
kw
(let [kw (keyword fqn)]
(unchecked-set kw-cache fqn kw)
kw)))
(defn js->clj-fast
View parse-json-with-transit.cljs
(ns transito.core
"
For easier transit handling...
Caching of keywords, no transit UUID's.
"
(:require
[cognitect.transit :as transit]
[com.cognitect.transit :as t]))
(deftype ^:no-doc MapBuilder []
@lmakarov
lmakarov / lambda-basic-auth.js
Created Aug 30, 2017
Basic HTTP Authentication for CloudFront with Lambda@Edge
View lambda-basic-auth.js
'use strict';
exports.handler = (event, context, callback) => {
// Get request and request headers
const request = event.Records[0].cf.request;
const headers = request.headers;
// Configure authentication
const authUser = 'user';
const authPass = 'pass';
@thheller
thheller / es6-class.cljs
Created Aug 24, 2017
class extends React.Component in CLJS
View es6-class.cljs
(defn my-component [props context updater]
(cljs.core/this-as this
(js/React.Component.call this props context updater)
;; anything else you want to set-up. use goog.object/set on this
this))
(gobj/extend
(.. my-component -prototype)
js/React.Component.prototype)