Skip to content

Instantly share code, notes, and snippets.

@premek
premek / mv.sh
Last active March 5, 2024 17:43
Rename files in linux / bash using mv command without typing the full name two times
# Put this function to your .bashrc file.
# Usage: mv oldfilename
# If you call mv without the second parameter it will prompt you to edit the filename on command line.
# Original mv is called when it's called with more than one argument.
# It's useful when you want to change just a few letters in a long name.
#
# Also see:
# - imv from renameutils
# - Ctrl-W Ctrl-Y Ctrl-Y (cut last word, paste, paste)

Reason

I have heard a lot of complaints about lack of editor integration or flaky editor tooling in the Reason community. At my previous job we had ~3000 modules and ~80k LOC. I'll admit that we were not very vigilant with .rei files or keeping our inter module dependencies really clean so this slowed both bsb and especially reason-language-server down a lot.

In fact so much that people couldn't use reason-language-server anymore on 15" MacBook Pros.

I myself have always used a Merlin based setup since I joined the Reason eco system before reason-language-server, and in our project my setup had never failed. Therefor I went on a quest of setting up 3 of the major editors (Emacs, Vim and VSCode) and documenting how to get them working

@hcarty
hcarty / Makefile
Last active October 19, 2017 17:33
Makefile template for a jbuilder-backed OCaml/Reason library project
.PHONY: all test benchmark doc repl clean gh-pages
all:
jbuilder build --dev
test:
jbuilder runtest --dev
benchmark:
jbuilder build benchmark/bench.exe
@pbiggar
pbiggar / .README.md
Last active May 20, 2020 15:55
using ocamlmerlin inside a docker container

We were able to make Spacemacs connect to ocamlmerlin in a Docker container. It definitely works in Spacemacs, and should work anywhere else. Please comment below if you can't make it work.

opam and ocamlmerlin are copies of the same file. ocp-indent, refmt, and other executables can be handled the same way.

The magic happens in run-in-docker. You most likely need to change the sed commands in fix_dirs_stdin and fix_dirs_stdout.

I've included a sample Dockerfile that we use with 4.04.2, note the env vars are important.

@Roulette
Roulette / command-proxy.sh
Last active October 3, 2017 05:11
Docker Proxy
#!/usr/bin/env bash
# This is the proxy. You'll want to configure your IDE settings in such way that it points to this file instead of the actual binary.
# This file has to be copy-pasted for each binary.
# For example, the VS Code Reason plugin needs paths to numerous binaries, such as opam, refmt and so on.
# You would need to have a file such as this one for each of them and replacing "ORIGINAL_COMMAND" with "opam" or "refmt".
# The "$@" is a forward of all parameters
# set -euo pipefail takes care of weird permission issues.
set -euo pipefail
@mrange
mrange / data_performance.md
Last active January 4, 2020 10:16
On the topic of data locality and performance

On the topic of data locality and performance

Full source code can be found here

It is well-known that a hard disk has a long delay from that we request the data to that we get the data. Usually we measure the hard disk latency in milliseconds which is an eternity for a CPU. The bandwidth of a hard disk is decent good as SSD:s today can reach 1 GiB/second.

What is less known is that RAM has the same characteristics, bad latency with good bandwidth.

You can measure RAM latency and badndwidth using Intel® Memory Latency Checker. On my machine the RAM latency under semi-high load is ~120 ns (The 3r:1w bandwidth is 16GiB/second). This means that the CPU on my machine has to wait for ~400 cycles for data, an eternity.

(* Good morning everyone, I'm currently learning ocaml for one of my CS class and needed to implement
an avl tree using ocaml. I thought that it would be interesting to go a step further and try
to verify the balance property of the avl tree using the type system. Here's the resulting code
annotated for people new to the ideas of type level programming :)
*)
(* the property we are going to try to verify is that at each node of our tree, the height difference between
the left and the right sub-trees is at most of 1. *)

Getting Started in Scala

This is my attempt to give Scala newcomers a quick-and-easy rundown to the prerequisite steps they need to a) try Scala, and b) get a standard project up and running on their machine. I'm not going to talk about the language at all; there are plenty of better resources a google search away. This is just focused on the prerequisite tooling and machine setup. I will not be assuming you have any background in JVM languages. So if you're coming from Python, Ruby, JavaScript, Haskell, or anywhere…  I hope to present the information you need without assuming anything.

Disclaimer It has been over a decade since I was new to Scala, and when I was new to Scala, I was coming from a Java and Ruby background. This has probably caused me to unknowingly make some assumptions. Please feel free to call me out in comments/tweets!

One assumption I'm knowingly making is that you're on a Unix-like platform. Sorry, Windows users.

Getting the JVM

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@atavener
atavener / database.ml
Created September 12, 2013 07:24
OCaml in-memory "database" -- I use this for component-based game-objects.
(* Database provides key-generation and table-instantiation,
* so that a key can be associated to various properties.
*)
(* This is for a fully-controlled specification...
*
* module Db = Database.Make (Database.IntKey)
* module Prop = Db.MultiInherit
* module PropHash = Prop.Table(Database.Hash)
* module Size = (val PropHash.create ~default:0 () : Db.Sig with type t = int)