MySQL Group BY Order By
12 Dec 2010 Leave a Comment
in MySQL
I was having a problem selecting the highest id of a table in a group. This was on a hosted server and I figured it was due to the mode that MySQL was in.
My TABLE looked something like this:
################
# id # title # category #
—————————–
# 1 # hello # cmi #
# 2 # test # cmi #
I wanted rows two as it had the highest id in the group so natually what I did was:
SELECT *, MAX(id) FROM mytable GROUP BY category
Alternatively, I thought
SELECT * FROM mytable GROUP BY category ORDER BY id
Neither worked
So I ended up doing something like this:
SELECT * FROM (SELECT MAX(id) AS max FROM mytable GROUP BY category) t1 LEFT JOIN mytable t2 ON t1.max = t2.id
The query in the parentheses gets executed first. What this is doing is selecting the highest id within a group of categories and returning to us the id of each each row.
Then from that set, we move to the main query and join the table back onto the first query by the matched ids giving whatever information we were originally after.
A little bit of a performance hit, but it works.
Resolved: jQuery Cycler not Working with IE PNGs
22 Aug 2010 Leave a Comment
in Javascript, jQuery Tags: cycle, fading, ie, Internet Explorer, png, transparency
For those of you who have read my stuff before, either here or elsewhere, know that I despise Internet Explorer with a passion. Nevertheless, until the powers that be (Google) stop supporting it so everyone else can follow suit, us burdened developers must still make our clients happy.
To fuel my anger against IE, I spent hours trying to get the jQuery Cycle plugin working with some PNGs that were laid on top of some other PNGs. I’m not sure if them being laid on other PNGs had anything to do with it…really didn’t care….should just work…..but it didn’t.
I tried revising the jQuery plugin with no luck. So I decided to write a custom solution. I haven’t made this all pretty for you guys to use, so sorry about that. This is just a case study and I’ll be happy to help you through your problem later. The issue was explained quite well here: http://stackoverflow.com/questions/1156985/jquery-cycle-ie7-transparent-png-problem; which basically says the problem is that IE can’t handle multiple filters at one time. So when you are fading your image, an alpha filter is applied to the image and it disregards any other filter you have…which if you have toiled through documents you probably have the Microsoft filter I’m about to mention already applied to your images, scratching your head, and cussing at an inanimate computer screen.
To fix this, we “simply” need to wrap our images in a div and fade the div.
Let’s look at our slideshow html:
<div id="prev"><a href="#"></a></div> <div id="slides" style="visibility:hidden"> <div style="position:absolute;"><img style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='image1.png'); margin-top:'.$tmargin.'px" src="image1.png" alt="Thumbnail Image" title="Thumbnail Image" /></div> <div style="position:absolute;"><img style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='image2.png'); margin-top:'.$tmargin.'px" src="image2.png" alt="Thumbnail Image" title="Thumbnail Image" /></div> <div style="position:absolute;"><img style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='image3.png'); margin-top:'.$tmargin.'px" src="image3.png" alt="Thumbnail Image" title="Thumbnail Image" /></div> </div> <div id="next""><a href="#"></a></div> </div>
To start off with, we make our slides div invisible. We do this so we have time to hide out image after the page loads. If we don’t, there’s a good change that you’ll see all your images dumped down the screen.
Then we wrap out list of images in a div that is absolutely positioned.
Then we apply the ridiculously stupid Microsoft filter to the images.
Now we add a little magic:
<script>
jQuery(document).ready( function(){
var set = 0;
var ci = -1;
var timer;
function createLoop(dir){
var id = 'slides';
var el = 'div';
var time = 5000;
var lp = document.getElementById(id).getElementsByTagName(el);
if(set == 0){
jQuery("#showcase #next").click( function(){ clearTimeout(timer); createLoop(); } );
jQuery("#showcase #prev").click( function(){ clearTimeout(timer); createLoop("reverse"); } );
}
set = 1;
if(dir == "reverse"){
ci = ci-1;
if(ci < 0){ ci = lp.length-1; }
}else{
ci = ci+1;
if(ci > lp.length-1){ ci = 0; }
}
for(var y=0; y<lp.length; y++){
if(y != ci){ jQuery(lp[y]).fadeOut('slow'); }
}
jQuery(lp[ci]).fadeIn('slow');
timer = setTimeout(function(){ createLoop(); }, time);
}
var lp = document.getElementById('slides').getElementsByTagName('div');
for(var i=1; i<lp.length; i++){
lp[i].style.display = 'none';
if(i == lp.length-1){ document.getElementById('slides').style.visibility = 'visible'; setTimeout(function(){ createLoop(); }, 5000); }
}
});
</script>
You’ll need to change these three lines:
var id = 'slides'; var el = 'div'; var time = 5000; id is the id of the wrapper that is around the img and img div wrapper. el is the img wrapper. In our case it's a div. time is the milliseconds until next fade. We are using a little jquery in there, so you'll need to include jQuery in your file. Take a look at that and chew it over...it works. I know that.![]()
Change AddThis Facebook Description and Title
22 Aug 2010 Leave a Comment
in AddThis, Javascript Tags: AddThis, Custom Description, Custom Title, Facebook
This is a super cheesy hack, but nonetheless, it got me through an website build.
So, as I’m sure you’ve read, using addthis.com api custom descriptions and title does not work with Facebook. Facebook insists on scanning your page for it’s own content and description.
Lucky for us, we can specify what URL is scans.
Using the information found here: http://developers.facebook.com/docs/share we can see that we can pass our own link to facebook. So that’s exactly what we’ll do.
Let’s look at our AddThis code
<div id="add_this"> <div> <a href="http://www.addthis.com/bookmark.php?v=250&username=xa-4c22c53745c89a46"><img src="http://s7.addthis.com/static/btn/sm-share-en.gif" width="83" height="16" alt="Bookmark and Share" style="border:0"/></a> <a><img src="/images/social_email.png" title="Email Us"/></a> <a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.allebrum.com%2Fsharefacebook.html&t=Share%20This" target="_blank"><img style="margin:0 3px 0 2px;" src="/images/social_facebook.png" title="Like Us On Facebook" /></a> </div> <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4c22c1bc64ddaee6"></script> </div>
You’ll want to make your own code on the addthis.com website.
Then you can make modifications to it like we did. Take a look at the facebook url. We added in the href=”" line.
the u= specifies the url that you want to share. You’ll have to make sure that it is an encoded url like you see above.
Now, sharefacebook.html is not the page that I really want to share at all. It’s just a dummy page that facebook can scan and get the information that I actually want it to have.
Let’s take a look at sharefacebook.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="title" content="Allebrum!" /> <meta name="description" content="Allebrum's cool new Content Management system to have first release soon!" /> <title>Untitled Document</title> </head> <body> <script> document.location.href = "http://www.allebrum.com/"; </script> </body> </html>
Notice the two title and description meta tags. That is where you will specify your custom Title and Description that will show up on Facebook.
Facebook will scan this page.
You’ll want to replace this line: document.location.href = “http://www.allebrum.com/”; with a url that goes to the actual page you want your users to see when they click on the facebook shared link.
jQuery UI Themes Messed Up
24 Jul 2010 Leave a Comment
in jQuery Tags: jQuery, Themes, UI
If you have included the jQuery UI, and are trying to use one of their themes, and it keeps showing up all messed up, you may need to include a few other files that you don’t know about.
Make sure you download the entire development bundle. Inside the development bundle, you’ll find some additional css files in there.
Let’s say you are using the datepicker.
You’ll want to include css files in this order:
development-core/css/core.css
development-core/css/datepicker.css
theme/smoothness/jquery-1.8.2.customer.css
lftp crontab linux options how to
22 Jul 2010 Leave a Comment
in Linux, Systems Admin Tags: cron, crontab, lftp, linux, scheduled tasks
first lets make a working directory. Open up ssh or go to the command console and type
cd /var/
Create a directory here
mkdir test
now create a file with vi (or use whatever editor you like, I personally hate vi but it’s what it on my server)
vi myFile.exe
Now type in the following:
#!/bin/bash/usr/local/bin/lftp -e ‘lcd /var/test/ && set ftp:ssl-protect-data yes && set ftp:passive-mode yes && open ftp://server:port -d -u “username”,”password” && mirror “.” && exit’
chmod u+x myFile.exe
find / -name ‘lftp’
crontab -e
30 18 * * * unbuffer /var/test/myFile.exe > /var/test/log.txt
Transferring WordPress to new server
15 Jul 2010 Leave a Comment
Just wanted to make a note here as there are plenty of tutorial on transferring wordpress to another server.
Dont’ forget to do a find and replace on the .sql file that you backed up.
Also, after the transfer, my site would just hang. After trying to track down the error, I renamed my wp-config.php file to wp-config.php.bak. Reloaded the site, and let wordpress create me a new one. I did not run the install as all my information was already there. A quick refresh and everything was working!
Shortcodes not rendering in WordPress
14 Jul 2010 Leave a Comment
in Wordpress Tags: not rendering, shortcodes, Wordpress
I have tried to use several plugins that use shortcodes in the post of page, such as, [contact] or [download].
But when I view the page, the shortcode is not rendered, instead is just shows me the shortcode.
To fix this, your template just have the following code in it:
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <?php if ( is_front_page() ) { ?> <h2><?php the_title(); ?></h2> <?php } else { ?> <h1><?php the_title(); ?></h1> <?php } ?> <?php the_content(); ?> <?php endwhile; ?>
That will fix all your shortcode problems.
Getting WordPress to work on GoDaddy’s free hosting account…finally!
12 Jul 2010 22 Comments
in CMS, GoDaddy, Javascript, jQuery, PHP, Wordpress Tags: fix, free hosting, Godaddy, Wordpress
Aye….another failed attempt. Close. If someone can provide some suggestions, I think we can get there….
Tested in Firefox 3.6.6 Does not work in Chrome. IE….won’t even try.
It took me a few tries….okay, a bunch of tries, but in the end it’s a really simple fix to get WordPress 3.0 to work on GoDaddy’s free hosting account.
From my experience, I have not had any issues on the front end of wordpress, it is only the admin that breaks.
To fix this, you’ll have to edit some files, but it’s not a big edit.
To get started, open up wp-admin/index.php
Change the top of index.php file to look like this:
<?php
ob_start();
/**
* Dashboard Administration Panel
All we’ve done here is add the line ob_start();
Next, at the very, very bottom of that page…I mean the very bottom, put the following code:
<?php$buffer = ob_get_contents();ob_end_clean();$buffer = str_replace(array(‘<html>’, ‘</html>’), ”, $buffer);$handle = fopen(“./temp.html”, ‘w+’);fwrite($handle, $buffer);fclose($handle);?><script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script><script type=”text/javascript”>$(document).ready(function() {$(“head”).remove();$(“body”).remove();$.get(“./temp.html”, function(data){ $(“html”).append(data); } );});</script>
Common Linux Commands I use
12 Jul 2010 Leave a Comment
unzip archive:
> unzip filename.zip
or
>tar cfv test.tar test/
to get hidden files as well
Move contents of directory A to directory B
> mv -i ./A/* ./B
Copy contents of directory A to directory B
> cp -r ./A/* ./B
Remove directory
>rmdir ./A
or
>rm -rf ./A to remove all subdirectories and file
Untar file
tar -xvf ./file.tar
if zipped also use -zxvf
Taken from: http://www.geekvenue.net/chucktips/jason/chuck/994016279/index_html
If you would like to preserve the permissions of the files you backup, use the p option with the tar command. This will save the uid, gid as well as the specific permission attributes of the files (read, write, execute etc.)
$ tar pzcvf tarball.tgz .
You should also use the p option with the tar extraction command:
$ tar pxvf tarball.tgz .