Skip to content

Instantly share code, notes, and snippets.

@nrdmn
nrdmn / gist:9bed16155eabe57cfe665173f45a4d2b
Last active July 29, 2024 23:10
NetBSD Pi Hole Howto
/etc/localtime:
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
/etc/rc.conf:
inetd=NO
postfix=NO
named=YES
import qualified Data.HashMap.Strict as M
import qualified Data.ByteString.Char8 as B
import Data.List (sortOn)
import Data.List.Split (chunksOf)
import Control.Parallel.Strategies (parMap, rdeepseq)
main = do
words <- B.words <$> B.getContents
let result = sortOn snd $ M.toList $ foldl (M.unionWith (+)) M.empty $ parMap rdeepseq (foldl (\acc x -> M.insertWith (+) x (1 :: Integer) acc) M.empty) (chunksOf 50000 words)
B.putStr . B.concat $ result >>= (\(a,b) -> [B.pack $ show b, B.singleton '\t', a, B.singleton '\n'])
@nrdmn
nrdmn / mandelbrot.hs
Created April 29, 2019 14:24
mandelbrot.hs
import Data.Complex
import Data.List
import Control.Parallel.Strategies
mandelbrot c = c : [z^2 + c | z <- mandelbrot c]
color (a,b,c,d) x y
| len < a = ' '
| len < b = '.'
| len < c = ':'
@nrdmn
nrdmn / triangles.hs
Last active May 24, 2019 14:27
pythagorean triples
triangles = [(a,b,c) | a<-[1..], b<-[1..a-1], c<-[a..a+b], a^2+b^2==c^2]
main = putStr $ unlines $ map show triangles
@nrdmn
nrdmn / port.zig
Created May 30, 2019 16:38
Access x86 IO ports in Zig
pub inline fn out(port: u16, value: var) void {
const TypeId = @import("builtin").TypeId;
const maxInt = @import("std").math.maxInt;
const value_ = switch (@typeId(@typeOf(value))) {
TypeId.ComptimeInt => switch (value) {
0...maxInt(u8) => @intCast(u8, value),
maxInt(u8) + 1...maxInt(u16) => @intCast(u16, value),
maxInt(u16) + 1...maxInt(u32) => @intCast(u32, value),
else => @compileError("port out of range"),
@nrdmn
nrdmn / colors.sed
Created August 11, 2019 20:52
ANSI colors to IRC colors
s/\x1b\[0m/\x0f/g
s/\x1b\[1m/\x02/g
s/\x1b\[30m/\x031/g
s/\x1b\[31m/\x035/g
s/\x1b\[32m/\x033/g
s/\x1b\[33m/\x037/g
s/\x1b\[34m/\x032/g
s/\x1b\[35m/\x036/g
s/\x1b\[36m/\x0310/g
s/\x1b\[37m/\x0315/g
Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
, additionalFonts = []
, borderColor = "black"
, border = TopB
, bgColor = "black"
, fgColor = "grey"
, alpha = 255
, position = Top
, textOffset = -1
, iconOffset = -1
@nrdmn
nrdmn / crash.c
Last active September 5, 2019 08:01
atop bug
#include <linux/perf_event.h>
#include <linux/hw_breakpoint.h>
#include <string.h>
#include <unistd.h>
#include <asm/unistd.h>
#include <stdio.h>
int main()
{
if (geteuid() != 0) {
@nrdmn
nrdmn / warp.c
Created September 13, 2019 12:46
#include <sys/time.h>
#include <stddef.h>
#include <stdio.h>
#define THRESHOLD 1000
int main()
{
struct timeval a;
struct timeval b;
@nrdmn
nrdmn / peano.zig
Last active September 16, 2019 22:34
Pointer Arithmetic
const std = @import("std");
fn Add(comptime A: type, comptime B: type) type {
if (A == type) {
return B;
} else {
return Add(@typeInfo(A).Pointer.child, *B);
}
}