Skip to content

Instantly share code, notes, and snippets.

View davestevens's full-sized avatar

Dave Stevens davestevens

View GitHub Profile
@davestevens
davestevens / dec_to_str.pl
Created December 6, 2012 20:26
Convert decimal numbers to string and vice versa
#!/usr/bin/perl
use strict;
# Kind of useless script to convert numbers to their word equivalent and back
# Call dec_to_str() with a decimal value, returns a string containing the word equivalent
# eg. dec_to_str(123456) := one hundred and twenty three thousand four hundred and fifty six
# Call str_to_dec() with a number in words, returns decimal value
@davestevens
davestevens / libxml2_error.c
Created July 3, 2012 10:05
Error produced by libxml2 when unlinking and linking xmlNodes from different xmlDocs and attempting to free the xmlDocs.
#include <stdio.h>
#include <libxml/parser.h>
/* compile:
gcc -m32 libxml_error.c `xml2-config --libs` `xml2-config --cflags` -Wall -Wextra -pedantic
*/
/* example xml input file
<?xml version="1.0"?>
<A>
@davestevens
davestevens / combinations.pl
Created June 24, 2012 14:07
Attempt to display all combinations of data set
#!/usr/bin/perl
use strict;
use Data::Dumper;
my @b = (['a','b'],['c','d'],['e','f']);
my @all;
my @single;
&rec(0, \@all, \@single, @b);
@davestevens
davestevens / publications.bib
Created March 21, 2012 13:30
BibTeX bibliography of publications
%% This BibTeX bibliography file was created using BibDesk.
%% http://bibdesk.sourceforge.net/
%% Created for dave stevens at 2012-03-21 13:28:29 +0000
%% Saved with string encoding Unicode (UTF-8)
@davestevens
davestevens / gist:2118282
Created March 19, 2012 16:31
Set stack pointers for each cpu in leon3mp
!! Instructions for adding assembly code for leon3mp to setup stack pointers for each available CPU.
!! Running sparc-elf-gcc includes some system files in the final elf file, but editing these it is possible to set the stack pointer for each CPU before main is entered.
!! Edit the file sparc-elf-*.*.*/src/libgloss/sparc_leon/crt0.s
!! Add in the following assembly beneath the _start: label
! added code for setting stack pointer for each cpu
rd %asr17, %g5 ! load in configuration reg into g5
srl %g5, 28, %g5 ! shift so only cpuid is seen
@davestevens
davestevens / linkedList.c
Created January 27, 2012 17:05
Simple linked list implementation in C.
#include <stdio.h>
#include <stdlib.h>
typedef struct elementT {
unsigned value;
struct elementT *next;
} elementT;
elementT *removeElement(elementT *, unsigned);
elementT *addElement(elementT *, unsigned);
@davestevens
davestevens / why.js
Created January 22, 2012 22:07
js isn't doing what i think it should be doing?
<html>
<head>
<script src="jquery.min.js"></script>
<script>
var rah;
var output = [];
/* i would assume that output would be the same as input
but the outcome is the a->a2->a3->a4 rather than a->a2, a->a3, a->a4
*/
@davestevens
davestevens / broken.c
Created January 12, 2012 16:09
broken code gen
/*
This is a stripped down piece of code from a code generator.
It works in GCC but with another compiler I'm using is fails, its a real corner case though.
If there was only one struct (structure) then it wouldn't be a problem, when there is more than one it messes up.
The fact that the static structures foo and bar are defined and then redefined causes a problem in the assembly output. GCC doesn't seem to mind this and the function pointer is correct. The VEX assembly will output 2 memory areas with the same tag, one empty and one with the correct data.
Question: what should be the proper behaviour of this? The code is technically redefining the structures, but GCC gives no compiler warnings? Are structs different for defining?
Or would you say this is bad coding?
*/
typedef struct structure {
@davestevens
davestevens / unsignedRightShift.c
Created January 9, 2012 09:49
Best way to unsign right shift a signed integer?
int unsignedRightShift(int input, char shift) {
if(shift == 0) {
return input;
}
return (((input >> 1) & 0x7fffffff) >> (shift - 1));
}
@davestevens
davestevens / example.cpp
Created October 22, 2011 10:40
no description
#include <iostream>
#include <stdlib.h>
using namespace::std;
class testClass {
public:
string myString1;
char *myString2;
unsigned myInt;
testClass();