Skip to content

Instantly share code, notes, and snippets.

@ansemjo
ansemjo / keybase.md
Last active February 22, 2018 11:48
this keybase account was replaced by https://keybase.io/ansemjo; access to this pgp key was lost.

Keybase proof

I hereby claim:

  • I am ansemjo on github.
  • I am baer (https://keybase.io/baer) on keybase.
  • I have a public key whose fingerprint is B104 6F23 C274 2782 DF1C 7B27 CE47 E7C9 38D5 209D

To claim this, I am signing this object:

@ansemjo
ansemjo / drivesleep
Last active January 16, 2023 19:47
script periodically polls drivestates with hdparm to show when drives go to sleep
#!/bin/bash
# The MIT License (MIT)
#
# Copyright (c) 2016 Anton Semjonov
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@ansemjo
ansemjo / install-pacaur.sh
Last active May 23, 2017 20:37 — forked from rumpelsepp/install-pacaur.sh
A small script for arch linux which builds and installs "pacaur" automatically
#!/bin/sh
#
# LICENSE AT END OF FILE
#
# This is a script to automatically install pacaur from the AUR. It is
# intended for fresh systems with no other means to install from AUR.
# Theoretically, this script can install other packages too. Just modify
# the $aurpkgs variable below.
#
@ansemjo
ansemjo / nginx-jail.sh
Last active April 26, 2016 21:37
A script to setup nginx in a mostly read-only jail.
#!/bin/env bash
#
# MIT License
#
# Copyright (c) 2016 Anton Semjonov
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@ansemjo
ansemjo / error_pages
Last active May 2, 2021 01:57
beautiful html5 error pages for nginx; applied globally for each server block
# this belongs inside a 'server {}' block
# I propose you put this in a file somewhere, e.g. /etc/nginx/error_pages
# and then include it with an 'include error_pages;' directive
#
# see it in larger context here:
# https://git.semjonov.de/server/nginx-conf/tree/b63de50001b15fbb33680de14fad05230f2b8fd2
#
# design is taken from html5-boilerplate:
# https://github.com/h5bp/html5-boilerplate/blob/master/src/404.html
#!/bin/env bash
# The MIT License (MIT)
#
# Copyright (c) 2016 Anton Semjonov
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@ansemjo
ansemjo / uuid-hash.ts
Created January 6, 2017 14:39
Hashing wrapper in TypeScript, which can use stable-stringify to convert any object to a UUID or just make hashing a little easier.
/** For use in node.js environments.
* Requires npm packages:
* "@types/json-stable-stringify": "^1.0.29"
* "json-stable-stringify": "^1.0.1"
* "@types/uuid": "^2.0.29"
* "uuid": "^3.0.1"
*/
import * as uuid from 'uuid';
import * as crypto from 'crypto';
@ansemjo
ansemjo / ssl-extract-from-certutil-db.sh
Last active March 21, 2017 18:10
extracts pem certificate and key with $hostname nick from certutil database
#!/bin/bash
db=./ssl
nick=$(hostname -f)
rand=$(< /dev/urandom tr -dc "A-Za-z0-9" | head -c32;echo;)
# remove any previous
rm server.{p12,key,crt} 2>/dev/null
# extract server
≡ DATABASE Executed (default): SELECT `orders`.`uuid`, `orders`.`contractor`, `orders`.`order_number`, `orders`.`order_date`, `orders`.`parts_designation`, `orders`.`parts_amount`, `orders`.`parts_drawing`, `orders`.`delivery_wished`, `orders`.`delivery_expected`, `orders`.`comments`, `orders`.`created_at`, `orders`.`ordertype_uuid`, `Processes`.`uuid` AS `Processes.uuid`, `Processes`.`label_de` AS `Processes.label_de`, `Processes`.`label_en` AS `Processes.label_en`, `Processes`.`created_at` AS `Processes.created_at`, `Processes`.`template_uuid` AS `Processes.template_uuid`, `Processes`.`specification_uuid` AS `Processes.specification_uuid`, `Processes.DEBUG`.`id` AS `Processes.DEBUG.id`, `Processes.DEBUG`.`created_at` AS `Processes.DEBUG.created_at`, `Processes.DEBUG`.`order_uuid` AS `Processes.DEBUG.order_uuid`, `Processes.DEBUG`.`process_uuid` AS `Processes.DEBUG.process_uuid`, `Ordertype`.`uuid` AS `Ordertype.uuid`, `Ordertype`.`name` AS `Ordertype.name`, `Ordertype`.`color` AS `Ordertype.color`, `Orderty
@ansemjo
ansemjo / prefix.js
Last active June 25, 2018 17:36
generate a unique local address prefix in javascript
#!/usr/bin/env node
/* generate a unique local address prefix */
/* usage: `node prefix.js 56`, where 56 can be replaced by any prefix length between 8 and 128 */
/* alternatively, a simple one-liner for a /48 ula prefix:
* node -pe "('fd' + crypto.randomBytes(5).toString('hex')).match(/.{1,4}/g).join(':') + '::/48'"
*/
/* iife-wrapped prefix generator */
console.log((function prefix() {