Skip to content

Instantly share code, notes, and snippets.

View hmil's full-sized avatar

Hadrien Milano hmil

View GitHub Profile
@hmil
hmil / FPGA_Invaders.asm
Last active December 28, 2015 00:59
A space invaders-like mips game for FPGA4U.
# === FPGA INVADERS ===
#
#
# VHDL symbols have invaded the FPGA, destroy them all to free your board
# from unpredictable behaviour, mind-fucking bugs and shitty simulations !
#
#
# == Controls ==
#
# +---------+
@hmil
hmil / goto_jira.js
Created August 25, 2016 18:17
Open a jira ticket in a new tab
/**
* === Goto JIRA ===
* Handy userscript to visit a JIRA ticket.
*
* Installation:
* Embed this piece of javascript prefixed with javascript: in a bookmark.
*
* Usage:
* 1. Highlight a piece of text containing the jira ticket number you want to visit
* 2. Click on the bookmarklet to open the ticket in a new tab
@hmil
hmil / grading_scheme.md
Created May 12, 2017 17:06
Alternative grading scheme

Grading scheme proposal

Idea

The TA writes down everything (s)he sees no matter how important it is and doesn't give any "point". The actual grade is computed from the list of issues collected from the comments.

The issues are not specific to the subject rather they are generic comments that can be made about any piece of C code. The issues are codified using a universal issue list. There is little to no room left for interpretation. A direct consequence is that the grading must be as fair* as possible.

* Fairness here means that the handouts should end up sorted by subjective quality based. There is still a subjectiveness bias but it applies to all handouts equally and is not dependent on which TA graded it.

@hmil
hmil / nullables.ts
Created August 1, 2017 15:00
The one true way to deal with nullables in TypeScript.
/**
* The one true way to deal with nullables in TypeScript.
*
* This code demonstrates a nice design pattern to deal with nullable
* values in TypeScript. In my blog post, I describe how sane practices
* around null values involved in both synchronous and asynchronous workflows
* enhance the quality of the code without any downside.
*
* http://blog.hmil.fr/2017/08/deal-with-nullables-like-theyre-not-even-here-good-coding-practices-in-typescript/
*
@hmil
hmil / class-to-test.ts
Created November 15, 2017 11:28
Asynchronous testing with jest and typescript
class SyncDB {
// ... attributes omitted for brievety
public remove<T extends ISyncEntity>(entity: ISavedDocument<T>): Promise<void> {
return this.lock.runExclusive( async () => {
await this.db.remove(entity);
const mutation = deleteMutation(entity, this.mutationSeq++);
await this.db.post(mutation);
return entity._id;
@hmil
hmil / Ajax.ts
Created November 23, 2017 14:31
Typescript API consumer
export interface AjaxRequest {
url: string;
method?: string;
data?: any;
}
let REPORT_ERRORS = true;
export function disableErrorReporting(): void {
@hmil
hmil / makefile.ts
Created August 31, 2018 14:40
Sample typed makefile
import build from 'awesome-build-system'
compiled = build.createTarget('/dist/app.js', () => {
build.exec('tsc -p tsconfig.json')
})
packaged = build.createTarget('/dist/package.tar.gz', [ compiled ], () => {
build.exec('npm pack')
build.exec(`cp artifact.tar.gz ${packaged}`)
})
@hmil
hmil / tuples.ts
Created September 20, 2018 16:34
Well-typed variable-length tuples in TypeScript
/**
* Arbitrary-length tuples
* =======================
*
* Working with tuples of unknown length in TypeScript is a pain. Most library authors fall back on enumerating all possible
* tuple lengths up to a threshold (see an example here https://github.com/pelotom/runtypes/blob/fe19290d375c8818d2c52243ddc2911c8369db37/src/types/tuple.ts )
*
* In this gist, I'm attempting to leverage recursion to provide support for arbitrary length tuples. This has the potential
* to make some kinds of declarative APIs nicer and enhance type inference in some cases.
* This example shows how to take a variable-length tuple as an input, transform each of its types and use the resulting
@hmil
hmil / my-script.sh
Created December 19, 2018 20:51
Shell script stem
usage() {
echo "my-script.sh [options]"
echo ""
echo "Options:"
echo " --simple-param, -s : activate a feature"
echo " --complex-param, -c <value> : set some value"
echo " --help, -h : print this help message"
}
while [ "$1" != "" ]; do
@hmil
hmil / frontend.ts
Created October 17, 2019 11:01
imperative-frontend-end
function buildUI() {
const window = createWindow();
const btn = createButton();
const label = createLabel();
let visitorNumber = 0;
label.text = `Hello visitor nr ${visitorNumber}`;
btn.label = "click me";
btn.onClick = () => {