Skip to content

Instantly share code, notes, and snippets.

@masterl
masterl / int_binary_visualization.c
Created June 2, 2017 05:01
Integer (int) binary visualization fun
#include <stdio.h>
#include <stdlib.h>
char *int_binary_to_str( int const value );
void test_int( int const value );
int main( void )
{
test_int( 5 );
@masterl
masterl / memory_binary_visualization.c
Created June 2, 2017 04:59
In-Memory binary visualization fun
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
char *binary_as_string( void const *data, size_t data_size );
void write_byte_to_string( char *str, unsigned char const *byte );
void test_int( int const value );
void test_char( char const value );
void test_float( float const value );
@masterl
masterl / scanf_wrong_length.c
Created January 1, 2016 18:05
Short source demonstrating the effects of using the wrong specifier on scanf
// The MIT License (MIT)
// Copyright (c) 2016 Leonardo de Oliveira Lourenço
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@masterl
masterl / .tmux.conf
Last active December 7, 2015 18:44
Conf file for tmux
# Shortcut for reloading config
bind r source-file ~/.tmux.conf \; display "Config Reloaded!"
# Terminal name
set -g set-titles on
set -g set-titles-string "#(whoami)::#h::#(curl ipecho.net/plain;echo)"
# Status bar customization
set -g status-utf8 on
set -g status-bg black
@masterl
masterl / .clang-format
Created July 28, 2015 03:38
Clang-format file I use
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: 0
AlignAfterOpenBracket: true
#AlignConsecutiveAssignments: true
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
@masterl
masterl / autotest.sh
Last active November 18, 2015 12:42
Automated on-save test runner
#!/bin/bash
find `pwd` | grep "[.][ch]$" | grep -v "/.git/" | entr sh -c 'make test'
@masterl
masterl / generic_fields_struct.c
Created June 10, 2015 03:49
Struct with generic fields defined on runtime
// The MIT License (MIT)
// Copyright (c) 2015 Leonardo de Oliveira Lourenço
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@masterl
masterl / substr.c
Last active August 29, 2015 14:20
Helping out to fix a C substring generator
// The MIT License (MIT)
// Copyright (c) 2015 Vanderci Curvelo Jr, Leonardo de Oliveira Lourenço
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@masterl
masterl / ignoring_align.c
Last active August 29, 2015 14:19
C Error (alignment)
// The MIT License (MIT)
// Copyright (c) 2015 Leonardo de Oliveira Lourenço
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@masterl
masterl / pointer_arithmetic_example.c
Last active December 20, 2015 04:27
Pointer arithmetic
// The MIT License (MIT)
// Copyright (c) 2015 Leonardo de Oliveira Lourenço
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: