Skip to content

Instantly share code, notes, and snippets.

View AlexisTM's full-sized avatar
🤠

Alexis Paques AlexisTM

🤠
View GitHub Profile
@AlexisTM
AlexisTM / factorial.js
Created May 18, 2020 14:40
Very fast algorithm for the a first approximation of a very large factorial (10 decimals)
function factorial(number) {
let result = 0;
for(let i = number; i > 0; --i) {
result += Math.log10(i);
}
return result;
}
function scientific_factorial(number) {
let fact = factorial(number);
@AlexisTM
AlexisTM / minimal_gcs.py
Last active May 31, 2019 12:11
Minimal heartbeat for a Ground control station in ROS for PX4
#!/usr/bin/env python2
"""
Minimal heartbeat for a Ground control station in ROS for PX4.
It enables STATUS_TEXT streams.
Author: AlexisTM
"""
from threading import Thread
import rospy
@AlexisTM
AlexisTM / cookie.js
Created January 20, 2019 16:06
Parse a cookie
@AlexisTM
AlexisTM / token-frontend.js
Created January 20, 2019 13:36
Login on the front-end side using AJAX
// To be used to set a cookie
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 86400000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
// Login through an AJAX call
function login(username, password) {
@AlexisTM
AlexisTM / token.js
Last active January 20, 2019 15:56
To create a token with expiration
// Express web app
const express = require('express');
const app = express()
const md5 = require('md5');
// Redis client
const redis = require("redis");
const client = redis.createClient({ host: '192.168.178.23' });
// Token generator
@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'
}
@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 / 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
@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 / 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