Skip to content

Instantly share code, notes, and snippets.

@hugokernel
hugokernel / dreammachineha.md
Last active September 6, 2023 08:08
Using a Dreammachine as a Doorbell with Home Assistant
@hugokernel
hugokernel / ratelimit.py
Last active December 2, 2021 19:24
Async rate limit call
def ratelimit(seconds=0, minutes=None, hours=None, days=None):
"""Rate limit call to a function"""
for var, delay in (
('minutes', 60),
('hours', 60 * 60),
('days', 60 * 60 * 24),
):
if locals()[var] is not None:
seconds += locals()[var] * delay
@hugokernel
hugokernel / test.py
Last active June 15, 2018 07:05
Test fit file
from fitparse import FitFile
from collections import OrderedDict
import datetime
UTC_REFERENCE = 631065600
fitfile = FitFile('lagny_fim.fit')
data = {}
for _, msg in enumerate(fitfile.get_messages('hr')):
@hugokernel
hugokernel / pled.py
Created March 3, 2016 14:42
pled.py
import time
import serial
import contextlib
DEVICE = '/dev/tty.usbmodemFD131'
DELAY = 0.01
class Serial:
@hugokernel
hugokernel / openalarm.yaml
Last active September 30, 2015 13:52
Fichier de configuration d'un OpenAlarm Node
devices:
/dev/toto:
config: default
/dev/tty.usbmodemfd131:
config: default
configs:
default:
group: 210
@hugokernel
hugokernel / outlet.py
Created May 19, 2015 07:08
Outlet driver
#!/usr/bin/python
import RPi.GPIO as GPIO
from time import sleep
class Power_Outlet:
OUTPUT0 = 12
OUTPUT1 = 11
OUTPUT2 = 13
@hugokernel
hugokernel / scan.py
Last active October 3, 2017 23:41
Python scanner for first line eval() based infection on php script
'''
Python scanner for first line eval() based infection on php script (ex: Wordpress infection)
Information: http://somewebgeek.com/2014/wordpress-remote-code-execution-base64_decode/
hugokernel, 09/2014
Usage:
python scan.py directory
'''
import sys
@hugokernel
hugokernel / fizzbuzz.py
Last active August 29, 2015 14:04
Mes versions du FizzBuzz en Python (http://sametmax.com/fizzbuzz-en-python/)
# -*- coding: utf-8 -*-
from __future__ import print_function
'''
Écrire un programme qui affiche les nombres de 1 à 199.
Mais pour les multiples de 3, afficher “Fizz” au lieu du nombre et pour les multiples de 5 afficher “Buzz”.
Pour les nombres multiples de 3 et 5, afficher “FizzBuzz”.
'''
# Simple version
@hugokernel
hugokernel / end.gcode
Created June 28, 2014 10:15
end.gcode
;End GCode
M104 S0 ;extruder heater off
M140 S0 ;heated bed heater off (if you have it)
G91 ;relative positioning
G1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure
G1 Z+0.5 E-5 X-20 Y-20 F{travel_speed} ;move Z up a bit and retract filament even more
G28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way
M84 ;steppers off
G90 ;absolute positioning
M81 ; Suicide !
@hugokernel
hugokernel / start.gcode
Created June 28, 2014 10:14
start.gcode
;Sliced {filename} at: {day} {date} {time}
;Basic settings: Layer height: {layer_height} Walls: {wall_thickness} Fill: {fill_density}
;Print time: {print_time}
;Filament used: {filament_amount}m {filament_weight}g
;Filament cost: {filament_cost}
M80 ; Power on !suicide
G21 ;metric values
G90 ;absolute positioning
M107 ;start with the fan off
;M190 S90 ; PLA: Heated bed on !