Skip to content

Instantly share code, notes, and snippets.

@amgraham
amgraham / Business Cat Cached
Created June 6, 2013 01:52
The base pictures for memes rarely change, but the words typically do. Cache the pictures, and CSS the words.
<?php $top = (@$_GET["top"]) ? $_GET["top"] : ""; $bottom = (@$_GET["bottom"]) ? $_GET["bottom"] : ""; ?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" media="all" href="http://smarterfish.com/assets/css/basic.css"/>
<title>Business Cat Cached</title>
</head>
<body>
@amgraham
amgraham / Player Faces in Minecraft
Last active December 11, 2015 14:58
Generate a list of logged-in players & show their skins head.
<?php
/* DEMO ---------------------------------------------------------------------------------------------------------------------- */
/* This file is a working example, so with a few edits to this file and server.properties and a file or two created (with accurate permissions) on your server, you can be up and running in no time.
You will need to edit server.properties to enable a remote connection in your Minecraft server: 'enable-query=true' amd set a port for querying your server: 'query.port=25565'. You shouldn't use the default port number.
Edit this file just below (the first block of code): YOURSERVER.COM & YOURPORTNUMBER to the URL for your Minecraft server and the port number you specified in server.properties (not your server-port; this one needs to be query.port).
This script needs one file to store the player names in temporarily, and a folder to store their skins, we store player names for 5 seconds by default and skins for 24 hours. We do this to stop overloading your server, and http://mi
@amgraham
amgraham / Status Code Errors
Last active October 1, 2015 04:58
A simple way to present error status codes in a web-based application
// error.php
/* $code would be set when included in another file, otherwise we assume apache is calling us, and look for $_GET["code"] */
$code = (empty($code)) ? $_GET["code"] : $code;
/* we messed something up, fake it and issue a 500 */
if (empty($code)) { $code = "500"; }
/* obviously, you can add more */
if ($code == "400") {
$status = "HTTP/1.1 400 Bad Request";
@amgraham
amgraham / Memo
Last active September 23, 2015 21:57
Am easy way for an application to talk with itself.
class Memo {
// we're going to set the message to something, could be nothing (meaning we want the message cleared), or something to else.
function set($message = '') {
if (setcookie('memo', $message, time() + 60, '/')) {
return false;
} else {
return true;
}
}
@amgraham
amgraham / Debug
Last active September 23, 2015 21:57
Lets you know what is going on with a variable in php.
function debug(&$var, $r = NULL) {
// if $var is an empty string, we're being called recursively
// this is an extreme guess, and might cause problems
// now we determine the variable name
$old = $var;
// var = $new = "unique".rand()."value";
$new = $var;
$var = "unique".rand()."value";
$new = $var;
@amgraham
amgraham / Excerpt
Last active September 23, 2015 21:57
Displays the needle, and some surrounding text, within a haystack
function excerpt($text, $phrase, $radius = 50, $ending = "...", $offset = 0) {
// excerpt('SuperLongStringThatMightNotFitInTheSpaceAllowed', 'That', 10)
// will return
// rLongStringThatMightNotFi...
$phraseLen = strlen($phrase);
if ($radius < $phraseLen) {
$radius = $phraseLen;
}
@amgraham
amgraham / Snipper
Created October 12, 2010 04:48
Return only the beginning and end of a long string
function snipper($string, $length) {
// snipper('SuperLongStringThatMightNotFitInTheSpaceAllowed', 10)
// will return
// SuperLongS...aceAllowed
if (strlen($string) > $length) {
$string = substr($string, 0, $length). "...".substr($string, strlen($string) - $length, $length);
}
return $string;