Skip to content

Instantly share code, notes, and snippets.

struct strnsplit {
const char* ptr;
size_t len;
};
const char* strnsplit(
const char* restrict str,
int c,
size_t len,
size_t *part_len,
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <threads.h>
/**
* @brief A single unit of data in a opusbuffer, that is capable of
* containing a contigous sequence of bytes being arbitrarily large.
*/
struct opuspacket {
@tripulse
tripulse / octopussy.c
Created November 9, 2021 07:18
Quality degradation simulation with OPUS codec.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <opus/opus.h>
#include <assert.h>
//#define M_E 2.3504023872876028
#define M_E_1 0.36787944117144233
#define M_E_NEG_M_E_1 2.3504023872876028
from scipy.fftpack import dctn,idctn
from numpy import any, clip, floor, array, asarray, zeros, round, resize
from functools import partial
# Orthonormal DCT is required for JPEG quantisation else
# the default one is quite crap and useless (cannot
# reproduce values after transformation).
dctn = partial(dctn, type=2, norm='ortho')
idctn = partial(idctn, type=2, norm='ortho')
@tripulse
tripulse / yttdl.py
Created December 17, 2020 11:35
YouTube video thumbnail downloader script.
#!/usr/bin/env python
# https://gist.github.com/tripulse/e319d24bbc7b8b48f73336f7bc230e0c
"""
yt-thumb: a script to download thumbnails of YouTube videos of quantized set
of qualities (lowest, low, mid, high, highest). This tool nor the method it
uses imposes any restrictions on downloading thumbnails.
Qualities and their co-respoding width, height dimensions:
* lowest 120x90
* low 320x180
@tripulse
tripulse / 5CP.c
Created December 17, 2020 06:34
5IGI0 Communication Protocol. Byte data from/to ASCII compatible Violeur format payload conversion subroutines.
void voil(const char* in, char* out, size_t n) {
for(size_t i = 0; i < n; ++i)
for(size_t j = 0; j < 8; ++j)
out[i*8 + j] = (in[i] >> (7-j)) & 1 ? '-' : '\'';
}
int unviol(const char* in, char* out, size_t n) {
for(size_t i = 0; i < n/8; ++i) {
char acc = 0;
for(size_t j = 0; j < 8; ++j) {
#include <cinttypes>
#include <tuple>
template<class>
struct function_traits {};
template<class R, class... Args>
struct function_traits<R(Args...)> {
typedef R ret_t;
typedef std::tuple<Args...> args_t;
@tripulse
tripulse / grs.py
Last active October 4, 2020 05:35
Guru Rajashekhar style upvote generator (^^^^^^^^^^*$&$*&*#$&)
from random import choice, choices
def upvote(upvote = '^',
numbers = '93475100809635819407912381031',
others = '~!@#$%^&*()`{}|":?><][;/.,',
weights = [0.2, 0.75, 0.05]):
"""Generate Guru Rajshekhar style upvotes.
:param upvote: a character representing upvote
:param numbers: random numbers (possibly phone numbers)
@tripulse
tripulse / dft.cc
Last active October 4, 2020 04:01
Amateur DFT (Discrete Fourier Transform) implementation in C++
/**
* (c) Copyright 2020 Tripulse.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@tripulse
tripulse / range.js
Created September 20, 2020 07:13
Python-like range implementation, using JS generators for lazy evaulation.
function* range(...args) {
var start = 0;
var stop = 0;
var step = 1;
if(args.length == 1)
stop = args[0];
else if(args.length == 2) {
start = args[0];
stop = args[1];