Skip to content

Instantly share code, notes, and snippets.

View hcarvalhoalves's full-sized avatar

Henrique Carvalho Alves hcarvalhoalves

View GitHub Profile
@hcarvalhoalves
hcarvalhoalves / README.md
Created October 23, 2024 02:29 — forked from lagagain/README.md
[practice] [Common Lisp] hello CFFI (Common Lisp + C)

This is a practice project to test Common Lisp + C with CFFI.

CFFI is a protocal for common lisp, and most popular impl like sbcl,ccl,cmucl,ecl and abcl have to this. So We can eazy to access C code from Common Lisp.

Env need

just only write for Linux(Unix) and need a lisp impl with cffi package. I pratice it with sbcl. You can install it with Roswell, or you can also ues more friendly env - cl-repl which also can install by roswell.

  • OS: Linux(Unix)
  • A Common lisp impl with cffi
# Exemplo usando a biblioteca https://pypi.org/project/pyshp/1.1.7/
import shapefile
from json import dumps
# read the shapefile
reader = shapefile.Reader("my.shp")
fields = reader.fields[1:]
field_names = [field[0] for field in fields]
buffer = []
@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