Skip to content

Instantly share code, notes, and snippets.

View mildsunrise's full-sized avatar
🦊
*rolls*

Alba Mendez mildsunrise

🦊
*rolls*
View GitHub Profile
@mildsunrise
mildsunrise / README.md
Last active September 13, 2023 09:47
OpenSCAD module for simple gears with round teeth

Simple module that makes gears with circular-shaped teeth. The gears maintain their shape even for extremely low teeth numbers up to 2. Parameters:

  • teeth: number of teeth.
  • step: width of one teeth (diameter of the circle).

Two gears produced with the same step will transfer movement, so one typically fixes a step for all the gears and varies teeth for each gear, which decides the radius and transfer ratio. Example:

@mildsunrise
mildsunrise / ffmpeg-barebones.c
Last active June 1, 2016 17:37
Barebones FFMPEG video processor
// Barebones program that reads a video file, extracts
// the video stream, processes it someway and then encodes
// it (alone) to another file.
#include <stdio.h>
#include <libavutil/opt.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavfilter/avfilter.h>
@mildsunrise
mildsunrise / dynamic-timelapse.c
Last active June 1, 2016 17:43
Speed up a video by a dynamic factor
/**
* Program I hacked up to produce timelapses with dynamic speedup
* factor. The `get_speed` function will be called periodically
* to decide what speedup should be applied at that point of the
* input video.
*
* This works by simply duplicating / dropping frames just as the
* `fps` filter would (zero-order hold). The program is based on
* the `transcoding.c` example, and is dirty. Make sure the input
* contains no streams other than the video stream to process.
@mildsunrise
mildsunrise / dhondt.py
Last active January 10, 2022 00:20
Implementation of the D'Hondt method
""" Implements the D'Hondt method.
Given a chamber of `total_seats` seats, and a dictionary of
integer values (vote counts), one for each party, assigns seats
to each party using the D'Hondt method.
Returns a dictionary of integer values (assigned seats). Results
are undefined if two parties have the same number of non-zero
votes, or there are no votes.
Example (taken from Wikipedia):
@mildsunrise
mildsunrise / candidaturas.txt
Created June 29, 2016 11:03
Raw election results for Spain Congress (2016-06-26)
Siglas Nombre Logo
ALCD ALIANZA DE CENTRO DEMOCRÁTICO http://resultados2016.infoelecciones.es/99imgs/LOGOCO990001.gif
AND PARTIDO SOMOS ANDALUCES POR ANDALUCÍA Y LOS PUEBLOS http://resultados2016.infoelecciones.es/99imgs/LOGOCO990002.gif
BNG-NÓS BNG-NÓS CANDIDATURA GALEGA http://resultados2016.infoelecciones.es/99imgs/LOGOCO990005.gif
C's CIUDADANOS-PARTIDO DE LA CIUDADANÍA http://resultados2016.infoelecciones.es/99imgs/LOGOCO990013.gif
CCa-PNC COALICIÓN CANARIA-PARTIDO NACIONALISTA CANARIO http://resultados2016.infoelecciones.es/99imgs/LOGOCO990007.gif
CCD CIUDADANOS DE CENTRO DEMOCRÁTICO http://resultados2016.infoelecciones.es/99imgs/LOGOCO990008.gif
CCD-CI CIUDADANOS DE CENTRO DEMOCRÁTICO-CANDIDATURA INDEPENDIENTE http://resultados2016.infoelecciones.es/99imgs/LOGOCO990009.gif
CDC CONVERGÈNCIA DEMOCRÀTICA DE CATALUNYA http://resultados2016.infoelecciones.es/99imgs/LOGOCO990010.gif
CENTRO MODERADO LOS VERDES-ECOPACIFISTAS http://resultados2016.infoelecciones.es/99imgs/LOGOCO990011.gif
@mildsunrise
mildsunrise / README.md
Last active April 19, 2018 15:56
Calculate usable bits (for data and error correction) on a QR

QR codes come in 40 sizes, or versions. Each version is 4 pixels wider than the previous. Version 1 is 21 by 21 pixels wide, version 2 is 25 by 25, and so on.

This function allows one to calculate the number of pixels (or bits) used for the actual content and error correction. More precisely: the count of pixels that are not part of the finders, separators, timing patterns, alignment modules, format info, version info, dark module or quiet zone. The pattern mask is applied to these pixels only.

It accepts a parameter v which is the version number. For example, a version 1 QR (the smallest possible) has 208 usable bits, so get_usable_bits(1) would return 208.

@mildsunrise
mildsunrise / README.md
Last active January 10, 2022 00:20
Helper program to add HTTP/SOCKS proxy support to SSH

ssh-proxy-dialer

This program adds proxy support to ssh. Once installed, ssh will obey the ssh_proxy environment variable (or all_proxy as a fallback) and will try to connect to the server through that proxy. Example:

export ssh_proxy="socks5://10.139.2.1:8066"
ssh example.com  # will connect through SOCKS5 proxy
@mildsunrise
mildsunrise / radial_avg.py
Created September 4, 2016 15:43
"Average" a series of angles in radians
import math
# Basic "convert to binomial, then back to polar" stuff, nothing interesting
def radial_avg(angles):
dx, dy = (0, 0)
for angle in angles:
dx += math.cos(angle)
dy += math.sin(angle)
return math.atan2(dy, dx)
@mildsunrise
mildsunrise / filler.py
Last active January 10, 2022 00:21
Program that fills transparent gaps in images (dirty)
# Program that tries to fill transparent gaps in an image from adjacent pixels.
# To use, take the image and remove the alpha channel. Write this alpha channel
# to a separate grayscale image. Feed both images to this script. You may want
# to tweak the constants below:
SIZES = [1,2,3,4,5,6,8,10,14,18,24,30]
BASE_BLUR = 1
GAUSSIAN_MULTIPLY = 1.2
import cv2
import numpy as np
@mildsunrise
mildsunrise / README.md
Last active October 30, 2021 09:47
Render LaTeX inline code to a small image

Quick boilerplate for when you need a LaTeX inline thing converted to an image. Enter the expression in fig.tex, and run:

pdflatex fig.tex < /dev/null && convert -density 600 fig.pdf -flatten -scale 50% -quality 90 fig.jpg

Things you may want to change:

  • To render block content (i.e. an equation) instead of a float or inline content, add varwidth=40em to the document options, or use \minipage for a fixed width.
  • Tweak the -density, -quality and border accordingly, or produce a .png.