Skip to content

Instantly share code, notes, and snippets.

View johnlettman-old's full-sized avatar

John Lettman johnlettman-old

View GitHub Profile
@johnlettman-old
johnlettman-old / HyClasses.php
Created July 19, 2011 22:30
Main classes file of Hybridium Engine -- contains a collection of previously created classes for easier development.
<?php
namespace Hybridium;
###############
## URL Class ##
###############
class URL {
public static function thisURL($forceSSL = false) {
if(!isset($_SERVER['REQUEST_URI']))
@johnlettman-old
johnlettman-old / natlist.php
Created August 6, 2011 18:21
Natural English list grammar from an array.
<?php
/**
* @author Jonathan Lettman
* @param input Array or String to convert to a natural list.
* @param alphabetical Option to sort the list input alphabetically before turning it into a string.
* @return string Product of Natlist in the natural English grammar of a list.
*/
function natlist($input, $alphabetical = false)
{
if(is_array($input)) $arrayCount = count($input);
@johnlettman-old
johnlettman-old / gist:1130704
Created August 7, 2011 19:46
SQL Search Template
SELECT MATCH(Content, Title) AGAINST ('%[[KEY1]]% %[[KEY2]]%') as SearchRelevance FROM [[TABLE]] WHERE MATCH(Content, Title) AGAINST('+[[KEY1]]+[[KEY2]]' IN BOOLEAN MODE) HAVING SearchRelevance > 0.1 ORDER BY SearchRelevance DESC
@johnlettman-old
johnlettman-old / gist:1131249
Created August 8, 2011 05:17
Mouse controller
class Controller
{
public static bool InProcess = false;
public static bool RemoteStop = false;
const int PAINT_FROMTOP = 150;
const int PAINT_FRONLEFT = 100;
[DllImport("user32.dll", SetLastError = true)]
static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
@johnlettman-old
johnlettman-old / gist:1131257
Created August 8, 2011 05:22
Collatz Conjecture for TI 89 Calculators
Input Q
int(Q)→Q
Lbl ITERATE
If Q≠1
Then
If (Q/2)=int(Q/2)
Then
(Q/2)→Q
Disp Q
Goto ITERATE
@johnlettman-old
johnlettman-old / gist:1144424
Created August 14, 2011 00:26
Status Code 304 manipulation for PHP. Allows a dynamically controlled "Last Modified" header for dynamic content, thus allowing for performance.
<?php
$_HEADERS = apache_request_headers(); # Get client headers.
$updateTime = strtotime('yesterday'); # Makes sure that it always caches.
/*
Mock page content.
Change this after first view. If refreshing
shows the old content, then the test worked!
*/
@johnlettman-old
johnlettman-old / reader.php
Created August 16, 2011 19:20
Persistent shared memory using PHP -- perfect for loading a webapplication's configuration one time only and quickly deserializing it per request. Faster than disk configuration mediums, including PHP-file configs.
<?php
// Open the memory location; read-only.
$memoryHandle = shmop_open(0x13c, "a", 0644, 100);
// Read the memory location and print it.
$string = shmop_read($memoryHandle, 0, 0); # Setting the byte count to 0 reads all bytes.
echo 'Data in RAM reads: '.$string;
shmop_close($memoryHandle);
@johnlettman-old
johnlettman-old / Haversine Formula
Created August 23, 2011 17:22
Haversine Implementation in PHP with Coordinate Lookup from named addresses.
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c
@johnlettman-old
johnlettman-old / gist:1212894
Created September 13, 2011 01:00
Quick implementation of Unix-time (seconds from epoch) in Javascript
(new Date().valueOf() * 0.001)|0
@johnlettman-old
johnlettman-old / gist:4642871
Created January 26, 2013 15:19
Langston's Ant (old program)
HTMLCanvasElement::relativeMouseCoordinates = (event) ->
x = new Number()
y = new Number()
if event.x isnt undefined and event.y isnt undefined
x = event.x
y = event.y
else
x = event.clientX + document.body.scrollLeft +
document.documentElement.scrollLeft