Skip to content

Instantly share code, notes, and snippets.

View mauri870's full-sized avatar
🌎

Mauri de Souza Meneguzzo mauri870

🌎
View GitHub Profile
@mauri870
mauri870 / ==.md
Last active December 4, 2023 21:04
Comparing strings and byte slices with ==

Comparing string == string and []byte == []byte

The types string and []byte share the same memory layout, it is a pointer to memory followed by the length (with a capacity, in the case of slices) and the actual contents. When we do a == comparison with slices (or strings, if that matter) the runtime issues a call to

runtime.memequal(a, b unsafe.Pointer, size uintptr) bool

This function is akin to libc’s memcmp(3).

Most compilers, such as gcc, will generate very optimized assembly for an operation like this, but it mostly boils down to:

@mauri870
mauri870 / u9fs-sharing-unix-files-with-plan9.md
Last active August 4, 2022 13:48
Sharing UNIX files with a Plan9 instance through 9P

Hi,

this gist summarizes how to share UNIX files/folders with a Plan9 instance using u9fs.

First of all, grab the latest u9fs release from source or install it with the package manager of your preference, then build and install.

Please be sure to find the correct path to your u9fs binary because it may differ based on the installation, normally it is /usr/local/bin/u9fs or /usr/bin/u9fs.

On older unix/linux systems you may use inetd, which is already covered by the u9fs man page.

@mauri870
mauri870 / tensorflow_audio_to_mfcc.py
Last active October 12, 2022 13:21
Wav audio to mfcc features in tensorflow 1.15
import tensorflow as tf
# FIXME: audio_ops.decode_wav is deprecated, use tensorflow_io.IOTensor.from_audio
from tensorflow.contrib.framework.python.ops import audio_ops
# Enable eager execution for a more interactive frontend.
# If using the default graph mode, you'll probably need to run in a session.
tf.enable_eager_execution()
@tf.function
def audio_to_mfccs(
@mauri870
mauri870 / asterisk-17.x-bfd-debian-bullseye.patch
Last active February 18, 2020 17:21
Asterisk PABX patch for GNU BFD in Debian Bullseye — undefined reference to bfd_get_section_flags, bfd_get_section_vma and bfd_get_section_size
diff --git a/main/backtrace.c b/main/backtrace.c
index 2623d7ff87..9b80622b04 100644
--- a/main/backtrace.c
+++ b/main/backtrace.c
@@ -124,12 +124,12 @@ static void process_section(bfd *bfdobj, asection *section, void *obj)
offset = data->pc - (data->dynamic ? (bfd_vma)(uintptr_t) data->dli.dli_fbase : 0);
- if (!(bfd_get_section_flags(bfdobj, section) & SEC_ALLOC)) {
+ if (!(bfd_section_flags(section) & SEC_ALLOC)) {
@mauri870
mauri870 / asterisk-unpause-all-members-not-ready-in-queue.sh
Created January 13, 2020 17:48
Unpause all paused agentes not in use in a Asterisk queue
#!/bin/sh
set -e
asterisk -rx "queue show ${1}"
grep '(paused) (Not in use)' |
awk '{$1=$1};1' |
cut -d' ' -f1 |
while read -r member
do
@mauri870
mauri870 / br-abnt2
Last active May 10, 2019 15:45
br-abnt2 kbmap for Plan9. Unfortunatelly I could't figure out how to make the acentuation work, hence the 0 value in line 1, 4, 9 and 12
0 26 0
0 27 '[
0 39 'ç
0 40 0
0 41 ''
0 43 ']
0 53 ';
0 115 '/
1 26 0
1 27 '{
@mauri870
mauri870 / tf-serving-client.go
Last active April 2, 2022 08:43
Tensorflow Serving Go client for the inception model
// Tensorflow Serving Go client for the inception model
// go get github.com/golang/protobuf/ptypes/wrappers google.golang.org/grpc
//
// Compile the proto files:
//
// git clone https://github.com/tensorflow/serving.git
// git clone https://github.com/tensorflow/tensorflow.git
//
// mkdir -p vendor
@mauri870
mauri870 / autoreload.sh
Created May 19, 2017 00:32
Rerun pdflatex on the fly when a file changes
#!/bin/bash
ls *.{tex,bib} | entr sh -c "bibtex main && pdflatex -synctex=1 -interaction=nonstopmode main.tex"
@mauri870
mauri870 / manjaro-avell-g1513.md
Last active March 2, 2022 02:23
Installation of Manjaro 17 and nvidia/bumblebee drivers on Avell G1513

After a weekend of research, stress and pain I finally figure out how to install manjaro 17 and configure the nvidia/bumblebee drivers on my avell laptop

Here's my notebook specs:

$ inxi -MGCNA

Machine:   Device: laptop System: Avell High Performance product: 1513
           Mobo: N/A model: N/A v: 0.1 UEFI: American Megatrends v: N.1.02 date: 09/28/2016
Battery    BAT0: charge: 44.0 Wh 100.0% condition: 44.0/44.0 Wh (100%)
@mauri870
mauri870 / queue.go
Last active November 20, 2016 17:42
Go program representing a queue data structure. Test it https://play.golang.org/p/QXC3OkMMT3
package main
import (
"fmt"
)
func main() {
// Create a new Queue
queue := NewQueue()