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 / 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 / .gitignore
Last active October 22, 2020 20:53
my megasec parsers
dist
.stack-work
#! /usr/bin/env bash
set -eu
pwd | grep -q '^/tmp'
cat > excl <<-EOF
a
b/*c*
./d
@siers
siers / redecorate.py
Created July 17, 2018 10:56
recursive chown uid/guid mapping for migrating ownership to LDAP
#!/usr/bin/env python
# recursive chown uid/guid mapping for migrating files' owners to
# the new LDAP ids by matching users' duplicate names in /etc/passwd and
# treating the upper ones (from `getent passwd` list) as the real ones
# Created around January, 2017
# raitis.veinbahs.lv
# This file may be freely used, modified, copied and repurposed. Public domain.
@siers
siers / ss-parse.rb
Created July 30, 2019 21:38
dumb, simple ss.com scraper for displaying notifications on diffs
#!/usr/bin/env ruby
script = <<-EOF
ccurl() {
curl -b cookie.txt -c cookie.txt "$@"
}
ccurl 'https://www.ss.com/lv/real-estate/flats/riga/agenskalns/filter/' -H 'authority: www.ss.com' -H 'cache-control: max-age=0' -H 'origin: https://www.ss.com' -H 'upgrade-insecure-requests: 1' -H 'content-type: application/x-www-form-urlencoded' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36' -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'referer: https://www.ss.com/lv/real-estate/flats/riga/agenskalns/' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' &> /dev/null || exit
ccurl 'https://www.ss.com/lv/real-estate/flats/riga/agenskalns/filter/fDgSeF4belI=.html' -H 'authority: www.ss.com' -H 'cache-control: max-age=0' -H 'origin: https://www.ss.com' -H 'upgrade-insecure-requests: 1' -H 'conte
@siers
siers / mount-propagation-showcast.sh
Last active June 3, 2017 16:39
Overlayfs example
#!/bin/bash
more="$@"
saved="$EUID"
if [ "$EUID" = "0" ]; then
echo "don't run as root"
exit
fi
@siers
siers / nap.rb
Last active April 30, 2017 06:04
a more natural alarm clock command line interface
#!/usr/bin/env ruby
require 'time'
def die(str)
$stderr.puts str
exit
end
def usage
#!/usr/bin/env bash
### BEGIN INIT INFO
# Provides: dockercompose
# Required-Start: $docker
# Required-Stop: $docker
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Docker Services
### END INIT INFO
@siers
siers / print-all-synchronized-files.rb
Last active January 30, 2017 16:11
Print all files synchronized with syncthing.
#!/usr/bin/env ruby
require 'json'
if ARGV.length == 0
puts "usage: $0 '?folder=$FOLDERID'"
exit
end
key = %x{grep -Po '(?<=<apikey>)[^<]+' ~/.config/syncthing/config.xml}.strip
@siers
siers / git-stack-log.sh
Created December 29, 2014 03:06
git-stack-log
#!/bin/sh
stashes() {
git stash list | sed "s/:.*//" | tr '\n' ' '
}
for s in $(stashes); do
git log -1 --format=short "$s" | cat
echo
git stash show -u "$s" | cat