Skip to content

Instantly share code, notes, and snippets.

@jheth
jheth / ansi-color-control
Last active December 12, 2015 00:58
PHP ANSI Color Control
<?php
echo chr(27) . '[32m' . "This is a green line" . chr(27) . '[0m' . "\n";
echo chr(27) . '[31m' . "This is a red line" . chr(27) . '[0m' . "\n";
function move_right($x) { echo chr(27) . "[{$x}C"; sleep(1); }
function move_left($x) { echo chr(27) . "[{$x}D"; sleep(1); }
function move_up($x) { echo chr(27) . "[{$x}A"; sleep(1); }
@jheth
jheth / palindrome
Last active December 12, 2015 00:58
PHP palindrome
<?php
$strings = array("racecar", "bob", "b", "abc", "car", "mom", "diary", null, '');
foreach ($strings as $str) {
if (palindrome($str)) {
print "$str is a palindrome\n";
} else {
print "$str is NOT a palindrome\n";
}
@jheth
jheth / jabber-bot patch
Created July 11, 2012 04:01
Jabber Subscription Request Callback
lib/jabber/bot.rb
204,208d203
< @jabber.roster.add_subscription_request_callback do |item,pres|
< @jabber.roster.accept_subscription(pres.from)
< puts 'accepted request from ' + pres.from.to_s
< end