Skip to content

Instantly share code, notes, and snippets.

(ns app.todo-list
(:require #?(:clj [app.xtdb-contrib :as db])
[hyperfiddle.electric :as e]
[hyperfiddle.electric-dom2 :as dom]
[hyperfiddle.electric-ui4 :as ui]
[xtdb.api #?(:clj :as :cljs :as-alias) xt]))
(e/def !xtdb)
(e/def db) ; injected database ref; Electric defs are always dynamic
@slifin
slifin / one-edit-away.clj
Created October 6, 2021 19:02
Detects if two strings are one edit away
(ns slifin.tdd2
(:require [hyperfiddle.rcf :refer [tests]]))
(defn one-edit-away? [a b]
(cond (= a b) true
(> (Math/abs (- (count a) (count b))) 1) false
(= (first a) (first b)) (recur (subs a 1) (subs b 1))
(and (= (count a) (count b))
(= a (str (first a) (subs b 1)))) true
(and (> (count a) (count b))
(ns BristolClojurians.interview
(:require [clojure.test :refer [deftest is]])
(:gen-class))
;; set is allowed
(defn unique? [string]
(= string (apply str (set string))))
(deftest unique?-test
(is (= true (unique? "abc")))
@slifin
slifin / temp.sql
Created March 11, 2021 12:31
temp table syntax with indexes
CREATE TEMPORARY TABLE
view_range ( INDEX view_date(date) )
AS
SELECT "2021-01-01" AS `date`, 1 AS overnight
UNION ALL
SELECT "2021-01-02" AS `date`, 0 AS overnight;
SHOW INDEX FROM view_range;
(ns slifin.io.weather
(:gen-class)
(:require [cheshire.core :as json]
[com.wsscode.pathom3.connect.indexes :as pci]
[com.wsscode.pathom3.connect.operation :as pco]
[com.wsscode.pathom3.interface.smart-map :as psm]))
(pco/defresolver ip->lat-long
[{:keys [ip]}]
{::pco/output [:latitude :longitude]}
<?php
class B {
public static function A(int $a, int $b = NULL) {
return 5;
}
public static function C(int $a, string $hey) {
activity_log = opening_line (qualifierFromTo|qualifierTo|qualifierRemoved)?+
opening_line = entity identifiers (for <space> name)? <space> was <space> verb (<space> location)? <space> on datetime source period newline?
source = (by <space> name) | 'via Birdie' | 'by the automatic confirmation process'
qualifierFromTo = attribute <space> modificationFrom from to_string to period newline?
qualifierTo = attribute <space> modificationTo to period newline?
qualifierRemoved = attribute <space> 'was removed' period newline?
@slifin
slifin / dispatch.php
Created April 28, 2020 20:15
dispatch on function signatures
<?php
class B {
public static function A(int $a, int $b = NULL) {
}
public static function C(int $a) {
return 2;
<?php
class DrupalPassword
{
/**
* Returns a string for mapping an int to the corresponding base 64 character.
*
* @return String map for base64.
*/
public static function itoa64() : string
@slifin
slifin / 00_script.clj
Created March 26, 2020 14:50 — forked from ericnormand/00_script.clj
Boilerplate for running Clojure as a shebang script
#!/bin/sh
#_(
#_DEPS is same format as deps.edn. Multiline is okay.
DEPS='
{:deps {clj-time {:mvn/version "0.14.2"}}}
'
#_You can put other options here
OPTS='