Wednesday, March 31, 2010

PHP Random Color

This kind of works okay!


<?php $hexColor=dechex(rand(0,255)).dechex(rand(0,255)).dechex(rand(0,255)); ?>
<div style="height: 100px; width: 100px; background: #<?php echo $hexColor; ?>">
</div>


// thius one works a little better

<?php $hexColor=str_pad(dechex(rand(0,255)), 2, "0", STR_PAD_LEFT).str_pad(dechex(rand(0,255)), 2, "0", STR_PAD_LEFT).str_pad(dechex(rand(0,255)), 2, "0", STR_PAD_LEFT); ?>

Monday, March 29, 2010

ajax load a jquery ui dialog box

$(function() {
        // ajax load a jquery dialog box
 $.fn.ajaxDialog = function(options) {
  var defaults = {
   autoOpen:false,
   modal:true,
   resizable:false,
   
  };
  var options = $.extend(defaults, options);
  var id = "dialog_"+Math.floor(Math.random()*11);
  var el = $("
").attr("id", id); $(this).after(el); el.dialog(options); $(this).click(function () { url = $(this).attr("href"); $("#"+id).load(url,{}, function() { $(this).dialog('open'); }); return false; }) }; $("a.dialog_link").ajaxDialog({width: '890px', height: '800px'}); });

Thursday, March 25, 2010

jQuery Flip Plugins

jQuery 3di Rotate Plugin (no IE support):
http://www.zachstronaut.com/projects/rotate3di/#demos
This is the perfect flip, exactly what i was looking for. It requires a few includes and does not support older browsers at all (it requires css3 support, which is rare amongst browsers). While it's what I want, I can't use it because it's not compatible enough with anyhting.

jQuery Flip Plugin:
http://lab.smashup.it/flip/
It's a good looking flip, except that it doesn't really do images properly. It only does the flipping motions with a gray background (or color of your choice), does a pretty smooth flip and then returns whatever content you had to the box. It might be okay with a black background, but not exactly what i was looking for. However, it does have full browser support, so you can't really complain

jQuery Image Flip
http://webmuch.com/image-flip-using-jquery/
This kind of works, it's not really flipping. It's squashing and expanding, but it could do possibly. Hmm.

Wednesday, March 24, 2010

jQuery .queue() and .dequeue()

jQuery has some weird stuff to do with making smooth animations.

There are the following functions:
.queue()
.stop()
.dequeue()
.clearQueue()

The normal queue() is the "fx" queue, which you can use for chaining effects (and it is used by default in the background). Hopefully with this command I can add things to the "fx" queue that can take advantage of some of the other chained functions like .delay() without having to use the animations hack. Hurray. Also stop() is cool, because it's a essentially a "pause" button, though I don't know how to resume() =)

Hopefully, I will post more on this soon!

Once I get it figured out!

- Jamund

Fun with offset and position

Today I learned the difference between the jQuery .offset() and .position() functions. At the outside they behave very similarly, but there are some subtle differences.

.offset() - returns the position relative to the page
.position() - returns the position relative to the container div

The following works assuming that both #head and #neck are located within the same container div.
// grab the offset relative to the page
pos = $("div#head").position();

// make some changes
pos.top += ("div#head").height();

// attach the neck on the head
$("div#neck").css(pos);


The following works no matter where the divs are located.
// grab the offset relative to the page
off = $("div#head").offset();

// make some changes
off.top += ("div#head").height();

// attach the neck on the head
$("div#neck").css(off);


Both have their merits. Occasionally using position you might find your tooltip clipped by the container div, so attach your tooltip to the body of the page and then absolutely position it on top of the container div but still in the correct location.

Hurray for the nerdery.

jQuery Random Filter

http://blog.mastykarz.nl/jquery-random-filter/

This is awesome by the way. I've made one small change that apparently makes it more browser compatible.


$(function() {

$.jQueryRandom = 0;
 $.extend($.expr[":"],
 {
     random: function(a, i, m, r) {
         if (i == 0) {
             jQuery.jQueryRandom = Math.floor(Math.random() * $(r).size());
         };
         return i == jQuery.jQueryRandom;
     }
 });
// hide a random div on your page
$("div:random").hide();

});

Saturday, March 13, 2010

Utah Web Design Companies

Code Greene - Just found out about these guys. It looks like they do some great work and rumor has it they do most of their stuff using CakePHP.

Ugly Fruit Media -Brand new start-up out of Provo, Utah. These guys have a lot of experience with front-end development and they do great work

BP3 -  Based out of Springville, these guys do some pretty cool sites using Joomla. They are experts at that and can also do Facebook applications and help with advertising and social networking.

Media Rain - My current employer. This place makes the best websites, FLEX, and iPhone apps in the industry. I love them!

Friday, March 12, 2010

Environmental IT

This post is  meant to review some of the areas of the Green IT arena. Currently, I'm trying to break out in doing consulting with my side project Green Sparks IT. I will be updating this post routinely as I learn more and we find more about this.

Here are some of the main areas where green IT can come into play:

Virtualization
- This technique uses software from XEN, VMWare or others to have several virtual server platforms running on the same system simultaneously. The argument is that the biggest environmental impact of computing is not just energy, but also the equipment. Being able to squeeze 2-20 servers onto one physical machine saves a lot energy and precious resources.

Less-intensive cooling - A big thing right now is trying to figure out how cool we need to keep servers. A big factor in data center energy use is in cooling the servers. A popular school of thought is to have hot rows and cold rows in the data center. The differences in air temperature creates drafts that keep the servers relatively cool in addition to what the cooling system already does. It's a good idea, but the question remains if they even need to be that cool. How hot can you keep the data center. Can you avoid not including all of that air conditioning. Can you use natural sources such as water to do the cooling that might not require as much energy to pump through? A lot of good work is being done here.

Fancy Websites

http:://www.pixlr.com/ - This is the best website I have used lately. Today, I was able to use to make transparent PNG buttons. I loved it! Worked super fast, especially in Google Chrome.

http://www.chromeexperiments.com/
- These are some of the finest examples of what's capable in a modern browser around. Making extensive use of the HTML5 Canvas and many other techniques. Some of my favorite examples are jsCanvasBike, 100 Tweets, Canvas 3D Engine, Colors Cube.

They're all very cool and fun examples of what can be possible in a modern browser using Javascript and HTML5 Canvas.

Wednesday, March 10, 2010

SQL Date Queries

MySQL is a powerful tool.

Lately I have been using a lot of the powerful date related functions.

How many years ago did they take the test?
SELECT
 FLOOR(PERIOD_DIFF(Test.taken, NOW())/12)) AS "Years Ago"
FROM
 tests Test 
How many people took the test per "years ago"
SELECT
 COUNT(*),FLOOR(PERIOD_DIFF(Test.taken, NOW())/12)) AS "Years Ago"
FROM
 tests Test 
GROUP BY
 FLOOR(PERIOD_DIFF(Test.taken, NOW())/12))

