Looping through a dict

It seems I’ve never looped through a dict in Python before. I just assumed that it would work the same as with a PHP associative array, since the syntax of creating one is fairly similar. I just thought this would work:

for key, value in somedict:
    print key, ': ', value

But I guess not.

You have to call the items or iteritems functions on the dictionary, where iteritems is faster, but also doesn’t allow certain actions that items might:

for key, value in somedict.iteritems():
    print key, ': ', value

I was trying to loop through a dictionary in a django template like so:

{% for key, value in somedict %}
  {{ key }}: {{ value }}<br/>
{% endfor %}

Which, since it just skips over most errors, generated this response:


Which I only later found out was caused by an error when trying it in some regular python code. It should be:

{% for key, value in somedict.iteritems %}
  {{ key }}: {{ value }}<br/>
{% endfor %}

I feel like this shouldn’t have happened to me. Oh well, now I know…


ntd progress #1

So I’ve only had a little bit of time to work on ntd. But at least I did do something, though nothing major. I got rid of the gets() function by replacing it with getline(), I know this is a GNU extension, but it’s apparently recommended and for now I don’t think anyone other than myself is using it, and since I only use archlinux I’m in minimal danger of incompatibilities.

I’m still getting some errors with valgrind, but if I eventually figure them out I will be able to fix it.

Maybe tomorrow I can finally start adding another command.

My ASP.Net intellisense was gone!

I use Visual Studio 2008 at work on a remote terminal server.
This server doesn’t have enough disk space on its C drive, and VS2008 likes to place a lot of ReflectedSchemas there.
It got to the point where I has some 4GB of ReflectedSchemas and this was too much, so I deleted them all (nice and definitive) and things were great again.

A couple of weeks later the exact same thing happened again, so I deleted them again, this time though I noticed that my Intellisense for the standard ASP.Net controls (like ) was gone! Still had it for other (custom) controls and HTML tags and everything, just not ASP.Net controls.

Today finally I decided to look into it (2 or 3 months later).
I got a tip to try devenv /ResetSettings, which didn’t help.
One person suggested you change the tag prefix, which also didn’t help.
I also tried copying someone else’s ReflectedSchemas, which still didn’t help, though this could be explained perhaps by the fact that I didn’t overwrite the entries.xml, I don’t know.
After this I tried deleting the ReflectedSchemas again, this time making 100% sure that I had closed devenv.exe. This fixed it…

So now I am enjoying my ASP intellisense once again.

Code::Blocks "process terminted with signal 255 (0 minutes, 0 seconds)"

Yesterday after I came home from work I thought I’d try working on a project I’ve been working on this past weekend.
I was away from home this weekend, so all the work I’d done had been on another computer, in a virtual Ubuntu installation, so I hadn’t yet tried it at home.

Trying to build it went fine. Running it from a terminal went fine. Even compiling and running on another Ubuntu installation (my work laptop, non-virtual) went fine, but Code::Blocks reported to me that whenever I tried running my application on my Fedora 11 home installation that it terminated with signal 255.
I couldn’t find what was wrong, I knew the application worked since I tested it in another terminal window and if I debugged it it’d go great up to the point where it met with a cin or cout.
Being tired from a really long day (getting up at 5:00am, get on train at 6:25am, get off train at 8:30am and at work 8:50am), I gave up fairly quickly.

This morning though the itch got worse and I just had to investigate further.
After about a minute of looking around I found someone at the Ubuntu Forums asking about the exact same thing and it turns out that the problem was that xterm wasn’t installed. So a simple

su -c "yum install xterm"

was enough to fix the problem.

Now I can start developing my application again!

SyntaxHighlighter follow-up

Something about SyntaxHighlighter has just caught my attention.

As I’d mentioned in my post about it I started out from an older version. I noticed there are a few more brushes then I’d initially added.

I added

<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushXml.js' type='text/javascript'/>

But the list consists of

<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushAS3.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushBash.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushDelphi.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushDiff.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushGroovy.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJavaFX.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPerl.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPlain.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPowerShell.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPython.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushRuby.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushScala.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushVb.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushXml.js' type='text/javascript'/>

Wow that’s quite a few. You can add any/all of these along with or instead of the ones I’d posted before. Each one is needed for it’s respective language, of course.

My custom RDP script

I have a crazy situation. I work at a .Net company, but my installed OS is Linux (Ubuntu Jaunty atm). This is ok though, I asked my boss first, because we use Remote Desktop to do almost all actual work.
Now we move around from time to time. So sometimes I have a different printer I need to share with the server. And since I also want to share a single folder with the server (not my entire filesystem like the TerminalServer client would like), so I decided to write a bash script to help me decide where I am.



# Ask where we are, since we don't know where we might end up we add 'other'
# which will default to no extra parameters
srem_WL=$(zenity --list --text="Were Are You?" --radiolist --column="Pick" --column="Locations" TRUE location1 FALSE location2 FALSE other)

# Only do something if cancel wasn't pressed
if [ -n "$srem_WL" ]; then

# The user on the server, I use $USER because I know that on this PC I'll
# always be logged in under the same name as on the server

# The IP address of the server

# The size I want my screen to be
# I add the -g here because one might want fullscreen (with -f)
srem_geo="-g 1910x1120"

# The shares I want to send along
srem_share="-r disk:ShareName=/path/to/some/share"

# The start of my execute command
srem_ex="rdesktop $srem_geo $srem_share"

if [ -n $srem_WL ]; then
# Here we define the configuration differences for each location
case $srem_WL in
srem_ex+=" -r printer:MyPrinterForLocation1"
srem_ex+=" -r printer:MyPrinterForLocation2"
# Since other has not been added to the case list it won't add anything

# The end of our execute command
srem_ex+=" -u $srem_usr $srem_up"


You could of course also always share both printers, rdesktop won’t complain if it isn’t connected, but I’m always looking for stuff to program. And this way you can kind-of create different profiles for different locations.