Find all files and directories with specific permissions (eg: CHMOD) using LS and GREP commands on Linux

Just a quick snippet that I used today to find all files/folders with specific permissions in a directory before moving a site from a development server to a production environment…

ls -Rl | grep -i 'rwxrwxrwx'

Note: The example above looks for all files and directories with maxed out (eg: 0777) permissions 😉

Improved database table structure for CodeIgniter sessions

I had a problem where CodeIgniter sessions stored in the database were creating multiple session_id’s (each time the session library was called) for the same user.

Here is how my session configuration is defined…

$config['sess_cookie_name']        = 'my-session';
$config['sess_expiration']        = 60*60*2; //2 hours
$config['sess_expire_on_close']    = TRUE;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']        = 'sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']    = 300;

Here is the updated table structure…

CREATE TABLE IF NOT EXISTS `sessions` (
  `session_id` varchar(32) NOT NULL default '0',
  `ip_address` varchar(16) NOT NULL default '0',
  `user_agent` varchar(255) NOT NULL,
  `last_activity` int(10) unsigned NOT NULL default '0',
  `user_data` text NOT NULL,
  PRIMARY KEY  (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

My solution… First, I increased the user_agent field to 255 characters in length. Then, since session_id is always 32 characters in length, I reduced that from 40. If you have any other suggestions, feel free to leave a comment.

Hope this helps someone else having the same problem with CodeIgniter sessions that are being stored in the database 🙂

Get distinct (unique) month and year of records in a mysql table

Here is a quick snippet to pulls the month and year from any date field in a MySQL table…

SELECT DATE_FORMAT(date_added, '%b %Y') AS sDate, COUNT(post_id) AS iCount FROM blog_posts GROUP BY sDate ORDER BY sDate DESC
sDate iCount
Jan 2012 4
Dec 2011 16
Nov 2011 0
Oct 2011 12

Mostly for my reference, but hope it helps someone else 😉

Reset Gallery3 Admin Password using phpMyAdmin

Just a quote note in case I need to find it again later…

If you forgot your admin password for Gallery3 by Menalto, open the users table via phpMyAdmin and replace the existing encrypted password with the following.

$P$DyhWrqfmMF/XKPf3CtPn0pIQDZpQKu

Now, you can log in using 12345 as the password. Make sure you change this immediately after logging back in!

Horizontal icon (footer) layout for Facebook chat contacts window… kind of like the Mac OSX app bar

If you came here looking for the code, that will be a bit further down the road. Here is the plan…

Take this…

Note: The above screen has my hide offline users mod applied 😉

And make it look more like this…

This is a “for fun” project and will be completed as time permits. So check back soon for progress updates.

 

Hide offline contacts from Facebook chat

If you’re like me, you stay logged into Facebook throughout the day. I work online so this is not uncommon.

One thing I have always hated is that there are no preferences for how you want to filter that list. Personally I find it pointless to show you offline contacts in an instant chat interface. I know some people use it to leave messages, but I am not one of them.

Assuming you know how to modify your browser’s custom style sheet, this is all you need to add and those offline users will no longer be visible!

.fbChatOrderedList li.item,
.fbChatOrderedList li.separator {
    display: none !important;
}
.fbChatOrderedList li.active,
.fbChatOrderedList li.mobile {
    display: block !important;
}

Feel free to post questions, comments or even improvements.

IMPROVED: Open all external links in a new window using jQuery

In the original post I covered how to use jQuery to automatically make external links open in a new window. The method however was slightly flawed in my opinion since…

  1. It did not check form action attributes
  2. It assumed ANY link starting with “http[s]://” was external

Here is my new and improved method for making all external site links open in a new window. It now includes form tags, one less selector for secure and non-secure link urls, AND excludes any of those which link to an internal page where the full url may have been specified.

$('a[href*="://"], form[action*="://"]').not($('a[href*="://'+location.host+'"]')).attr('target','_blank');

A quick breakdown…

  1. a[href*=”://“] and form[action*=”://“] matches the elements where a full url has been specified
  2. .not($(‘a[href*=”://’+location.host+'”]’)) excludes all matched items that include the current host (eg: http://www.robertmullaney.com/)
  3. finally we update the target attribute of the the remaining links open in a new window

Why this is important:

Once you have a user on your site, the worst thing you can do is send them away. Also, you will easily annoy them if all links open in new windows and cause them to leave anyhow. This way, only the links that pull them away from site site are opened in new windows. When they are done on the external sites, they close the browser and there your site remains.

Calculate the total height of child elements of a clipped (overflow: hidden) parent tag

Ever have an element with clipped content and wanted to know the total height of the elements contained therein? I have a client who wants the height of the main content to be clipped to a preset height (don’t ask me why). Which means I need to dynamically add a “read more” link to expand the container and show all the content.

Well, here’s how you calculate the combined height of the children with jQuery… Continue reading

Remove www prefix from domain using PHP

I see this question a lot and usually it comes down to getting the current host name for use with cookies. Lets say I want to make a domain-wide cookie, that does not include the standard www prefix such as www.robertmullaney.com. In order for the cookie to work with or without the www prefix, it needs to become ‘.robertmullaney.com’.

preg_replace('/^www\./i', '.', $_SERVER['HTTP_HOST'])

Now, some of you may be looking for a way to determine the top-level domain for something like this.subdomain.robertmullaney.com. That is not an easy solution (since many TLDs have multiple suffixes like .co.uk). If that’s what you’re looking for, check back later and see if I have come up with a good solution… that one’s tricky.

Happy New Year 2012

I’d like to wish all of my visitors and fellow coders a happy and prosperous new year. Keep checking out my blog in 2012 for some new sections included but not limited to java, c++ and iphone/android app development. This should be a good year.

Calculator: Convert Xbox Live Microsoft Points (MSP) to USD

Here is a calculator (requires JavaScript) to convert Xbox Live Microsoft Points into USD (dollars) and vice versa.

Microsoft Point Converter

USD MSP

Simply enter an amount into either field and the conversion is automatic.

PS: If you leech my code, at least link to me for credit 😉