Skip to content

Instantly share code, notes, and snippets.

View fw_error.h
#pragma once
#include <map>
#include <string>
#include <cstdio>
#include <exception>
#include <filesystem>
#define chrstr(a) std::string(a)
@Dracovian
Dracovian / osdev_mediawiki_exporter.py
Created Jun 14, 2020
Automating the process of exporting XML data for MediaWiki. This one targets OSDev Wiki since the major backup is janky and outdated.
View osdev_mediawiki_exporter.py
from http.client import HTTPSConnection
from os import makedirs, getcwd, path
from re import findall as regex
from urllib.parse import quote
get_conn = lambda: HTTPSConnection('wiki.osdev.org', 443)
category_lists = [
@Dracovian
Dracovian / totp.php
Created May 27, 2020
Jetbrains PhpStorm stub for my php_totp extension.
View totp.php
<?php
/**
* Generate a Base32 encoded string.
* @link https://en.wikipedia.org/wiki/Base32
* @param string $input <p>
* The input string that you want to encode.
* </p>
* @return string If it succeeds to encode the string.
*/
@Dracovian
Dracovian / PKGBUILD
Created May 27, 2020
PHP 8.0.0-dev PKGBUILD for Arch-based distributions.
View PKGBUILD
pkgbase="php"
pkgname=("php")
pkgver=8.0
pkgrel=0
arch=('x86_64')
license=('PHP')
url='https://www.php.net/'
makedepends=('bison' 're2c' 'systemd-libs' 'acl' 'libxml2' 'openssl' 'sqlite'
'bzip2' 'curl' 'systemd' 'libpng' 'icu' 'oniguruma' 'libsodium'
'postgresql-libs' 'argon2' 'tidy' 'pcre2' 'icu' 'libxslt' 'libzip'
@Dracovian
Dracovian / alloc.h
Last active May 27, 2020
Some useful C snippets.
View alloc.h
/*
* This is a slightly modified copy of the malloc/free example from Brian Kernighan and Dennis Ritchie
* Eventually I'll figure out a way to futher compress this code and to replace the sbrk requirement altogether.
* There's currently no ETA on either of those, but there'll be some additions and modifications to this Gist.
*/
#ifndef __NASTY_ALLOC_H
#define __NASTY_ALLOC_H
#undef NALLOC
@Dracovian
Dracovian / print_x64.c
Last active May 12, 2020
I'll just store some inline assembly related stuff in here.
View print_x64.c
static void print(const char *message, long length) {
asm ("mov $1, %rax"); // Call OS function sys_write.
asm ("mov $1, %rdi"); // Set sys_write stream to STDOUT or standard output.
asm ("mov %0, %%rsi" :: "S"(message)); // The message string
asm ("mov %0, %%rdx" :: "d"(length)); // The message length
asm ("syscall"); // Transfer control back to the OS.
}
@Dracovian
Dracovian / openlibrary.c
Created Mar 28, 2020
Cross-platform method of accessing functions within shared objects/libraries.
View openlibrary.c
#include <stdio.h>
#include <string.h>
/* Preprocessor Macros */
#ifdef _WIN32
#include <windows.h>
#define EXTENSION ".dll"
#define OPENLIB(a) LoadLibrary(a)
#define CALLFUNC(a, b) GetProcAddress(a, b)
#define CLOSELIB(a) FreeLibrary(a)
@Dracovian
Dracovian / pytime.cc
Last active Feb 18, 2020
Incomplete C++ stuff for ArchAlessus
View pytime.cc
#ifdef __cplusplus
#include <cstdio>
#include <cstdlib>
#include <ctime>
/*
* We're not going to bother to extern "C" this whole file despite that
* being the preferred route to take when writing code that can be compiled
* as C or C++.
*
View CIDR Ranges IPv4
Legend:
IPv4/CIDR = Starting IPv4 - Ending IPv4 | Number of IP addresses (Binary Formatting of Subnet) - Subnet Address
0.0.0.0/32 = 0.0.0.0 - 0.0.0.0 | 1 address (11111111 11111111 11111111 11111111) - 255.255.255.255
0.0.0.0/31 = 0.0.0.0 - 0.0.0.1 | 2 addresses (11111111 11111111 11111111 11111110) - 255.255.255.254
0.0.0.0/30 = 0.0.0.0 - 0.0.0.3 | 4 addresses (11111111 11111111 11111111 11111100) - 255.255.255.252
0.0.0.0/29 = 0.0.0.0 - 0.0.0.7 | 8 addresses (11111111 11111111 11111111 11111000) - 255.255.255.248
0.0.0.0/28 = 0.0.0.0 - 0.0.0.15 | 16 addresses (11111111 11111111 11111111 11110000) - 255.255.255.240
0.0.0.0/27 = 0.0.0.0 - 0.0.0.31 | 32 addresses (11111111 11111111 11111111 11100000) - 255.255.255.224
0.0.0.0/26 = 0.0.0.0 - 0.0.0.63 | 64 addresses (11111111 11111111 11111111 11000000) - 255.255.255.192
@Dracovian
Dracovian / archiver.py
Created Jan 27, 2020
What I used to manage my master tracks.
View archiver.py
from os import makedirs, getcwd, walk, path
from zipfile import ZipFile, ZIP_DEFLATED
def create_archive(filename, root, files):
zipfile = path.join(getcwd(), 'Archives')
if not path.exists(zipfile):
makedirs(zipfile)
zipfile = path.join(zipfile, filename)
You can’t perform that action at this time.