Skip to content

Instantly share code, notes, and snippets.

View Kraks's full-sized avatar
🐈
no longer working from home

Guannan Wei Kraks

🐈
no longer working from home
View GitHub Profile

Getting Help

Getting help with FreeBSD has been... interesting.

The best place to start is often the FreeBSD forums, where the question you may have has very often been answered in full. But this comes with some important caveats:

  • The forums explicitly state that if you're using a derivative (like GhostBSD) then the forum rules say to just not post there. This is on one hand understandable: derivatives in general can make wild changes (I've been around long enough to remember early Ubuntu users trying to get help from long-time Debian users.... even early Ubuntu had made major changes to the point where Debian users genuinely couldn't help). And certainly there are some FreeBSD derivatives that have made major changes, like helloSystem and ravynOS, not to mention whatever sourcery NomadBSD has done to filesystem mounting. On the other hand, GhostBSD seems (famous last words) to have made rather minimal changes
@dvanhorn
dvanhorn / checkedc-monolith.rkt
Created December 4, 2020 02:01
Redex model of Checked C (monolithic style)
#lang racket
(provide (all-defined-out))
(require redex/reduction-semantics)
;; Redex model of Achieving Safety Incrementally with Checked C,
;; by Ruef, Lampropoulos, Sweet, Tarditi, & Hicks, POST'19.
;; http://www.cs.umd.edu/~mwh/papers/checkedc-incr.pdf
;; This is written in a monolithic-style where there is a single judgment
;; "⊢" that takes a relation name and input and ouput (in order to be
@sjoerdvisscher
sjoerdvisscher / OpenStarSemiring.lhs
Created June 14, 2020 13:31
Playing with 'A Very General Method of Computing Shortest Paths'
This is an extension of "A Very General Method of Computing Shortest Paths" to use "open matrices".
This is from a paper "The Open Algebraic Path Problem" by Jade Master https://arxiv.org/abs/2005.06682
> {-# LANGUAGE TypeFamilies #-}
> {-# LANGUAGE TypeApplications #-}
> {-# LANGUAGE FlexibleContexts #-}
> {-# LANGUAGE StandaloneDeriving #-}
> {-# LANGUAGE AllowAmbiguousTypes #-}
> {-# LANGUAGE ScopedTypeVariables #-}
> module OpenStarSemiring where
@jdegoes
jdegoes / afp-examples.scala
Last active February 12, 2019 19:50
Example code from Applied Functional Programming with Scala
package lambdaconf.introfp2
// import scalaz._
// import Scalaz._
object functions {
object totality {
///def f[A]: A = null
def g[A]: A = throw new Error
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

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

@danidiaz
danidiaz / _FP reading lists.md
Last active May 23, 2024 04:02
assorted reading lists

A series of reading lists mostly related to functional programming.

@palladin
palladin / stage-fix.fsx
Created October 10, 2015 22:00
Staged Fixed-point combinator
open Microsoft.FSharp.Quotations
// <@ fun x -> (% <@ x @> ) @> ~ lambda (fun x -> x)
let lambda (f : Expr<'T> -> Expr<'R>) : Expr<'T -> 'R> =
let var = new Var("__temp__", typeof<'T>)
Expr.Cast<_>(Expr.Lambda(var, f (Expr.Cast<_>(Expr.Var var))))
// fixed-point combinator
let rec fix : (('Τ -> 'R) -> ('Τ -> 'R)) -> 'Τ -> 'R = fun f x ->
@andrejbauer
andrejbauer / Bijection.md
Last active November 29, 2023 22:05
A bijection between numbers and pairs of numbers.

A bijection between numbers and pairs of numbers

Every once in a while I am faced with someone who denies that the rational numbers (or fractions, or pairs of integers) can be put into a bijective correspondence with natural numbers. To deal with the situation, I coded up the bijection. So now I can just say: "Really? Interesting. Please provide a pair of numbers (i,j) which is not enumerated by f, as defined in my gist." I am still waiting for a valid counter-example.

Anyhow, here is a demo of f and g at work. I am using the Python version, but a Haskell variant is included as well.

The 100-th pair is:

>>> f(100)

(10, 4)