Skip to content

Instantly share code, notes, and snippets.

@quelgar
quelgar / typed_errors.md
Last active January 16, 2024 09:36
Every Argument for Static Typing Applies to Typed Errors

Every Argument for Static Typing Applies to Typed Errors

Think of all the arguments you've heard as to why static typing is desirable — every single one of those arguments applies equally well to using types to represent error conditions.

An odd thing I’ve observed about the Scala community is how many of its members believe that a) a language with a sophisticated static type system is very valuable; and b) that using types for error handling is basically a waste of time. If static types are useful—and if you like Scala, presumably you think they are—then using them to represent error conditions is also useful.

Here's a little secret of functional programming: errors aren't some special thing that operate under a different set of rules to everything else. Yes, there are a set of common patterns we group under the loose heading "error handling", but fundamentally we're just dealing with more values. Values that can have types associated with them. There's absolutely no reason why the benefits of static ty

@EvanBacon
EvanBacon / Info.plist.json
Last active May 15, 2023 08:53
[Expo Config Plugins] JSON version of CFBundleDocumentTypes, UTExportedTypeDeclarations, UTImportedTypeDeclarations from VLC app Info.plist -- good for importing different file formats into your app
{
"CFBundleDocumentTypes": [
{
"CFBundleTypeName": "Folder",
"CFBundleTypeRole": "Viewer",
"LSItemContentTypes": [
"public.folder"
]
},
{
@unrealwill
unrealwill / collisionLSH.py
Created August 8, 2021 10:20
Proof of Concept : generating collisions on a neural perceptual hash
import tensorflow as tf #We need tensorflow 2.x
import numpy as np
#The hashlength in bits
hashLength = 256
def buildModel():
#we can set the seed to simulate the fact that this network is known and doesn't change between runs
#tf.random.set_seed(42)
model = tf.keras.Sequential()
@glowinthedark
glowinthedark / RsyncBackup.js
Last active October 21, 2024 07:04
MacOS RsyncBackup — simplest possible rsync GUI for MacOS
#!/usr/bin/osascript -l JavaScript
// ^^^^ COMMENT/REMOVE THIS SHEBANG IF RUNNING FROM SCRIPT EDITOR!!!!! ^^^^^^^^^^^
// The SHEBANG is only needed if the file is executable and is run from a terminal with `./RsyncBackup.js`
// 1. In MacOS Spotlight type 'Script Editor' and paste the code below
// 2. Click the top-left dropdown which says 'AppleScript' and select 'JavaScript'
// 3. Under menu File pick Export
// 4. In the Export dialog select File Format = Application
// 5. Save the app in /Applications
@gephaest
gephaest / generate-routes.sh
Last active March 1, 2021 23:16
Generate vpnc_server_script.sh for VPN whitelisting. Only for padavan firmware
#!/bin/bash
input="$(pwd)/domains.txt"
outputFile="$(pwd)/vpnc_server_script.sh"
routerSSH="[email protected]"
addOps=()
delOps=()
ipAddrRegular='[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'

Fibers

Fibers are an abstraction over sequential computation, similar to threads but at a higher level. There are two ways to think about this model: by example, and abstractly from first principles. We'll start with the example.

(credit here is very much due to Fabio Labella, who's incredible Scala World talk describes these ideas far better than I can)

Callback Sequentialization

Consider the following three functions

@osamaqarem
osamaqarem / nginx_macos.md
Last active April 4, 2025 08:54
Nginx on MacOS

Install nginx (Homebrew)

brew install nginx

Configuration file for nginx will be at /usr/local/etc/nginx/nginx.conf

Web apps can be stored at /usr/local/var/www

Commands

Start:

@jfcherng
jfcherng / st4-changelog.md
Last active May 30, 2025 15:19
Sublime Text 4 changelog just because it's not on the official website yet.
sealed trait Path
case class Field(name: String, child: Option[Path]) extends Path {
override def toString: String = child match {
case None => name
case Some(path) => s"$name.$path"
}
}

Easy Scala Publication

The following describes how you can publish artifacts for any sbt project using the GitHub Package Registry and the sbt-github-packages plugin.

Step 1: Create a GitHub Token

In your GitHub account, go to Settings > Developer settings > Personal access tokens, then click on Generate new token (or click here). Fill in some sort of meaningful name (I chose Dev) and click on the write:packages checkbox:

the new personal access token page with the above steps having been followed