How many people took the test between now and 2 years ago?
SELECT
 COUNT(*)
FROM
 tests Test
WHERE
 Test.taken >= DATE_SUB(NOW(), 'INTERVAL 2 YEAR')

How many people took the test between 2 and 3 years ago?
SELECT
 COUNT(*)
FROM
 tests Test 
INNER JOIN
 users User
ON
 User.id = Test.user_id
WHERE
 Test.taken <= DATE_SUB(NOW(), 'INTERVAL 2 YEAR')
AND
 Test.taken >= DATE_SUB(NOW(), 'INTERVAL 3 YEAR')
GROUP BY
 User.id

What if a user could take the test multiple times in one year
SELECT
 COUNT(*),FLOOR(PERIOD_DIFF(Test.taken, NOW())/12)) AS "Years Ago"
FROM
 tests Test 
INNER JOIN 
 users User
ON
 User.id = Test.user_id
GROUP BY
 FLOOR(PERIOD_DIFF(Test.taken, NOW())/12)), User.id 

How many times each user took a test each year
SELECT
 User.id,
 User.name,
 COUNT(*),
 FLOOR(PERIOD_DIFF(Test.taken, NOW())/12)) AS "Years Ago"
FROM
 tests Test 
INNER JOIN 
 users User
ON
 User.id = Test.user_id
