Skip to content

Instantly share code, notes, and snippets.

@briansunter
briansunter / cached_db.cljs
Last active October 13, 2023 23:39
nbb-logseq-typescript
(ns logseq.bb-tasks.nbb.cached-db
"Handles nbb side of cached-db functionality. File path and cache implementation
encapsulated in this ns"
(:require [datascript.transit :as dt]
[datascript.core :as d]
[logseq.graph-parser.cli :as gp-cli]
[logseq.graph-parser :as graph-parser]
[clojure.string :as string]
[logseq.db.rules :as rules]
[clojure.edn :as edn]
const express = require('express');
const app = express();
app.get('/', (req, res) => {
return res.send('Received a GET HTTP method');
});
app.post('/', (req, res) => {
return res.send('Received a POST HTTP method');
@briansunter
briansunter / recursion.md
Last active December 29, 2020 19:22
Explanation of recursion and fibonacci numbers

[[recursion and the stack]] #recursion

  • Recursion is when a function calls itself.
  • A recursive algorithm must have a base case, which is a state that tells the recursive function to stop calling itself and return a value
  • fibonacci numbers

  • The Fibonacci numbers are a sequence of integers in which the first two elements are 0 & 1, and each following elements are the sum of the two preceding elements:
  • 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ..., 233
  • fibo(n) = fibo(n-1) + fibo(n-2)

Iterative

@briansunter
briansunter / romantointeger.js
Created October 3, 2020 20:15
Convert Roman Numeral to Integer
/**
Roman to Integer
https://leetcode.com/explore/interview/card/top-interview-questions-easy/102/math/878/
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
Symbol Value
I 1
V 5
X 10
L 50
@briansunter
briansunter / top500songsrollingstones.csv
Created September 3, 2020 07:03
Top 500 Songs Rolling Stones
Song Artist
Like a Rolling Stone Bob Dylan
(I Can't Get No) Satisfaction The Rolling Stones
Imagine John Lennon
What's Going On Marvin Gaye
Respect Aretha Franklin
Good Vibrations The Beach Boys
Johnny B. Goode Chuck Berry
Hey Jude The Beatles
Smells Like Teen Spirit Nirvana

Keybase proof

I hereby claim:

  • I am briansunter on github.
  • I am bsunter (https://keybase.io/bsunter) on keybase.
  • I have a public key ASBVOoYHoBuiOUESsbkQWkzNtgWfyBubrPz-MUrL_DaC6Qo

To claim this, I am signing this object:

@briansunter
briansunter / anagrams.clj
Created April 6, 2017 01:26
Hacker Rank: Making Anagrams
;; https://www.hackerrank.com/challenges/ctci-making-anagrams
(defn char-frequencies
[x]
(reduce #(update %1 %2 (fnil inc 0)) {} x))
(let [a (read-line)
b (read-line)
a-freq (char-frequencies a)
b-freq (char-frequencies b)
@briansunter
briansunter / clojure-protocol-redux.md
Created January 24, 2017 08:16
clojure spec multimethods as a better protocol

How can we extend functionality in Clojure without modifying the orignal source?

Let's say we want to computer the area of some Shape types like Square and Circle

We have multiple shapes all of which have an area function

We may have some function called sum-areas that takes a list of Shape , calls area on each of them, and sums them up. We don't have access to the original source, but want the ability to add new shapes.

### Keybase proof
I hereby claim:
* I am brsunter on github.
* I am bsunter (https://keybase.io/bsunter) on keybase.
* I have a public key ASBzjQ_kiOqWsGQwMPjxucWSWfX4cUoBNTfvhQ0Aaw2Vggo
To claim this, I am signing this object:
@briansunter
briansunter / reddit.clj
Created September 8, 2016 06:02
Infinite reddit post channel
(defn get-posts
[ch]
(go-loop [a nil]
(let [res (get-posts-page a)
posts (res :children)
after (res :after)]
(do
(doseq [p posts]
(>! ch p))
(recur after)))))