Skip to content

Instantly share code, notes, and snippets.

@travisbrown
travisbrown / response-de-goes.md
Last active March 31, 2024 14:41
Response to cease and desist letter from John A. De Goes, CEO of Ziverge
@wmayner
wmayner / color_swatch_notebook_cell.py
Last active August 22, 2024 13:51
Display a color swatch from hex color strings with IPython in a Jupyter Notebook
from IPython.display import Markdown, display
colors = ['#018700', '#00acc6', '#e6a500']
display(Markdown('<br>'.join(
f'<span style="font-family: monospace">{color} <span style="color: {color}">████████</span></span>'
for color in colors
)))
import cats.effect.Concurrent
import cats.effect.concurrent.{Deferred, Ref}
import cats.implicits._
trait Cache[F[_], K, V] {
def getOrUpdate(k: K)(v: F[V]): F[V]
def values: F[Map[K, Deferred[F, V]]]
}
@johnynek
johnynek / TreeList.scala
Created December 14, 2018 19:45
Implementation of "Purely Functional Random Access Lists" by Chris Okasaki in scala. This gives O(1) cons and uncons, and 2 log_2 N lookup.
package org.bykn.list
import cats.Applicative
import cats.implicits._
/**
* Implementation of "Purely Functional Random Access Lists" by Chris Okasaki.
* This gives O(1) cons and uncons, and 2 log_2 N lookup.
*/
@mpkocher
mpkocher / AmmoniteOpsExample.ipynb
Created November 7, 2018 00:56
Ammonite Ops /dev/tty: Device not configured Issue
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ssaavedra
ssaavedra / pre-commit
Last active September 19, 2018 13:29
Setup a repo pre-commit hook to use scalafmt
#!/bin/sh
# Licensed under CC0 in jurisdictions where this is not directly in the Public Domain
# Authored by Santiago Saavedra (github.com/ssaavedra)
git scalafmt --test || exit 1
# If there are whitespace errors, print the offending file names and fail.
exec git diff-index --check --cached $against --
@parente
parente / README.md
Last active December 26, 2023 14:31
Jupyter Tidbit: Use nbconvert to clear notebook outputs

Summary

nbconvert has a preprocessor that clears cell outputs from notebook files, leaving cell inputs intact.

Example

The following shell command reads my_input_notebook.ipynb, removes its cell outputs, prints the cleaned notebook to stdout, and redirects that output to a new notebook file named my_output_notebook.ipynb.

jupyter nbconvert my_input_notebook.ipynb --to notebook --ClearOutputPreprocessor.enabled=True --stdout &gt; my_output_notebook.ipynb
@holmberd
holmberd / deploy-keys.md
Last active February 11, 2024 20:36
Setup GitHub repository SSH deploy keys

Setup GitHub repository SSH deploy keys

  1. Create GitHub repository in github and save the SSH repository url

  2. Init git on server in code directory

  • git init
  1. Create SSH keys on the server
  • ssh-keygen -t rsa -b 4096 -C [email protected]
  • Rename the key that doesn't end with .pub to repo-name.deploy.pem

Quick Tips for Fast Code on the JVM

I was talking to a coworker recently about general techniques that almost always form the core of any effort to write very fast, down-to-the-metal hot path code on the JVM, and they pointed out that there really isn't a particularly good place to go for this information. It occurred to me that, really, I had more or less picked up all of it by word of mouth and experience, and there just aren't any good reference sources on the topic. So… here's my word of mouth.

This is by no means a comprehensive gist. It's also important to understand that the techniques that I outline in here are not 100% absolute either. Performance on the JVM is an incredibly complicated subject, and while there are rules that almost always hold true, the "almost" remains very salient. Also, for many or even most applications, there will be other techniques that I'm not mentioning which will have a greater impact. JMH, Java Flight Recorder, and a good profiler are your very best friend! Mea

Principled Meta Programming for Scala

This note outlines a principled way to meta-programming in Scala. It tries to combine the best ideas from LMS and Scala macros in a minimalistic design.

  • LMS: Types matter. Inputs, outputs and transformations should all be statically typed.

  • Macros: Quotations are ultimately more easy to deal with than implicit-based type-lifting

  • LMS: Some of the most interesting and powerful applications of meta-programming