Skip to content

Instantly share code, notes, and snippets.

View mrpossoms's full-sized avatar

mrpossoms

  • Loveland CO
View GitHub Profile
@mrpossoms
mrpossoms / ssss.c
Created October 3, 2015 19:06
Super Stupid Simple Sort
void sort(int* arr, int len)
{
for(int i = 0; i < len; ++i){
for(int j = len - 1; j > i; j--){
if(arr[i] > arr[j]){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
@mrpossoms
mrpossoms / IpsumTest.c
Created February 20, 2015 15:04
Test for memory allocators that recursively builds lorem ipsum strings, that effectively double in length for each level of depth.
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
void* myAlloc(void* optionalParam, size_t bytes)
{
// as an example, we will use malloc()
return malloc(bytes);
void __dump(void* buf, int len){
int i = 0;
for(i = 0; i < len; i++){
char str[16];
sprintf(str, "%02x ", ((char*)buf)[i] & 0xff);
write(1, str, strlen(str));
}write(1, "\n", 1);
}
static inline int bet(float a, float m, float b){
return fabs(a - m) + fabs(m - b) == fabs(a - b);
}
typedef float vec2[2];
typedef struct{
vec2 p;
vec2 n;
} ray2;
static inline void vec2_add(vec2 r, vec2 a, vec2 b){
@mrpossoms
mrpossoms / JS String formatting
Created April 8, 2014 20:03
Convenient format strings
"".__proto__.format = function(params){
var temp = this;
for(var i = params.length; i--;)
temp=temp.replace("{"+i+"}",params[i]);
return temp;
};
// ___ _
// | __|_ ____ _ _ __ _ __| |___
@mrpossoms
mrpossoms / matrix.js
Created March 28, 2014 03:22
Basic matrix
// ___ _ _ _ _ _
// / __| |___| |__ __ _| | | |_ ___| |_ __ ___ _ _ ___
// | (_ | / _ \ '_ \/ _` | | | ' \/ -_) | '_ \/ -_) '_(_-<
// \___|_\___/_.__/\__,_|_| |_||_\___|_| .__/\___|_| /__/
// |_|
var rot2d = function(theta, size){
// construct a result matrix
var r = new Array(size);
for(var i = size; i--; ){
r[i] = Array
@mrpossoms
mrpossoms / linkedlist.js
Created March 25, 2014 19:16
Javascript Linked List
function ll(){
this.last = this.first = null;
this.add = function(value){
node = {value: value, next: null, prev: this.last};
this.first = this.first ? this.first : node;
if(this.last) this.last.next = node;
this.last = node;
return node;
};
@mrpossoms
mrpossoms / genalg
Created March 24, 2014 15:02
Hello genetic algorithims.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using C5;
namespace GeneticHelloWorld
{
class Program
{
@mrpossoms
mrpossoms / test.pde
Created February 22, 2014 18:26
UART SPI bridge test
/*Basic Sketch to Setup the SC16IS750 and
test transmitting and revceiving characters
UART Setup
-9600bps baudrate
-8 data bits
-1 stop bit
-No Parity
-No RTS,CTS
-Enable FIFO w/o extra features