Skip to content

Instantly share code, notes, and snippets.

View InnovativeInventor's full-sized avatar

Max Fan InnovativeInventor

View GitHub Profile
@InnovativeInventor
InnovativeInventor / Dockerfile
Created May 8, 2023 05:01
Dockerfile for using Dafny 4.0.0
FROM ubuntu:latest
RUN apt-get update && apt-get install -y dotnet-sdk-6.0 curl zip neovim emacs && rm -rf /var/lib/apt/lists/*
RUN curl -L https://github.com/dafny-lang/dafny/releases/download/v4.0.0/dafny-4.0.0-x64-ubuntu-20.04.zip -o dafny-4.0.0.zip
RUN sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
RUN unzip dafny-4.0.0.zip
import sys
"""
Example usage (on slurm cluster):
scontrol show nodes | python cores.py | sort -n
Outputs list of free cores per node, along with the load.
"""
for line in sys.stdin:
@InnovativeInventor
InnovativeInventor / queens.hs
Last active May 14, 2021 03:09
Mini Non-Attacking queens calculator in Haskell
-- These imports are only needed for parallelism
import Control.Parallel.Strategies (parMap, rpar)
pickCoords n = sequence (replicate 2 [0..n-1])
mex list = head (filter (`notElem` list) [0..(maximum list+1)])
checkIntersect [x,y] [n,m] = not (x == n || y == m) && (abs (x-n) /= abs (y-m))
nextMoves max history = filter (\move -> null history || all (checkIntersect move) history) (pickCoords max)
calcNimber max history | null (nextMoves max history) = 0 | otherwise = mex (map (\move -> calcNimber max (history ++ [move])) (nextMoves max history))
a344227 n = calcNimber n []
@InnovativeInventor
InnovativeInventor / .tmux.conf
Last active April 18, 2021 20:08
Personal tmux conf
bind-key -T copy-mode-vi 'v' send -X begin-selection; \
bind-key -T copy-mode-vi 'V' send -X select-line; \
bind-key -T copy-mode-vi 'r' send -X rectangle-toggle; \
bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
@InnovativeInventor
InnovativeInventor / example.yaml
Created September 20, 2020 15:49
Example yaml schema of a housing assignment input with encoded preferences
houses:
- name: East Cottage
capacity: 4
- name: Memorial House
capacity: 3
- name: Tenny House
capacity: 3
- name: Atwater
capacity: 3
Developer's Certificate of Origin 1.1 (modified from the Linux kernel)
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the repository; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
package main
import (
"fmt"
"encoding/json"
"io/ioutil"
"github.com/willf/bloom"
)
func main() {
package main
import (
"fmt"
"log"
"bufio"
"encoding/json"
"io/ioutil"
"os"
"github.com/willf/bloom"

There are three steps to the locking operation, the lock step (which we will refer to as lock()), the execution actual payout function (payout()), followed by the lock release (release()). We assume that all of these functions will return true if and only if the action succeeded. Specifically, we assume that lock() will return false if the atomic database operation did not modify the document and will return true when the document has been modified and the modification has been fully propagated. These are guarantees provided by MongoDB's atomic update operation (source: https://pymongo.readthedocs.io/en/stable/api/pymongo/results.html#pymongo.results.UpdateResult) and by mongodb_dataset's update result checks.

Given the lock only has two states, locked or unlocked, and if it is unlocked, lock() will succeed, lock() can only return false if the file is already locked.

This is the pseudo structure of both programs:

worker 1 (w_1):