Win7/Vista: Disable password expiration

One day, I got an annoying message saying "Your password has expired". Wtf?

Anyway, to disable the password expiry feature:

  • open a command prompt in Administrator mode.
  • Then type "lusrmgr.msc" to load up the "Local Users and Groups" management console.
  • Go into "Users" and edit the profile that has expired.
  • Select "Password never expires" and apply.

If you get "Access is denied", that means you didn't run the console with administrative rights (step #1).

While you're at it, you might want to take the time to disable the Guest account as well.

Left 4 Dead 2: Uncensored Australian Hack

Censorship sucks, no matter in what form. Hide reality long enough and we'll end up with a nation of fucking sissies that'll cry if a dog leaves a turd on grass.

In the pansie Australian version of Left 4 Dead 2:

  • Zombie bodies will fade straight away
  • Body parts will not be sliced. The whole zombie dies intact no matter how you kill it.
  • No blood on your screen.
  • Zombies will not burn when hit with molotovs or incendiary ammo)

Well fuck you "Office of Film and Literature Classification" (OFLC)! We still don't have an R18+ rating because according to them, Australia doesn't have anyone that is mentally older than that.

So to get these features back, you'll have to first understand there are some side effects.

  • It works best on single player and offline play.
  • You cannot play online with your friends (even if they have patched it). There are some places that mention an "sv_pure 0" setting but I've never looked too much into it.
  • This works on the Steam version, but its easier to just buy it from the UK store.
  • You cannot start the game through Steam, but you need it to be running to play.

Editing

  • Upon up your Steam folder
  • Go to "steamapps\common\left 4 dead 2"
  • Open "steam_appid.txt"
  • Change 550 to 510
  • Save the file and close it
  • Now right click "steam_appid.txt" and click "Properties"
  • Make it "read only" and save
  • Now create a shortcut to "left4dead2.exe" on your desktop (or where ever you want that is convenient)
  • From the current folder you're in, go into "left4dead2"
  • Open "gameinfo.txt" and change "SteamAppId" from 550 to 510
  • Now make that file read only

The reason we created a desktop is that you cannot start the game via Steam. Otherwise it'll just quit when the gameplay starts.

You also cant start the game without Steam running in the background. Quite annoying.

Now you can enjoy L4D2 while burning and cutting up zombies, the way that nature intended.

[ Source ]

(The source seems to be a bit outdated, but the majority of the instructions still work)

Facebook: Post RSS feeds to your Page wall (not personal wall)

I haven't had much luck with finding information about this, but somehow I stumbled upon a little site called TwitterFeed.

Surprisingly, the site wasn't just about Twitter (ugh) and it provided a very simple yet helpful service; read off an RSS feed and post it to various social networks such as Twitter, Facebook, Statusnet, Ping.fm and Hellotxt.

Whats better is that it actually supports posting to your business/organisation page, rather than just your personal page.

Unfortunately there is no "about us" page of some sort on TwitterFeed, so I had to sign up to see what it was all about.

Very simple to use

  • Create a new feed (enter in name and URL)
  • You can configure how often it updates and how many posts to make from each update, post suffix/prefix and also filter out keywords.
  • Each feed is configured independantly, so you can choose which social network that a feed is directed to.
  • (Facebook) Upon entering your account details, you can then selected which page it displays on, but only if you have admin rights on the page.

That's all!

WordPress: Custom query builder to list posts in a certain category or tag

I wanted to a page which displayed posts in a specific category, on a given date and didn't want to write some custom SQL query for it.

Luckily, the WordPress API makes it easy to modify the query even while in the template.

A global variable called $wp_query is available during most parts of the code.

This snippet below lets you list:

  • All posts (no paging)
  • In chronological order
  • and listed in the 'Links' category
$wp_query->set('nopaging', true);
$wp_query->set('order', 'ASC');
$wp_query->set('category_name', 'Links');

$wp_query->query($wp_query->query_vars);

get_template_part('loop');

Now you've got a snippet that does just that, in a few lines of code without having to write up any SQL at all!

The "loop" and argument in get_template_part() can be any template name you want.

You can also filter by tags and categories (or exclude), limit the number of posts shown, restrict by date range, author or paging options.

See the documentation for many more options.

[ Documentation ]

mIRC: stop /var from evaluating mathematical expressions

I can't see why this is a useful feature, since $eval() and $calc() already exist.

So I've finally gotten around to fixing a bug in my script that's been haunting me for the good part of 4 years.

It was in the script I've been using to highlight URLs which I paste in a blue underlined format.

