Skip to content

Instantly share code, notes, and snippets.

View andrestc's full-sized avatar
⛑️
Firefighting

André Carvalho andrestc

⛑️
Firefighting
View GitHub Profile
@andrestc
andrestc / robot.js
Created December 2, 2012 15:08
Robotnik
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot;
robot = ev.robot;
robot.ahead(150);
@andrestc
andrestc / .bash_profile
Last active March 21, 2016 12:32
Colored bash_profile with git branch and aliases
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' -e 's/^[ \t]*//'
}
export PS1="\[\033[36m\]\u\[\033[m\]:\[\033[33;1m\]\w\[\033[m\]:\[\033[00m\]\[\033[31m\]\$(parse_git_branch)\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=GxFxBxDxCxegedabagacad
alias ls='ls -GFh'
# Git aliases
# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# split panes using | and -
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %
@andrestc
andrestc / magic.go
Created May 26, 2017 14:38
reboot(2) magic numbers
package main
import (
"fmt"
"strconv"
)
func main() {
consts := []int64{672274793, 85072278, 369367448, 537993216}
for _, c := range consts {
#include <fcntl.h>
#include "tlpi_hdr.h"
#include "error_functions.c"
#include "get_num.c"
int main(int argc, char *argv[])
{
int outputFd, openFlags;
mode_t filePerms;
off_t offset;
int i, holes = 0;
while ((numRead = read(inputFd, buf, BUF_SIZE)) > 0)
{
if (keepHoles == 1) {
for (i = 0; i < numRead; i++) {
if (buf[i] == '\0') {
holes++;
continue;
} else if (holes > 0) {
lseek(outputFd, holes, SEEK_CUR);
@andrestc
andrestc / malloc_test.c
Last active June 14, 2017 15:31
malloc
#include <malloc.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
malloc(atoi(argv[1]));
}
void *
_malloc(size_t size)
{
void *block_mem;
block_t *ptr, *newptr;
size_t alloc_size = size >= ALLOC_UNIT ? size + sizeof(block_t)
: ALLOC_UNIT;
ptr = head;
while (ptr) {
if (ptr->size >= size + sizeof(block_t)) {
/* scan_merge scans the free list in order to find
* continuous free blocks that can be merged and also
* checks if our last free block ends where the program
* break is. If it does, and the free block is larger then
* MIN_DEALLOC then the block is released to the OS, by
* calling brk to set the program break to the begin of
* the block */
void
scan_merge()
{
Verifying that "andrestc.id" is my Blockstack ID. https://onename.com/andrestc