Skip to content

Instantly share code, notes, and snippets.

View siers's full-sized avatar
:octocat:

Raitis Veinbahs siers

:octocat:
View GitHub Profile
@siers
siers / gist:63df7694c42062349c57c89969a9fbc7
Created August 27, 2024 14:08
nix-shell --run 'python -m uploadserver' oneliner
nix-shell -E 'with (import <nixpkgs> {}); with python3; mkShell { buildInputs = [ (withPackages (p: [(pkgs.buildPythonPackage rec { pname = "uploadserver"; version = "5.2.1"; src = fetchPypi { inherit pname version; hash = "sha256-qp2xkzLvnrnx8dHZpwlF3RjRg8jYC7WAaVS4ltJFZaU="; }; })]) ) ]; }' --run "python -m uploadserver 65353"
# you're welcome
@siers
siers / NaiveCopy.hs
Created January 4, 2024 12:51
Naive directory tree copy with full contents in memory and using recursion schemes (cata/anaM)
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UnicodeSyntax #-}
@siers
siers / leveldb-cli.nix
Created December 22, 2023 22:30
leveldb-cli nix buildGoModule
{ fetchFromGitHub, buildGoModule }:
buildGoModule {
name = "leveldb-cli";
vendorHash = "sha256-xM32ynbK8rF6JZty4701A+g6WxHOPx+frBngVIXizV4=";
src = fetchFromGitHub {
owner = "liderman";
repo = "leveldb-cli";
rev = "4233523f321208dfda6dce4908d407ad6ee39b0c";
hash = "sha256-BwxCpBw+ChpENc44SAXKoQKXs4ckI1Fayy9Mq55KWiw=";
@siers
siers / flake.nix
Last active October 11, 2023 08:05
printing out a lamb
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-23.05";
};
outputs = { self, nixpkgs }:
with nixpkgs.legacyPackages.x86_64-linux;
let
system = "x86_64-linux";
@siers
siers / index.html
Last active March 6, 2022 12:22
mandelbrot set with smoothing
<!-- original: https://jsfiddle.net/poetix/KtCnB/ -->
<!-- testing hypothesis for generating: https://twitter.com/matthen2/status/1498717789233758222 -->
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<canvas width="500px" height="500px" id="canvas"></canvas>
<input type="range" id="iterations" name="iterations" min="0" max="100" value="50" step="1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
@siers
siers / Supergraphs.hs
Last active June 8, 2021 09:02
Lattice joining graph connected components by their partition order
module Main where
import Algebra.PartialOrd (PartialOrd(..))
import Data.Bifunctor (bimap)
import Data.Foldable (for_)
import Data.Function (on)
import Data.List.Extra (groupSortOn)
import Data.List (sortOn)
import Data.Set (Set)
import qualified Data.POSet as POSet
@siers
siers / LensSuffix.hs
Created April 24, 2021 19:49
Lens Template Haskell data fields with suffix
import Control.Lens.Internal.FieldTH (makeFieldOptics, LensRules(..))
import Language.Haskell.TH.Syntax (mkName, nameBase)
import Control.Lens.TH (DefName(..), lensRules)
data Field = { a :: Int, b :: Int }
makeFieldOptics lensRules { _fieldToDef = (\_ _ -> (:[]) . TopName . mkName . (++ "L") . nameBase) } ''Field
-- hopefully someone find this useful
@siers
siers / yourkit.nix
Last active September 7, 2021 15:10
YourKit Java profiler Nix/NixOS package
{ stdenv, fetchzip, zlib, openjdk8, openjdk11, version ? "v2019" }:
# https://www.yourkit.com/docs/java/help/running_profiler.jsp
let
versions = {
v2019 = {
date = "2019.1";
buildnr = "b133";
sha256 = "06p8y0mmyfrzjk5jz783gcfjsq6mk4rqddbqxarkkar7va5w5vk6";
#! /usr/bin/env bash
set -eu
pwd | grep -q '^/tmp'
cat > excl <<-EOF
a
b/*c*
./d
@siers
siers / bank-statement-parser.sh
Last active June 2, 2023 06:48
Swedbank bank statement parser
#! /usr/bin/env zsh
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p python36Packages.csvkit
# map <f9> :%!./parse 2>/dev/null <CR>
summer() {
(echo "Saņēmējs/Maksātājs,Summa,Datums"; grep -v "Summa,Datums") | \
csvsql --tables input --query 'SELECT SUM("Summa")/100.0 FROM input'