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])
@mpereira
mpereira / amazon_wish_list.js
Last active December 25, 2015 03:39
Show the total cost of an Amazon Wish List.
//
// This script shows the total cost of an Amazon Wish List.
//
// Usage:
//
// 1. Open an Amazon Wish List
// 2. Select the "Compact" option in the "View" drop-down
// 3. Click the "GO" button
// 4. Copy and paste the code below in the browser console
// 5. Press Enter
2013-09-07 10:01:47,341 DEBUG [main] - ScalaPlugin - added compilation unit __eclim_temp_person.scala
2013-09-07 10:01:47,342 INFO [main] - ScalaPresentationCompiler - shutting down presentation compiler on project: scala
2013-09-07 10:01:47,342 INFO [main] - ScalaProject - Scheduling for reconcile: ArrayBuffer()
2013-09-07 10:01:47,360 DEBUG [main] - ScalaProject - Added output folder: F/scala/src: F/scala/bin
2013-09-07 10:01:47,367 DEBUG [main] - ScalaProject - javabootclasspath: /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rhino.jar:/usr/lib/jvm/java-7-openjdk-common/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-7-openjdk-common/jre/lib/ext/pulse-java.jar:/usr/lib/jvm/java-7-openjdk-common/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-7-openjdk-common/