Posts Tagged: github


6
Mar 11

Instead of just Killing off IE6…

Why not kill off IE7 while we are at it?

So, IE6 is on the death march. It’s support ended July 13th 2010. Unfortunately it persists because of Windows XP, as it’s support lasts until 2014.

http://www.theie6countdown.com/

I figured I should help out, but I want to help kill of IE7 as well, so I found an IE6 notice script here: https://code.google.com/p/ie6-upgrade-notification-bar/. I have made quite a few changes to it, and here is the result:

http://seanja.com/demos/ie7-notice/.

The source is available on github https://github.com/SeanJA/ie7-notice.


27
May 10

Orms and Circular References

In my spare time I have been working on an ORM… not one meant to be used in the real world (well… not yet anyway). I currently have hasOne and hasMany working like so:

<?php
 
/**
 * @property int $id
 * @property string $type
 * @property int $car_id
 */
class wheelBoilerplate extends orm{
	protected function init(){
		$this->addProperty('type', array(
			'type'=>'string',
			'default'=>'monster truck',
		));
		$this->hasOne('car');
	}
}
 
class wheel extends wheelBoilerplate{}
 
/**
 * @property int $id
 * @property int $wheel_count
 * @property array $wheels
 * @property string $type
 */
abstract class carBoilerplate extends orm{
	protected function init(){
		$this->addProperty('wheel_count', array(
			'default'=>4,
			'type'=>'int',
		));
		$this->addProperty('type', array(
			'default'=>'monster truck',
			'type'=>'string',
		));
		$this->hasMany('wheels');
	}
}
 
class car extends carBoilerplate{}
 
$car = new car();
 
echo $car->wheels[0]->car->wheels[2]->car->wheels[3]->car->wheels[0]->type; #=> 'monster truck'

The problem as you can probably guess, is you now have 4 of the same car loaded into memory, and 4 wheels, 2 of which are the same. So, when you do this:

$car->type = 'Ford Pinto';

You are only actually changing one instance of all of the instances of car that you have created in memory. Not so good for keeping things straight, which one do you save? What happens if you save one over top of the other?

$car->type = 'Ford Pinto';
$car->save();
$car->wheels[0]->car->save();

You have just overwritten your changes in the database. I didn’t think that was a good thing to let someone do (even accidentally). That is where this class came from:

<?php
 
class factory {
	/**
	 * Holds all of the items in the factory
	 * @var array
	 */
	protected static $created = array();
	/**
	 * Create/Load an object from the factory
	 * @param string $className
	 * @param int $id
	 * @return orm
	 */
	public static function Create($className, $id=null ) {
		$className = strtolower($className);
		if(!isset(self::$created[$className][$id])) {
			self::$created[$className][$id] = new $className($id);
		}
		return self::$created[$className][$id];
	}
	/**
	 * Load an object from the factory
	 * @param string $className the object's class
	 * @param int $id the id of the object you are loading
	 * @return orm or null
	 */
	public static function Load($className, $id ) {
		$className = strtolower($className);
		return (isset(self::$created[$className][$id]))? self::$created[$className][$id]:null;
	}
	/**
	 * Add an object to the factory, has no effect if the object is already part of the factory
	 * @param string $className
	 * @param orm $class
	 */
	public static function Add(orm &$class) {
		$className = strtolower($class->class_name);
		if(!isset(self::$created[$className][$class->id])) {
			self::$created[$className][$class->id] = &$class;
		}
	}
	/**
	 * Destroy an instance of something in the factory and the object itself
	 * @param orm $class the class being destroyed
	 */
	public static function Destroy(orm &$class){
		$className = strtolower($class->class_name);
		$id = $class->id;
		unset(self::$created[$className][$id]);
		$class = null;
	}
}

I haven’t had the chance to actually merge them together, but this is how it should work:

 
$car = factory::Create('car', 1);
 
$car->wheels[0]; //#=> factory::Create('wheel', 1);
$car->wheels[1]; //#=> factory::Create('wheel', 2);
$car->wheels[2]; //#=> factory::Create('wheel', 3);
$car->wheels[3]; //#=> factory::Create('wheel', 4);
 
$car->wheels[0]->car; //#=> factory::Load('car', 1);
$car->wheels[0]->car->wheels[0]; //#=> factory::Load('wheel', 1);
 
$car->wheels[0]->car->type = 'Ford Pinto';
 
echo $car->type; //#=> 'Ford Pinto'

Now, no matter which of the cars that you load (as long as it has the same ID), it will be the same one instead of just another instance of the same one. Changes are made to all of them, because they are all the same instance of that car.

The factory class and some sample usage code are on github, if’n you want to look at it, or fork it, or whatever.


31
Mar 10

PHP DateTime is missing methods in 5.2

It turns out that in PHP 5.2, the DateTime class is missing a couple of methods (get/setTimestamp) that are available in PHP 5.3. These are some strange methods to be missing as a lot of people in the PHP world seem to work on Timestamps using these concepts, so you would have thought that php would have included these methods initially. Unfortunately they did not, so here is a fix for that:

