Skip to content

Instantly share code, notes, and snippets.

@serg06
serg06 / all.json
Created October 5, 2020 02:26
Jerma Youtube captions archive Oct 04 2020
This file has been truncated, but you can view the full file.
{
"id": "UUK3kaNXbB57CLcyhtccV_yw",
"videos": {
"t9OC2ToZIQ0": {
"id": "t9OC2ToZIQ0",
"title": "Yearly Channel Doctor's Appointment",
"description": "You thought I ran out of Spider-Man games? \n\n2nd Channel\nhttps://www.youtube.com/channel/UCL7DDQWP6x7wy0O6L5ZIgxg\n\nTwitch\nhttp://www.twitch.tv/jerma985\n\nTwitter\nhttp://www.twitter.com/jerma985",
"thumbnail": "https://i.ytimg.com/vi/t9OC2ToZIQ0/hqdefault.jpg?sqp=-oaymwEZCNACELwBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLBqzhvyJZO0NP_N8-7VJ-UNBWyjFQ",
"date": "20170829",
"duration": 554
@serg06
serg06 / any.hpp
Last active July 9, 2020 00:24
Simple header-only C++11 implementation of std::any (tested with GCC)
#include <functional>
#include <typeinfo>
#include <type_traits>
namespace std17
{
class bad_any_cast : public std::bad_cast
{
public:
bad_any_cast() noexcept = default;
@serg06
serg06 / main.cpp
Last active December 20, 2022 08:31
cppzmq (libzmq) multi-threaded pub-sub example on Windows 10 VS 2019
#include <future>
#include <iostream>
#include <string>
#include "zmq.hpp"
void PublisherThread(zmq::context_t* ctx)
{
// Prepare publisher
zmq::socket_t publisher(*ctx, zmq::socket_type::pub);
@serg06
serg06 / deref_equal_to.h
Created May 24, 2020 00:12
std::equal_to modified to dereference pointers N times before comparing
// Similar to std::equal_to but dereferences pointers `derefs` times before comparing
template<class T, const int derefs>
struct deref_equal_to
{
constexpr bool operator()(const T& lhs, const T& rhs) const
{
static_assert(derefs >= 0);
if constexpr (derefs >= 1)
{
static_assert(std::is_pointer_v<T>);
@serg06
serg06 / settings.json
Last active March 18, 2021 16:25
Windows Terminal settings
// This file was initially generated by Windows Terminal 1.4.3243.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@serg06
serg06 / powff.c
Last active March 3, 2020 16:01
A short pow(float x, float y) = x^y approximation that doesn't use any libraries (not even math.h.)
#include <stdio.h>
// Iterations for exp(x) approximation. Higher = more accurate, but higher likelihood of running into inf.
#define EXP_ITERATIONS 100
// Iterations for ln(x) approximation. Higher = more accurate, but slower.
#define LN_ITERATIONS 10000
// Returned if invalid input entered.
#define ERROR_RESULT -999999999
@serg06
serg06 / index.js
Last active February 5, 2020 03:13
Amazon Lambda Node.js 12.x async handler function example
/* Grr, Amazon's documentation sucks!
* Their own documentation: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html
* says that you're allowed to return strings, but that always results in "Internal Server Error"!
* In reality, your result has to be structured like the one you see below.
*/
exports.handler = async (event, context) => {
return {
statusCode: 200,
headers: {
@serg06
serg06 / main.c
Last active January 21, 2020 20:40
Little C program for making bright pixels in a .png file transparent. Useful for cleaning up a picture of a document. TODO: Maybe a fragment-deletion filter and a smoothing filter.
// Image-read library
// https://github.com/nothings/stb/blob/master/stb_image.h
#define STB_IMAGE_IMPLEMENTATION
#define STBI_ONLY_PNG
#include "stb_image.h"
// Image-write-library
// https://github.com/nothings/stb/blob/master/stb_image_write.h
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
@serg06
serg06 / render_arrays.fs.glsl
Last active January 10, 2020 22:42
OpenGL shaders for rendering an array of sequential unsigned integers starting at 0
#version 450 core
// get color from geometry shader
in vec4 gs_color;
// output color
out vec4 color;
void main(void)
{
@serg06
serg06 / mcp44
Last active November 29, 2021 15:02
Miscellaneous solutions
Attempting to decompile older versions of Minecraft using
[ModCoderPack](https://minecraft.gamepedia.com/Programs_and_editors/Mod_Coder_Pack)
results in the following error:
Traceback (most recent call last):
File "C:/<the path>/mcp44/main.py", line 4, in <module>
decompile.main2()
File "C:\<the path>\mcp44\runtime\decompile.py", line 118, in main2
main(options.config, options.force_jad)
File "C:\<the path>\mcp44\runtime\decompile.py", line 16, in main