Skip to content

Instantly share code, notes, and snippets.

View unhammer's full-sized avatar
kevin :: Coffee → Code

Kevin Brubeck Unhammer unhammer

kevin :: Coffee → Code
View GitHub Profile
@vshabanov
vshabanov / OneBRC.hs
Last active March 21, 2024 22:19
One billion lines challenge
{-# LANGUAGE GHC2021, LambdaCase, PatternSynonyms, RecordWildCards,
ViewPatterns, OverloadedStrings, GADTs, NoMonoLocalBinds,
UnboxedTuples, MagicHash #-}
{-# OPTIONS_GHC -O2 -fspec-constr-count=100 -fllvm #-}
-- need at least 8 to completely remove all allocations
-- (I don't know what change lead to it)
{-# OPTIONS_GHC -Wall -Wno-gadt-mono-local-binds -Wno-type-defaults #-}
@ttesmer
ttesmer / AD.hs
Last active March 19, 2024 03:04
Automatic Differentiation in 38 lines of Haskell using Operator Overloading and Dual Numbers. Inspired by conal.net/papers/beautiful-differentiation
{-# LANGUAGE TypeSynonymInstances #-}
data Dual d = D Float d deriving Show
type Float' = Float
diff :: (Dual Float' -> Dual Float') -> Float -> Float'
diff f x = y'
where D y y' = f (D x 1)
class VectorSpace v where
zero :: v
@moyix
moyix / arith1000_t0.1_k0_p0.0_results.txt
Created February 10, 2022 21:52
Data files for GPT-NeoX-20B arithmetic (100 and 1000 questions)
Question Real Guess Correct? RelErr Digits
What is 18857 - 592? 18265 18265 Yes 0.0% 5/5
What is 30752 - 3087? 27665 27365 No 1.1% 4/5
What is 2241 + 19873? 22114 22114 Yes 0.0% 5/5
What is 5412 + 10169? 15581 15581 Yes 0.0% 5/5
What is 11831 - 9178? 2653 3153 No 18.8% 2/4
What is 1701 * 19933? 33906033 33953373 No 0.1% 4/8
What is 11648 + 17851? 29499 30509 No 3.4% 1/5
What is 29253 - 6202? 23051 22151 No 3.9% 3/5
What is 27365 + 24989? 52354 53554 No 2.3% 3/5
@Arnavion
Arnavion / ip-flash.awk
Created November 18, 2019 19:34
Flash Raspberry Pi's IP address using its LED
#!/usr/bin/awk -f
BEGIN {
while (1) {
split(exec_line_match("ip addr show dev eth0", " inet "), ip_a_parts, " ")
split(ip_a_parts[2], ip_value_parts, "/")
split(ip_value_parts[1], ip_parts, ".")
reset();
@kosmikus
kosmikus / Tutorial.hs
Last active May 1, 2020 23:59
Preliminary rewrite of Gabriel's lens tutorial to use `optics` instead of `lens`
{-| This @lens@ tutorial targets Haskell beginners and assumes only basic
familiarity with Haskell. By the end of this tutorial you should:
* understand what problems the @lens@ library solves,
* know when it is appropriate to use the @lens@ library,
* be proficient in the most common @lens@ idioms,
* understand the drawbacks of using lenses, and:
@yolabingo
yolabingo / wp-email-validate-check.php
Last active May 21, 2020 04:15
Test Wordpress email validation regular expression
<?php
/*
Wordpress bug https://core.trac.wordpress.org/ticket/47855
When using a current PHP version, class-phpmailer.php:validateAddress() uses a complex regex ("pcre8") for email address validation.
PHP < 7.3 uses libpcre 8.x.
PHP 7.3 uses libpcre2 10.x.
Due to a bug in libpcre2 < 10.32-RC1 https://bugs.exim.org/show_bug.cgi?id=2300,
@rjhansen
rjhansen / keyservers.md
Last active April 14, 2024 12:28
SKS Keyserver Network Under Attack

SKS Keyserver Network Under Attack

This work is released under a Creative Commons Attribution-NoDerivatives 4.0 International License.

Terminological Note

"OpenPGP" refers to the OpenPGP protocol, in much the same way that HTML refers to the protocol that specifies how to write a web page. "GnuPG", "SequoiaPGP", "OpenPGP.js", and others are implementations of the OpenPGP protocol in the same way that Mozilla Firefox, Google Chromium, and Microsoft Edge refer to software packages that process HTML data.

Who am I?

@unhammer
unhammer / intervec.py
Last active July 27, 2021 15:59
Multilingual word vectors for SpaCy (based on https://github.com/Babylonpartners/fastText_multilingual )
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# A SpaCy implementation of
# https://github.com/Babylonpartners/fastText_multilingual
#
# heavily based on
# https://github.com/Babylonpartners/fastText_multilingual/blob/master/align_your_own.ipynb
import numpy as np
@unhammer
unhammer / signal
Last active February 21, 2022 20:04
Launch Signal if not running, otherwise toggle hidden/shown state. Put signal.desktop in ~/.config/autostart/.
#!/bin/bash
run () {
signal-desktop &
disown
}
show () {
local -r id="$1"
idx="$(printf "0x%08x" "${id}")"
@alphapapa
alphapapa / replace-words-randomly.el
Created July 24, 2017 22:40
Emacs: Replace all words in buffer with random words of the same length
;; This function replaces all words in a buffer with words of the same length,
;; chosen at random from /usr/share/dict/words. Words are replaced consistently,
;; so e.g. "A" is always replaced with "Z". The mapping changes when Emacs is
;; restarted or when the cache buffer is killed. If all unique words of a certain
;; length are exhausted, random strings are used.
(defun ap/replace-words-randomly (&optional buffer)
"Replace all words in BUFFER or current buffer with randomly selected words from the dictionary.
Every time a new word is found, it is mapped to a replacement
word, so every instance of word A will be replaced with word Z."