We're growing into something new. Read More
ajcates

A.J. Cates  Pro


Discussion

Ziptastic

Ziptastic is a simple API that allows people to ask which Country, State and City are associated with a Zip Code. The purpose for this service is to STOP the madness of having to fill those information out on webforms. If you've ever filled out a webform, then you have probably gotten to the address section and simply entered in your street information and then your city, state, country and then your zip code. This has always bothered me because the 3 fields prior to the zip code can be determined from the zip code! I've always that it was redundant when on a form it would ask you for your city, state & zipcode. When really if you have someones zip code you can tell what city & state they live in.

var include = function(scripts, done) {
	(typeof scripts === "string") && (scripts = [scripts]);
	var loading = function () { scripts.pop() && !scripts.length && done.call(); };
	scripts.forEach(function (script) {
		var el = document.createElement("script");
		el.addEventListener('load', loading), el.async = true, el.src = script;
		document.head.appendChild(el);
	});
	return arguments.callee;
};

Async Javascript Lazy Loader

I wrote a small little function that lets you load in external javascript files asynchronously. I plan to use it in greasemonkey scripts and bookmark lets. I've also set up a Gist with the code. I've only tested it in Webkit and Firefox, and really don't expect it to work in InternetExplorer. I have a demo set up that loads Zepto and Underscore at the same time. Below is an example of how to use it. The first argument in the function can be ether an array or string. include( ["cdnjs.cloudflare.com/ajax/libs/zepto/0.8/…", "cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.1/…"], function() { //Our javascript is loaded and ready togo… $(function() { //Dom ready… console.log( _ ); //Logging our underscore object. } } ); Raw Code »

Discussion

Tumblr Wolf CMS Plugin

I Made a plugin for Wolf CMS that allows you to embed Tumblr content directly on your site. Return an array of posts from tumblr. tumblrPosts($username, $page); Raw Code » Set $username to what ever your tumblr username is, and $page to the page you would like return. printTumblrPosts($username, $page); Raw Code » You can also use printTumblrPosts() to print the posts directly to the screen. tumblrInfo($username); Raw Code » The tumblrInfo() function will return an associative array with information from the tumblr of $username. tumblrPost($username, $id); Raw Code » The tumblrPost() function will return a single tumblr post array object. printTumblrPost($username, $id); Raw Code » The printTumblrPost() function will print a single tumblr post. Github Repo

Personal Logo

This is my new personal logo that I plan to use on my upcoming redesign of ajcates.com. Any feedback or critiques are welcomed.

base64_decoder Tool I Made

This is a little base64 decoder tool I wrote to help me kick some ass on obfuscated php code. Turns base64_decode("S2ljayBBc3M=") in your php code into "Kick Ass". The source is available on github. Design is the Less4 css framework with a hint of css3. What do you think about the design? Any ideas on features I could add?

static function _buildWhere($group, $groupOperator='AND', $escape=true) {
	//"Bitch I'll pick the world up and I'ma drop it on your f*ckin' head" - Lil Wayne.
	$keys = array_keys($group);
	if(is_int(f_last($keys)) && is_string(f_last($group))) {
		$operator = f_last($group);
		$group = f_chop($group);
	} else {
		$operator = '=';
	}
	if(is_int(f_first($keys)) && is_string(f_first($group))) {
		$groupOperator = f_first($group);
		$group = f_rest($group);
	}
	$builtArray = f_keyMap(
		function($value, $key) use($groupOperator, $operator, $escape) {
			if(is_int($key) && is_array($value)) {
				$bWhere = Query::_buildWhere($value, $groupOperator, $escape);
				if(!empty($bWhere)) {
					return '(' . "\n\t" . $bWhere . "\n" .')';
				} else {
					return null;
				}
			}
			if(is_string($key)) {
				static $escapeFunc = array('Query' , 'nullEscape');
				if(!$escape) {
					$escapeFunc = 'nothing';
				} else {
					$escapeFunc = f_callable($escapeFunc);
				}
				if(is_array($value)) {
					$key = $escapeFunc($key);
					if(f_first(array_keys($value)) !== 0) {
						return join(' ' . $groupOperator . ' ', f_keyMap(function($v, $k) use($key, $escapeFunc) {
							return $key . ' BETWEEN (' . $escapeFunc($k) . ' AND ' . $escapeFunc($v) . ')';
						}, $value));
					}
					return $key . ' IN (' . join(', ', array_map($escapeFunc, $value)) . ')'; 
				} else {
					$value = call_user_func($escapeFunc, $value);
					if($value === 'null') {
						if($operator == '=') {
							$operator = 'IS';
						} else {
							$operator = 'IS NOT';
						}
					}
					return Query::escape($key) . ' ' . $operator . ' ' . $value;
				}
			}
		},
		$group
	);
	if(!empty($builtArray)) {
		return join(' ' . $groupOperator . ' ', array_filter($builtArray));
	}
}

Query Builder's _buildWhere() function

This is my Query builder's where function builder. It amazing supports, IN, BETWEEN, IS, IS NOT, and crazy ass combos of nested groups of conditions. I have yet to run into a situation that my function couldn't handle, and best of all unlike many other frameworks who force you to use raw strings for really complex things I use array's so I can make sure I'm actually escaping all the values. //where() Examples: $this->select('*')->where(array('item' => 5))->from('table') //SELECT * FROM table WHERE item = '5' $this->select('*')->where(array('item' => 5, 'thing' => 'what'))->from('table') //SELECT * FROM table WHERE item = '5' AND thing = 'what' $this->select('*')->where(array('OR', 'item' => 5, 'thing' => 'what'))->from('table') //SELECT * FROM table WHERE item = '5' OR thing = 'what' $this->select('*')->where(array('item' => 5, 'thing' => 'what', '!='))->from('table') //SELECT * FROM table WHERE item != '5' AND thing != 'what' $this->select('*')->where(array('item' => array('what', 'who'))->from('table') //SELECT * FROM table WHERE item IN ('what', 'who') $this->select('*')->where(array('item' => array(10 => 30))->from('table') //SELECT * FROM table WHERE item BETWEEN (10 AND 30) Raw Code »

Discussion

Untitled

Explains the difference between javascript and php coming from the perspective of a php developer. Awesome guide for anyone looking to write better and more organized javascript code.

Write one good Forrst comment a day.

Everybody should add this to your Streakly's! Anyone who uses both Forrst and Streakly should really try and write out 1 meaningful comment with good feedback in it. When I say good feedback I don't mean just saying "Awesome textures!" or something like that, I mean taking your time and writing down 2-3 things about the design/code you like, don't like. Offer ways for the person to improve there post, be as helpful as possible! Something I struggle with is getting good feedback on my designs/code and hopefully this will be a way to encourage more people to give more meaningful feedback, and what the heck hopefully it will come back around to me. Hopefully this well help make Forrst an even more awesome place!