GROUP BY
 FLOOR(PERIOD_DIFF(Test.taken, NOW())/12)), User.id



Explanation:
FLOOR - Essentially takes off the extra digits after the division
PERIOD_DIFF - The number of months between dates

Saturday, March 6, 2010

Coda Plug-ins

I love Panic's Coda software, but when you first get started you might have some questions about what plug-ins to install. There are a few that I consider absolutely essentially. I'll share some here and explain why they're so important. Oh, by the way, I obviously develop on Mac OS X and usually am programming in PHP on Apache servers, so that's where I am coming from here. Post a comment if you have any other suggestions or questions!

Thanks,
J

1. Coda PHP Toolkit
This plugin helps you validate your PHP code inline, allowing you to spot errors before going to your web browser for testing. Very helpful. It also allows you to Tidy your code and strip white spaces. It's great.

2. Apache Configuration Module 
When I first setup a new box and get Coda installed on there the first thing I do is setup a "Site" for editing my local XAMPP   configuration  and adding new vhosts. Obviously, a minor annoyance is that there is no built-in module for viewing apache configuration files. I love this plugin.

3. Lorum Ipsum Plugin
This really simple plugin just generates gibberish text useful for creating mockups that have content that looks slightly more realistic than "123. 123. 123. 123. 123. 123. 123" copy and pasted a million times.

4. MD5 Hash Plugin
This simple plugin helps when you're debugging things that need MD5 content like passwords and gravatar URLs. It's really basic, but I've used it a lot, actually. It's highly recommended.

5. PHP Docblock Generator
I know, comments, really, but they're actually really important and this will automatically add a comment to your function that includes the parameters and some basic information. Quite nice. And helps your comments maintain a bit of posh formality.

6. Pastie Plugin
Pastie is a simple site that lets you post snippets of code for yourself or sharing with others. This plugin makes it super easy to share your code with the world!

Friday, March 5, 2010

Git Bash Prompt

To get a bash prompt like this:
~/Sites/project [master] $


Add this to your /etc/profile file. Once done, save it and open a new prompt.

function parse_git_branch {
 ref=$(git symbolic-ref HEAD 2> /dev/null) || return
 echo "["${ref#refs/heads/}"] "
}

WHITE="\[\033[1;37m\]"
LIGHTGRAY="\[\033[0;37m\]"
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
LIGHTCYAN="\[\033[0;36m\]"
GREEN="\[\033[0;32m\]"

PS1="$LIGHTGRAY\w $LIGHTCYAN\$(parse_git_branch)$GREEN$ "

Bash colors tutorial:
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html

Another git prompt tutorial:
http://railstips.org/blog/archives/2009/02/02/bedazzle-your-bash-prompt-with-git-info/

Thursday, March 4, 2010

apache config file module for coda

this is a great module for editing apache files with coda. download and instructions here:

http://nagpals.com/blog/post.cfm/apache-configuration-language-module-for-coda

Tuesday, March 2, 2010

Restarting the dock in Mac OS X

My dock recently stopped working, including cmd-tab and the desktop. This seemed to fix it.

> ps aux | grep Dock | grep -v grep
jamund     193   0.3  0.4   440160   8572   ??  S     1:56PM   0:33.83 /System/Library/CoreServices/Dock.app/Contents/MacOS/Dock -psn_0_53261
> kill -HUP 193

Monday, March 1, 2010

Opera Mini (WAP Browser) on Mac OS X

http://my.opera.com/chaals/blog/2009/01/22/opera-mini-on-mac-os