Skip to content

Instantly share code, notes, and snippets.

View zambony's full-sized avatar
🐶

zambony

🐶
View GitHub Profile
from collections import deque
import os
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
clear()
@zambony
zambony / chained-print.py
Last active March 1, 2020 22:13
Given an array, will stagger printing out the list by splitting it into groups and waiting between each group print
from threading import Timer
def chained(iterable, delay = 1.0, groupSize = 10):
def anon(arr, size, *args, **kwargs):
inc = kwargs["increment"] if "increment" in kwargs else 10
start = kwargs["start"] if "start" in kwargs else 0
finish = kwargs["finish"] if "finish" in kwargs else inc
if (finish >= size):
@zambony
zambony / serialize.c
Last active February 29, 2020 07:47
Basic non-portable example of serialization in C using void* buffers
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define BUFFER_INIT 32
typedef struct SerializedBuffer
{
void* data;
size_t index;
@zambony
zambony / simple-readline.c
Last active March 1, 2020 22:14
Custom function to accept input of unknown length from a user. Can change the max size the buffer can grow to.
#define CHUNK_SIZE 256
#define MAX_CHUNKS 4
/**
* Homemade readline. Dynamically read input.
*
* @param prompt The text to prefix the user's input with
* @param line Assigned the value of the user's input if not NULL
*
* @return The size of the read input
*/
@zambony
zambony / explodeByTag.c
Last active February 29, 2020 07:53
Better string separation in C
typedef enum BOOL
{
false = 0,
true = 1
} bool;
/**
* Tokenize a string using a custom separator and obey tags (such as chevrons or double quotes)
*
* When finished, remember to free each entry and then the array itself
local function iterstr(str)
return str:gmatch(".")
end
local function count(obj)
local x = 0
for k, v in pairs(obj) do
x = x + 1
end
local function explode(str, separator)
local out = {}
for w in str:gmatch("([^" .. separator .. "]+)") do out[#out + 1] = w end
return out
end
local NODE = {}
-- Convenience function to explode some text
local function explode(str, separator)
local out = {}
for w in str:gmatch("([^" .. separator .. "]+)") do out[#out + 1] = w end
return out
end
local defaultComp = function(a, b) return a > b end
-- Convenience function to explode some text
local function explode(str, separator)
local out = {}
for w in str:gmatch("([^" .. separator .. "]+)") do out[#out + 1] = w end
return out
end
function table.swap(t, a, b)
-- Convenience function to explode some text
local function explode(str, separator)
local out = {}
for w in str:gmatch("([^" .. separator .. "]+)") do out[#out + 1] = w end
return out
end
Node = {}