Skip to content

Instantly share code, notes, and snippets.

@rogersguedes
rogersguedes / memcmp_idx.c
Created April 17, 2020 22:27
memcmp with unmatched index.
uint8_t memcmp_idx(uint8_t *arr1, uint8_t *arr2, size_t len, size_t *diff_idx){
size_t i = 0;
uint8_t ret = 0;
while(i < len)
{
if(arr1[i] > arr2[i])
{
ret = 1;
break;
@rogersguedes
rogersguedes / ptp-calc.py
Created February 5, 2020 16:50
PTP Increment and Addend calculator
#!/usr/bin/env python
from tabulate import tabulate
import math
def getHexStr(num, dig):
return '0x{0:0{1}X}'.format(num, dig)
minClk=50000000.0
sysClk=216000000.0
#sysClk=76000000.0
@rogersguedes
rogersguedes / server-cors.py
Created January 31, 2020 20:13 — forked from mkows/server-cors.py
Allow CORS with python Simple HTTP Server – for Python 3
'''
Based on https://gist.github.com/enjalot/2904124 (in Python 2) -> quick-migrated to Python 3
Usage: python server-cors
'''
import http.server as httpserver
class CORSHTTPRequestHandler(httpserver.SimpleHTTPRequestHandler):
def send_head(self):
"""Common code for GET and HEAD commands.
@rogersguedes
rogersguedes / mysql-backup.sh
Created January 26, 2020 22:56
This scripts generate a mysqldump commands to backup a MySQL database into two separate files. One for tables creation only and other for for data insertion;
#!/bin/bash
discendingTime(){
date '+%Y.%m.%d.%H.%M.%S'
}
TIME_NOW=$(discendingTime)
HOST=$1
PORT=$2
USER=$3
DATABASE=$4
DB_FILE=$5-${DATABASE}-${TIME_NOW}
// http://www.uel.br/projetos/matessencial/superior/calculo/cilide/cilide00.htm
// http://www.uel.br/projetos/matessencial/superior/calculo/cilide/cilide00.js
function testa_entrada(form, button) {calcula_volume(form);return;}
// r = raio da base do cilindro, h = altura do liquido
// L = comprimento do cilindro, A = área e V = volume
function calcula_volume(form) {
if(form.entrada1.value=="" || form.entrada1.value==" " || form.entrada1.value=="0" || form.entrada2.value=="" || form.entrada2.value==" " || form.entrada2.value=="0" || form.entrada3.value=="" || form.entrada3.value==" " || form.entrada3.value=="0")
{alert("Existe alguma medida nula. Preencha as caixas de modo correto.");
return;
}
#/usr/bin/python
import math
r = 47.5
h = 23.75 # 47.5 #95.0
L = 150.0
if h > 2*r:
print "'h' nao pode ser maior que 'r'"
exit()
A_t = math.pi * math.pow(r, 2)
V_t = A_t * L
#!/usr/bin/python
def getBinStr(num, dig):
return format(num, '#0'+str(dig+2)+'b')
def getHexStr(num, dig):
return '0x{0:0{1}X}'.format(num, dig)
@rogersguedes
rogersguedes / public-ip-tracker.sh
Created October 15, 2019 13:41
This script check your public IP on checkip.dyndns.org and logs its changes
#/bin/bash
LOGFILE_NAME=whatismyip.log
GATEWAY_IP=192.168.0.1
IP_PAGE_URL=checkip.dyndns.org
LAST_IP=`curl -s ${IP_PAGE_URL} | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`
echo "Initial IP: ${LAST_IP}"
while true
@rogersguedes
rogersguedes / openocd-config-backup.sh
Created September 12, 2019 13:36
this scripts copies the first file modified in current folder. It was used to backup a config file generated by SW4STM32 during the OpenOCD firmware upload invocation.
#!/bin/bash
# this scripts copies the first file modified in current folder. It was used to backup a config file generated by
# SW4STM32 during the OpenOCD firmware upload invocation.
# 'inotifywait' binary is part of 'inotify-tools' package on Ubuntu 18.04.1 LTS
EVT_OUTPUT=`inotifywait -e modify,create,delete -r .`
FILE_NAME=`echo ${EVT_OUTPUT} | sed "s/[^ ]\+\s\+[^ ]\+\s\+\([^ ]\+\)/\1/g"`
cp ${FILE_NAME} ${FILE_NAME}.bak
@rogersguedes
rogersguedes / gs.sh
Created August 28, 2019 20:33 — forked from esrever10/gs.sh
gstreamer send and receive h264 rtp stream
# linux send h264 rtp stream:
gst-launch-1.0 -v ximagesrc ! video/x-raw,framerate=20/1 ! videoscale ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000
# Macos send h264 rtp stream:
gst-launch-1.0 -v avfvideosrc capture-screen=true ! video/x-raw,framerate=20/1 ! videoscale ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000
# receive h264 rtp stream:
gst-launch-1.0 -v udpsrc port=5000 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! autovideosink