Skip to content

Instantly share code, notes, and snippets.

View mpereira's full-sized avatar

Murilo Pereira mpereira

View GitHub Profile
import json
import os
import urllib.parse
import requests
WEBSCRAPERAPI_BASE_URL = "https://api.webscraperapi.ai/v1/scrape"
def scrape(url: str, prompt: str, narrowing_css_selector: str) -> requests.Response:
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:

RFC: The POSIX Resource Limits interface between the SDK and Mesos

The DC/OS SDK allows one to set POSIX resource limits for tasks running in particular pods.

For example:

name: "some-service"
pods:
  some-pod:
@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])