Skip to content

Instantly share code, notes, and snippets.

View justinhj's full-sized avatar

Justin Heyes-Jones justinhj

View GitHub Profile
@justinhj
justinhj / middleearth.ts
Created March 7, 2024 23:34
Weird use of Omit
type Species = 'hobbit' | 'orc' | 'elf' | 'man';
interface MiddleEarthDenizen {
name: string
species: Species
}
interface Hobbit extends Omit<MiddleEarthDenizen, 'species'> {
burrow: string
species: 'hobbit'
@justinhj
justinhj / main.cpp
Created October 7, 2023 03:10
leetcode.com/problems/multiply-strings
#include <iostream>
#include <vector>
#include <ranges>
#include <algorithm>
using namespace std;
class Solution {
public:
string m2(string num1, int multiplier, int zeros) {
@justinhj
justinhj / git-add-dired.el
Created July 7, 2013 21:28
Allows you to use dired to add multiple files to a git repository. This is useful since staging files in magit is sluggish and takes a long time when you have a lot of files.
(defun git-add-files(files)
"Run git add with the input file"
(interactive)
(shell-command (format "git add %s" files)))
(defun dired-git-add-marked-files()
"For each marked file in a dired buffer add it to the index"
(interactive)
(if (eq major-mode 'dired-mode)
(let ((filenames (dired-get-marked-files))
@justinhj
justinhj / gist:eb2d354d06631076566f
Created May 12, 2014 02:01
Sending a notification from emacs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Terminal notifier
;; requires 'sudo gem install terminal-notifier'
;; stolen from erc-notifier
(defvar terminal-notifier-command (executable-find "terminal-notifier") "The path to terminal-notifier.")
; (terminal-notifier-notify "Emacs notification" "Something amusing happened")
(defun terminal-notifier-notify (title message)
Found 546487 words in the book
Words with the most uncommon occurence in the English words found on the web
See https://www.kaggle.com/rtatman/english-word-frequency
sibilance (12720)
hubristic (12760)
hellishly (12784)
jerkily (12785)
antimissile (12799)
mildews (12801)
@justinhj
justinhj / FutureTimeout.scala
Last active September 29, 2021 08:22
How to write a future timeout with the Scala/Java standard library
package justinhj.concurrency
import java.util.concurrent.TimeoutException
import java.util.{Timer, TimerTask}
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.language.postfixOps
object FutureUtil {
@justinhj
justinhj / howto.txt
Last active August 23, 2021 04:56
How to do Rust on Windows with Gnu tools
Follow these instructions after you have Rustup, Scoopy and cmder installed.
https://jrhawley.ca/2020/05/25/rust-toolchain-windows
One extra bit of info is to set the path in cmder follow these instructions
https://jonathansoma.com/lede/foundations-2019/terminal/adding-to-your-path-cmder-win/
Find msys in the scoop folder and add the path, mine was here...
package org.justinhj
object Scala2WriterTWithCats extends App {
// Implement WriterT using Cats implementation of Monad and Monoids
import cats.{Monad, Monoid}
case class WriterT[F[_]: Monad,W,A](val wrapped: F[(W,A)])
@justinhj
justinhj / WriterTTest.scala
Last active January 29, 2021 02:01
Scala 3 WriterT
object WriterTest extends App {
trait Semigroup[A]:
def combine(al: A, ar: A): A
object Semigroup:
def apply[A](using s: Semigroup[A]) = s
trait Monoid[A] extends Semigroup[A]:
def zero: A
@justinhj
justinhj / WriterTOldSchool.scala
Last active January 27, 2021 23:44
Implementation of the WriterT monad transformer leveraging Cats for Monad and Monoid
package org.justinhj
object WriterTOldSchool extends App {
import cats.{Monad, Monoid}
case class WriterT[F[_]: Monad,W,A](val wrapped: F[(W,A)])
implicit def writerTMonad[F[_]: Monad,W: Monoid] = new Monad[WriterT[F,W,?]] {