Skip to content

Instantly share code, notes, and snippets.

@h4k1m0u
h4k1m0u / mandelbrot.c
Last active July 20, 2024 12:20
Produce a fractal image using Mandelbrot set
#include <stdio.h>
#include <complex.h>
#include <gd.h>
/**
* Produce a fractal image using Mandelbrot set
* - Js implementation: https://www.youtube.com/watch?v=6z7GQewK-Ks
* - Description: https://en.wikipedia.org/wiki/Mandelbrot_set
* - GD documentation: https://libgd.github.io/manuals/2.1.1/files/preamble-txt.html
*
@h4k1m0u
h4k1m0u / Example_vtk.cpp
Created September 19, 2021 22:17
Basic example from VTK website
#include <vtkNew.h>
#include <vtkCylinderSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
/* vtkNew allocates & init instance of vtk object on construction */
int main() {
@h4k1m0u
h4k1m0u / PCL_read_pcd.cpp
Last active September 18, 2021 20:03
Read, filter, & visualize pointcloud with PCL
#include <pcl/common/distances.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/filters/passthrough.h>
int main() {
// pointer to pointcloud
pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud(new pcl::PointCloud<pcl::PointXYZ>);
// load pcd pointcloud file
@h4k1m0u
h4k1m0u / Webworker.md
Created September 12, 2021 14:24
Basic example using webworkers

Description

Main thread triggers the computing of fib(100) by worker thread on button click. Once done, the worker transmits the result to the main thread.

How to run

Browser cannot load local js file containing worker.

python -m http.server
@h4k1m0u
h4k1m0u / cli_tweets.py
Last active May 16, 2021 22:00
Show on CLI tweets from the profile page of a given USER with Selenium
""" Get tweets from the profile page of a given USER """
import sys
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# get twitter user from command-line
if len(sys.argv) != 2:
@h4k1m0u
h4k1m0u / grub-repair.md
Last active March 21, 2021 19:17
How to repair grub in case Windows was installed after Linux
# fdisk -l # determine Linux partition (e.g. /dev/sda1)
# mount /dev/sda1 /mnt
# mount --bind /dev /mnt/dev
# mount --bind /sys /mnt/sys
# mount --bind /proc /mnt/proc
# update-grub # in case it fails, run before it: grub-install /dev/sda
# umount /mnt/proc
# umount /mnt/sys
# umount /mnt/dev
@h4k1m0u
h4k1m0u / linux-usb.md
Created March 21, 2021 13:57
Few bash commands dealing with usb sticks
# df -hT # Show filesystem of devices & partitions
# unmount /dev/sdb1 # Unmount usb stick
# mkfs.fat /dev/sdb1 # Format usb stick using FAT filesystem
# eject /dev/sdb1 # eject usb stick
@h4k1m0u
h4k1m0u / advanced-programming-unix.md
Last active December 24, 2020 10:22
advanced-programming-unix

From the 3rd edition of W. Richard Stevens's Advanced Programming in the Unix Environment 1.

  • Kernel: Software that controls hardware (e.g. linux).
  • OS: Kernel plus other apps (e.g. shell).
  • System calls: Interface to the kernel.
  • File descriptor: Small non-negative integer to identify files.
  • When a new program is run the following files are opened (all correspond by default to terminal):
  • Standard input: fd = 0.
@h4k1m0u
h4k1m0u / HelloFFMpeg.md
Last active February 14, 2025 22:14
hello-ffmpeg

Program

  • src/hello_ffmpeg.cpp: Read mp4 video and display its metadata.

Prerequisite

sudo apt install libavformat-dev

Notions about video processing

  • Demuxing: Split individual streams (video, audio, subtitles...) and send them to their respective decoders.
@h4k1m0u
h4k1m0u / c.md
Last active April 20, 2024 16:48
C notions

Linkage

Identifiers for variables and constants declared at file scope have external linkage (i.e. visible in other translation units).

Global and static variables

Both are initialized to zero for variables and NULL for pointers by default, and exist for all the lifetime of the program.

Static keyword

  • A variable declared inside a function that keeps its value between invocations (as if it were global), and so is initialized only once.
  • Function or variable is only visible (callable) within the same *.c file it was defined into (limited scope => optimal performance).