Skip to content

Instantly share code, notes, and snippets.

View gawen's full-sized avatar

Gawen Arab gawen

View GitHub Profile
package main
import (
"context"
"log"
"time"
"github.com/ngrok/ngrok-go"
ngrokconfig "github.com/ngrok/ngrok-go/config"
)
@gawen
gawen / version_cmp.py
Last active June 17, 2022 23:10
Compare versions in Python
def cmp_version(va, vb):
# Split over '.' and convert members into int
va = map(int, va.split("."))
vb = map(int, vb.split("."))
# Get max length of versions
l = max(len(va), len(vb))
# Make the version the same length by appending 0
va = va + [0] * (l - len(va))
@gawen
gawen / README
Created February 14, 2020 12:49
VIM cheatsheet
i: interactive mode
v: visual mode
escape to go back to no mode
# classic commands
:e <filename>: open <filename> in current window
:e **/<filename>: fuzzy search for <filename>
:w [<filename>]: write current window
:q: quit
@gawen
gawen / 0001-avoid-cyclic-assigment-of-.ra.patch
Last active October 24, 2019 12:14
breakpad patch to avoid the pseudo-register .ra to be self-assigned
From 13a5ab8b7f1a427182027ad6e3a2f64246fe27a7 Mon Sep 17 00:00:00 2001
From: Gawen Arab <g@wenarab.com>
Date: Thu, 24 Oct 2019 12:54:16 +0200
Subject: [PATCH] fix: DW_CFA_same_value of the return address for .ra
A DWARF CFI rule `DW_CFA_same_value` of the return address register
assigned to `.ra` should reload the return address register and assign
it to `.ra`. The recorded rule should be `.ra: <address register>`.
But `DwarfCFIToModule::RegisterName` always replaced the return address
@gawen
gawen / 0001-add-ld-option-alwaysRestoreDWARFLinkRegister-false.patch
Created October 23, 2019 19:01
add ld option '-alwaysRestoreDWARFLinkRegister[=false}' for go1.13.1
From 0b30d58c6b06dcdb8203f400c1b74ec08392a08f Mon Sep 17 00:00:00 2001
From: Gawen Arab <g@wenarab.com>
Date: Wed, 23 Oct 2019 19:37:41 +0200
Subject: [PATCH] add ld option '-alwaysRestoreDWARFLinkRegister[=false}'
---
src/cmd/link/internal/ld/dwarf.go | 2 +-
src/cmd/link/internal/ld/link.go | 2 ++
src/cmd/link/internal/ld/main.go | 1 +
3 files changed, 4 insertions(+), 1 deletion(-)
@gawen
gawen / iir.c
Last active July 7, 2019 20:44
IIR filter sample implementation
#define P 3
#define Q 3
const float feedforward_coeffs[P] = { 0.0316, -0.06319, 0.0316 };
const float feedback_coeffs[Q] = { 0.99835, -1.99835, 1.0 };
float feedforward_buf[P] = { 0.0 };
float feedback_buf[Q] = { 0.0 };
float pass(float inp) {
@gawen
gawen / mac.py
Created November 26, 2018 11:40
Calculate all MAC addresses between two MAC addresses.
# Everything prefixed by a # is a comment, and therefore is read by human and
# ignored by the machine
# First MAC address of the batch
FIRST_MAC = "E08E3C3923A2"
# Last MAC address of the batch
LAST_MAC = "e08e3c393234"
# we convert the first and last macs in decimals. To do so, we call 'int' with
@gawen
gawen / replace.c
Created February 6, 2015 14:17
Rename/Replace function behind "os.replace" in Python 3
static PyObject *
internal_rename(PyObject *args, PyObject *kwargs, int is_replace)
{
char *function_name = is_replace ? "replace" : "rename";
path_t src;
path_t dst;
int src_dir_fd = DEFAULT_DIR_FD;
int dst_dir_fd = DEFAULT_DIR_FD;
int dir_fd_specified;
PyObject *return_value = NULL;
@gawen
gawen / server.js
Created December 2, 2016 14:28
HTTP Digest Auth with express, passport-http and routers
var express = require('express'), http = require('http');
var app = express();
var passport = require('passport');
var Strategy = require('passport-http').DigestStrategy;
passport.use(new Strategy(
{ qop: "auth" },
function(username, done) {
return done(null, {}, "password");

Keybase proof

I hereby claim:

  • I am gawen on github.
  • I am gawenr (https://keybase.io/gawenr) on keybase.
  • I have a public key ASAA85dRvVCjFKMusnK7qLNpzmyqK-04XNoGDHNOFZTQiQo

To claim this, I am signing this object: