Skip to content

Instantly share code, notes, and snippets.

View vicentebolea's full-sized avatar
🎯
Focusing

Vicente Bolea vicentebolea

🎯
Focusing
View GitHub Profile
@vicentebolea
vicentebolea / git_correct_email.sh
Created January 31, 2017 07:29
Correct the email and name in a git repository
#!/bin/sh
git filter-branch -f --env-filter '
OLD_EMAIL="vicentebolea@gmail.com"
CORRECT_NAME="Vicente Adolfo Bolea Sanchez"
CORRECT_EMAIL="vicente.bolea@gmail.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
@vicentebolea
vicentebolea / gist:43a03112c6159eb21453
Created January 27, 2016 04:00 — forked from digitaljhelms/gist:4287848
Git/GitHub branching standards & conventions

Branching

Quick Legend

Description, Instructions, Notes
Instance Branch
@vicentebolea
vicentebolea / terminal_statusbar.c
Created May 20, 2014 06:26
A simple status bar for terminal using ANSI escape sequences
#include <stdio.h>
#include <unistd.h>
#include <string.h>
void statusbar_to_stdout (const char * item, int percentage) {
int i, pos;
char per_bar [50 + 1] = {'-'};
if (percentage > 100) percentage %= 100;
pos = percentage / 2;
printf ("\e[?25l"); // Hide cursor
@vicentebolea
vicentebolea / ip_of
Created July 29, 2013 20:06
Get local ip of network interface of an UNIX system in C.
//! EX: char* my_ip = ip_of ("eth0");
#include <ifaddrs.h>
char* ip_of (const char* interface) {
static char if_ip [INET_ADDRSTRLEN];
struct ifaddrs *ifAddrStruct = NULL, *ifa = NULL;
getifaddrs (&ifAddrStruct);
@vicentebolea
vicentebolea / LRU_cache.c
Created May 9, 2013 15:17
A LRU cache written in C
#include <string.h>
#include <uthash.h>
// this is an example of how to do a LRU cache in C using uthash
// http://uthash.sourceforge.net/
// by Jehiah Czebotar 2011 - jehiah@gmail.com
// this code is in the public domain http://unlicense.org/
#define MAX_CACHE_SIZE 100000
@vicentebolea
vicentebolea / reset_stdout_orientation
Created December 31, 2012 03:26
Reset the stdout stream with the porpose of reset the orientation of stdout in order to alternate between printf and wprintf
/*
* Reset the stdout stream with the porpose
* of reset the orientation of stdout in order
* to alternate between printf and wprintf
*/
void reset_stdout_orientation (void) {
freopen ("/dev/stdout", "a", stdout);
}
@vicentebolea
vicentebolea / bin_to_str
Last active December 10, 2015 09:49
write in binary an int in a string
/*
* It assume that the string is at maximum of 32 bits,
* also assume that the binary has maximum 32 bits width
*/
void bin_to_str (int binary, char* str, size_t size) {
if (size != 32 && size != 16 && size != 8) return;
int i;
for (i = 1; i <= size; i++)
str [size-i] = (binary & (1<<(i-1))) ? '1': '0';
}
@vicentebolea
vicentebolea / gist:4375227
Created December 25, 2012 20:20
Aggregation vs composition OOP
simple rule:
we have object A and object Z.
if we have a pointer from object A to object Z then its aggregation.(no pointing from Z to A ,since it maks a simple relation).
if object Z cannot exists in the system without object A, then its composition.
its not that hard, even more ITS NOT THAT USEFUL. why? beacuse no body uses this stuff to the fine lines, its a loose model that lets you grasp what you want from the system.