Cygwin — Gitk won’t start suddenly

Setting up a new environment always causes problems.

For whatever reason, gitk won’t start. It just immediately returns with no error message.

After trying many things… the fix that worked for me is to reinstall python-tkinter and tcltk.

Good luck.

Cygwin — Installing PIL on Cygwin and getting gcc: vfork: Resource temporarily unavailable.

I’m moving from mac to PC environment and converting everything the mac did to the PC.

One of the most important aspects is the unix environment.

While running my local deployment script, I ran into multiple problems. One involved running out of PIDs, solved by running the ash shell and running /bin/rebaseall.

Now, PIL is choking on the error gcc: vfork: Resource temporarily unavailable

The solution that worked for me is from this post:
http://cygwin.com/ml/cygwin/2007-01/msg00498.html

Run the following:

rebase -b 0x1000000000 /bin/tk84.dll

And your pip install PIL will work…

Magic.

Windows 7 – OSX Like Screenshot Command

Strangely, one of the most useful things about OSX was the screenshot capability.

CMD+SHIFT+3 takes the whole screen to the desktop.
CMD+SHIFT+4 takes a selection to the desktop

CTRL+CMD+SHIFT+4 takes a selection to the clipboard.

Well, in windows 7 you can pretty much get most of that functionality by right clicking on the “Snipping Tool”, and assigning a hotkey to it. I made it CTRL+SHIFT+4.

Simple. Done!

It also saves to the clipboard for easy photoshop pasting available via the options dropdown in snipping tool.

Windows remove delay before aero-peek on alt+tab

Aero peek is actually pretty damn useful to tell which program window you’re tabbing into — but the delay is a good few seconds.

I found a SuperUser post that explains how to set this delay.

http://superuser.com/questions/45259/windows-7-alttab-transparent-windows-effect-delay

Set a registry key at:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AltTab.

In that key, create the following DWORD value: LivePreview_ms and set it to the delay (in milliseconds) of the first live preview.

I set mine to 1 (0 doesn’t work) and it’s instant!

Sublime 2 Windows Hotkey Setup from OSX

Switched to windows environment from OSX.

Most important for me is…

  • Making Ctrl+T the “goto” hotkey
  • Making Ctrl+g the “find next” hokey
  • Making Ctrl+shift+g the “find prev” hotkey
  • Making Ctrl+1~0 the “go to specific tab” hotkey
[
	{ "keys": ["ctrl+t"], "command": "show_overlay", "args": {"overlay": "goto"} },
	{ "keys": ["ctrl+g"], "command": "find_prev" },
	{ "keys": ["ctrl+shift+g"], "command": "find_under" },


    { "keys": ["ctrl+1"], "command": "select_by_index", "args": { "index": 0 } },
    { "keys": ["ctrl+2"], "command": "select_by_index", "args": { "index": 1 } },
    { "keys": ["ctrl+3"], "command": "select_by_index", "args": { "index": 2 } },
    { "keys": ["ctrl+4"], "command": "select_by_index", "args": { "index": 3 } },
    { "keys": ["ctrl+5"], "command": "select_by_index", "args": { "index": 4 } },
    { "keys": ["ctrl+6"], "command": "select_by_index", "args": { "index": 5 } },
    { "keys": ["ctrl+7"], "command": "select_by_index", "args": { "index": 6 } },
    { "keys": ["ctrl+8"], "command": "select_by_index", "args": { "index": 7 } },
    { "keys": ["ctrl+9"], "command": "select_by_index", "args": { "index": 8 } },
    { "keys": ["ctrl+0"], "command": "select_by_index", "args": { "index": 9 } }
]

Git — Undo a hard reset via Reflog

Straight out of this stackoverflow question which I wish I could upvote 50 times.

http://stackoverflow.com/questions/5473/undoing-a-git-reset-hard-head1

I accidentally did a hard reset to a commit too far back and lost some changes. Luckily git reflog shows hashes you can revert to even if its technically not in your repository.

Copy and pasted from the answer at SO, saved for posterity.

$ git init
Initialized empty Git repository in .git/

$ echo "testing reset" > file1
$ git add file1
$ git commit -m 'added file1'
Created initial commit 1a75c1d: added file1
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file1

$ echo "added new file" > file2
$ git add file2
$ git commit -m 'added file2'
Created commit f6e5064: added file2
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file2

$ git reset --hard HEAD^
HEAD is now at 1a75c1d... added file1

$ cat file2
cat: file2: No such file or directory

$ git reflog
1a75c1d... HEAD@{0}: reset --hard HEAD^: updating HEAD
f6e5064... HEAD@{1}: commit: added file2

$ git reset --hard f6e5064
HEAD is now at f6e5064... added file2

$ cat file2
added new file

Django — Formfield for ForeignKey

I’ve googled formfield_for_foreignkey on many occasions to look up what parameters it accepts, but it always fails me.

I bet you anything posting this blog will make it to the top of the google results and serve as a redirect : )

The docs on formfield for foreignkey:

http://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey

The docs on formfield for manytomany:

http://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_manytomany

The docs on formfield for choice field:

http://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_choice_field

Django / Python — Store Dictionary as String

I’d like to store a dictionary as a string on my django model.

It would simply be a few key=value pairs separated by commas. I prefer not to pickle this so that it can easily be edited as a string.

I will use this field for arbitrary types of gateway arguments. For example, for the “Gift Card” payment gateway, i’d store a card_id code in this field.

For the CreditCard gateway, I’d store a transaction ID number.

Here’s what I came up with: please, comments and suggestions are welcome.

    @property
    def gateway_arguments(self):
        """
        Dictionary stored as string.
        """
        if not hasattr(self, '_gateway_arguments'):
            try:
                self._gateway_arguments =  dict(
                        (x.strip().split('=') for x in self.gateway_args.split(',') if x)
                    )
            except Exception, e:
                log.critical("Malformed gatway_args on order {id}".format(id=self.id))
               self._gateway_arguments = {}
        return self._gateway_arguments

    
    @gateway_arguments.setter
    def gateway_arguments(self, value):
        self._gateway_arguments = value


    def save(self, *args, **kwargs):
        """ Convert dictionary to string """
        if getattr(self, '_gateway_arguments', None):
            self.gateway_args = ','.join(('{key}={value}'.format(key=key, value=value) for
                key, value in self._gateway_arguments.iteritems() ))
        super(Order, self).save(*args, **kwargs)