Skip to content

Instantly share code, notes, and snippets.

@sapher
sapher / map_pic.c
Last active May 25, 2025 11:38
Map function for PIC microcontroller that map a value from a range to another range
uint16_t map(uint16_t value, uint16_t fS, uint16_t fE, uint16_t tS, uint16_t tE) {
return ((long)(value - fS) * (long)(tE - tS)) / ((fE - fS) + tS);
}
// map(512, 0, 1024, 0, 512); > 127
@sapher
sapher / sdl2_window_example.c
Created December 29, 2015 08:41
SDL2 Basic Window code example
#include <stdbool.h>
#include <SDL.h>
int main(int argc, char** argv) {
// Declaration
SDL_Window* window;
SDL_Renderer* renderer;
bool isRunning = true;

Install and configure External Secret Operator (ESO)

Install external-secret with Helm

helm repo add external-secrets https://charts.external-secrets.io

helm upgrade --install --create-namespace -n eso external-secrets \
    external-secrets/external-secrets \
    -n external-secrets \
@sapher
sapher / gist:ad6c727d8ef4ce460bec98b695054be1
Created September 9, 2024 20:32
garage door zigbee (change device id)
"""Tuya based cover and blinds."""
from typing import Dict
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
import zigpy.types as t
from zigpy.zcl.clusters.general import Basic, GreenPowerProxy, Groups, Ota, Scenes, Time
from zigpy.zcl.clusters.security import IasZone
from zhaquirks.const import (
@sapher
sapher / install.sh
Last active June 16, 2023 09:29
Conf WS2
sudo apt-get update -y
sudo apt-get upgrade -y
# Install packages
sudo apt-get install zsh git unzip curl wget build-essential jq file -y
# Install oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Install brew
@sapher
sapher / pic12f615_adc_interrupt.c
Last active April 27, 2023 14:46
PIC12F615 ADC interrupt exemple
#include "xc.h"
#include "config.h"
#define _XTAL_FREQ 4000000
unsigned short pot = 0;
void interrupt isr() {
// Disable GIE (best practice?)
@sapher
sapher / crane_delete_repo.sh
Created November 5, 2022 19:00
crane delete repo
crane auth login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
crane delete "${FULL_IMAGE_NAME}@$(crane digest ${FULL_IMAGE_NAME})"
@sapher
sapher / main.py
Created July 15, 2022 16:32
Parse SUPER U monmagasin U ticket
#!/usr/bin/env python3
from asyncore import read
import argparse
from PyPDF2 import PdfReader
import re
import json
if __name__ == "__main__":
@sapher
sapher / template.json
Last active June 3, 2019 04:50
Packer.io template file for RancherOS
{
"variables": {
"ros_version" : "v0.5.0",
"iso_md5" : "467caa8394684ba54e8731aed8480652",
"vm_name" : "rancher_image"
},
"builders": [
{
"type": "vmware-iso",
"iso_url": "https://releases.rancher.com/os/{{ user `ros_version` }}/rancheros.iso",
package sapher.com.instabooth.ui;
import android.content.Context;
import android.content.res.Configuration;
import android.view.OrientationEventListener;
import android.view.Surface;
import android.view.WindowManager;
import java.util.concurrent.locks.ReentrantLock;