January 2012 M T W T F S S « Nov 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Categories
- Allergy Diary
- Back Doors
- Bash/Shell Scripts
- Child's Mind
- Daily commute
- Dance
- Food
- Food allergies
- Fun with Family
- git
- Greener pasture diary
- Health
- Home Improvement
- HTML
- Humor
- JavaScript
- Music
- NO milk NO eggs NO nuts!
- Non sequitur
- Panorama
- Passé
- Photographs
- php
- Potty training
- Pre-K Shows
- Recipes
- San Francisco Living
- Sentimental
- Tech
- Uncategorized
- Urban Gardening
- Woodworking
Allergy Resources
Blogroll
Comic Strip
Documentaries
Photos
Stories
Tech
Tools
Meta
Custom JavaScript String Functions
I’ve created some missing native JavaScript String function to trim, convert to camel case, to underscored and to dashed formats.
Here is the trim() function (gist page):
/**
* trim: removes leading and trailing white space
*/
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, "");
};
And the toCamelCase() function (gist page):
/**
* toCamelCase: converts string to camel case
*/
String.prototype.toCameCase = function () {
return this.replace(/^\s+|\s+$/g, "")
.toLowerCase()
.replace(/(\s[a-z0-9])/g, function ($1) {
return $1.replace(/\s/, '').toUpperCase();
})
.replace(/\W/g, '');
};
And the toDashed() function (gist page):
/**
* toDashed: converts string to dashed
*/
String.prototype.toDashed = function () {
return this.replace(/^\s+|\s+$/g, "")
.toLowerCase()
.replace(/-/g, '')
.replace(/(\s[a-z0-9])/g, function ($1) {
return $1.replace(/\s/, '-');
})
.replace(/[^a-z0-9-]/g, '');
};
And finally, the toUnderscored() function (gist page):
/**
* toUnderscored: converts string to underscored
*/
String.prototype.toUnderscored = function () {
return this.replace(/^\s+|\s+$/g, "")
.toLowerCase()
.replace(/_/g, '')
.replace(/(\s[a-z0-9])/g, function ($1) {
return $1.replace(/\s/, '_');
})
.replace(/[^a-z0-9_]/g, '');
};
Irish Dancing
This one goes out to Tom and Claire.
Posted in Child's Mind, Fun with Family
Comments Off
Showing selected drop-down option in WordPress archive select menu
I needed to show as selected, the option in the WordPress archives drop-down menu (<select>) corresponding to the current page address. One possibility was to alter the get_archives_link(…) function in the /wp-includes/general-template.php. Doing so meant the modification would get over written if WordPress were updated, so I opted to add a custom modifier in the functions.php file of the custom WordPress 3.0 theme I was creating.
Here’s my custom modifier function from my functions.php file:
function get_archives_option_mod ( $link_option ) {
preg_match ("/value=[\'\"](.+?)[\'\"]/", $link_option, $url);
$requested = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
if ($requested == $url[1]) {
$link_option = str_replace("<option value=", "<option selected=\"selected\" value=", $link_option);
}
return $link_option;
}
add_filter("get_archives_link", "get_archives_option_mod");
My git frequent commands
I’m writing this only for my own usage, so I have a place to find them when I need them. Do all of the following from within the local git project folder.
Initializing a repository
git init git add * git commit -m 'initial commit'
Then create your repository on Github: my_repo_name with my_user_account
git remote add origin git@github.com:my_user_account/my_repo_name.git git push origin master
Checking what is not yet committed:
git status -s
Adding all new/updated files:
git add *
Adding a file by name:
git add /path/to/file
Committing the additions:
git commit -m 'comment for this commit'
Pushing the updates:
git push
Updating a local repository with remote content:
git remote update
Another useful one to delete remote files that were deleted locally:
for i in `git status | grep deleted | awk '{print $3}'`; do git rm $i; done