Skip to content

Instantly share code, notes, and snippets.

@tkellogg
tkellogg / .default_model
Last active November 15, 2024 22:56
Ollama zsh aliases
qwen2.5
import re
# Remove leading and trailing text, leaving just the JSON
_JSON_TRIM_PATTERN = re.compile(
r"^" # Start of string
r"[^{\[]*" # Drop everything up to { or [
r"([{\[].*[}\]])" # Keep the JSON
# Greedy match here should force it to not consume JSON
r"[^}\]]*" # Drop everything after } or ]
r"$", # End of string
@tkellogg
tkellogg / servers.md
Last active January 19, 2024 21:23
ports.sh — What servers am I running?

What?

Find all the servers I have running on my laptop. It just prints port, pid and the command that started it (from ps aux)

Why?

Why not?

No, Really...

idk i just have a lot of servers running on my laptop and i sometimes forget where/what each is

It works fine on Mac OS 14.2

@tkellogg
tkellogg / git-rebranch
Created April 5, 2023 19:05
git-rebranch: A simpler git workflow
#!/usr/local/bin/oil
# Re-create the current branch on top of "master" after pulling latest.
#
# Normal usage:
# git rebranch
#
# On a branch other than master:
# git rebranch prod-master
#
# Alternately, configure a default branch in the local repository:
@tkellogg
tkellogg / lazy-val-javap.txt
Created April 17, 2016 10:14
Scala's lazy val is not thread safe. See line 65, I don't see anything related to synchronization.
~> scala
Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_66).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class Foo { lazy val bar = 2 }
defined class Foo
scala> :javap Foo
Size 831 bytes
def mergeFields(vs1: List[JField], vs2: List[JField]): List[JField] = {
def mergeRec(xleft: List[JField], yleft: List[JField]): List[JField] = xleft match {
case Nil => yleft
case (xn, xv) :: xs => yleft find (_._1 == xn) match {
case Some(y @ (yn, yv)) =>
JField(xn, merge(xv, yv)) :: mergeRec(xs, yleft filterNot (_ == y))
case None => JField(xn, xv) :: mergeRec(xs, yleft)
}
}
@tkellogg
tkellogg / CBOR-objectives.md
Last active August 29, 2015 14:15
I copy & pasted this from RFC 7049 (http://tools.ietf.org/html/rfc7049) because I believe it succinctly embodies many of the goals of IoT. TL;DR - it must be simple, interchangeable, small wire size and small code size

Objectives

The objectives of CBOR, roughly in decreasing order of importance, are:

  1. The representation must be able to unambiguously encode most common data formats used in Internet standards.
    • It must represent a reasonable set of basic data types and structures using binary encoding. "Reasonable" here is
@tkellogg
tkellogg / embedded-db.md
Created December 10, 2014 03:47
Requirements for an embedded database for Windows commandline apps

A couple open source .NET projects have need for a headache-free storage option. [Jump-Location][1] is a command line tool that currently uses flat files to store information about what directories a user has visited. Flat files were great at first, but we need more. Also, PSReadLine is also running into similar problems.

Storage Engine

This will most likely wrap an existing storage engine to take care of the administrative tasks. We'll have to choose a storage engine that meets some basic requirements.

  • Small size -- It will have to be packaged with other apps, especially commandline apps where there is an expectation of small size. The storage engine itself should probably be < 10MB.
  • Easy to use -- Otherwise, what's the point of this project?
module Test.Main where
import Debug.Trace
import Data.Char
import Data.String
parse [] = []
-- Error: unexpected "'"
parse ('h':cs) = cs
parse (c:cs) = c:c:cs

Keybase proof

I hereby claim:

  • I am tkellogg on github.
  • I am kellogh (https://keybase.io/kellogh) on keybase.
  • I have a public key whose fingerprint is 402D 2BD0 DEF8 57ED DFAA A221 A1B1 2838 7802 BD5E

To claim this, I am signing this object: