Skip to content

Instantly share code, notes, and snippets.

View unclechu's full-sized avatar

Viacheslav Lotsmanov unclechu

  • RELEX Solutions
  • Finland
View GitHub Profile
@unclechu
unclechu / unique-value.hs
Created December 9, 2019 02:32
Reference-ish equality in Haskell
#!/usr/bin/env stack
{- stack script
--resolver=nightly-2019-12-08
--package=base-unicode-symbols
--package=hashable
-}
-- Author: Viacheslav Lotsmanov <lotsmanov89@gmail.com>
-- Date: December 2019
-- License: BSD-3-Clause
@unclechu
unclechu / synthetic-type-level-coaching.hs
Created October 6, 2019 16:26
synthetic-type-level-coaching.hs
#!/usr/bin/env stack
{- stack script
--resolver=lts-14.7
--package=aeson
--package=attoparsec
--package=text
--package=unordered-containers
-}
{-# OPTIONS_GHC -Wall -Wno-missing-signatures #-}
@unclechu
unclechu / grant-access-to-input-devices.hs
Created October 2, 2019 12:39
Application that grants ACL read access to all input devices to specific set of users, intended to be used for https://github.com/unclechu/xlib-keys-hack with root SUID
-- Compile with this command, get rid of access to run by random users,
-- set SUID (to run by root), give ACL read+executing access
-- to your own user only ('uc' for instance, replace to your own user name):
--
-- stack ghc --resolver=lts-14.7 \
-- --package=directory \
-- --package=filepath \
-- --package=typed-process \
-- --package=unix \
-- -- -Wall -O2 -j$(nproc --all) grant-access-to-input-devices.hs &&
@unclechu
unclechu / laptop-backlight.hs
Last active October 2, 2019 12:36
Laptop backlight control application for using with root SUID
-- Compile with this command, get rid of access to run by random users,
-- set SUID (to run by root), give ACL read+executing access
-- to your own user only ('uc' for instance, replace to your own user name):
--
-- stack ghc --resolver=lts-14.7 \
-- --package=attoparsec \
-- --package=filepath \
-- -- -Wall -O2 -j$(nproc --all) laptop-backlight.hs &&
-- chmod 4550 laptop-backlight &&
-- setfacl -m u:uc:rx laptop-backlight
@unclechu
unclechu / dzen-box
Last active July 13, 2019 20:22
dzen-box bash script
#!/usr/bin/env bash
set -e
BG_COLOR=black; FG_DEFAULT_COLOR=white
TEXT=$1; FG_COLOR=$2; [[ -z $FG_COLOR ]] && FG_COLOR=$FG_DEFAULT_COLOR
WM_TITLE='dzen-box'
BUS="/tmp/${WM_TITLE}-u${UID}-d${DISPLAY#:}"
BUS_LOCK="${BUS}.lock"
FONT_FAMILY=Hack; FONT_STYLE=bold
@unclechu
unclechu / helpers-to-write-generic-instance-manually.hs
Created July 6, 2019 01:29
Haskell: Helpers to write Generic instance manually
#!/usr/bin/env stack
-- stack script --resolver=lts-13.27 --ghc-options -Wincomplete-patterns
{-# LANGUAGE GADTs, DataKinds, TypeFamilies, TypeOperators #-}
{-# LANGUAGE FlexibleInstances, UndecidableInstances, DeriveGeneric #-}
import GHC.Generics
import GHC.TypeLits
type family MetaDataOf (typeRep :: * -> *) (typeName :: Symbol) :: Meta where
@unclechu
unclechu / adt_picture.nim
Last active July 4, 2019 03:14
adt_picture.nim
type
Point = tuple[x: float, y: float]
PictureKind* = enum
Blank, Polygon, Line, Circle, ThickCircle, Arc,
ThickArc, Text, Translate, Rotate, Scale, Pictures
Picture* = object
case kind*: PictureKind
of Blank: discard
@unclechu
unclechu / real-quick-sort.hs
Created May 1, 2019 02:29
real-quick-sort.hs
#!/usr/bin/env stack
{-stack script
--resolver=lts-13.18
--package=base-unicode-symbols
--package=array
--package=MonadRandom
--package=hspec
-}
-- Author:
@unclechu
unclechu / connect-to-vpns.sh
Last active April 24, 2019 19:30
connect-to-vpns.sh
#!/usr/bin/env bash
# Script for connecting to VPN connections via Network Manager.
# all of these will be connected (`up' command).
# those which you want to be always connected when turn VPNs on.
vpns=(
foo
bar
)
@unclechu
unclechu / 277777788888899.pl6
Last active April 10, 2019 18:44
277777788888899.pl6
#!/usr/bin/env perl6
use v6;
my Int \magic = 277777788888899;
my Str \separator = "\n" ~ "~" x 60 ~ "\n";
my Int \cores = try { $*KERNEL.cpu-cores } // 1;
('CPU cores: ' ~ cores).say;
class CalcResult {