Skip to content

Instantly share code, notes, and snippets.

View mpereira's full-sized avatar

Murilo Pereira mpereira

View GitHub Profile
import type { Root, Parent, Data } from "mdast";
import { visit } from "unist-util-visit";
import { mdastHeadingToString } from "app/lib/headingToString";
import slugify from "app/lib/slugify";
export default function remarkHeadingIdsToSectionIds() {
return (tree: Root) => {
visit(tree, "heading", (node: Parent, _index, parent: Parent) => {
if (parent.type === "section") {
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for purescript-0.14.0:
Cabal-3.2.1.0 from stack configuration does not match >=2.2 && <3.0 (latest matching version is 2.4.1.0)
Glob-0.10.1 from stack configuration does not match ==0.9.* (latest matching version is 0.9.3)
aeson-1.5.6.0 from stack configuration does not match >=1.0 && <1.5 (latest matching version is 1.4.7.1)
ansi-terminal-0.10.3 from stack configuration does not match >=0.7.1 && <0.9 (latest matching version is 0.8.2)
base-4.14.1.0 from stack configuration does not match >=4.11 && <4.13 (latest matching version is 4.12.0.0)
base-compat-0.11.2 from stack configuration does not match >=0.6.0 && <0.11 (latest matching version is 0.10.5)
clock-0.8 from stack configuration does not match <0.8 (latest matching version is 0.7.2)
@mpereira
mpereira / make-uuid.el
Created March 5, 2021 17:52
An Emacs Lisp function that returns a UUID and makes it the latest kill in the kill ring
(defun make-uuid ()
"Return a UUID and make it the latest kill in the kill ring."
(interactive)
(kill-new (format "%04x%04x-%04x-%04x-%04x-%06x%06x"
(random (expt 16 4))
(random (expt 16 4))
(random (expt 16 4))
(random (expt 16 4))
(random (expt 16 4))
(random (expt 16 6))
@mpereira
mpereira / keybase.md
Created March 18, 2020 19:04
Keybase identity proof

Keybase proof

I hereby claim:

  • I am mpereira on github.
  • I am mpereira (https://keybase.io/mpereira) on keybase.
  • I have a public key ASAHgSmrszkAjxvPMl61bIufRbebQcVJlv-w4tnSSwmQlgo

To claim this, I am signing this object:

@mpereira
mpereira / split_by.clj
Last active July 18, 2017 17:50
Splits coll by pred. Returns a vector with a vector where (pred item) returns true followed by a vector where (pred item) returns false.
(defn split-by
"Splits coll by pred. Returns a vector with a vector where (pred item) returns
true followed by a vector where (pred item) returns false.
Example:
(split-by pos? [0 1 2 -1 3 -2 4 -3])
=> [[1 2 3 4] [0 -1 -2 -3]]"
[pred coll]
(reduce (fn [split item]
(update split (if (pred item) 0 1) conj item))
@mpereira
mpereira / substring_offsets.clj
Last active June 16, 2017 16:16
Returns a vector of [start end] offsets for substrings in s.
(defn substring-offsets
"Returns a seq of [start end] offsets for substrings in s."
[s substring]
(when-not (empty? substring)
(let [s (.toLowerCase s)
substring (.toLowerCase substring)
s-length (count s)
substring-length (count substring)]
(loop [offset 0
offsets nil]
@mpereira
mpereira / merge_sort.js
Last active May 14, 2017 21:29
Merge sort implementation in JavaScript.
function merge(xs, leftStart, leftEnd, rightStart, rightEnd) {
var i = leftStart;
var j = rightStart;
var merged = [];
var currentLeft, currentRight;
// Merge.
while (i <= leftEnd || j <= rightEnd) {
currentLeft = xs[i];
currentRight = xs[j];
(defn find-pairs-sum-equal-k [xs k]
(let [x-indices (into {} (map-indexed (fn [idx x] [x idx]) xs))]
(keep (fn [[x idx]]
(if-let [x-complement-idx (get x-indices (- k x))]
(when (not= idx x-complement-idx)
[x (- k x)])))
x-indices)))
(find-pairs-sum-equal-k (range 0 20) 12)
;; => ([0 12] [7 5] [1 11] [4 8] [3 9] [12 0] [2 10] [11 1] [9 3] [5 7] [10 2] [8 4])
$ curl -s 'http://divulga.tse.jus.br/2014/divulgacao/oficial/143/dadosdivweb/br/br-0001-e001431-w.js' -H 'Referer: http://divulga.tse.jus.br/oficial/index.html' -H 'Cache-Control: no-cache' | python -mjson.tool
{
    "a": "22212872",
    "c": "92334638",
    "cand": [
        {
@mpereira
mpereira / gist:9574586
Last active August 29, 2015 13:57
Determine if a point is within a triangle
(defn point-in-triangle? [[px py] [[p0x p0y] [p1x p1y] [p2x p2y]]]
(let [n (* 0.5
(+ (* (- p1y) p2x)
(* p0y (+ (- p1x) p2x))
(* p0x (- p1y p2y))
(* p1x p2y)))
sign (if (neg? n) -1 1)
s (* sign
(+ (* p0y p2x)
(- (* p0x p2y))