Skip to content

Instantly share code, notes, and snippets.

// @author silverweed
// Finds all svg files under the current directory and appends a newline to them if they don't end with a newline already.
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <strsafe.h>
BOOL verbose = 0;
@silverweed
silverweed / numspell.rs
Created March 4, 2020 10:54
English number speller
use std::borrow::Cow;
type NumType = u128;
fn read_num_from_args() -> Result<NumType, Cow<'static, str>> {
let mut args = std::env::args();
let program_name = args.next().unwrap();
let num = if let Some(num) = args.next() {
if let Ok(num) = u128::from_str_radix(&num, 10) {
@silverweed
silverweed / hostsup.fast
Last active July 6, 2023 07:53
Checks if LAN hosts are up in parallel
#!/bin/bash
# parallel port check via nc. Takes ~1 s per scanned service, but
# should almost not depend on the number of hosts.
# by silverweed
# FIXME: echo-ing lines from check_host may result in more lines
#+ bloated together.
# file containing the IPs to scan
HOSTLIST="$HOME/.hostlist.txt"
NC="/bin/nc"
@silverweed
silverweed / inle.svg
Created January 22, 2019 16:55
Inle Icon
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@silverweed
silverweed / PoolAllocator.hpp
Last active November 15, 2017 12:12
Pool allocator
#pragma once
#include <cstdlib>
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <utility>
#define ABORT(x) do { \
fprintf(stderr, "%s\n", x); \
@silverweed
silverweed / pre-commit
Created September 25, 2017 12:31
Git hook that warns when there are lines longer than 120 characters
#!/bin/bash
HARDLIMIT=120
FOUND=$(find src/ -not -path \*third\* -type f -name \*pp -exec awk -v HL=$HARDLIMIT '
length($0) > HL {
printf "%s:%d %s", FILENAME, FNR, $0
}' {} +)
if [[ -n $FOUND ]]; then
echo "Following lines are longer than hardlimit $HARDLIMIT:"
while read LINE; do echo $LINE; done < <(echo -e $FOUND)
@silverweed
silverweed / app.d
Last active September 24, 2017 14:27
D + SFML + OpenGL
import std.stdio;
import derelict.sfml2.system;
import derelict.sfml2.window;
import derelict.opengl3.gl3;
bool running = true;
void main() {
// Load shared C libraries
DerelictGL3.load();
@silverweed
silverweed / makefile
Last active April 20, 2019 19:47
Cuda + SFML test
CC = nvcc
CFLAGS = -std=c++11 --compiler-options -Wall --compiler-options -Wextra --compiler-options -ggdb
LDFLAGS = -lsfml-graphics -lsfml-window -lsfml-system -lcurand
all: test2
%: %.o
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
%.o: %.cu myutils.hpp
@silverweed
silverweed / indentcount.hs
Last active July 6, 2023 07:54
Counts line indents in code and shows stats
-- @author silverweed, 2016
-- @license WTFPL
import System.Environment
import System.IO
import Data.List
showIndents input = header ++ (mkList input) ++ "\n"
where
header = "indent: occurrences\n"
mkList = intercalate "\n" . map (\(o,i) -> (show i) ++ ": " ++ (show o)) .
@silverweed
silverweed / .clang-format
Last active June 4, 2018 15:05
vimrc + clang-format
---
Language: Cpp
AccessModifierOffset: -8
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true