Skip to content

Instantly share code, notes, and snippets.

View AlexisTM's full-sized avatar
🤠

Alexis Paques AlexisTM

🤠
View GitHub Profile
@jclosure
jclosure / docker_reverting
Created June 5, 2015 08:07
How to revert a docker container to a previous commit
$ docker history imagename
IMAGE CREATED CREATED BY SIZE
f770fc671f11 12 seconds ago apt-get install -y curl 21.3 MB
28445c70c2b3 39 seconds ago apt-get install ping 11.57 MB
8dbd9e392a96 7 months ago 131.5 MB
$ docker tag 2844 imagename # <-- that's the secret right there
$ docker history imagename
IMAGE CREATED CREATED BY SIZE
@esromneb
esromneb / debounce.py
Created November 12, 2015 01:57
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):
@eric-wieser
eric-wieser / ROS msg.sublime-syntax
Created May 8, 2016 15:19
Basic syntax highlighting for message files
%YAML 1.2
---
name: ROS message definition
file_extensions: [msg]
scope: source.rosmsg
contexts:
main:
- match: \#.*$
scope: comment.line.rosmsg
@jlblancoc
jlblancoc / gist:44be9d4d466f0a973b1f3808a8e56782
Last active October 22, 2024 07:40
GCC sanitizer with CMake

For memory leaks

Build in CMake with these params:

CMAKE_CXX_FLAGS:STRING= -fsanitize=address  -fsanitize=leak -g
CMAKE_C_FLAGS:STRING=-fsanitize=address  -fsanitize=leak -g
CMAKE_EXE_LINKER_FLAGS:STRING=-fsanitize=address  -fsanitize=leak
CMAKE_MODULE_LINKER_FLAGS:STRING=-fsanitize=address  -fsanitize=leak

Which can be done with:

@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 / singleton.hpp
Last active November 20, 2020 15:47
The safe singleton in C++
class Singleton {
public:
static Singleton& get() {
static Singleton instance;
return instance;
}
Singleton(Singleton&&) = delete;
Singleton& operator=(Singleton&&) = delete;
@AlexisTM
AlexisTM / magic.h
Last active June 11, 2021 06:13
C/C++ performance magic functions (prevent optimization)
/**
* 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
*/
@RubenKelevra
RubenKelevra / fast_firefox.md
Last active November 11, 2024 20:23
Make Firefox fast again
import tweepy, json, time, sys
auth = tweepy.OAuth1UserHandler(
<api keys here>
)
api = tweepy.API(auth)
d = json.loads(open(sys.argv[1]).read().split("=", 1)[1])
@tristanisham
tristanisham / 1.fan
Created December 4, 2023 17:59
Advent of Code Day 1, Part 1
import "std/fs" for Fs
import "std/os" for Runtime
var input = Fs.read("./1/input.txt")
var output = []
for (line in input.split("\n")) {
var fromStart = Fiber.new {