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 / 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);
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_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
@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 / 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 / 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: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 / killport.sh
Last active February 25, 2019 16:49
Kill all processes running on port passed to killport (e.g. 'killport 8080')
# Add this to your .zshrc file (or equivalent)
# Kills all processes running on a given port
# Usage: killport <port>
function killport() {
lsof -i:$1 | grep LISTEN | awk '{print $2}' | xargs kill -9
}
@rasgo-cc
rasgo-cc / heroku_dotenv.sh
Last active March 18, 2019 01:53
Fetch Heroku config vars and save them into a dotenv file
#!/bin/bash
# Usage: heroku_dotenv.sh <heroku_app_name> <dotenv_file>
# Default dotenv_file: .env
dotenv=${2-".env"}
heroku config -a $1 |
sed -n '1!p' |
awk '{ gsub(/:/,"", $1); f=$1; $1=""; print f"="substr($0,2) }' > $dotenv
cat $dotenv
echo "File written: $dotenv"
@rasgo-cc
rasgo-cc / docker-ip.sh
Last active March 18, 2019 02:46
IP address of Docker container
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $1