Skip to content

Instantly share code, notes, and snippets.

View bayleedev's full-sized avatar
🍿

Baylee Schmeisser bayleedev

🍿
View GitHub Profile
@bayleedev
bayleedev / gist:3659846
Created September 6, 2012 19:44
Align text in PHP GD
<?php
function textSize($size, $angle, $font, $text) {
$f = imagettfbbox($size, $angle, $font, $text);
return array(
'height' => $f[1] - $f[5],
'width' => $f[4] - $f[0]
);
@bayleedev
bayleedev / Test Compact and Extract.php
Created September 17, 2012 15:26
Will compact and extract keep the object reference?
<?php
$provider = new stdClass();
echo '<pre>';
echo 'First: ' . spl_object_hash($provider) . PHP_EOL;
function testProvider(stdClass $provider) {
$provider->name = 'Blaine';
@bayleedev
bayleedev / alpha.php
Created September 18, 2012 16:56
Get all alpha characters
<?php
$alpha = array_map('chr', range(97, 122)); // a-z
$_alpha = array_map('chr', range(65, 90)); // A-Z
print_r($alpha);
print_r($_alpha);
@bayleedev
bayleedev / changeObjectFunction.php
Created October 16, 2012 01:18
Can change object but can't write over it
<?php
$response = new stdClass();
echo '1): ' . spl_object_hash($response) . PHP_EOL; // 0000000021e89fcd00000000e93b17ba
call_user_func_array(function($response) {
$response = new stdClass();
echo '2): ' . spl_object_hash($response) . PHP_EOL; // 0000000021e89fcf00000000e93b17ba
}, array($response));
@bayleedev
bayleedev / routes.php
Created October 16, 2012 03:02
Rewrite response in laravel
<?php
Route::filter('after', function($response)
{
$params = \Laravel\Request::$route->parameters;
// The 'type' is the last param
// example: /product/(:num).(:any)
$type = array_pop($params);
if($type == 'json') {
$res = Response::json($response->content->data);
@bayleedev
bayleedev / depInjection.php
Created October 31, 2012 00:17
Dep Injection
<?php
interface iGame {
public function start();
public function end();
public function move();
}
class tictactoe implements iGame {
public function start() {
@bayleedev
bayleedev / FeatureContext.php
Created November 2, 2012 23:18
Mink + Behat
<?php
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
use Behat\Mink\Driver\GoutteDriver,
Behat\Mink\Driver\Selenium2Driver,
@bayleedev
bayleedev / question.php
Created November 15, 2012 22:33
Lithium
<?php
use lithium\analysis\Logger;
// Setup firephp in one file
Logger::config(array(
'firebug' => array(
'adapter' => 'FirePhp',
),
));
// Setup file adapter in another place
Logger::config(array(
<?php
namespace app\tests\cases\controllers;
class AssertTest extends \lithium\test\Unit {
public function testSomething() {
$this->assert(true, 'this is true'); // true
$this->assertCount(10, array(1)); // false
}
# Clear the cache
alias .hb.remote.cc="ssh mdxdev '.hb.cc'"
function .hb.cc() {
# Directory
.hb
# CSS
if [ $(ls app/webroot/css/compiled/ | wc -l) -gt 0 ]
then
echo Ridding CSS