Skip to content

Instantly share code, notes, and snippets.

View vdudouyt's full-sized avatar

Valentin Dudouyt vdudouyt

  • Novosibirsk, Russia
View GitHub Profile
@vdudouyt
vdudouyt / client.c
Last active February 28, 2021 14:21
USB bulk device example with libopencm3 & libusb-1.0
#include <libusb.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
int main()
{
libusb_init(NULL);
libusb_device_handle *handle;
assert(handle = libusb_open_device_with_vid_pid(NULL, 0x0483, 0x5740));
@vdudouyt
vdudouyt / Makefile.libopencm3
Created June 9, 2017 01:54
Sample makefile for libopencm3 project
PREFIX=/usr/bin/arm-none-eabi
CC=gcc
OBJCOPY=objcopy
TARGET=STM32F3
STFLASH=st-flash
%.o: %.c
$(PREFIX)-$(CC) -O0 -Wextra -Wshadow -Wimplicit-function-declaration -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes -fno-common -ffunction-sections -fdata-sections -MD -Wall -Wundef -I../third-party/libopencm3/include -D$(TARGET) -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -gdwarf-2 -g3 -o $@ -c $<
%.elf: %.o
#!/bin/bash
FFMPEG=~/bin/ffmpeg/ffmpeg
FILE=$1
$FFMPEG -threads 0 -i $FILE -vf vidstabdetect=stepsize=6:shakiness=10:accuracy=15:result=$FILE.trf -f null -
$FFMPEG -threads 0 -i $FILE -vf vidstabtransform=input=$FILE.trf:smoothing=30 -c:v libx264 -preset slow -crf 22 -c:a aac -b:a 256k $FILE.stab.mp4
@vdudouyt
vdudouyt / jsnprintf.c
Last active January 26, 2017 08:56
A small and idiomatic plain C library for composing JSON strings
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
/* Composes a string accordingly to format with correctly escaping JSON literals.
* Correctly fails when runs up of output buffer space.
* Replaces all occurences of ' with " in format string for convenience.
* Terminates a string with '\0'.
* Format specifiers:
* %% - literally '%'
/* Canonicalize virtual path
* License: public domain
*/
void canonicalize(const char *path, char *output) {
do {
while(path[0] == '/') path++;
char *chunk_end = strchr(path, '/');
int chunk_length = chunk_end ? chunk_end - path : strlen(path);
/*
* @seed: 20 bytes
* @result: 120 bytes (but use first 107 bytes only)
*/
int mgf1(char *seed, BYTE *result)
{
int hlen = 20;
int length = 127 - hlen;
int i, d = 0;
#include <stdio.h>
#include <gtkhotkey.h>
void hotkey_activated_callback (GtkHotkeyInfo *hotkey, guint event_time, void *data)
{
g_message("activated");
}
int main(int argc, char **argv)
{
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ftdi.h>
#include <assert.h>
#include <math.h>
/*
* Input: RxD
* OUT0: CTS
dissect :: (Data a, Data d) => a -> [(String, Maybe d)]
dissect a = zip (constrFields $ toConstr a) (gmapQ cast a)
#include <functional>
using namespace std;
class Test
{
public:
Test();
void say_hello(string way);
private: