Skip to content

Instantly share code, notes, and snippets.

View creativenucleus's full-sized avatar

James R creativenucleus

View GitHub Profile
```ruby
# Author: JR
isbn_in = IO.readlines( 'books.txt' );
isbn_in.each { |n|
scan_digits = n.scan(/\d/)
scan_filtered = scan_digits.join;
Some Kind of Cosmic Jam
[James Rutherford, for TSC14 Poetry Slam]
=========================================
What is it *like* to be..
..a Toward a Science of Consciousness attendee?
To take a biennial pilgrimage
to sunny Tucson?
To drink in the talks
// Takes a string and returns a stub suitable for a URL
// Mostly tested ;)
private function stubify($string) {
// Replace anything that's not a whitelisted character...
$string = preg_replace('/[^(a-z0-9\s_\-)]/i', '', $string);
// Transform multiple spaces/underscores/dashes to dashes
$string = preg_replace('/[\s_\-]{1,}/', '-', $string);
// crc32 can give different results on 32 bit and 64 bit machines running PHP.
// If you have legacy stored CRC32 values to match against, this will convert them.
$crc32 = crc32($value);
if(PHP_INT_SIZE == 8) {
// recast to 32 bit CRC on 64 bit machines...
if($crc32 > 0x7FFFFFFF) { // Negative bit is set
$crc32 -= 0x100000000;
}
}
@creativenucleus
creativenucleus / snippet.lua
Last active January 22, 2023 13:33
TIC-80/Lua rotated filled ellipse
// d1,d2: ellipse width/height
// r: rotation
function ellipf(x,y,d1,d2,r)
-- i is the angle step. We increment this until we've passed 2*PI
i=0.2
for a=0,6.29+i,i do
x1,y1=rotate(x,y,d1,d2,r,a)
x2,y2=rotate(x,y,d1,d2,r,a+i)
tri(x,y,x1,y1,x2,y2,2)