Surprisingly, this doesn't come as a standard function in the Exception class.
import traceback
try:
raise Exception("print exception!")
except:
print traceback.format_exc()
Short and simple, so good!
Mainly notes to future-Twig (and for anyone else who may find them useful)
If you've found one or more of my blog posts helpful, why not say thanks by buying me a coffee or beer?
Surprisingly, this doesn't come as a standard function in the Exception class.
import traceback
try:
raise Exception("print exception!")
except:
print traceback.format_exc()
Short and simple, so good!
I needed a quick way to clear out all the compiled Python ".pyc" and Java ".class" files on my drive, and searching via Windows Explorer is just slow.
del /S *.pyc
del /S *.class
It'll all be over after the wall of text has finished moving.
Well, this one had me baffled for a while. I thought that the user had to exist before I could send emails "from" that address.
But that makes no sense if I were to ignore all emails from noreply@thatawesomeshirt.com.
So, I did a little research and discovered that it's a CPanel setting!
Log into your CPanel and go to "Email" > "Set default address".
You can choose to forward the email to a valid address, but in the case of a "no-reply", just discard it by selecting "Discard (Not Recommended)".
Click "Change" to save.
This is what I felt like after putting up with error emails for so long...
It's often useful to fetch the raw image data without having to save it to a file first (eg. as serving images by HTTP or sending email attachments)
To do that, we make use of the class StringIO.
import StringIO
# Save the file to a temporary file because that's how email attachments work
output = StringIO.StringIO()
pil_image.save(output, format = "PNG")
email.attach(filename = "whatever.png", mimetype = "image/png", content = output.getvalue())
output.close()
And there you have it!
Screen is a handy little thing that lets you run an extra persistent console in the background which stays active after you disconnect.
However, scrolling back up the screen buffer is a tad more tricky.
After using it on and off for a few years, I've finally run into the need to scroll up to see what's in the buffer.
To do that:
Since it's such a short snippet, I'll keep this post nice and simple.
from email.utils import parsedate_tz
print parsedate_tz('Fri, 15 May 2009 17:58:28 +0700')
That's it!
This is a lightweight editor plug-in with syntax highlighting and folding.
My Eclipse didn't have it, probably because I downloaded the classic release without all the extra Java trinkets.
Firstly, find out which release you're on. It usually displays a name under the word "Eclipse" on the splash screen when loading.
Then go to:
Once your back in Eclipse, try editing a HTML file.
If it's not highlighted, you'll have to:
You should now have a great HTML editor!
This thing was driving me NUTS!
After upgrading to the new Messenger, I contemplating going back because I often receive dev links from workmates.
Unfortunately, these dev links are marked as "low traffic sites" and "isn't well known" because, well. they're secret dev links...
An example of the annoying "Protect yourself" screen is here:
Seriously, I'm not protecting myself, YOU ARE. STOP IT!
It might just be an extra click, but it's annoying!
Firstly, disabling Internet Explorer's smart screen filter won't fix anything. This is coming straight from WLM 2011 into your default browser (Firefox/Chrome/etc).
Secondly, GreaseMonkey scripts are flakey at best.
To properly disable it:
Argh preinstalled software which cannot be uninstalled... the worst kind.
Usually you can just uninstall crap like this from the control panel or from the Vaio Care suite, but no not this one...
Open up a command prompt and paste these instructions.
regsvr32 /u "C:\Program Files\Sony\VAIO Gate\VAIOGateDesktopShellExt.dll"
regsvr32 /u "C:\Program Files\Sony\VAIO Gate\EN-US\VAIOGateShellExt.dll"
del /F "C:\Program Files\Sony\VAIO Gate"
And viola!
When I downloaded the latest drivers for Synaptics touchpad, I didn't expect it to come with Scrybe (even though the package specifically says "with Scrybe")
Well, when I saw it appear on my taskbar my immediate instinct was to kill it. What foul heathen dare trespass on my grounds!?
Shamefully, there was no uninstaller provided. Strangely enough, it was easy to kill it, which I'm not complaining about.
net stop ScrybeUpdater
sc delete ScrybeUpdater
del /F "C:\Program Files (x86)\Synaptics\Scrybe"
Obviously replacing "Program Files (x86)" with "Program Files" if you've got 32bit Windows.
Eat that bundleware!
Something that's been annoying me for a while is the lack of template tag definitions.
Today I gleamed the template code and found something that would help.
To identify between a listing page (a list of blog posts) and a detail page (a page dedicated to a particular post, where comments are shown), you need the following condition check.
<b:if cond='data:blog.pageType == "item"'>
<p>This is the post item page. Put your code here</p>
</b:if>
Now, where was I again? Oh yeah, the sign-off image.