Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View olivergeorge's full-sized avatar

Oliver George olivergeorge

  • Tasmania, Australia
View GitHub Profile
@roman01la
roman01la / analyze.clj
Created March 18, 2021 01:42
analyzing unused and undefined re-frame subscriptions via clj-kondo
(ns analyze.core
(:require [clj-kondo.core :as clj-kondo]
[clojure.set :as set]))
;; checks re-frame's :<- syntax
;; to mark dependency subscriptions as used
(def analyze-reg-sub
"(require '[clj-kondo.hooks-api :as api])
(fn [{node :node}]
(let [[_ kw & children] (:children node)
@roman01la
roman01la / re-frame.clj
Last active October 21, 2020 11:32
Debugging re-frame subscriptions
(ns utils.re-frame
(:require [cljs.compiler :as cljsc]))
(defn- anonymous-function-declaration? [form]
(and (list? form)
(= 'fn (first form))
(vector? (second form))))
(defn- query-id->js-fn-name [query-id]
(let [ns-part (when-let [ns-part (namespace query-id)]
@cdbkr
cdbkr / react-testing-library-clojurescript.cljs
Last active February 3, 2023 15:24
React-testing-library and Re-frame clojurescript app
(ns demo.core-test
(:require [cljs.test :refer [deftest
testing
is
use-fixtures]]
[clojure.string :refer [lower-case]]
[demo.components :refer [title-component
counter-component]]
[reagent.core :as r]
["react-testing-library" :as rtl]))
@ncochard
ncochard / babel-webpack.md
Last active September 29, 2023 05:15
The correct way to compile ES6 using babel...

When you create a npm package, remember it might be used in a browser or a server, or even a command line utility… For each package you create, please pay attention at what it will be used for:

  1. Is it going to be used as a dependency to a nodejs application that is not bundled? (e.g. command line utilities)
  2. Is it going to be used as a dependency to a nodejs application that is bundled? (e.g. AWS Lambdas)
  3. Is it going to be used as a dependency to a browser application (always bundled)?.
  • In cases 2) and 3) you want to allow for tree shaking.
  • In cases 1) and 2) you want to benefit from the "ES6"/"ES next" features supported natively by nodejs.
  • In case 3) you also want to benefit from the native support of "ES6" from your browser.
@raymcdermott
raymcdermott / decoding-jwt.clj
Last active October 26, 2022 05:47
Simple JWT Decoder in Clojure
(defn base64-decode
"Utility function over the Java 8 base64 decoder"
[to-decode]
(String. (.decode (Base64/getDecoder) ^String to-decode)))
(defn string->edn
"Parse JSON from a string returning an edn map, otherwise nil"
[string]
(when-let [edn (json/decode string true)]
(when (map? edn)
@terjesb
terjesb / latency.txt
Created May 4, 2017 15:06 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS CloudFormation sample template that contains a single Lambda function behind an API Gateway",
"Resources": {
"GreetingLambda": {
"Type": "AWS::Lambda::Function",
"Properties": {
@pesterhazy
pesterhazy / error_boundary.cljs
Last active October 12, 2021 00:19
Reagent error boundary for recovering from exceptions
(ns error-boundary.error-boundary
(:require [reagent.core :as r]
[reagent.impl.component :as comp]
[reagent.impl.util :as util]
[goog.object :as gobj]))
;; (c) 2016 Paulus Esterhazy
;;
;; License: MIT
@kennyjwilli
kennyjwilli / defspec-test.clj
Created November 5, 2016 01:37
clojure.spec.test integration with clojure.test
(defmacro defspec-test
([name sym-or-syms] `(defspec-test ~name ~sym-or-syms nil))
([name sym-or-syms opts]
(when t/*load-tests*
`(def ~(vary-meta name assoc :test `(fn []
(let [check-results# (clojure.spec.test/check ~sym-or-syms ~opts)
checks-passed?# (every? nil? (map :failure check-results#))]
(if checks-passed?#
(t/do-report {:type :pass
:message (str "Generative tests pass for "
@freewayz
freewayz / django_model_deletable.py
Created September 27, 2016 14:43
Django check if model has related object before Deleting the model
#After looking for a way to check if a model instance can be deleted in django ,
#i came across many sample, but was not working as expected. Hope this solution can help.
#Let start by creating an Abstract model class which can be inherited by other model
class ModelIsDeletable(models.Model):
name = models.CharField(max_length=200, blank=True, null=True, unique=True)
description = models.CharField(max_length=200, blank=True, null=True)
date_modified = models.DateTimeField(auto_now_add=True)