on *:input:#: {
if ($left($1,1) != /) {
var %input $1-

.echo -q $regsub(%input, /((?:telnet:\/\/|ftp:\/\/|https?:\/\/|www2?\.)[^<>\.\s]+(?:\.[^<>\.\s]+)+(?:\/[^<>\.\s]+)*)/g, 12\1, %input)
.echo -q $regsub(%input, /(irc:\/\/[^<>\.\s]+(?:\.[^/<>\.\s]+)+(?:\/[^/<>\.\s]*)?\/?(?![^\s\x2c\.]))/g, 12\1, %input)
.echo -q $regsub(%input, /(aim:goim\?screenname=[^\s&]+(?:&message=[^\s&=]+)?)/g, 12\1, %input)

if (%input != $null) {
msg $active %input
haltdef
}
}
}

However, whenever I would enter in text like "1 / 2" or "1 + 1", the script would evaluate it into "0.5" and "2" respectively.

Baffled, I had no idea behind to why this was happening. Tonight, I had enough of it and looked for an answer. Thankfully, "Sigh" wrote up a little blurb about /var that solved my problems.

All I had to do was change /var to /set -n and it would stop it from evaluating. Simple as that!

set -n %input $1-

The reason is that both commands evaluate mathematical expressions, but /set actually has a switch to treat the value as plain text.

[ Source ]

Firefox: Bring back old session windows with TabMixPlus

After upgrading to a very gay Firefox v3.6, I was annoyed that it disabled many of my working extensions.

To add to my annoyance, it didn't restore my window sessions correctly. I had heaps of windows opened over a period of many weeks and many of the pages were ridiculously difficult to find.

Luckily, I had the TabMixPlus extension installed. It automatically saves your sessions. I know, I know, Firefox does this automatically already. But Firefox only saves one or two sessions.

TMP saves up to a week by default. So it doesn't really matter how many times you open and close your windows, you can be sure its protected in case of a stupid update.

If you need to restore the sessions:

  • Close your Firefox session (and make sure nothing important is opened). You may want to copy these instructions somewhere first.
  • Find your profile folder
  • Go into "sessionbackups"
  • Find the latest "tabmix_sessions-***.rdf" file and copy it
  • Go up a folder, delete/move/rename "session.rdf"
  • Paste the file into "sessionbackups"
  • Rename it to "session.rdf"
  • Your sessions should be restored the next time you open Firefox

[ Source ]

Firefox: Re-enable the "enable" button on extensions that are "not compatible with Firefox"

Sometimes these version checks are just plain annoying. Well, as of Firefox v3.6 they just got MORE annoying!
Anything before the gay persona 3.6, use this trick.
As of v3.6 and onwards, they decided to modify that key use a more stupid convention and append the version to the string.
WHY THE HELL? The very reason that key exists is to disable those fucking stupid version checks!
So, to enable extensions that aren't compatible, do the following:
  • Type "about:config" into the browser
  • Right click on the main area and click "New" > "Boolean"
  • Call it "extensions.checkCompatibility.<version>" where <version> is the version of your Firefox.
  • Set it to False.
image
The old and the new way of doing it. How fucking annoying.
For me, I'm using Firefox 3.6.6, so you can call it "extensions.checkCompatibility.3.6" and it'll work.
The other reason I'm so annoyed at upgrading Firefox is because it cleared the windows I had open. I've fixed it and posted the method here.

*update 11.04.2011* This will also solve the problems with " could not be installed because it is not compatible with this Firefox" errors when trying to install a new extension.

[ Source ]

WordPress: Insert a post via code

To insert a post programatically, you'll need to make a simple call to wp_insert_post().

$data = array(
'post_status' => 'draft',
'post_type' => 'post',
'post_author' => $user_ID,
'ping_status' => get_option('default_ping_status'),
'post_parent' => 0,
'menu_order' => 0,
'to_ping' => '',
'pinged' => '',
'post_password' => '',
'guid' => '',
'post_content_filtered' => '',
'post_excerpt' => '',
'import_id' => 0,
'post_content' => '',
'post_category' => array(),
'post_title' => ''
);

$post_id = wp_insert_post($data);

add_post_meta($post_id, 'some-field-name', 'this was added programmatically');

Anything in that $data array can be removed because those are the default values.

The trickiest bit is to get the categories working. The post_category bit requires the category ID, which you can get using get_cat_ID('Category Name').

add_post_meta() is optional, in case you needed to append some meta fields to your post.

And thats all there is to it!

WordPress: Get current user's username or ID

There is a global variable called "$current_user".

global $current_user;

And in there is a field called "user_login".

$current_user->user_login;

You can also use "$current_user->id" to get the user id.

Wordpress: Make cForms II pass named fields instead of field_X

When capturing the form data in my_cforms_filter() you may have noticed that the posted data does not use proper field names.

