To open anything from cygwin with explorer, use this executable.
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 } }
]
Django — Proxy model admin inline not appearing
If your proxy model admin inline is not appearing, make sure you remember to set your inline model as the real model, not the proxy model.
class MyInline(admin.TabularInline):
model = MyRealModel # not MyProxyModel
That’s all folks.
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:
The docs on formfield for manytomany:
The docs on 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)
Django — django-mailer multi account setup plus throttling
I forked django mailer to support multiple accounts and email queue throttling per day per account.
https://github.com/yuchant/django-mailer
django-mailer by James Tauber http://jtauber.com/
http://code.google.com/p/django-mailer/
A reusable Django app for queuing the sending of email
Forked to support multiple accounts and email throttling.
Forked to allow django-mailer to use multiple email accounts and to impose a daily sending limit per email account.
Specifically made for Google Apps users who have a 500 email a day per user sending limit and are also limited to a from_address that is the actual authenticated account.
If you’d like to use different “from” emails, it’s currently not an option with google apps.
Options
DAILY_SENDING_LIMIT
Specify an optional MAILER_DAILY_SENDING_LIMIT in settings.py to limit the amount of emails per 24 hours.
Throttling is done via emails sent in the last 24 hours, not discrete days.
# settings.py MAILER_DAILY_SENDING_LIMIT = 400
MULTIPLE ACCOUNTS
send_mail takes an extra keyword argument, account, which is an integer mapped to a specific account in settings.py.
Account 0 is mapped to the default email settings EMAIL_HOST, EMAIL_PORT, etc.
Account 1 is mapped to EMAIL1_HOST, EMAIL1_PORT, etc.
All settings below are required and mailer will complain if it fails to find a setting.
# settings.py EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_HOST_USER = 'foo@example.com' EMAIL_HOST_PASSWORD = 'password' EMAIL_USE_TLS = True EMAIL1_HOST = 'smtp.gmail.com' EMAIL1_PORT = 587 EMAIL1_HOST_USER = 'bar@example.com' EMAIL1_HOST_PASSWORD = 'password' EMAIL1_USE_TLS = True
Usage
from mailer import send_mail
send_mail("Subject", "Body", "from@example.com", ["to@example.com"]) # uses default email settings
send_mail("Subject", "Body", "from@example.com", ["to@example.com"], account=1) # uses EMAIL1_* settings
send_mail("Subject", "Body", "from@example.com", ["to@example.com"], account=2) # uses EMAIL2_* settings
bash $ python manage.py send_mail
# iterates through Messages by account and sends up to DAILY_SENDING_LIMIT per account if specified.