Skip to content

Instantly share code, notes, and snippets.

View danidiaz's full-sized avatar

Daniel Díaz Carrete danidiaz

View GitHub Profile
@ngxson
ngxson / FAQ.md
Last active April 11, 2025 16:27
convert ARM NEON to WASM SIMD prompt

Why did you do this?

Relax, I only have one Sunday to work on idea, literally my weekend project. So I tried Deepseek to see if it can help. Surprisingly, it works and it saves me another weekend...

What is your setup?

Just chat.deepseek.com (cost = free) with prompts adapted from this gist.

Does it work in one-shot or I have to prompt it multiple times?

@VictorTaelin
VictorTaelin / collapse_monad.hs
Last active April 14, 2025 15:05
The Collapse Monad
import Control.Monad (ap, forM_)
import qualified Data.Map as M
-- The Collapse Monad
-- ------------------
-- The Collapse Monad allows collapsing a value with labelled superpositions
-- into a flat list of superposition-free values. It is like the List Monad,
-- except that, instead of always doing a cartesian product, it will perform
-- pairwise merges of distant parts of your program that are "entangled"
-- under the same label. Examples:
@kmicinski
kmicinski / dpll.rkt
Last active November 15, 2024 11:52
;; Traditional Abstract DPLL (no clause learning)
;; See this paper: https://homepage.cs.uiowa.edu/~tinelli/papers/NieOT-JACM-06.pdf
#lang racket
(define (clause? cl)
(match cl
[`(,(? integer? x) ...) #t]
[_ #f]))

Understanding the Phases Applicative

While I was researching how to do level-order traversals of a binary tree in Haskell, I came across a library called tree-traversals which introduced a fancy Applicative instance called Phases. It took me a lot of effort to understand how it works. Although I still have some unresolved issues, I want to share my journey.

Note: I was planning to post this article on Reddit. But I gave up because it was too long so here might be a better place.

See the discussion.

Note: This article is written in a beginner-friendly way. Experts may find it tedious.

@ramirez7
ramirez7 / th-ghci
Last active January 5, 2025 14:01
ghci command to run top-level TH. Thanks /u/affinehyperplane for the trick! https://www.reddit.com/r/haskell/comments/18vkivp/comment/kh9byjd/?utm_source=reddit&utm_medium=web2x&context=3
:{
let doTH code = do
u <- Data.Unique.newUnique
let decls = "ghciTH_" ++ show (Data.Unique.hashUnique u)
pure $ unlines
[ unwords ["let", decls, "=", code]
, "() = ();" ++ decls
]
:}
@quad
quad / 0-interceptors-are-functions-too.md
Last active April 10, 2024 09:06
Interceptors Are Functions Too

Interceptors Are Functions Too

I could not agree more with my colleague and friend Travis Johnson's opinion that "[INTERCEPTORS ARE SO COOL][iasc]!" In that post, he succinctly describes the [Interceptor pattern][pattern] as used adroitly by [OkHttp][okhttp]. But, as is often the case, I believe a complicated object-oriented pattern obscures the simple functional gem within it.

What is an Interceptor?

I'll quote liberally from [OkHttp's documentation on the topic][okhttp-interceptor]:

Interceptors are a powerful mechanism that can monitor, rewrite, and retry calls. […] >

@zanzix
zanzix / CartCata.idr
Last active October 27, 2023 07:39
Free Cartesian Categories using Recursion Schemes
infixr 5 ~~> -- Morphisms of graphs
-- | Boilerplate for recursion schemes
-- Objects are graphs
Graph : Type -> Type
Graph o = o -> o -> Type
-- Morphisms are vertex-preserving transformations between graphs
@zanzix
zanzix / MonoidalTricategory.idr
Last active October 23, 2023 20:07
From monoid to monoidal tricategory
infixr 5 +++
infixr 5 ***
-- A list over a type
-- data List : Type -> Type where
-- Nil : List a
-- (::) : a -> List a -> List a
Graph : Type -> Type
Graph obj = obj -> obj -> Type
@kconner
kconner / macOS Internals.md
Last active April 9, 2025 08:19
macOS Internals

macOS Internals

Understand your Mac and iPhone more deeply by tracing the evolution of Mac OS X from prelease to Swift. John Siracusa delivers the details.

Starting Points

How to use this gist

You've got two main options: