git: Ignore dirty or untracked submodules in diff or status commands

Git 1.7.0 added a feature which marks submodules as dirty if an untracked file is in it.

--- a/article
+++ b/article
@@ -1 +1 @@
-Subproject commit aba7c80124b0ac07299f224f1bf7ddd4c9a095e3
+Subproject commit aba7c80124b0ac07299f224f1bf7ddd4c9a095e3-dirty

...

diff --git a/south b/south
--- a/south
+++ b/south
@@ -1 +1 @@
-Subproject commit 6512510da9a408b178730f38fcac664483451ab0
+Subproject commit 6512510da9a408b178730f38fcac664483451ab0-dirty

Personally find it annoying because the files there just patch files or something I'm saving for later.

git status

# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#   (commit or discard the untracked or modified content in submodules)
#
#       modified:   article (modified content)
#       modified:   south (untracked content)

So you can see that "article" has files thats been modified, while "south" has files which are untracked.

To ignore this, you have to add the --ignore-submodules flags to your diff and status commands.

git status --ignore-submodules=dirty
git diff --ignore-submodules=dirty

Sources

Android: Managing AsyncTask, progress dialog and screen orientation

For my app Moustachify Everything, I was getting quite a few 1-star ratings when users got a black screen for the results.

It took me a while to figure out why it was happening. Because I test on WiFi, the images upload quite quickly.

When testing with 3G, I accidentally rotated the screen and the progress dialog was cleared, leaving me with just a black screen and an ad.

When the AsyncTask completes, it updates the image (in the old Activity) but the image in the current Activity is still black.

To fix this, you'll need to keep track of your AsyncTask. It sounds longer than it actually is, but you'll learn some new tricks on the way.

The AsyncTask

If using an anonymous instance of AsyncTask, extract it out into it's own class or into an inner class of the activity. You'll need to be able to store a reference to it somewhere.

Important things to do are:

  • Keep a reference to the current activity
  • Keep an instance of the ProgressDialog

The Activity

Using onRetainNonConfigurationInstance(), we pass the new Activity the existing information about the AsyncTask.

This is how we update the "current activity" within the AsyncTask.

Important things to note are:

  • Keep an instance of your AsyncTask
  • Implement onRetainNonConfigurationInstance()
  • During onCreate(), check getLastNonConfigurationInstance()

A working example

public class SomeActivity extends Activity {
private ProgressAsyncTask m_progressTask;

// This is purely a data storage class for saving information between rotations
private class LastConfiguration {
Drawable drawable;
ProgressAsyncTask progressTask;

public LastConfiguration(Drawable drawable, ProgressAsyncTask progressTask) {
this.drawable = drawable;
this.progressTask = progressTask;
}
}

private class ProgressAsyncTask extends AsyncTask<String, Integer, Bitmap> {
private ProgressDialog progressDialog;
private Activity m_activity;

protected ProgressAsyncTask(Activity activity) {
setActivity(activity);
}

public void setActivity(Activity activity) {
m_activity = activity;

progressDialog = new ProgressDialog(m_activity);
progressDialog.setMessage("Growing your mo ...");
progressDialog.setCancelable(false);
progressDialog.setMax(100);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

progressDialog.show();
}

// Just some example code to update your progress dialog
protected void onProgressUpdate(Integer... values) {
progressDialog.setProgress((int) ((values[0] / (float) values[1]) * 100));
};

// Once we're done, make sure you reference the activity
@Override
protected void onPostExecute(Bitmap result) {
ImageView img = (ImageView) m_activity.findViewById(R.id.imgResult);
img.setImageBitmap(result);
progressDialog.hide();
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);

// See if we've got any information from the existing Activity
LastConfiguration lastConfiguration = (LastConfiguration) this.getLastNonConfigurationInstance();

// Screen was rotated, re-apply data we already have
if (lastConfiguration != null) {
ImageView img = (ImageView) findViewById(R.id.imgResult);
img.setImageDrawable(lastConfiguration.drawable);
m_progressTask = lastConfiguration.progressTask;
// Update the task because it is currently pointing to a stale activity
m_progressTask.setActivity(this);
}
// New instance of SomeActivity, fetch image
else {
m_progressTask = new ProgressAsyncTask(this);
m_progressTask.execute("http://www.url.com/to/file.jpg");
}
}

// Remember the information when the screen is just about to be rotated.
// This information can be retrieved by using getLastNonConfigurationInstance()
public Object onRetainNonConfigurationInstance() {
ImageView iv = (ImageView) findViewById(R.id.imgResult);
return new LastConfiguration(iv.getDrawable(), m_progressTask);
}
}

Source

Android: Fix "Error generating final archive: Debug certificate expired"

Now this was surprising. I had to update a project and I guess it's been over a year since I've started Android development.

Apparently Android SDK only signs the debug certificate for a year. This can be a bit annoying because you have to uninstall all your testing apps after you create a new debug certificate.

  • First up, open up Windows Explorer and paste in "%HOMEPATH%\.android"
  • Locate "debug.keystore" and delete it
  • Now back in Eclipse, hit Project > Clean in the menu
  • You should now have a new debug certificate.

If you want to make the certificate last longer, see the Androidian link below for steps on creating your own certificate.

Source

Django: A simple order and distinct query

A common query in SQL would be:

SELECT DISTINCT type FROM Item ORDER BY type;

In Django however, it's a little tricker since we've got the ORM.

Items.objects.order_by('type').values_list('type', flat = True).distinct()

Unusual? Yes. Impossible? No.

Excel: Creating a dropdown list in cells

I've seen this a couple of times but never got around to figuring out how it works.

image

  • First, type up the cells which will be used as reference.
  • image 
  • Select the cells you want to apply the "dropdown list" to
  • Click on Data > Validation
  • Change "Allow" to "List"
  • Click the little weird icon in "Source"
  • image
  • Select the cells containing the list of items
  • image 
  • Confirm by clicking the little weird icon on the right.
  • image
  • Click OK
  • Now the dropdowns should be enabled.
  • image

Source

Python: Setting up PostgreSQL support in Windows Python

Took me some time to get this working but I finally got it!

You can grab the Python 2.4 to 3.2 binaries (for both x86 and x64) from StickPeople.

  • I used WinRAR to extract the contents of the EXE by right clicking the file.
  • Move the contents of "PLATLIB\psycopg2"
  • To "your_python_folder\Lib\site-packages\psycopg2"

Source

Windows Live Messenger: Disable "File Transfer Warning" notification when trying to send a file

All I want to do is send a fucking ZIP file to my friend.

image

I'm not going to install an antivirus just so I can send files. Security in airports I can understand. Over-zealous security on my computer? Please go away.

I don't have an antivirus. Seriously. Common sense has kept my work computer safe for over 3 years now.

My solution? Fuck installing an antivirus and just run the command prompt.

  • Tools > Options > File Transfer
  • Tick "Scan files for viruses using"
  • Paste in "cmd /k exit" into the textbox
  • Click OK

image

Solution works brilliantly. No black box flickers, you can send files without any complaints and no registry hacks to allow file types.

Source

Diablo 2: Getting PlugY to work on patch v1.13d

Sad to say it, but I've been hooked on a 11yr old game again. The latest patch however is not compatible with many hacks and mods. At time of writing, the latest patch is 1.13d.

One of the most popular mods being PlugY, which increases your stash size and allows you to get Ladder/Online Only rune words in single player mode.

To get it working, you'll need to downgrade. Sorry, I don't know of any other way.

Ingredients needed for this cube recipe are:

Rather than reinstalling, simply download and install D2SE. When you run it, it'll let you select which version you can switch to.

image

  • Select "1.13c LOD Vanilla". This will reset your install back to v1.13c.
  • Click on "Start D2" to make sure the game still works. Since you're on v1.13d, the save games should still show up even though you're using 1.13c.
  • Now Exit.
  • Install PlugY as normal by extracting the contents of the zip file into your D2 folder.
  • "PlugY.exe" and "PlugY.ini" should be in the same folder as "Diablo II.exe"
  • Edit "PlugY.ini" to your liking.
  • Run the game using "PlugY.exe"
  • If it's attached, you should see the PlugY version in the bottom right corner.
  • Load a game and if it doesn't crash after the loading screen finishes then you've got yourself a winner!

By the way, get my Diablo 2 Runewords Android app!

Sources

Opera Browser: Change next tab keyboard shortcut

I like to use the keyboard where possible. In Firefox, I set my Ctrl+Page Up/Down buttons to switch between tabs so I don't have to reach for my mouse as much.

However, when I tried to do this on Opera... god damn wut!? This is one of the cases where it's harder than it should have been.

Firstly, find the settings dialog by:

  • Going to Opera > Settings > Preferences (Ctrl + F12)
  • Advanced > Shortcuts
  • if you haven't already, under "Keyboard setup" make a duplicate of "Opera Standard". I named mine "Opera Standard (modified)".
  • Select the new scheme then press "Edit".

image

Try not to gasp when you see this hideous dialog.

Type in "page" to start filtering the options.

image

  • Under "Application", search for "Switch to next page".
  • In the left column, double click it and paste in "ctrl + PageDown" (it's case sensitive!)
  • As for "Switch to previous page", paste in "ctrl + PageUp".

It should now look like this:

image

Alright! Confirm to exit and it should apply straight away.

I really hope Opera takes the time to polish these features as Firefox has become buggy and downright stupid after adopting the rapid release schedule.

Windows 7: Disable "To help protect your computer, Windows has blocked access to this file"

So I was using the work PC to extract some files I received in my email.image

Damn it I'm just trying to extract some files for work, stop treating me like a grandma!

Fuck this.

Right click on the file > "Properties" > "Unblock".

image

Try extracting again and it'll work.

To prevent files from being tagged as "unsafe", follow the instructions in my previous post Windows 7: Disable the "Open File Security Warning" message.

Source

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