Skip to content

Instantly share code, notes, and snippets.

View davestevens's full-sized avatar

Dave Stevens davestevens

View GitHub Profile
#!/usr/bin/perl
# read from object file, output all variable names and types.
# object needs to be compiled with -g CFLAG
if($ARGV[0] eq '') {
print "need to specify an objectfile\n";
}
else {
$objfile = $ARGV[0];
@davestevens
davestevens / perlObf.pl
Created April 15, 2011 16:04
Quick way to mangle variable names in a Perl script
#!/usr/bin/perl
# run with;
# perl perlObf.pl inputFile.pl > outpuFile.pl
use Digest::MD5 qw(md5_hex);
while( <> ) {
while(/([\$\%\@]#?)([A-Za-z]\w+)/gm) {
if($2 ne 'ARGV') {
@davestevens
davestevens / bandcamprip.js
Created April 25, 2011 21:13
Get links to music in bandcamp
javascript:(function(){
var TEMP = -1;
var HTML = '';
while(mine = TralbumData.trackinfo[++TEMP]) {
HTML += '<a href="' + mine.file + '" target="_blank">' + mine.title + '</a><br/>' + "\n";
}
var newdiv = document.createElement('div');
newdiv.setAttribute('id', 'helloWorld');
newdiv.style.background = "#000";
newdiv.innerHTML = HTML;
@davestevens
davestevens / crap.c
Created May 27, 2011 19:15
3 Dimensional static array with pointer access
#include <stdio.h>
#define ONE 5
#define TWO 2
#define THREE 3
typedef struct {
unsigned int temp;
} rah;
@davestevens
davestevens / admin.php
Created June 9, 2011 09:39
Example of preg_match
<?php
/* test regex */
$input[] = 'admin/';
$input[] = 'mens-books';
$input[] = 'admin/foo';
$input[] = 'foo/bar';
$input[] = 'min';
$input[] = 'admin';
@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();
@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 / 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 / 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 / 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);