Skip to content

Instantly share code, notes, and snippets.

View hrlou's full-sized avatar
👋

Hess Lewis hrlou

👋
  • Ontario, Canada
View GitHub Profile
/// mime = "0.3.0"
/// image = "0.24.0"
/// ffmpeg-next = "5.0.2"
extern crate ffmpeg_next as ffmpeg;
use image::{ImageBuffer, Rgb};
use ffmpeg::{
util::frame::video::Video,
format::{input, Pixel},
@hrlou
hrlou / mkpath.cpp
Last active February 9, 2022 19:58
recursive mkdir in C++
#include <iostream>
#include <string>
#include <sys/stat.h>
#ifdef _WIN32
#include <direct.h>
#define MKDIR(PATH) ::_mkdir(PATH)
#else
#define MKDIR(PATH) ::mkdir(PATH, 0755)
#endif
@hrlou
hrlou / Makefile.mk
Created May 17, 2021 17:33
Basic Makefile for most projects
CXX=c++
CXXFLAGS=-std=c++11 -pipe -pedantic -O3 -Wall
PREFIX=/usr/local
INCLUDE=-I. -I./include
LDFLAGS=
BIN=bin
BUILD_DIR=./build
CPP=$(wildcard src/*.cpp)
@hrlou
hrlou / libzip-example.c
Created April 23, 2021 18:56
C libzip example
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include <errno.h>
#include <zip.h>
@hrlou
hrlou / quitegood.hs
Created April 21, 2021 19:55
gets perfect numbers
-- usage
-- quitegood test_size tolerance
import System.Environment
import Data.List
getDivisors :: Int -> [Int]
getDivisors n =
(1:) $ nub $ concat [ [x, div n x] | x <- [2..limit], rem n x == 0 ]
where limit = (floor.sqrt.fromIntegral) n
@hrlou
hrlou / itoa.c
Created January 27, 2021 18:26
int to char*
/* taken from http://www.strudel.org.uk/itoa/
cannot handle negative numbers */
char* itoa(int val, int base){
static char buf[32] = {0};
int i = 30;
for(; val && i ; --i, val /= base)
buf[i] = "0123456789abcdef"[val % base];
return &buf[i+1];
}
@hrlou
hrlou / curl_write-callback-and-parse.c
Last active December 13, 2020 19:44
functions to get html, store it and it's information in a structure and parse them
/* functions to get html, store it and it's information in a structure and parse them.
* alot of this was taken from
* https://curl.se/libcurl/c/CURLOPT_WRITEFUNCTION.html
* I just wanted to modify it a little for my own purposes
* compile with "gcc curl_write-callback-and-parse.c -lcurl"
*/
#include <curl/curl.h>
#include <stdlib.h>
@hrlou
hrlou / stdout-from-child.c
Last active December 13, 2020 23:39
Example of how to pipe the stdout of a child process into the parent process and read it into a buffer
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#define PROCESS "/bin/ls"
#define ARGV "ls", "-la"
void main(void) {
// fd is the file descriptor for input and output