-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|535|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-



HoboBen

naturaltime.py

26th March 2016

human readable time deltas for Python


HoboBen

Better C error handling with goto and macros

1st December 2012

I use gotos for error handling in C. (yes this is a valid use for gotos). It allows me to jump to any point in cleanup section.

For a good example, see StackOverflow: [url]http://stackoverflow.com/questions/788903/valid-use-of-goto-for-error-management-<snip>


HoboBen

Exact supported OpenGL texture sizes

23rd June 2011

To get an idea of the maximum size textures your graphics card supports, you can use "proxy textures" in OpenGL 1.1 and above.

This can depend on the specific implementation of your textures, which is why this can't always be known in advance.<snip>


HoboBen

Circular Buffer (C)

22nd April 2011

A fast fixed-size buffer. which you can pretend is "infinite memory" for data that you don't care too much about.

When you write to it, it fills up until you start overwriting the oldest data. When reading, it returns the oldest data it has.
<snip>


HoboBen

Bi-directional C and Lua

12th January 2011

Just the simplest of examples. A C host program runs a Lua script, gets and sets the script's variables, runs the script's functions, and provides a C function for the script to call.

(Lua 5.1)

bidirectional.lua
[code] FirstName = "Unse<snip>


HoboBen

Convert a double to bytes and back in C

6th December 2010

By using a C union data structure, it's simple to convert a double to its raw bytes and back.

Note that the actual order of bytes varies depending on machine endianness.

[code] #include <stdlib.h>
#include <stdio.h>

union {
doub<snip>


HoboBen

Algorithm to Draw a Line of Arbitrary Thickness

4th September 2010

By modifying Bresenham's line algorithm to plot rectangles instead of pixels, it is possible to draw lines of any thickness.

[code] Program
Uses
pure2d,
keyset

<snip>


HoboBen

Parse point-pair string

3rd September 2010

Using a simple parser, extract the point-pairs from a string such as:

"-850.5,75.0 958,137.5 958,-262.5 850,325 742,262.6 742,137.5"

By using a simple tokenizer/lexer, we can safely catch all errors. And it's much more readable and maintain<snip>


HoboBen

PHP robots.txt access parser

8th August 2010

Reads a robots.txt file and attempts to discover if a given robot is permitted to access a given file on the server.

[code] <?php

/*
* robots.php
*
* Author: ben@tophatstuff.co.uk
* Date: 2010-08-08
*
* R<snip>


HoboBen

Wikipedia/MediaWiki API example

7th August 2010

Short examples showing how to get information from MediaWiki (e.g. Wikipedia) websites


HoboBen

Fast text wrapping

7th July 2010

Fast - Tries to do as little string manipulation as possible.

[code] Program
Uses
keyset,
pure2d

Const
WT_ARRAY_SIZE = 1024
LINE_SPACING = 1.0

Var
breakPoint: Array [WT_ARRAY_SIZE] of Integer
breakPo<snip>


HoboBen

Generate english place names

13th June 2010

A set of rules for programatically generating English-sounding place names.

[code] town = *ton, *tone, *ham, *shire, *by, *cot, *cott, *cotte, *stoke, *stow, *wick, *wich, *worth, *eaton, *folk
castle = *bury, *borough, *brough, *burgh, *burh, *ch<snip>


HoboBen

Simple Random Terrain Generator

14th May 2010

Simple fractal random terrain generation. Less than 100 lines of code, including displaying to screen. Adjustable turbulence.

[code] {
By Ben Golightly 2010, tophatstuff.co.uk
Feel free to modify and use with or without credit
}
Program
<snip>


HoboBen

A* Path finding - Cobra

7th March 2010

wikipedia had a great bit of psuedo code for A* Pathfinding, I quickly translated it into cobra:

Required file: (save as map.png)

<snip>


HoboBen

PHP: daysBetween(date1, date2)

26th November 2009

|edit| Fixed, hopefully! |edit|

function daysBetween($date1, $date2)

returns an array of dates containing every day between $date1 and $date2 in YYYYMMDD format.

[code]
<?php
<?php

/*
* Updated 20091127
*
*
*
* function<snip>


HoboBen

Mergesort a linked list

26th August 2009

Mergesort is a sorting algorithm that is especially suited to sorting linked lists.

Note: You really, really don't want to sort any lists that contain strings!!!

Feel free to use for any purpose, with or without attribution.

[code] {
<snip>


HoboBen

Get Router Port Range Forwarding Rules

12th October 2008

For a Linksys WRT54GS router


HoboBen

Point-Line Distance

11th July 2008

Needed this for my shmup, I figured I may as well post it in case it comes in handy.

function DistancePointLine(px: Real, py: Real, x1: Real, y1: Real, x2: Real, y2: Real): Real

Returns the smallest distance between a point and a line


[code] Un<snip>


HoboBen

LNK Resolver

21st April 2008

Contains functions to resolve windows shortcut (.lnk) files.


HoboBen

FlipMesh

13th October 2007



This applies a transformation matrix that flips a mesh in Cobra3D inside out.


HoboBen

Justified Text

14th June 2007

Center text horizontally or vertically.


HoboBen

String To Uppercase

21st April 2007

Simple and light


HoboBen

Breadcrumb Naviation

23rd March 2007

Hmmm, bread crumbs!


HoboBen

Intelligent Cobra LoadImage

18th February 2007

Checks if the image exists at the path specified, and if it does, checks if it loads OK, then passes the element back via the Cobra "result" variable.

On an error, it displays a message box and requests an exit.

[code] function LoadImageC(imgpath:st<snip>


HoboBen

(Less) Simple BAT command promt

20th January 2007

Command prompt bat file.

More - Older Posts