Skip to content

Instantly share code, notes, and snippets.

Avatar

Henrique Carvalho Alves hcarvalhoalves

View GitHub Profile
@hcarvalhoalves
hcarvalhoalves / render.clj
Created Feb 3, 2021
sicmutils ->TeX w/ equate symbol
View render.clj
(ns render
(:require [clojure.string :as s]
[sicmutils.ratio :as r]
[sicmutils.expression.render :refer :all]))
(def ->TeX2
"Convert the given (simplified) expression to TeX format, as a string."
(let [TeX-accent (fn [accent]
(fn [[_ stem]]
(str "\\" accent " " (#'sicmutils.expression.render/maybe-brace (->TeX stem)))))
View pre-commit
#!/bin/bash
# Add to project/.git/hooks/ w/ +x permission
echo "Running pre-commit linter..."
files=$(git diff --diff-filter=d --cached --name-only | grep -E '\.(base|clj)$' | tr '\n' ' ' | xargs)
lein do cljfmt fix $files, nsorg -e $files
if [ $? -ne 0 ]; then
View gist:498af57c462ea6d473c29c84d6821178
IDE: lsp-mode + clojure-lsp
REPL: cider
Static analysis: clj-kondo or joker
:flutter:
IDE: lsp-dart
@hcarvalhoalves
hcarvalhoalves / poc.clj
Last active Jul 24, 2020
Calculating interest w/ linear algebra
View poc.clj
(ns poc
(:gen-class)
(:require [clojure.pprint]
[clojure.string :as str])
(:import (java.math RoundingMode MathContext)
(clojure.lang Ratio PersistentVector IPersistentCollection)))
(def ^:dynamic *precision* 10)
(def ^:dynamic *scale* 2)
(def ^:dynamic *rounding* RoundingMode/HALF_EVEN)
@hcarvalhoalves
hcarvalhoalves / dl-springer-ebooks.sh
Last active Apr 24, 2020
Download Free Springer Books
View dl-springer-ebooks.sh
# Download TSV from https://docs.google.com/spreadsheets/d/1HzdumNltTj2SHmCv3SRdoub8SvpIEn75fa4Q23x0keU/edit#gid=793911758
cat Free\ Springer\ Books\ -\ eBook\ list.tsv |
tail -n +1 |
cut -f 1,8 |
tr '\t' '\n' |
sed 's/^/"/;s/$/"/' |
xargs -n2 sh -c 'echo "url = \"https://link.springer.com/content/pdf/10.1007%2F$2.pdf\"\noutput = \"$1.pdf\""' sh
View gist:1291bfbb40ecf525184e24452ff18567
(ns logic.y
(:refer-clojure :exclude [== reify inc])
(:use [clojure.core.logic minikanren prelude
nonrel match]))
(defna findo [x l o]
([_ [[?y :- o] . _] _]
(project [x ?y] (== (= x ?y) true)))
([_ [_ . ?c] _] (findo x ?c o)))
@hcarvalhoalves
hcarvalhoalves / type.scm
Created Feb 26, 2020
minikanren type inference
View type.scm
;;; WEB -- 18 June 2016
;; Type inferencer in miniKanren, adapted from Oleg's Kanren polymorphic type inferencer
;;
;; http://kanren.cvs.sourceforge.net/viewvc/kanren/kanren/examples/type-inference.scm?view=markup
;;
;; Unlike the Kanren inferencer, this definition of !- is a pure
;; relation, with no cuts and no uses of project. This inferencer
;; also does not require a parser/unparser, and allows shadowing.
@hcarvalhoalves
hcarvalhoalves / site.mk
Created Nov 24, 2019
Pandoc S3 Site Makefile
View site.mk
MARKDOWN = pandoc --standalone --from markdown+smart --to html --css theme.css
all: $(patsubst %.md,%.html,$(wildcard *.md)) Makefile
clean:
rm -fv $(patsubst %.md,%.html,$(wildcard *.md))
publish:
aws-3.7 s3 sync . s3:/<BUCKET> --exclude "*" --include "*.html" --include
View coercedate.scala
def coerceDate(dateFormat: String)(dateAsString: String) = {
val fmt = new java.text.SimpleDateFormat(dateFormat)
val dt = fmt.parse(dateAsString)
new java.sql.Date(dt.getYear, dt.getMonth, dt.getDay)
}
View circuit_breaker_pid.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.