Skip to content

Instantly share code, notes, and snippets.

View sambatyon's full-sized avatar

Alexander Rojas sambatyon

View GitHub Profile
@sambatyon
sambatyon / rgb2yuv.cc
Created February 13, 2012 16:02
Transforms a bitmap int RGB 8:8:8 24bpp into an equivalent YUV420p 4:2:0 12bpp
void Bitmap2Yuv420p(boost::uint8_t *destination, boost::uint8_t *rgb,
const int &width, const int &height) {
const std::size_t image_size = width * height;
boost::uint8_t *y = destination;
boost::uint8_t *u = destination + image_size;
boost::uint8_t *v = destination + image_size + image_size / 4;
boost::uint8_t *r = rgb;
boost::uint8_t *g = rgb + 1;
boost::uint8_t *b = rgb + 2;
@sambatyon
sambatyon / .bashrc
Created February 13, 2012 19:15
My own bashrc file
if [ -n "$PS1" ]; then
alias ls='ls -h --color'
alias grep='grep --color'
alias egrep='egrep --color'
alias fgrep='fgrep --color'
else
alias ls='ls -h'
fi
alias ll='ls -l --group-directories-first'
@sambatyon
sambatyon / Sha1Sum.cc
Created February 13, 2012 19:17
Small function to compute the sha1 sum of data in c++
#include <boost/uuid/sha1.hpp>
#include <sstream>
#include <cstddef>
#include <string>
std::string Sha1sum(void *data, std::size_t count) {
boost::uuids::detail::sha1 hasher;
char hash[20];
hasher.process_bytes(data, count);
unsigned int digest[5];
@sambatyon
sambatyon / .emacs
Last active February 19, 2019 12:42
Latest OS agnosic version
;;; package -- Sumary
;;; Commentary:
;;; Code:
;;; Set load path
(add-to-list 'load-path "~/.emacs.d/custom/")
;;;; PACKAGE SYSTEM
;; For some reason, this must be one of the first things to be loaded.
(require 'package)
@sambatyon
sambatyon / save-jpeg.cc
Created July 24, 2012 14:04
Encode an rgb to jpeg and save it to a buffer
void EncodeJPEG(boost::uint8_t *rgb, const int &width, const int &height,
boost::shared_array<boost::uint8_t> &outbuffer, int *size) {
jpeg_compress_struct cinfo = {0};
jpeg_error_mgr jerror = {0};
jerror.trace_level = 10;
cinfo.err = jpeg_std_error(&jerror);
jerror.trace_level = 10;
cinfo.err->trace_level = 10;
jpeg_create_compress(&cinfo);
@sambatyon
sambatyon / joinpdf.sh
Last active November 9, 2021 16:25
small scripts used to create a full pdf document.
#!/bin/bash
if [[ `uname` =~ MINGW.* ]]; then
GS=gswin64c
else
GS=gs
fi
output=$1
shift
@sambatyon
sambatyon / gist:9134348
Created February 21, 2014 13:37
Extracts headers from a source tree.
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: extractheaders src dest"
exit
@sambatyon
sambatyon / redistribute.js
Last active August 29, 2015 13:56
Translates a list of numbers assumed to be distributed normally to another normal distribution with the required mean and standard deviation.
function redistribute(numbers, new_mean, new_std_deviation) {
// compute the mean of the list of numbers
// μ = (Σ x_i) / n
var sum = 0;
numbers.forEach(function (i) {sum += i});
var mean = sum / numbers.length;
// compute the std deviation of the numbers:
// σ = √(Σ (x_i - μ)² / n)
sum = 0;
@sambatyon
sambatyon / .bashrc
Last active August 29, 2015 13:57
msys configuration files with git support
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \$ '
#\[\033]0;$MSYSTEM:\w\007 \033[32m\]\u@\h \[\033m\w$(__git_ps1)\033[0m\] $
# If not running interactively don't do anything
case $- in
*i*) ;;
*) return;;
esac
@sambatyon
sambatyon / extractheaders.sh
Created May 30, 2014 07:26
Extract Headers from folder keeping structure
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: extractheaders src dest"
exit
fi
orig_dir=`pwd`
origin=$1