Skip to content

Instantly share code, notes, and snippets.

View Bigcheese's full-sized avatar

Michael Spencer Bigcheese

View GitHub Profile
.syntax unified
.cpu cortex-m3
.fpu softvfp
.thumb
.global g_pfnVectors
.global Default_Handler
.section .text.Reset_Handler
.weak Reset_Handler
cmake_minimum_required(VERSION 2.8.10)
include(CMakeForceCompiler)
set(CMAKE_SYSTEM_NAME Generic)
CMAKE_FORCE_C_COMPILER(clang GNU)
CMAKE_FORCE_CXX_COMPILER(clang++ GNU)
project(badninja C)
@Bigcheese
Bigcheese / gist:6606668
Created September 18, 2013 09:20
Description of why there are 10 unique meshes for cables in MC mods.
/**
* There are 64 possible meshes, as each of the 6 sides can be either connected or not connected. In the following
* the connected state is treated as a 6 bit value where 0 indicates not connected and 1 indicates connected.
*
* 0 1 2 3 4 5
* (+x -x) (+y -y) (+z -z)
*
* To derive all the meshes, we first determine the number combinations of values for each number of bits set from 0
* to 6.
*
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
{
super.render(entity, f, f1, f2, f3, f4, f5);
setRotationAngles(f, f1, f2, f3, f4, f5, entity);
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
{
renderSide(orientation, true);
}
}
/**
* Sleeps for the specified number of milliseconds.
*/
protected void snooze( long milliseconds )
{
try
{
Thread.sleep( milliseconds );
}
catch( InterruptedException e ){}
@Bigcheese
Bigcheese / aligned_alloc.cpp
Last active December 17, 2015 06:19
C++Now code samples
#include <cassert>
#include <cstddef>
#include <cstdlib>
#include <memory>
void *aligned_alloc(std::size_t size, std::size_t alignment) noexcept {
std::size_t alloc_size = size + std::size_t(alignment) + sizeof(void *) - alignof(std::max_align_t);
void *alloc = std::malloc(alloc_size);
if (!alloc)
return nullptr;
@Bigcheese
Bigcheese / gist:5529530
Last active December 17, 2015 01:38
Bit hacks library API design.
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <limits>
enum class zero_behaivor {
undefined,
max,
width
};
bin/clang-3.3 :
section size addr
.interp 28 4194872
.note.ABI-tag 32 4194900
.note.gnu.build-id 36 4194932
.gnu.hash 173396 4194968
.dynsym 555384 4368368
.dynstr 1710192 4923752
.gnu.version 46282 6633944
.gnu.version_r 368 6680232
#define GLEW_STATIC
#include "GL/glew.h"
#include "GL/glfw3.h"
#include "glm/ext.hpp"
#include "glm/glm.hpp"
#include <cstdlib>
#include <functional>
#include <iostream>
@Bigcheese
Bigcheese / alignment.cpp
Created February 10, 2013 01:16
Adding alignment to the C++ type system.
// typealign is a type qualifier. It binds to the left, and only applies to
// types.
int typealign(16) foo; // Aligned int.
int foo typealign(16); // Error, typealign only applies to types.
typealign(16) int foo; // Same.
// But...
char buffer[32]; // How do I align buffer?