Skip to content

Instantly share code, notes, and snippets.

View nvictor's full-sized avatar

Victor Noagbodji nvictor

View GitHub Profile
@nvictor
nvictor / rename_lower.sh
Created December 30, 2019 09:45
Rename files to lowercase (non recursive)
for f in *.txt; do mv "$f" "$(echo $f | tr '[A-Z]' '[a-z]')"; done
@nvictor
nvictor / search_github.txt
Created January 19, 2020 15:40
GitHub search
# python repositories, sorted by stars descending
https://www.github.com/topics/python?o=desc&s=stars
@nvictor
nvictor / db_sizes.sql
Created February 20, 2020 23:34
Database sizes
select name, pg_size_pretty(pg_database_size(datname)) as size from pg_database;
ffmpeg -i input.mp3 output.wav
ffmpeg -i input.mp3 -ss hh:mm:ss.lll -t ddd -acodec copy output.mp3
@nvictor
nvictor / fatal.c
Last active February 20, 2020 23:38
Fatal and error functions
#include <stdarg.h> # va_list, va_start, va_end
#include <stdio.h> # vprintf
#include <stdlib.h> # exit
void fatal(const char *format, ...) {
va_list args;
va_start(args, format);
printf("Fatal: ");
vprintf(format, args);
printf("\n");
@nvictor
nvictor / win32_main.c
Last active February 20, 2020 23:41
Win32 API standard main
#include <windows.h>
// Win32 API programs entry point
// 1. C might give you a hard time if you don't name the parameters
// 2. use __stdcall, which is an alias for WINAPI, which is an alias for APIENTRY, etc...
int __stdcall wWinMain(
// call it module, not instance (back in the days modules share multiple instances, not anymore).
HINSTANCE module,
// previous "instance", not often used
HINSTANCE previous,
@nvictor
nvictor / win32_create_window.c
Last active February 20, 2020 23:42
Win32 API create window
void create_window(HINSTANCE module, LPCTSTR class_name, LPCTSTR title) {
// 1. filling WNDCLASS / WNDCLASSEX
// wc = {} and wc {.hCursor = ..., .hInstance = ...} don't work in VS2017
WNDCLASS wc = {0};
// Only 3 components are necessary
// hCursor sets the cursor for when the mouse is over the window
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
// hInstance is the handle to the module's instance
// and lpszClassName is the window class name.
@nvictor
nvictor / win32_window_proc.c
Last active February 20, 2020 23:43
Win32 API standard window proc
LRESULT __stdcall window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) {
switch(message) {
// calls to BeginPaint and EndPaint are still needed
// even when using newer rendering engines
case WM_PAINT:
{
PAINTSTRUCT ps;
VERIFY(BeginPaint(window, &ps));
EndPaint(window, &ps);
}
@nvictor
nvictor / win32_process_messages.c
Last active February 20, 2020 23:50
Win32 API process messages
// basic version
void process_messages1() {
MSG message;
BOOL result;
// GetMessage() blocks and waits for a message
// returns 0 when it sees WM_QUIT
// returns -1 when something goes wrong
// returns a nonzero when there is a valid message to dispatch
while (result = GetMessage(&message, 0, 0, 0)) {
if (result != -1) {