Skip to content

Instantly share code, notes, and snippets.

View AlexisTM's full-sized avatar
🤠

Alexis Paques AlexisTM

🤠
View GitHub Profile
<?php
include 'json.php';
function cache_get($key) {
@include "/tmp/$key";
return isset($val) ? $val : false;
}
$response = new \Simple\json();
@AlexisTM
AlexisTM / cache_set.php
Last active January 31, 2018 15:57
cache_set.php for Medium post
<?php
include "json.php";
use \Simple\json;
function cache_set($key, $val) {
 $val = var_export($val, true);
 $val = str_replace("stdClass::__set_state", "(object)", $val);
 $tmp = "/tmp/$key." . uniqid("", true) . ".tmp";
 file_put_contents($tmp, "<?php $val = " . $val . ";", LOCK_EX);
 rename($tmp, "/tmp/$key");
@AlexisTM
AlexisTM / PCA9633.py
Created May 29, 2018 14:05
PCA9633 LED Python library
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
PCA9633.py
Author : Alexis PAQUES (@AlexisTM)
"""
import wiringpi2 as wpi
import time
@AlexisTM
AlexisTM / PCA9633.ros.py
Last active May 29, 2018 14:08
ROS version of the PCA9633 LED controller library for Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
PCA9633.py
Author : Alexis PAQUES (@AlexisTM)
"""
import rospy
import wiringpi2 as wpi
import time
@AlexisTM
AlexisTM / rootless.gpio.odroid.sh
Last active May 29, 2018 14:15
Rootless GPIO/I2C access for odroid XU4 C1 and C2
# See https://wiki.odroid.com/troubleshooting/gpiomem
sudo apt-get install i2c-tools python-smbus
sudo addgroup gpio
sudo usermod -a -G gpio odroid
# meson-gpiomem is for C1/C2
# exynos-gpiomem is for XU4
echo """SUBSYSTEM==\"exynos-gpiomem\", GROUP=\"gpio\", MODE=\"0660\"
SUBSYSTEM==\"meson-gpiomem\", GROUP=\"gpio\", MODE=\"0660\"
@AlexisTM
AlexisTM / itohex.c
Last active September 5, 2018 06:55
The clever integer to ASCII hexadecimal conversion !
#include <stdio.h>
char *itohex(int n) {
int i = 2*sizeof (int);
char *str = malloc(i + 1);
str[i] = '\0';
for ( ; i > 0; n >>= 4)
str[--i] = "0123456789ABCDEF"[n&0xF];
return str;
@AlexisTM
AlexisTM / Adhoc.sh
Created September 7, 2018 15:35
Adhoc alias example; to be sourced
adhoc() {
if [ -z ${1+x} ];
then echo -e "Run this using: \nadhoc on wlan0\nadhoc off";
return 1
else
ACTION=$1
WIFI_INTERFACE=$2
case $ACTION in
@AlexisTM
AlexisTM / named_throttle.js
Last active October 23, 2018 08:46
Throttle any function with a namespace. Named allows to throttle a same function differently depending on a name.
// Normal throttle for a normal function call
function throttle(func, delay) {
let timeout;
return function(...args) {
if (!timeout) {
timeout = setTimeout(() => {
func.call(this, ...args)
timeout = null
}, delay)
}
@AlexisTM
AlexisTM / debounce.py
Last active January 4, 2019 20:56 — forked from esromneb/debounce.py
This is a proper debounce function, the way a electrical engineer would think about it.
import time
""" This is a proper debounce function, the way a electrical engineer would think about it.
This wrapper never calls sleep. It has two counters: one for successful calls, and one for rejected calls.
If the wrapped function throws an exception, the counters and debounce timer are still correct """
class Debounce(object):
def __init__(self, period):
@AlexisTM
AlexisTM / redis-token-template.js
Created January 20, 2019 13:14
Redis token template
users/[username]:token-[token] = {
'location': 'Brussels',
'origin': 'weblogin',
'creation-ip': 'x.x.x.x',
'last-use-ip': 'x.x.x.x'
}