Skip to content

Instantly share code, notes, and snippets.

View AlexisTM's full-sized avatar
🤠

Alexis Paques AlexisTM

🤠
View GitHub Profile
@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");
<?php
include 'json.php';
function cache_get($key) {
@include "/tmp/$key";
return isset($val) ? $val : false;
}
$response = new \Simple\json();
@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 / install.wiringpi.xu4.sh
Last active October 3, 2019 06:19
WiringPi for Odroid XU4
sudo apt update
sudo apt install python-dev python-setuptools swig3.0
git clone --recursive https://github.com/hardkernel/WiringPi2-Python.git
cd WiringPi2-Python
swig3.0 -python -threads wiringpi.i
sudo python setup.py build install
### PYTHON 3
@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 / 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 / mavros_gcs.py
Created November 23, 2018 15:49
Mavros GCS heartbeat simulation => Have status_recv message allowing calibration.
#!/usr/bin/env python2
from __future__ import division
import os
import glob
import rospy
from pymavlink import mavutil
from threading import Thread
from mavros_msgs.msg import Mavlink, StatusText
from mavros import mavlink