Array(
[field_1] => title
[field_2] => name
[field_3] => state
[field_4] => content
[id] =>
)



When setting up your cform, make sure you click "Use custom input field NAMES & ID's" under "Core Form Admin / Email Options".



You should note that this only applies to non-ajax forms, so you'll also have to untick the "Ajax enabled" option next to the form name.



Now you should see some named indexes which are a bit more relevant.




Array(
[Title] => title
[Name] => name
[State] => state
[Letter] => content
[cf_working] => One%20moment%20please...
[cf_failure] => Please%20fill%20in%20all%20the%20required%20fields.
[cf_codeerr] => Please%20double-check%20your%20verification%20code.
[cf_customerr] => yyy
[cf_popup] => nn
[sendbutton] => Submit
)



Lastly, if you want to name these fields, you'll have to set the label in a certain format.



Changing the "Title" label to "Title [id:my-title-field]" would now give you:




Array(
[my-title-field] => title
[Name] => name
...
)



Note: I've had problems using the ID "name", which causes the form to display a 404.

Wordpress: Easy to use and fairly customisable forms

cForms II is a pretty nice plugin for WordPress that allows you to create a custom form quite quickly and embed it into your post or page.

It has a fairly wide set of options (see information page) but does not support the high level of customisation which Drupal allows such as custom validation (as far as I can tell).

Creating a form

In order to embed a form, firstly you'll have to create one.

Go to the admin and you'll see a new menu group called "cForms II". Under that, click "Form settings". From here you can add or remove fields from the default form, change some messages and other options related to ONLY this form.

Note: It's a good idea to click "Update settings" after you're done modifying parts of the form as some changes (such as adding a new field) will refresh the page, causing you to lose other changes in the form.

image

Update settings can be found on the right side of the admin form under the expandable "Admin Actions" widget.

You can mess with the global settings too, but I'm not gonna cover that in this tutorial.

Inserting the form into a post or page

When you're happy with it, figure out where you want to use it. Forms can be embedded in the post, a page, or anywhere on the template.

If you're using the WYSIWYG editor for posts or pages, you can use the cForms button in the TinyMCE toolbar.

image
Clicking on this will grant you three wishes.

Select the form you want to insert.

image

And whalla! Form inserted into post/page.

Inserting form into template

Lastly you can insert the form directly into the template using some PHP code.

If you're adding it into the template somewhere, then use the following snippet.

insert_cform(check_form_name('your_form_name'));

I'm not sure why the first arg isn't the form name, but it took me a while to figure that one out.

Documentation

That should be enough to get you started with cForms. There are also information pages within the plugin administration panels to give you a fair idea of how things work.

[ Download ]

Django: Easy template fallback selection

Django has some pretty neat features that allow for simple template selection.

You can generate a list of templates you wish to use, and it'll go through and see if they exist. The first one that exists will be returned.

from django.template.loader import select_template

An example below:

def section_page(request, section_slug, subsection_slug):
c = { 'title': 'blah blah blah', 'section': section_slug, }

template_list = (
'section/home_%s_%s.html' % (section_slug, subsection_slug),
'section/home_%s.html' % section_slug,
'section/base.html'
)

