Skip to content

Instantly share code, notes, and snippets.

View hcarvalhoalves's full-sized avatar

Henrique Carvalho Alves hcarvalhoalves

View GitHub Profile
@hcarvalhoalves
hcarvalhoalves / render.clj
Created February 3, 2021 15:32
sicmutils ->TeX w/ equate symbol
(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)))))
#!/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
IDE: lsp-mode + clojure-lsp
REPL: cider
Static analysis: clj-kondo or joker
:flutter:
IDE: lsp-dart
@hcarvalhoalves
hcarvalhoalves / poc.clj
Last active July 24, 2020 07:14
Calculating interest w/ linear algebra
(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 April 24, 2020 15:13
Download Free Springer Books
# 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
(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 February 26, 2020 12:03
minikanren type inference
;;; 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 November 24, 2019 01:48
Pandoc S3 Site Makefile
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
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)
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.