Skip to content

Instantly share code, notes, and snippets.

View arialdomartini's full-sized avatar

Arialdo Martini arialdomartini

View GitHub Profile
@arialdomartini
arialdomartini / swap-marks.el
Last active November 30, 2023 19:54
swap-marks.el
(defun my-dired--first-char-or-ask ()
(if (member (char-after (line-beginning-position)) `(?\s ,dired-marker-char))
(read-char "Which mark are you targeting? ")
(char-after (line-beginning-position))))
(defun my-dired-swap-marks-ask ()
(interactive)
(let ((mark (my-dired--first-char-or-ask)))
(my-dired-swap-marks (string mark))))
@arialdomartini
arialdomartini / conways.md
Last active March 25, 2024 06:58
Conway's Game of Life

Selezionati

No-s

  • No mutable state
  • no loops (for, while)
  • no statements
  • no mouse
  • no primitives
  • no else (only guards)
  • no conditionals
@arialdomartini
arialdomartini / Linq.rs
Created November 13, 2023 06:55
LINQ.rs
content
.lines()
.filter(|line| line.to_lowercase().as_str().contains(query))
.collect()
content
.lines()
.map(|line| line.to_lowercase().as_str())
.filter(|line| line.contains(query))
.collect()
@arialdomartini
arialdomartini / hasPath.hs
Created November 9, 2023 09:51
hasPath.hs
module Main where
type Point = Int
type From = Point
type To = Point
type Segment = (From, To)
type Graph = [Segment]
hasPath :: Graph -> From -> To -> Bool
hasPath [] _ _ = False
@arialdomartini
arialdomartini / TextEditor.cs
Created November 9, 2023 07:31
TextEditor.cs
private delegate IEnumerable<string> ManipulateHistory(IEnumerable<string> history);
ManipulateHistory append(string tail) =>
history => history.Append(new[] { history.Last() + tail });
ManipulateHistory delete(int k) =>
history => history.Append(new[] { delete(history.Last(), k) });
string delete(string last, int k) => last.Substring(0, last.Length - k);
@arialdomartini
arialdomartini / primenumbers.cs
Created August 21, 2023 08:36
Factorization in Prime Numbers
public class PrimeFactorTest
{
[Property]
bool boolean_factorization_in_prime_numbers(PositiveInt positiveNumber)
{
var n = positiveNumber.Item;
var factors = factorize(n);
return factors.AreAllPrime() && factors.Multiplied() == n;
@arialdomartini
arialdomartini / repeatChars.fs
Last active August 13, 2023 08:38
Randomly repeat characters in a string
test
"repeated characters are replaced with one"
{
let randomlyRepeat char =
gen {
let! randomLength = Arb.generate<int> |> Gen.map (fun i -> abs i + 1)
return String(char, randomLength)
}
let arbitrarilyRepeatCharactersInString s =
@arialdomartini
arialdomartini / fix-ghci-on-windows.md
Last active July 8, 2023 06:42
Windows GHCI: user specified .o/.so/.DLL could not be loaded

If running GHCI on Windows returns

ghci
GHCi, version 9.4.1: https://www.haskell.org/ghc/  :? for help
<command line>: user specified .o/.so/.DLL could not be loaded (addDLL: pthread or dependencies not loaded. (Win32 error 5))
Whilst trying to load:  (dynamic) pthread
Additional directories searched:   C:/Users/arialdomartini/scoop/apps/haskell/9.4.1/mingw/lib/clang/13.0.0
   C:/Users/arialdomartini/scoop/apps/haskell/9.4.1/lib/../mingw/x86_64-w64-mingw32/lib
 C:/Users/arialdomartini/scoop/apps/haskell/9.4.1/lib/../mingw/lib
@arialdomartini
arialdomartini / yt-to-markdown.el
Last active July 3, 2023 06:47
Download the subtitles from a YouTube video and print it into a markdown tabl
(progn
(defun download-captions (youtube-link)
(shell-command (concat "yt-dlp --write-sub --write-auto-sub --no-warnings --sub-lang en --skip-download --sub-format srv1 -o temp-file -U" youtube-link)))
(defun xml-attribute (name item)
(cdr (assoc name (xml-node-attributes item))))
(defun xml-items (file-path)
(with-temp-buffer
(insert-file-contents file-path)
;; printing the variable name used by the caller
(defmacro name (var)
`(format "Name=%s, Value=%s" ',var ,var))
(let ((x 42))
(name x))
"Name=x, Value=42"