Skip to content

Instantly share code, notes, and snippets.

View jrenner's full-sized avatar

Jon Renner jrenner

  • Minneapolis, Minnesota, USA
View GitHub Profile
@jrenner
jrenner / dec_convert.c
Created June 15, 2012 04:15
Convert decimal to hex and binary in C
#include <stdio.h>
#include <math.h>
int main (){
char large_text[100];
int i = 0;
char c;
printf("\nInput: ");
for (i = 0;(c = getchar()); i++){
@jrenner
jrenner / highlight_search.c
Created July 15, 2012 13:08
Searching track names for keywords, then putting brackets around them in C
#include <stdio.h>
#include <string.h>
char* highlight_word(char* text, char* word, char* final);
int main(int argc, char *argv[]){
char tracks[][80] = {"i am not a dog you fool",
"what do you mean by this, bear?",
"now this is a silly situation",
@jrenner
jrenner / Test.txt
Created July 19, 2012 09:31
I test things
What do you think about bears in forests?
I for one, am avgains them.
@jrenner
jrenner / strcat.c
Created July 23, 2012 14:53
custom strcar() in C
#include <stdio.h>
#include <string.h>
#define STRINGSIZE 80
int cat(char *a, const char* b, const size_t max_size)
{
//puts("FUNCTION BEGIN");
size_t size = strlen(a);
a += size;
while (*b)
@jrenner
jrenner / countchars.c
Created August 19, 2012 12:42
count number of chars in a string and display by rank
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int** count_chars(char *s)
{
int **counts = (int**)malloc(256 * sizeof(int) * sizeof(char));
int i;
for(i = 0; i < 256; i++)
{
@jrenner
jrenner / unsafe.go
Created September 21, 2012 04:14
Can't convert unsafe.Pointer to int
func getPixel(surface *sdl.Surface, x, y int) uint32 {
var bpp uint8 = surface.Format.BytesPerPixel
/* Here p is the address to the pixel we want to retrieve */
var p *uint32 = *uint32(int(surface.Pixels) + y*int(surface.Pitch) + x*bpp)
return *p
return 1 /* shouldn't happen, but avoids warnings */
}
@jrenner
jrenner / autounit_test.py
Last active December 15, 2015 03:29
A script for testing glances' autoUnit function
#!/usr/bin/python
__author__ = 'jrenner'
import random
import sys
"""
This script is useful for testing the autoUnit function. It is not guaranteed
to be the same as in glances.py. You may need to copy and paste the exact
code you want to test from glances.py
#!/usr/bin/python
# test memory info from a glances server
import xmlrpclib
import sys
if len(sys.argv) < 2:
print "Please give 'host:port' as argument"
sys.exit()
host = sys.argv[1]
print "Getting data from " + host
@jrenner
jrenner / box2d_air_resistance.java
Last active January 14, 2022 04:30
box2d air resistance
float dragForce;
Vector2 appliedDrag = new Vector2();
float dragAngle;
float p, A, Cd, v; // elements of the formula see wikipedia entry for Drag (physics)
/*
ρ is the density of the fluid,
v is the speed of the object relative to the fluid,
A is the cross-sectional area
Cd is the drag coefficient – a dimensionless number.
sample drag co-efficients (http://en.wikipedia.org/wiki/Drag_coefficient)
@jrenner
jrenner / sigsegv.txt
Created May 5, 2013 07:52
libgdx box2d block allocator SIGSEGV
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f7e0ad30504, pid=10789, tid=140178498938624
#
# JRE version: 7.0_21-b11
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.21-b01 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libgdx64.so+0x23504] b2BlockAllocator::Allocate(int)+0x54
#