This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
users/[username]:token-[token] = { | |
'location': 'Brussels', | |
'origin': 'weblogin', | |
'creation-ip': 'x.x.x.x', | |
'last-use-ip': 'x.x.x.x' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Singleton { | |
public: | |
static Singleton& get() { | |
static Singleton instance; | |
return instance; | |
} | |
Singleton(Singleton&&) = delete; | |
Singleton& operator=(Singleton&&) = delete; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is to be used with catkin_make or catkin_tools if we want to merge compile_commands.txt in a single file to allow some tools to work such as Sourcetail. | |
sudo apt install jq | |
jq -s 'map(.[])' PATH_TO_COMPILE_COMMANDS_ROOT/**/compile_commands.json > compile_commands.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Those functions are related to: https://www.youtube.com/watch?v=nXaxk27zwlk&t=2446s | |
* | |
* They are used to allow to benchmark functions with -O3 that would otherwise be removed because it is unused. | |
* | |
* escape(&object) prevents object to be optimized out | |
* "This ASM code has some unknowable side effects and possibly stored the pointer globally" | |
* clobber() tells the compiler some asm might be reading the whole memory | |
* "This ASM code could probably read/write to all memory" => observe all memory | |
*/ |