And since using it in production would be no good if it were not tested properly, here are the unit tests to make sure that it returns the same values as the new one in PHP 5.3:

You use it the same way that you would use the normal DateTime class, it even includes the poorly named php functions date_timestamp_get / date_timestamp_set if they don’t exist so you can use them as well.

Hopefully this is helpful for those of you that have used this functionality mistakenly (as I did) before realizing that it wasn’t actually available.

(get it on github: http://gist.github.com/349273)


4
Feb 10

Daily Digest for February 4th

twitter (feed #2)
twitter (feed #2)
RT @TheOnion: In Focus: Mischievous Raccoon Wreaks Havoc On International Space Station http://onion.com/6Zxlt7 [SeanJA]
twitter (feed #2)
@kristelknab Only if the price goes up [SeanJA]
twitter (feed #2)
Will the new AvP game be as awesome as the old one? I hope so [SeanJA]
twitter (feed #2)
I do wish I could install the AvP demo from steam though… it doesn’t seem to be working [SeanJA]
twitter (feed #2)
@kristelknab Ring ring… ring ring…. [SeanJA]
twitter (feed #2)
RT @Spl0it: Why gay marriage should be illegal http://imgur.com/y3haF #gay #marriage #USA – great insight! [SeanJA]
twitter (feed #2)
@mezzoblue Been there, done that [SeanJA]
googlereader (feed #5)
twitter (feed #2)
State abnormal [SeanJA]
twitter (feed #2)
Oh noes! Draculas! RT @wigu A new http://overcompensating.com/ in which Weedmaster P worries about DRACULAS. [SeanJA]
googlereader (feed #5)
googlereader (feed #5)
twitter (feed #2)
twitter (feed #2)
twitter (feed #2)
@github seems to be having problems, good thing it is not a centralized versioning system, otherwise people would be SOL [SeanJA]
twitter (feed #2)
@github I think stackoverflow was having a similar problem at one point… damn Yahoo! spiders [SeanJA]

23
Oct 09

Daily Digest for October 23rd

twitter (feed #2)
New blog post: Daily Digest for October 22nd http://bit.ly/m48bd [SeanJA]
twitter (feed #2)
@gavinblair NOT FOUND [SeanJA]
twitter (feed #2)
@zoster Shorts and a t-shirt [SeanJA]
twitter (feed #2)
YESSS!!! RT @TimCAD: This is some crazy good shit right here: http://twurl.nl/4a1msh [SeanJA]
twitter (feed #2)
Just Bust a Move [SeanJA]
twitter (feed #2)
@gavinblair Still nothing… :( [SeanJA]
twitter (feed #2)
RT @late2game: LOL – Something in here to offend just about everyone – What Religion Should You Follow? – http://bit.ly/ivL8R [SeanJA]
twitter (feed #2)
Anyone know how to calm down @mojitobunny? He is kind of freaking out a lot… [SeanJA]
twitter (feed #2)
jQuery is now on github! http://github.com/jquery/jquery [SeanJA]
twitter (feed #2)
You can make an unmaintainable mess out of any templating language (engine). Smarty seems to make that even easier. [SeanJA]
twitter (feed #2)
I am in a heated debate with someone on the internets about whether or not Smarty is any good… guess which side I am on [SeanJA]
googlereader (feed #5)
twitter (feed #2)
@gavinblair Bah… French Press is really fast :P [SeanJA]
twitter (feed #2)
@gavinblair Never heard of it, but it has to be better than Smarty [SeanJA]
twitter (feed #2)
@gavinblair I am partial to haml’s syntax though… if I use a template language I want something less verbose that makes it faster to write [SeanJA]
twitter (feed #2)
How do you keep the Toronto Maple Leafs out of your yard? You put up a net #bdoomkch [SeanJA]
twitter (feed #2)
@gavinblair Nice and simple to do like this: http://bit.ly/3aAmE7 I wish people would figure that out and stop using things like smarty… [SeanJA]
twitter (feed #2)
@gavinblair I think this guy is mad at me because I voted down a link on dZone because I think that smarty is not a ‘must have’ for php devs [SeanJA]
twitter (feed #2)
@gavinblair The only thing that is not html there is the form, because I wrote my own form helper, so I might as well use it. [SeanJA]
twitter (feed #2)
Avoid the Christmas Special #protip http://xkcd.com/653/ [SeanJA]
twitter (feed #2)
@gavinblair True… I wrote one of those too, it works similar to the one that CodeIgniter has. [SeanJA]
twitter (feed #2)
@gavinblair I am still partial to the CodeIgniter one, which is why this happened: http://bit.ly/3QoyTC [SeanJA]
twitter (feed #2)
Mozilla Raindrop != Google Wave? http://labs.mozilla.com/raindrop [SeanJA]
twitter (feed #2)
@gavinblair Hmmm… perhaps I could add a second form helper to ShoestringPHP? [SeanJA]
twitter (feed #2)
googlereader (feed #5)