Skip to content

Instantly share code, notes, and snippets.

View beoliver's full-sized avatar

Benjamin E. Oliver beoliver

View GitHub Profile
(defun note ()
"Create and edit a new Markdown note in a temporary buffer.
This function generates a new buffer with a Markdown document based on the current timestamp
in the iCloud directory '~/Library/Mobile Documents/com~apple~CloudDocs/Notes/'.
The buffer is not associated with any file until explicitly saved by the user. When the
function is called interactively, it opens a new buffer for editing the Markdown note.
The Markdown buffer is initialized with a timestamped heading, allowing you to start
writing notes immediately. The buffer remains unsaved until the user chooses to save
(ns simple-router)
(defn- update-handlers
;; utility fn to update all values keyed by `::handlers` in routes using `f`
[routes f]
(reduce-kv (fn [routes k v]
(if (= k ::handlers)
(assoc routes k (update-vals v f))
(assoc routes k (update-handlers v f))))
{}
(ns bitmap
(:require [clojure.core.matrix :as matrix]
[clojure.java.io :as io])
(:import
java.awt.image.BufferedImage
javax.imageio.ImageIO
java.awt.Color
java.io.File))
(matrix/set-current-implementation :vectorz)
(ns dijkstra.core
(:require [clojure.data.priority-map :refer [priority-map]]))
(def ^:private ^:const infinity ##Inf)
(defmacro infinity? [x] `(= ~x ##Inf))
(defn- construct-path [m start end]
(loop [weight 0
path (list)
(defn invert-one-to-one
"returns a one-to-one mapping"
[m]
(persistent!
(reduce (fn [m [k v]] (assoc! m v k)) (transient {}) m)))
(defn invert-many-to-one
"returns a one-to-many mapping"
([m] (invert-many-to-one #{} m))
([to m]
def dfs_pre_order(root,edges):
stack = [root]
visited = set()
while stack:
v = stack.pop()
if v not in visited:
print "PRE-ORDER visting: " + v
visited.add(v)
for u in edges[v]:
from operator import itemgetter
def dijkstra_multi_query(edges, edge_weights, s, terminals):
# terminals is a set of vertices t that we want to find the distance to
# given a start vertex s
count = len(terminals)
optimal = {} # vertices that we know the min path to { vertex : weight }
open Core.Std
module MiniTypeChecker = struct
type t = U | Int | Bool | A of t * t
type e = Var of string | Abs of string * t * e | App of e * e
let compose_types x y = match (x,y) with (_,U) -> U | (U,_) -> U | _ -> A (x,y)
let apply_types x y = match x with A (a,b) -> if a = y then b else U | _ -> U
let get_type ctx = function
| "T" -> Bool | "F" -> Bool
| x -> try int_of_string x |> ignore ; Int
module Main where
import System.IO
import System.Environment (getArgs)
balancedSmileys ('(':xs) count = balancedSmileys xs (count + 1)
balancedSmileys (')':xs) count = (count > 0) && (balancedSmileys xs (count - 1))
balancedSmileys (':':x:xs) count = if (x == '(') || (x == ')')
then (balancedSmileys xs count) || (balancedSmileys (x:xs) count)
else (balancedSmileys (x:xs) count)
balancedSmileys (x:xs) count = balancedSmileys xs count
def balancedSmileys(string):
def f(string,string_len,i,count):
while i < string_len:
w = string[i]
if w == '(':
# keep track of how many left brackets we have seen
count += 1
elif w == ')':
# decrement "stack"
count -= 1