Skip to content

Instantly share code, notes, and snippets.

View rasgo-cc's full-sized avatar
🎯
Focusing

Mario Ribeiro rasgo-cc

🎯
Focusing
View GitHub Profile
@rasgo-cc
rasgo-cc / docker_build_stop.sh
Last active May 1, 2019 12:43
Bash functions to build/stop/remove Docker images/containers
#!/bin/bash
DOCKERFILE=Dockerfile.dev
build_image() {
# Uncomment if you don't want to build an image if it already exists
#if [ ! "$(docker image ls | grep $1)" ]; then
echo "Build"
docker build . -t $1 -f $DOCKERFILE
#fi
@rasgo-cc
rasgo-cc / main.c
Last active November 14, 2015 00:29
Assign a new value to j based on i and previous value of j
uint32_t i = 999999999;
uint32_t j = 1;
for( ; i > 0 ; i--) j += i;
printf("j final value: %u\n", j);
@rasgo-cc
rasgo-cc / main.c
Last active November 14, 2015 00:29
Assign a new value to j based on i
uint32_t i = 999999999;
uint32_t j = 1;
for( ; i > 0 ; i--) j = i;
@rasgo-cc
rasgo-cc / main.c
Last active November 14, 2015 00:28
Decrement integer without volatile
#include <stdio.h>
#include <stdint.h>
#include <time.h>
int main()
{
puts("Lets go");
time_t t;
int elapsed_time = time(&t);
@rasgo-cc
rasgo-cc / octave_squarewave.m
Created September 13, 2015 01:39
Comparing a perfect square wave with a real and imperfect one
clear all
close all
clc
pkg load signal;
Ns = 4096;
t_max = 0.1;
Ts = t_max / 4096;
Fs = 1/Ts;
t = linspace(0, t_max, Ns);
@rasgo-cc
rasgo-cc / fixed_point_mul_div.c
Last active August 29, 2015 14:24
Fixed-point multiplication and division
// http://theramblingness.com
#include <stdio.h>
#include <stdint.h>
#define Qn 15 // Q-format
// These types should be defined according to CPU bitness
#define FXPLONG int64_t
#define FXPSHORT int32_t
op1 = (int32_t)(f_op1*(double)scaler); // op1 in Qn format
op2 = (int32_t)(f_op2*(double)scaler); // op2 in Qn format
// Convert the dividend to Q(2*n) format
tmp = ((uint64_t)op1 << Qn);
// Round by summing half the divisor
tmp += op2 >> 1;
// Division
tmp /= (uint64_t)(op2);
@rasgo-cc
rasgo-cc / fixed_point_mult.c
Last active August 29, 2015 14:23
Fixed-Point Multiplication
// http://theramblingness.com
#include <stdio.h>
#include <stdint.h>
#define Qn 31
int main()
{
// Variables
uint32_t scaler = (uint32_t)(1<<Qn);