Skip to content

Instantly share code, notes, and snippets.

@flaminggoat
flaminggoat / main.rs
Created March 3, 2023 21:23
ESP32 SD card access from Rust using esp_idf_sys
use std::io::{BufWriter, Write};
use std::ptr::{null, null_mut};
use std::time::Instant;
use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported
use esp_idf_sys::c_types::{c_int, c_void};
use std::fs::{self, File};
fn main() {
@tsnobip
tsnobip / NodePostgres.res
Created March 1, 2023 09:16
Node-PG Rescript bindings
open Belt
let {then, thenResolve, catch, resolve, reject} = module(Promise)
module PgResult = {
module FieldInfo = {
type t = private {
name: string,
dataTypeId: string,
}
@CRTified
CRTified / README.md
Last active March 24, 2024 18:03
VFIO Passthrough on NixOS

VFIO Setup on NixOS

Disclaimer: Nobody else tested my setup so far, so this is a "works on my machine" scenario. I am not responsible for anything you break on your machine (although I'd not expect much harm).

Hardware

My system has the following hardware:

  • Board: ASRock X570 Pro4
@chrisdone
chrisdone / Intro.md
Last active April 10, 2023 06:33
Statically checked overloaded strings

Statically checked overloaded strings

This gist demonstrates a trick I came up with which is defining IsString for Q (TExp a), where a is lift-able. This allows you to write $$("...") and have the string parsed at compile-time.

On GHC 9, you are able to write $$"..." instead.

This offers a light-weight way to enforce compile-time constraints. It's basically OverloadedStrings with static checks. The inferred return type

@i-am-tom
i-am-tom / FizzBuzz.hs
Last active June 26, 2023 16:35
Arguably the fastest implementation of FizzBuzz ever written.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UnsaturatedTypeFamilies #-}
import GHC.TypeLits
import Prelude hiding (Functor, Semigroup)
type Main = (Fizz <> Buzz) <$> (0 `To` 100)

Example use:

> import Network.HTTP.Simple
> import qualified Data.ByteString.Char8 as B8
> :set -XOverloadedStrings
> import Data.String
> withWebService (responseBs "Hello!") (\port -> httpBS (fromString ("http://localhost:" ++ show port)) >>= B8.putStrLn . getResponseBody)
Hello!
&gt;
@Icelandjack
Icelandjack / blog_deriving.markdown
Last active October 7, 2019 22:43
Blog Post: Derive instances of representationally equal types

Reddit discusson thread.

I made a way to get more free stuff and free stuff is good.

The current implementation of deriveVia is here, it works with all the examples here. Needs GHC 8.2 and th-desugar.

It doesn't take long

for new Haskellers to get pampered by their compiler. For the price of a line or two the compiler offers to do your job, to write uninteresting code for you (in the form of type classes) such as equality, comparison, serialization, ... in the case of 3-D vectors

@genekogan
genekogan / scrapeImages.py
Created February 22, 2017 11:49
scraping full size images from Google Images
from bs4 import BeautifulSoup
import requests
import re
import urllib2
import os
import argparse
import sys
import json
# adapted from http://stackoverflow.com/questions/20716842/python-download-images-from-google-image-search
@chrisdone
chrisdone / FieldTH.hs
Last active February 13, 2017 22:17
$(lens 'foo) -- handy one-off lens maker for record fields
{-# LANGUAGE TemplateHaskell #-}
-- | For when you have a record that doesn't have lenses derived for
-- it and you need a lens, just use @$(lens 'thefield)@ and away you go.
module Control.Lens.FieldTH where
import Language.Haskell.TH
lens :: Name -> Q Exp
lens name = do
[|\f r ->
fmap
$(lamE
@3noch
3noch / We've Moved.md
Last active January 26, 2017 17:50
NixOps wrapper script to use git-managed state files