Skip to content

Instantly share code, notes, and snippets.

View fabriceleal's full-sized avatar
😫
meh

Fabrice Ferreira Leal fabriceleal

😫
meh
  • Leiria, Portugal
View GitHub Profile
@pizlonator
pizlonator / pizlossafull.md
Last active May 2, 2025 17:21
How I implement SSA form

This document explains how I would implement an SSA-based compiler if I was writing one today.

This document is intentionally opinionated. It just tells you how I would do it. This document is intended for anyone who has read about SSA and understands the concept, but is confused about how exactly to put it into practice. If you're that person, then I'm here to show you a way to do it that works well for me. If you're looking for a review of other ways to do it, I recommend this post.

My approach works well when implementing the compiler in any language that easily permits cyclic mutable data structures. I know from experience that it'll work great in C++, C#, or Java. The memory management of this approach is simple (and I'll explain it), so you won't have to stress about use after frees.

I like my approach because it leads to an ergonomic API by minimizing the amount of special cases you have to worry about. Most of the compiler is analyses and transformations ov

@hirrolot
hirrolot / CoC.ml
Last active May 3, 2025 05:34
How to implement dependent types in 80 lines of code
type term =
| Lam of (term -> term)
| Pi of term * (term -> term)
| Appl of term * term
| Ann of term * term
| FreeVar of int
| Star
| Box
let unfurl lvl f = f (FreeVar lvl)
@hirrolot
hirrolot / CoC.ml
Last active March 27, 2025 12:53
Barebones lambda cube in OCaml
(* The syntax of our calculus. Notice that types are represented in the same way
as terms, which is the essence of CoC. *)
type term =
| Var of string
| Appl of term * term
| Binder of binder * string * term * term
| Star
| Box
and binder = Lam | Pi
@fabriceleal
fabriceleal / gist:2e35d0b4b4f879930550
Created November 3, 2014 08:56
Call C pre processor without line markers in the output
gcc -E -P some.h > some.prep.h
@chaitanyagupta
chaitanyagupta / _reader-macros.md
Last active April 25, 2025 03:09
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

@fabriceleal
fabriceleal / gist:8286782
Created January 6, 2014 18:04
Apache as proxy
# From:
# http://stackoverflow.com/questions/17475587/setup-mod-proxy-on-apache-http-server
# http://www.forums.serverwatch.com/showthread.php?16887-mod_proxy-problem
# http://serverfault.com/questions/242650/setting-up-a-basic-mod-proxy-virtual-host
# http://stackoverflow.com/questions/14775248/apache-http-proxy-based-on-hostname
# http://stackoverflow.com/questions/1997001/setting-up-a-basic-web-proxy-in-apache
# http://ubuntuforums.org/showthread.php?t=983222
#
# put on httpdvhosts.conf
@SPY
SPY / andb_eq_orb.v
Last active January 1, 2016 22:38
(** **** Exercise: 2 stars (andb_eq_orb) *)
(** Prove the following theorem. (You may want to first prove a
subsidiary lemma or two.) *)
Lemma orb_always_true :
forall b,
orb true b = true.
Proof. reflexivity. Qed.
Lemma andb_always_false :
@fabriceleal
fabriceleal / gist:7803969
Last active February 22, 2024 09:21
Decent enough macro for exporting csvs from Excel.
' http://support.microsoft.com/kb/291296/en-us
' http://superuser.com/questions/130592/how-do-you-force-excel-to-quote-all-columns-of-a-csv-file
' - change integer to long indexing
' http://stackoverflow.com/questions/2524703/save-text-file-utf-8-encoded-with-vba
' - output utf8 content
Sub QuoteCommaExport()
' Dimension all variables.
Dim DestFile As String
Dim FileNum As Integer
@fabriceleal
fabriceleal / gist:7417279
Created November 11, 2013 17:49
Search for sql inserts without explicit columns.
grep -Eir "insert +into +[a-zA-Z0-9_]+ values" *
@fabriceleal
fabriceleal / gist:6994504
Created October 15, 2013 16:34
Find big files
find . -type f -size +10000k -exec ls -lh {} \;