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




HoboBen

Text wrapping in Go

16th October 2019

[code]
package main
import (
''strings''
)
// wrap quickly word-wraps a string
// (source: (Linkage)
func wrap(message string, length int) string {
var atoms = strings.Fields(strings.TrimSpace(message))
var results = make([]str*snip*


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: stackoverflow.com
It just occurred to me that I could throw in a macro and automaticall*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.
Id*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 = ''Unset'';
S*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 {
double d; *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
Procedure BLine(x0: Integer, y0: Integer, x1: Integer, y1: Integer, color*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 maintainable*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
*
* Reads*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
breakPointS*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, *ches*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

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 daysBetwe*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]
{
Mergesort a l*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]
Unit
{
*snip*


HoboBen

LNK Resolver

21st April 2008

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


HoboBen

String To Uppercase

21st April 2007

Simple and light


HoboBen

Breadcrumb Naviation

23rd March 2007

Hmmm, bread crumbs!


HoboBen

(Less) Simple BAT command promt

20th January 2007

Command prompt bat file.


HoboBen

MouseIn Alternative

13th December 2006

A slightly modified version of Jayenkai's


HoboBen

Returning original colours from functions

12th December 2006

For handy remembrance of colours in functions


HoboBen

SSI Random Content

13th September 2006

Using Server Side Includes to display random content.

More - Older Posts