Skip to content

Instantly share code, notes, and snippets.

View un1tz3r0's full-sized avatar
🕶️
acting natural

Victor Condino un1tz3r0

🕶️
acting natural
View GitHub Profile
@averne
averne / color.hpp
Created April 10, 2019 17:39
C++ templates for pixel data
#pragma once
#include <cstdint>
#include <utility>
#include <type_traits>
#define ASSERT_SIZE(x, sz) static_assert(sizeof(x) == sz, "Wrong size in " #x)
#define ASSERT_STANDARD_LAYOUT(x) static_assert(std::is_standard_layout_v<x>, #x "is not standard layout")
struct rgb565_t {
@ethernetdan
ethernetdan / door.py
Created October 17, 2018 21:16
Application to open door with WebSockets
#!/usr/bin/env python
import asyncio
from contextlib import contextmanager
import datetime
import RPi.GPIO as GPIO
import http
import random
import signal
import socket
@leoluk
leoluk / journal-reactor.py
Created October 3, 2018 22:19
Example code that demonstrates how to listen to journald using Python 3 + asyncio.
#!/usr/bin/python3 -u
import asyncio
import sh
from systemd import journal
from systemd.daemon import notify
GATEWAY_IP = "192.168.10.1"
@un1tz3r0
un1tz3r0 / perdevicethreadpool.py
Created August 26, 2018 20:38
This is a sample implementation of a linux udev monitor to watch for devices being added and removed and spawns/stops a reader thread for each active device. The classes are reusable and some are very useful patterns that are common in asynchronous programs. The simple example application at the end demonstrates reading from all connected input …
from contextlib import contextmanager
import pyudev
from select import select
import threading
import select, os, queue, socket
class PollableQueue(queue.Queue):
def __init__(self):
super().__init__()
# Create a pair of connected sockets
@kellerza
kellerza / oauth2_session.py
Last active February 12, 2025 19:29
OAuth2 authentication with aiohttp and oauthlib (based on requests_oauthlib)
"""OAuth2Support for aiohttp.ClientSession.
Based on the requests_oauthlib class
https://github.com/requests/requests-oauthlib/blob/master/requests_oauthlib/oauth2_session.py
"""
# pylint: disable=line-too-long,bad-continuation
import logging
from oauthlib.common import generate_token, urldecode
from oauthlib.oauth2 import WebApplicationClient, InsecureTransportError
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@un1tz3r0
un1tz3r0 / private.py
Last active February 9, 2021 09:26
Private/Public dispatch decorators in Python
import inspect
from functools import wraps
def privatemethod(func):
"""decorator for making an instance method private by dispatching on whether the name 'self' in the local namespace of the calling frame is a reference to the same object as the first positional argument (the self argument when invoking an instance method.) the decorated function will have a 'public' member which is a decorator for specifying an alternate implementation to dispatch calls from outside of the instance."""
pubfunc = None
privfunc = func
@wraps(func)
def func_wrapper(*args, **kwargs):
@ryancat
ryancat / colorDiffUtil.js
Created May 9, 2018 06:07
Color difference in RGB and LAB
/**
* Compare color difference in RGB
* @param {Array} rgb1 First RGB color in array
* @param {Array} rgb2 Second RGB color in array
*/
export function deltaRgb (rgb1, rgb2) {
const [ r1, g1, b1 ] = rgb1,
[ r2, g2, b2 ] = rgb2,
drp2 = Math.pow(r1 - r2, 2),
dgp2 = Math.pow(g1 - g2, 2),
@jmjatlanta
jmjatlanta / pub_sub_cpp.cpp
Last active December 23, 2024 05:33 — forked from makomweb/pub_sub_cpp.cpp
Fun with C++: implementing a pub/sub scenario using std::bind and other standard facilities. The approach is pretty similar to the well known .NET event mechanism.
#include <iostream>
#include <map>
#include <algorithm>
#include <functional>
#include <memory>
using namespace std;
/***
* A base class for event arguments
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.