Skip to content

Instantly share code, notes, and snippets.

@nrdmn
nrdmn / color-ip.sh
Created July 7, 2017 11:21
color IP addresses
#!/bin/sh
# colors IP addresses
grep -a --color=always -E "((0|1{0,1}[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.){3}(0|1{0,1}[0-9]{1,2}|2[0-4][0-9]|25[0-5])|(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))|$" $1
@nrdmn
nrdmn / ipcollapse.py
Last active February 9, 2024 13:57
collapse a list of IP addresses
#!/usr/bin/python3
# reads a list of IP subnets in CIDR notation from stdin and collapses it
import sys
import ipaddress
subnets6 = []
subnets4 = []
input_list = sys.stdin.readlines()
@nrdmn
nrdmn / mandelbrot.c
Created July 7, 2017 11:23
mandelbrot
#include <math.h>
#include <stdio.h>
#ifndef EXAMPLE
#define EXAMPLE 0
#endif
#ifndef ACCURATE
#define ACCURATE 1
#endif
@nrdmn
nrdmn / .Xmodmap
Last active October 14, 2017 08:33
us-intl-de
keycode 14 = 5 percent EuroSign EuroSign eacute Eacute
keycode 24 = q Q adiaeresis Adiaeresis aacute Aacute
keycode 26 = e E eacute Eacute EuroSign EuroSign
keycode 29 = y Y udiaeresis Udiaeresis uacute Uacute
keycode 30 = u U uacute Uacute udiaeresis Udiaeresis
keycode 32 = o O oacute Oacute odiaeresis Odiaeresis
keycode 33 = p P odiaeresis Odiaeresis oacute Oacute
keycode 38 = a A aacute Aacute adiaeresis Adiaeresis
keycode 94 = less greater less greater bar bar
URxvt.scrollBar: false
URxvt.internalBorder: 0
URxvt.font: xft:DejaVuSansMono:size=9.4:antialias=true
URxvt.boldFont: xft:DejaVuSansMono:bold:size=9.4:antialias=true
URxvt.saveLines: 1000
URxvt.color0: #000000
URxvt.color1: #b21818
URxvt.color2: #18b218
URxvt.color3: #b26818
# ,-------------------------------------- Minute [0,59]
# | ,------------------------------ Hour [0,23]
# | | ,---------------------- Day of the month [1,31]
# | | | ,-------------- Month of the year [1,12]
# | | | | ,------ Day of the week ([0,6] with 0=Sunday)
# | | | | |
@nrdmn
nrdmn / sigtermme.c
Created January 26, 2019 12:27
SIGTERM me!
#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
char *name;
void term(int signum)
{
@nrdmn
nrdmn / functional.c
Created February 21, 2019 17:37
functional C with lambdas and CPS
#include <stdio.h>
#include <assert.h>
#include <malloc.h>
#include <stdbool.h>
#include <stdlib.h>
#define FN void __attribute__((noreturn))
#define LAMBDA(c_) ({ FN _ c_ _;})
@nrdmn
nrdmn / primes.hs
Last active September 15, 2019 13:17
import System.Environment (getArgs)
import System.IO (hPutStrLn, stderr)
import Data.List (genericTake)
import Text.Read (readMaybe)
-- sqrt possibly inaccurate for large primes.
primes = 2 : [ n | n<-[3,5..], all (\x -> n `mod` x /= 0) $ takeWhile (<= (floor $ sqrt $ fromIntegral n)) primes]
-- guaranteed to be correct for all primes, but much slower:
-- primes = 2 : [ n | n<-[3,5..], all (\x -> n `mod` x /= 0) $ takeWhile (<= (quot n 2)) primes]
-- for all n out of [1..] there's a prime p so that n < p < 2*n (Bertrand's postulate)
* {
animation-name: colors;
animation-duration: 4s;
animation-iteration-count: infinite;
}
@keyframes colors {
0% { text-shadow: 0 0 1pt hsl(0, 100%, 50%); }
17% { text-shadow: 0 0 1pt hsl(60, 100%, 50%); }
33% { text-shadow: 0 0 1pt hsl(120, 100%, 50%); }