Skip to content

Instantly share code, notes, and snippets.

View bobmagicii's full-sized avatar
🤌

Bob Magic II bobmagicii

🤌
View GitHub Profile
@bobmagicii
bobmagicii / gist:2126256
Created March 19, 2012 20:06
gtkassistant
<?php
class test extends GtkAssistant {
public $entry;
public $view;
public function __construct() {
parent::__construct();
@bobmagicii
bobmagicii / gist:3061604
Created July 6, 2012 17:51
colorizing greyscale images whilst preserving alpha
<?php
function colorize($img,$color) {
$fill = new Imagick;
$fill->newImage(
$img->getImageWidth(),
$img->getImageHeight(),
$color
);
@bobmagicii
bobmagicii / gist:3106911
Created July 13, 2012 19:36
Example using Menagerie
<?php
/* assuming the config file has been set to load the surface library, and to
automatically run the surface for us, this would result in a complete page
output to the browser in the current site theme. it would say, 'lol', lol. */
require('m/application.php');
echo 'lol';
?>
@bobmagicii
bobmagicii / gist:3106970
Created July 13, 2012 19:45
Using Database in Menagerie
<?php
/* this is assuming we have a database configured in the config file under the
alias of 'default' - for this example we assume it is MySQL. */
require('m/application.php');
$db = new m/database;
$id = 42;
// when using the queryf method of the database library, all format arguments
@bobmagicii
bobmagicii / gist:3107242
Created July 13, 2012 20:29
Setting image opacity in Imagick (bad result)
<?php
$img = new Imagick('input.png');
$img->setImageOpacity(0.25);
$img->writeImage('output.png');
$img->destroy();
?>
@bobmagicii
bobmagicii / gist:3107329
Created July 13, 2012 20:40
Setting image opacity in Imagick (good result)
<?php
function bob_opacity($img,$alpha) {
if(!is_object($img)) return false;
if($alpha > 1 || $alpha < 0) return false;
$rows = $img->getPixelIterator();
foreach($rows as $cols) {
foreach($cols as $pixel) {
// we now have an object pointing at a single pixel of the image
@bobmagicii
bobmagicii / gist:3180599
Created July 26, 2012 06:35
Apache log in JSON format...
LogFormat "{ \"Time\":%{%s}t, \"RemoteIP\":\"%a\", \"Host\":\"%V\", \"Port\":\"%p\", \"Request\":\"%U\", \"Query\":\"%q\", \"File\":\"%f\", \"Method\":\"%m\", \"Status\":\"%s\", \"UserAgent\":\"%{User-agent}i\", \"Referer\":\"%{Referer}i\" }" jsonlog
CustomLog "/var/log/apache2/access-json.log" jsonlog
<?php
$file = new SplFileObject('/var/log/apache/access-json.log');
$file->setFlags(SplFileObject::DROP_NEW_LINE);
foreach($file as $line) {
if(!$line) continue;
$log = json_decode($line);
if(!is_object($log)) continue;
@bobmagicii
bobmagicii / gist:3287846
Created August 7, 2012 17:59
gd image class
<?php
// sort of psuedo, but a basic image class.
/*
$img = new image($file);
$img->scale(640,480)->crop(64,64,128,128);
*/
class image {
<?php
class BobWindow extends GtkWindow {
public function __construct() {
parent::__construct();
$this->set_size_request(256,256);
$this->set_title('BobWindow');
$this->set_position(Gtk::WIN_POS_CENTER);