git: Show history with a helpful branching tree

Tracking down branching ancestry in revision control is horrible to say least. At least git has a nice little feature which lets you change the log output into a nicer layout.

git log --graph

To look at a specific revision:

git log --graph commitid

This will give a nice branched log format to help you track down commits.

image

git: Show difference between commits

git diff commitid1..commitid2

C++: Parse command line arguments

First off, you should not use lpCmdLine which is given by the main function of your application.

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)

Be aware that lpCmdLine will only support ASCII characters. If you are creating a project which works with wide characters or multibyte strings, it will be horrible to deal with.

Not to mention you have to parse the string yourself, which means you also have to manage "strings within quotes" yourself as well.

1263914772happy 
HEAD ASPLODES!

Instead, you should be using CommandLineToArgvW() with GetCommandLine(). They will retrieve the arguments for your program, in the correct character set.

You can also use this anywhere, so there is no need to complicate your code and cause hell by passing lpCmdLine down the initialisation function chain.

The magic code:

// Parse command line arguments
LPTSTR *szArgList;
int argCount;

szArgList = CommandLineToArgvW(GetCommandLine(), &argCount);

if (szArgList) {
for (int i = 0; i < argCount; i++) {
//MessageBox(NULL, szArgList[i], L"Arglist contents", MB_OK);

if (!_tcscmp(L"--no-icon", szArgList[i])) {
bShowTrayIcon = false;
}
}

LocalFree(szArgList);
}

LocalFree() is required to unallocate the memory, which is set by CommandLineToArgvW().

Other than that, this is fairly straight forward.

[ Source ]

Wii: Game kicks you back to system menu - You need to install the required IOS

Sometimes a game will kick you back to the main menu after you click "Start" on the channel banner. This happens when it can't find the right IOS files it needs.

I'm not quite sure about the specifics of IOS files, but I think of them like drivers for your Wii and are often upgraded with new system menus.

Just like with PC games, some expect a certain version of Direct X to be installed in order to work properly. Same with Wii games, some require certain versions of IOS files in order to work.

Before, we had to wait for the system menu to be hacked before homebrew can be run. Now, we can simply download the files we need even if the system menu is on an older version. It's like running Starcraft 2 on your Windows 95 machine!

Best part is that all the old versions are kept, so installing a new one doesn't mean you're overwriting an older version of the same IOS file!

packet_sauce
"There's an easier way...? WHAAAAAAAAAA?"

In comes the NUS Downloader. It allows you to download specific files from Nintendo's Update Server and pack it into WAD files for easy installation with the WAD Manager.

image
The NUS Downloader interface.

I prefer this method as DOP Mii only allows me to install certain IOS files, which isn't very helpful for a guy like me who doesn't have the time to sit down and learn every single quirk about IOS files.

To use this, just download the NUS Downloader and run it.

  • Tick "Pack -> WAD"
  • Click on "Database"
  • IOS
  • Find the IOS you wish to download and select the latest.
  • Then click "Start NUS download!"
  • It will now begin to download the IOS file you want and stash it away in a folder where you extracted the program.

Once you find the compiled WAD file, install it like any other WAD file using WAD Manager.

This should fix any problems with games kicking you back to the main menu. The problems are game specific, so different games will require different IOS files.

Wii: How to install Wad Manager?

Homebrewing

Firstly, if your Wii isn't homebrew ready, you'll need to make it so (see sections "Setting up your Wii to run homebrew" and "Installing Homebrew Channel").

Don't worry about old versions. If you've WiFi connectivity from the Wii it'll auto update.

It really is amazing how far Wii homebrew has evolved since the first Twilight Princess hack was discovered.

What's needed?

You'll also need:

  • Wad Manager 1.7 (in executable form)
  • Wad Manager 1.7 (in WAD form). This is only needed if you want to run it from a channel.
    Just search for it on Google and use the one that has a ".wad" extension.

Preparing

Your SD card should already have an apps folder folder, so go to "SD:\apps\" and create "wad_manager". Throw in the Wad Manager executable files there.

Create a folder at "SD:\wad\" on your SD card and throw in any games you wish to install there. Copy over the Wad Manager WAD files if you want to install it as a channel for easy access.

Load up the Homebrew Channel on your Wii and choose the Wad Manager.

  • A to agree to T&C.
  • Select IOS249.
  • Disable NAND emulator.
  • Choose your source device. For SD card users, it's Wii SD slot.
  • Go down to the WAD folder.
  • Select the wad you want to install.
  • Select (un)install.
  • Let it do its thing.
  • When you're done, press HOME to exit back to the system menu.

Now you're WAD Manager ready!

Django: Formate datetime.now() to Unix timestamp

To convert the datetime object to a Unix timestamp using Django:

from django.utils.dateformat import format

timestamp_string = format(datetime.now(), u'U')

slidedog
Now go forth and be happy!

Python: psycopg2.ProgrammingError: syntax error at end of input

This error may come in different flavours, but the majority of the time its because the SQL being executed has a quote around the %s value.

