Skip to content

Instantly share code, notes, and snippets.

@9999years
9999years / weird_rust_error.rs
Created March 15, 2019 16:27
Build fails when using type parameter for function in Rust
// this compiles
fn validator<F, T>(f: F) -> Box<Fn(String) -> Result<(), String> + 'static>
where F: Fn(String) -> Result<T, String> + 'static {
Box::new(move |s| f(s).map(|_| ()))
}
// this fails with:
// error[E0308]: mismatched types
// --> src\main.rs:17:14
// |
@9999years
9999years / build-command-t.ps1
Created February 27, 2019 22:51
Command-T Vim plugin build script
Begin { pushd; cd 'ruby/command-t/ext/command-t' }
Process {
/tools/ruby26/bin/ruby ./extconf.rb
/tools/msys64/usr/bin/make
}
End { popd }
@9999years
9999years / infix.scm
Created February 4, 2019 22:22
Infix arithmetic evaluation in Scheme
#lang r5rs
(#%require schemeunit)
(define (any pred lst)
(if (null? lst)
#f
(or (pred (car lst)) (any pred (cdr lst)))))
(define (list-contains? el lst)
(any (lambda (el*) (equal? el el*)) lst))
@9999years
9999years / girlmarkdown.py
Last active February 4, 2019 22:20
Girl’s Markdown
import sys
# `pip install Markdown`
from markdown import markdown
FLOWER = '🌸'
START_PINK = '<span style="color: pink">'
END_PINK = '</span>'
def girlmarkdown(text):
@9999years
9999years / ligs.py
Created February 4, 2019 15:08
something about the LaTeX listings package and OpenType ligatures
import sys
def esc(txt):
left = txt
right = txt
chrs = r'\~^'
for chr in chrs:
right = right.replace(chr, '\\char"' + format(ord(chr), 'X'))
left = left.replace('\\', '\\\\')
chrs = r'$&%#{}_'
from itertools import product
from operator import itemgetter
bools = [True, False]
def p6eq(a: bool, b: bool, c: bool) -> bool:
return (a and (b or c),
(a and b) or (a and c))
def p6():
return [list(p6eq(a, b, c))
@9999years
9999years / pragmata-pro-liga.sty
Last active October 13, 2021 07:17
Ligatures with PragmataPro 0.827, probably XeLaTeX or LuaTeX, and listings / fontspec
% setup
\usepackage{fontspec}
\setmonofont[
Contextuals=Alternate,
]{PragmataPro Liga}
\usepackage{listings}
\lstset{
basicstyle=\ttfamily,
}
@9999years
9999years / cjkdefine.vim
Created December 19, 2018 03:05
CJK Definition Vimscript function
function! CJKDefine(...)
if a:0 == 0
let b:cjk_char = matchstr(getline('.'), '\%' . col('.') . 'c.')
else
let b:cjk_char = a:1
endif
python3 << EOF
# unbelievable bullshit
setattr(sys, '__stdout__', sys.stdout)
from cihai.core import Cihai
@9999years
9999years / hashcode.py
Last active September 3, 2018 23:23
Generate a String for an arbitrary Java String::hashCode
import math
import logging
def string(hashCode):
"""
The hash code for a String object is computed as
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
using int arithmetic, where s[i] is the ith character of the string, n is
the length of the string, and ^ indicates exponentiation. (The hash value
of the empty string is zero.)
@9999years
9999years / src.xml
Created August 14, 2018 23:16
Maven source-zip assembly boilerplate
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
http://maven.apache.org/xsd/assembly-1.1.2.xsd"
>
<id>src</id>
<formats>