Skip to content

Instantly share code, notes, and snippets.

View netgusto's full-sized avatar
:bowtie:

netgusto netgusto

:bowtie:
View GitHub Profile
@netgusto
netgusto / siginfo.go
Last active November 11, 2022 10:02
SIGINFO (Ctrl+t) to dump live metrics in go
// Send SIGINFO (Ctrl+t on the shell, or kill -info <pid>)
// To dump live metrics
go func() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINFO)
for range sigs {
duration := time.Since(start)
// obviously adapt this next line to your need :)
logger.Info(fmt.Sprintf("Processed %d jobs in %s; Throughput=%.4f/s\n", nbprocessed, duration.String(), float64(nbprocessed)/duration.Seconds()))
@netgusto
netgusto / Graph.js
Last active February 5, 2022 01:24
Graph Data Structure, adjacency list implementation + Traversals (DFS, BFS)
module.exports = class Graph {
constructor(V, E, directed = false) {
this.vertices = V;
this.edges = {};
E.map(e => {
const a = e[0]; const b = e[1]; const w = e[2] === undefined ? 1 : e[2];
this.addEdge(a, b, w);
@netgusto
netgusto / index.js
Last active February 5, 2022 01:24
Polynomial Hash for node.js
const PRIME_BASE = 257;
const PRIME_MOD = 1000000007;
function polynomialHash(s) {
let hash = 0;
for (let i = 0; i < s.length; i++) {
hash = hash * PRIME_BASE + s.charCodeAt(i);
hash %= PRIME_MOD; //don't overflow
}
@netgusto
netgusto / reactive-conf-talk.md
Last active February 5, 2022 01:24
Byte Arena: Digital Playground for Intelligent Agents

Code your autonomous agent and live watch it challenge other players AIs in deathmatch arenas, CTF maps or in physically realistic race simulations.

Your agent is a program that perceives it's digital environment, make decisions, and take actions to reach it's objectives. Tweak it, evolve it, refine it, script it, make it learn - whatever works; one goal : overcome the opponents with your code.

Perceive your environment and react accordingly !

@netgusto
netgusto / README.md
Last active February 5, 2022 01:24
WebSocket/Node response time & latency (localhost loop)

Evaluate websocket/Node response time for 100 clients triggered simultaneously every second.

$ npm install
$ node wsperf.js

# with socket.io debug
$ DEBUG=socket.io* node wsperf.js

Why so slow ? I was kind of expecting the connections to be handled in parallel, but it seems they're in fact processed sequentially by node. Could that be properly parallelized somehow ?

@netgusto
netgusto / Dockerfile
Created May 14, 2016 09:08
Rustup in a container
FROM ubuntu:latest
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y apt-utils
RUN apt-get install -y curl build-essential
RUN apt-get install -y file
@netgusto
netgusto / README.md
Last active February 5, 2022 01:25
Run a graphical app in docker on OSX

Run a graphical app in docker on OSX

Note: Replace 192.168.0.5 below by your own interface ip

mac $ socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
mac $ docker run --device=/dev/tty0 -e DISPLAY=192.168.0.5:0 -i -t ubuntu /bin/bash
ubuntu $ apt-get update && apt-get install -y firefox
ubuntu $ firefox
@netgusto
netgusto / pegjs-htmlish.peg
Last active February 5, 2022 01:25
PEG.js grammar for parsing simple HTML-ish balanced markup language - use it on http://pegjs.majda.cz/online
Content = (DocType / Comment / BalancedTag / SelfClosingTag / Text)*
DocType = "<!doctype " doctype:[^>]* ">" {
return {
type: 'DocType',
content: doctype.join('')
};
}
Comment = "<!--" c:(!"-->" c:. {return c})* "-->" {
@netgusto
netgusto / ExceptionEventListener.php
Created June 2, 2014 11:04
Symfony: Interception des exceptions
<?php
// My/CoreBundle/EventListener/ExceptionEventListener.php
namespace My\CoreBundle\EventListener;
use Symfony\Bundle\FrameworkBundle\Routing\Router,
Symfony\Bundle\FrameworkBundle\Translation\Translator,
Symfony\Component\HttpFoundation\Session\Session,
Symfony\Component\HttpFoundation\Request,