Strangely enough, this seems rather counter intuitive to everything we've been using thus far. I'm not sure where abouts down the chain this happens, but the quotes are added for us automagically.

Error thrown:

psycopg2.ProgrammingError: syntax error at end of input
LINE 1: ...nd-post/1010314'', 'E'Senior Business Development Manager'')

Cause:

cursor.execute("INSERT INTO table_name (id, link, title) VALUES (%s, '%s', '%s')", (id, link, title))

Fixed by removing quotes:

cursor.execute("INSERT INTO table_name (id, link, title) VALUES (%s, %s, %s)", (id, link, title))

[ Source ]

Python: psycopg doesn't insert or delete

I had to write a quick feed parser using psycopg before and was wondering why stuff didn't save.

Turns out I was missing a very important line at the end... connection.commit() !

A quick example below shows how to use psycopg.

import psycopg2

class SaveStuff():
connection = None
cursor = None

def __init__(self):
# Connect to an existing database
self.connection = psycopg2.connect("dbname=yourdbname user=username host=twigstechtips.blogspot.com")
self.cursor = self.connection.cursor()

def __del__(self):
if self.cursor is not None:
self.cursor.close();

if self.connection is not None:
self.connection.close();

def save(self, items):
if self.cursor is None:
raise Exception("Invalid connection to database.")

# Delete existing
self.cursor.execute("DELETE FROM table_name")

# Fill in the new values
for item in items:
sql = "INSERT INTO table_name (id, name, weight) VALUES (%s, %s, %s)"
self.cursor.execute(sql, (item.id, item.title, item.order))

# Write the new info to db
self.connection.commit()

[ Source ]

django: Custom template on admin form

Most of the time, the auto generated Django admin forms are pretty sufficient.

Although there are other times when you'd find it helpful to add some information into the form such as "current results" for the polls or current weather trends for the week if looking at a weather station.

To customise the admin template:

  • Create a template file in "templates/admin/appname/model_name/change_form.html"
  • Make it extend "admin/change_form.html"
  • A sample change is:

{% block after_field_sets %}
{% if change %}
You are changing {{ original }}
{% else %}
This is a new objecct
{% endif %}
{% endblock %}

  • Save and refresh to see it take effect.

To see what blocks you can replace, see the folder "django/contrib/admin/templates/".

[ Source ]

Thunderbird - Images not sent properly in forwarded emails

The email protocol is riddled with mixed up clients and badly formed content. It's no wonder that clients are so confused because there a bazillion ways of sending an email.

The main issue I've noticed is when I receive an email filled with funny pictures as either:

  • Inline attachments (embedded into the email body)
  • File attachments (which hang off the email)
  • External image links (URL pointing to an external source)

When you try to forward the email, the images are visible on your end, but after its sent off the person you sent to will not be able to see it.

Fix

First, go to Tools > Options > Composition > General.

image
Options dialog.

  • Set "Forward messages" to inline.
  • Click on "Send options..."
  • In "Text Format", set "Send the message in html anyway"

Now go to the account settings for each account.

  • See the "Composition & Addressing" item.
  • Under "Composition", tick "Compose messages in HTML format".

Now your emails will be able to send, reply and forward images (and other attachments) correctly as you see them.

Now theres nothing left to do but DANCE!

mini-tux
Like this kid from the Apple store...

Thunderbird: Rearrange the order of email accounts

The other day I had to change an email account from POP3 to IMAP. It was 3rd on my long list of email addresses (yes, I am a massive email whore) and when I added a new account it went smack bang down to 10th at the very bottom =(

To rearrange the email accounts on the left hand tree, you have one of two three options.

Use my order generation script

I spent 15mins whipping up this script because I really don't wanna install something I don't need to.

On the other hand, its a pain in the ass to do it manually.

I've put the script here if anyone wants to use it. You can read the source code before entering any data in.

Download the FolderPanes Extension

This is the easiest way. I've never tried it, but lots of people say it works. Get it here.

pichu
Success!

Edit the file manually

This can be a little painful, as the account IDs aren't what you'd expect.

Close off Thunderbird and open up your Thunderbird profile folder. Edit "prefs.js" in notepad.

Search for "mail.accountmanager.accounts".

Now that whole row should read something like this:

user_pref("mail.accountmanager.accounts", "account9,account1,account7,account5,account8,account11,account10,account6,account3,account2,");

Now the tricky bit is to find the matching ID's. You'll have to scroll past the whole chunk of "mail.identity.id#" blocks and look for "mail.server.server#".

Naturally you'd presume that the identity IDs are the ones you need, but it isn't. It actually needs the server ones.

To make your life easier, open up a blank notepad file and copy over all the values of "mail.server.server#.name".

Rearrange them in the notepad to the order you want and then change the value of "mail.accountmanager.accounts" accordingly.

Save "prefs.js" and start Thunderbird to check if the order matches what you set.

megakick
Even more success!

[ Source ]

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