Skip to content

Instantly share code, notes, and snippets.

View samspills's full-sized avatar
💜

Sam Pillsworth samspills

💜
View GitHub Profile
@samspills
samspills / org-refile-and-link.org
Last active February 23, 2024 08:58
Org refile and leave a link behind
@samspills
samspills / config.el
Last active February 18, 2021 22:11
27-05-2020 -- Doom Config
;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-
;; Place your private configuration here! Remember, you do not need to run 'doom
;; sync' after modifying this file!
;; Some functionality uses this to identify you, e.g. GPG configuration, email
;; clients, file templates and snippets.
(setq user-full-name "Sam Pillsworth"
user-mail-address "")
@samspills
samspills / howto.org
Last active August 18, 2024 17:26
Org-capture prompt for heading

How to prompt for a heading during org-capture

Background

I use one file as my org-mode daily driver. This file is called journal.org. It starts with a datetree, which is where I capture general notes, individual tasks, ideas, things to read, etc. etc. I have separate headings for other content, for example all of my projects are under a projects heading, further split by context. Roughly the file looks like this:

* 2021
** 2021-03 March
*** 2021-03-15 Monday
**** [2021-03-15 Mon 16:29] note title :tagA:tagB:
     - note content here ooooo
generated Jan 07, 2023 14:44:56
system MacOS 12.5.1 Darwin 21.6.0 x86_64 ns
emacs 28.1 ~/.emacs.d/ -> ~/.emacs.d/
doom 3.0.0-dev HEAD 6cac7b05 2022-09-12 16:01:43 +0200 ~/.doom.d/ -> ~/.doom.d/
shell /bin/zsh
features ACL GLIB GMP GNUTLS JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP NOTIFY
KQUEUE NS PDUMPER PNG RSVG THREADS TIFF TOOLKIT_SCROLL_BARS XIM ZLIB
traits gui server-running envvar-file
modules :completion company (vertico +icons) :ui doom doom-dashboard hl-todo
indent-guides ligatures modeline ophints (popup +defaults) (treemacs +lsp)
@samspills
samspills / Scheduled.scala
Created January 11, 2023 19:31
toy example with fs2 streams + cats-effect ref
//> using lib "co.fs2::fs2-core:3.4.0"
//> using lib "org.typelevel::cats-effect:3.4.4"
/** Toy example with streams + ref. The ref is initialized to some value, and there are two
* concurrent streams that are passed the ref. The first stream prints the value of the ref every
* second. The second stream updates the value of the ref every 3 seconds. The whole example runs
* for 10 seconds.
*
* This example is pretty simple. The thing that really tripped me up while writing it was passing
* the `IO[Ref[IO, Int]]` to the two streams, which led to them evaluating the ref fresh on each
@samspills
samspills / ScheduledEndpoint.scala
Last active January 16, 2023 21:40
toy example of an http server to query or update a ref, which is also being updated on a schedule
//> using lib "co.fs2::fs2-core:3.4.0"
//> using lib "org.typelevel::cats-effect:3.4.4"
//
//> using lib "org.http4s::http4s-core:0.23.17"
//> using lib "org.http4s::http4s-dsl:0.23.17"
//> using lib "org.http4s::http4s-ember-server:0.23.17"
//> using lib "org.http4s::http4s-server:0.23.17"
import fs2.Stream
import cats.effect.IO
@samspills
samspills / ScheduledRefInClass.scala
Created January 19, 2023 23:09
toy example of an http server to query or update a ref inside of a class, which is also being updated on a schedule
//> using lib "co.fs2::fs2-core:3.5.0"
//> using lib "org.typelevel::cats-effect:3.4.5"
//
//> using lib "org.http4s::http4s-core:0.23.18"
//> using lib "org.http4s::http4s-dsl:0.23.18"
//> using lib "org.http4s::http4s-ember-server:0.23.18"
//> using lib "org.http4s::http4s-server:0.23.18"
import fs2.Stream
import cats.effect.IO
@samspills
samspills / LotORef.scala
Last active January 24, 2023 22:06
many ref updates
//> using lib "org.typelevel::cats-effect:3.4.5"
import cats.effect.{IO, IOApp, Sync}
import cats.effect.kernel.Ref
import cats.syntax.all._
class Worker[F[_]](id: Int, ref: Ref[F, Int])(implicit F: Sync[F]) {
private def putStrLn(value: String): F[Unit] =
F.blocking(println(value))
@samspills
samspills / OpensearchRepro.scala
Created February 17, 2023 19:48
opensearch reproduction start
//> using lib "org.typelevel::cats-effect:3.4.7"
//> using lib "org.http4s::http4s-core:0.23.18"
//> using lib "org.http4s::http4s-dsl:0.23.18"
//> using lib "org.http4s::http4s-ember-client:0.23.18"
//> using lib "org.http4s::http4s-client:0.23.18"
//> using lib "org.http4s::http4s-circe:0.23.18"
//> using lib "io.circe::circe-core:0.14.4"
//> using lib "io.circe::circe-literal:0.14.4"
import cats.effect.kernel.Resource
@samspills
samspills / 3131Example.scala
Created March 7, 2023 02:59
CE 3131 example (maybe)
import cats.effect.std.Dispatcher
import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContext, Future}
import cats.effect.unsafe.implicits.global
object StackTraceExample {
case class SomeError(message: String) extends Exception
val (dispatcher, dispatcherShutdown) = Dispatcher.parallel[IO].allocated.unsafeRunSync()