Skip to content

Instantly share code, notes, and snippets.

View Justasic's full-sized avatar
🏍️
Making computers do things they don't want to

NightShadow Justasic

🏍️
Making computers do things they don't want to
View GitHub Profile
@Justasic
Justasic / openvpn_gen.py
Created November 8, 2015 06:24
This is a python script to generate client OpenVPN configuration files. This is based mostly on the easyrsa script and is much simpler to understand.
import os
import socket
from OpenSSL import crypto, SSL
# OpenVPN is fairly simple since it works on OpenSSL. The OpenVPN server contains
# a root certificate authority that can sign sub-certificates. The certificates
# have very little or no information on who they belong to besides a filename
# and any required information. Everything else is omitted or blank.
# The client certificate and private key are inserted into the .ovpn file
# which contains some settins as well and the entire thing is then ready for
@Justasic
Justasic / fcgitest.c
Created April 19, 2014 06:28
This is a nice example on how to use the FastCGI library in C.
// libfcgi-dev includes
#define NO_FCGI_DEFINES 1
//#include <fcgio.h>
#include <fcgi_config.h>
#include <fcgi_stdio.h>
#include <string.h>
int main()
{
FCGX_Request request;
@Justasic
Justasic / test.cpp
Created June 4, 2013 19:54
Use C++11 features to implement a function queue which calls functions later but queues them up in a FIFO queue. Compile with: clang -std=c++11 -stdlib=libc++
#include <iostream>
#include <functional>
#include <queue>
// These includes are for later experimentation
#include <thread>
#include <atomic>
std::queue<std::function<void()>> funcs;
# Color shortcuts
RED=$fg[red]
YELLOW=$fg[yellow]
GREEN=$fg[green]
WHITE=$fg[white]
BLUE=$fg[blue]
RED_BOLD=$fg_bold[red]
YELLOW_BOLD=$fg_bold[yellow]
GREEN_BOLD=$fg_bold[green]
WHITE_BOLD=$fg_bold[white]
@Justasic
Justasic / SerialBridge.ino
Created October 26, 2015 16:19
An arduino program that will bridge a UART and USB serial interface using an Arduino and software serial.
/*
This is a basic Arduino program to read the UART serial interface on an old
SpeedStream 5360 DSL modem I have. The code sets up a UART software serial
interface using the Arduino's 2 and 3 pins as RX and TX.
This program bridges the serial interfaces between USB and the UART software
serial. This will allow communication between the 3 devices.
This example code is in the public domain.
@Justasic
Justasic / tlo.hexpat
Last active May 1, 2023 16:00
ImHex (https://imhex.werwolv.net/) Telegram TLO object decoding (TLO schema v2 should match what Telegram uses)
#include <std/mem.pat>
#include <std/io.pat>
#include <std/sys.pat>
enum ConstructorIDType : u32 {
CID_TLSTYPE = 0x12eb4386,
CID_NATCONST = 0x8ce940b1,
CID_NATVAR = 0x4e8a14f0,
CID_EXPRNAT = 0xdcb49bd8,
CID_EXPRTYPE = 0xecc9da78,
@Justasic
Justasic / message.md
Last active December 22, 2022 22:10
.run() is bad for libraries

.run() is bad for libraries

As a developer I have noticed a trend in libraries where the library developer will write this amazing library that does everything you need it to except that it has a .run() or .start() method. The intent is for the user of said library to do the initialization code in the application entry point and then do something like return app.run();. Whether it's in Python, Java, C++, or Rust they all abstratct away the application's main event loop.

What is an event loop?

@Justasic
Justasic / 0x62646179.c
Last active October 26, 2022 16:26
Compile with Visual Studio on Windows. Make sure your system sounds are unmuted if you're not using Windows XP.
#include <stdio.h>
#include <stdint.h>
#include <Windows.h>
uint32_t hdata[] =
{
0x48617070, // 1
0x79204269, // 2
0x72746864, // 3
0x6179210A // 4
@Justasic
Justasic / TLCRC.py
Created March 24, 2022 22:27
Calculate the CRC32 values of Telegram's Type Language constructor IDs
#!/usr/bin/env python3
import sys, re
from zlib import crc32
from typing import Tuple
from PyQt5.QtWidgets import QWidget, QLineEdit, QApplication, QLabel, QVBoxLayout, QHBoxLayout
class Calculator(QWidget):
def __init__(self):
super().__init__()
@Justasic
Justasic / colorunion.c
Created January 3, 2017 15:56
This is a simple union which can make decoding RGB and hexadecimal colors easier in Windows C/C++
// Neat trick using unions and structs for clean code.
typedef union
{
// 32-bit integer is 4 bytes.
uint32_t hexadecimal;
// An array if we want to use that instead.
uint8_t bytearray[4];
// Colorref which is a DWORD on windows (aka, uint32_t)
// This may be inverse of what RGB() makes so this could be wrong.
// Which wouldn't surprise me. It's windows and everything has to be