return render_to_response(select_template(template_list), c, context_instance = RequestContext(request)

Now following the given example, if we tried to load a section such as "funny" and the subsection of "comics", it'll see if you have a customised layout for "home_funny_comics.html" and use it.

If that file doesn't exist, it'll try to get "home_funny.html" and use it.

Now if that doesn't exist, as last resort it'll use "base.html" as the template.

If none of those exist, it'll raise an exception.

Tutorial: Logic behind resizing image and keeping aspect ratio

Once in a while you'll encounter this problem and the logic usually remains the same regardless of what language you're using.

Use cases are:

  1. Resize to given width and height, ignoring image aspect ratio
  2. Resize to given width, keeping height in the correct aspect ratio
  3. Resize to height, keeping height in the correct aspect ratio

The tutorial/example below is given in PHP, but if you skim the lines of code its just some common control statements that are used.

if (!file_exists($resized_file)) {
$image_info = image_get_info($input_file);
$w = $image_info['width'];
$h = $image_info['height'];

if (!$reso['keep_ratio']) {
$w = intval($reso['width'] != -1 ? $reso['width'] : $image_info['width'] * ($reso['height'] / $image_info['height']));
$h = intval($reso['height'] != -1 ? $reso['height'] : $image_info['height'] * ($reso['width'] / $image_info['width']));
}

else {
// Check if resize needed ...
if (($image_info['width'] > $reso['width']) || ($image_info['height'] > $reso['height'])) {
// Compare ratios to determine which side is longer
// If width ratio < height ratio, then use height/width, otherwise width/height
$resize_by_width = (($image_info['width'] / $reso['width']) > ($image_info['height'] / $reso['height']));

$resize_ratio = ($resize_by_width ? $reso['width'] / $image_info['width'] : $reso['height'] / $image_info['height']);

$w = $image_info['width'] * $resize_ratio;
$h = $image_info['height'] * $resize_ratio;
}
}

image_resize($input_file, $resized_file, $w, $h);
}

Hopefully thats fairly easy to translate into another programming language.

You're one of those ...

I normally don't like reading comics, but this one struck me as funny as it reminds me of a few people I've met before.

image

Win7: Stop grouping of taskbar items when dragging with 7 Taskbar Tweaker

The Windows 7 superbar is great, minus a few exceptions.

I kinda hate the fact that sorting of taskbar items are grouped by application. Although you can sort within the same group, its not usually helpful.

Also, I prefer to have the right click as it used to be instead of the stupid jump menu. To get it to show up normally, I'd have to hold Shift and then right click.

Luckily some clever chap called RaMMicHaeL created a funky little program that does just that and a bit more.

You can also disable aero peek (if you don't like it) and change the behaviour when you drop files into the taskbar.

image
Screenshot of the options dialog.

It works in both 32 and 64 bit flavours and has worked wonderfully for me for over a year now without any bugs.

[ Download page ]

Django: Get the latest comments for a particular object

Its easy enough if you're using the template tags. Just refer to the documentation and you should be set.

First, remember to load the comments tags.

{% load comments %}

To get the number of comments for an object:

{% get_comment_count for entry as comment_count %}

Or quickly display all the comments:

{% render_comment_list for whatever_object %}

If you want more control displaying the comments:

{% get_comment_list for object as comment_list %}

{% for comment in comment_list %}
...
{% endfor %}

However if you're trying to get that info in the code, good luck.

from django.contrib.comments.models import Comment
from django.contrib.sites.models import Site
site = Site.objects.get_current()
comments = Comment.objects.for_model(self).filter(site = site, is_public = True, is_removed = False)

 

[ Source ]

Postgres SQL: Installing Postgres SQL and PhpPgAdmin on Windows

Assuming you already have Apache and PHP installed and configured correctly, what you'll need now are:

These were the latest versions at time of writing, but it shouldn't vary the setup that much.

PostgreSQL

Installation for Postgre should be pretty straight forward.

Choose a place to stash it, give it a root password and skip through the bits that don't really matter to you.

phpPgAdmin

Extract phpPgAdmin and open up "conf\config.inc.php".

Change:

$conf['servers'][0]['host'] = '';

to

$conf['servers'][0]['host'] = 'localhost';

If you're unable to login (even though you're SURE the password is correct) and keep getting "Login disallowed for security reasons", see here.

Django: Set cookie expiry time to one day

To set browser cookies in Django that automatically expire in the specified time, use the following snippet:

d = datetime.datetime.now() + datetime.timedelta(days = 1)
response.set_cookie('something', value = 50, expires = d.strftime("%a, %d-%b-%Y %H:%M:%S GMT"))

Linux: Dump contents of all files matching certain filename

I had to look for a specific line of code across multiple branches of a project. There were over 30 or so branches, so it'd be terribly time consuming to look through them all one by one.

Instead of doing that, write up a little snippet that'll dump all the contents of those files into vim.

find -name "your_filename.py" -exec echo '-----' {} '-----' \; -exec cat {} \; | vim -

This will search any folder under the current working directory for "your_filename.py" and dump its contents into vim.

The contents of the files are seperated by "----- path/to/your_filename.py -----" for easy searching.

[ Source ]

YouTube: Finally fixed slow loading during peak hours and some videos don't load at all

For months I've been wondering why the hell my YouTube kept buffering during peak hours.

At first I thought it was my ISP oversubscribing users on high data plans, but it was during the peak periods so that didn't quite make sense. (Australia doesn't quite have truly unlimited internet plans yet.)

So after contacting my ISP and getting some generic responses back like:

  • Check your firewall
  • Antivirus subscription
  • Windows Updates
  • No Peer 2 Peer programs running
  • Speedtest on another computer
  • Isolation test (unplug all telephony devices except for router/modem)

I didn't bother with trying out another modem, because it had been working fine the whole time and the problem was only during certain hours of the day.

Eventually I figured it out. For some time now I had configured my router to use OpenDNS. At first it was not an issue, but I guess something changed and it couldn't cope with the stress.

Disabling the use of OpenDNS and reverting back to the DNS hosts provided by the ISP worked wonders. Once again the videos stream without buffering.

PHP: List methods/functions in a class or object

Use the built-in function get_class_methods() which returns an array of method names. It'll take a class or object as the first argument.

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog