Skip to content

Instantly share code, notes, and snippets.

View benregn's full-sized avatar

Tomas Thor Jonsson benregn

View GitHub Profile
@benregn
benregn / certain_fields_editing.py
Created August 11, 2011 15:53
Only show certain fields when editing in Django
class SomeForm(forms.ModelForm):
class Meta:
model = SomeModel
def __init__(self, *args, **kwargs):
super(SomeForm, self).__init__(*args, **kwargs)
if self.instance:
print "There is an instance, so were editing."
self.fields['anewfieldonlywhenediting'] = forms.CharField()
@benregn
benregn / gist:2037715
Created March 14, 2012 16:38 — forked from ambar/gist:1534274
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@benregn
benregn / Dir structure
Created April 17, 2012 14:47
Heroku debug
manage.py
twitter_favorites
-settings.py
-urls.py
-wsgi.py
twitter_favs
-templates/
-static/
-templatetags/
-models.py
@benregn
benregn / last_number_filename.py
Created June 10, 2012 11:31
Replace last number in filename with string formattor
filename = "filename123.txt"
formattor = "%1d"
filename_split = filename.split('.')
new_filename = filename_split[0][:-1] + formattor
new_filename = '.'.join([new_filename, filename_split[1]])
print new_filename
@benregn
benregn / Instructions.md
Created September 18, 2012 19:52
Fix openFrameworks XCode SDK error

For XCode 4.4 and OS X 10.8 Mountain Lion

If you get the "check dependencies error: There is no SDK with the name or path '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk'" error, the following steps should help:

  1. Download the MacOSX 10.6 SDK
  2. Extract the zip file
  3. Put the resulting folder in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
  4. Then fix the Build Settings for yourProject.xcodeproj and the openFrameworksLib.xcodeproj to have the Base SDK pointing at 10.6
  5. Restart XCode and compile again
  6. Now it should work!
@benregn
benregn / main.py
Created October 31, 2012 15:30
Panda3D questionnaire GUI
from direct.showbase.ShowBase import ShowBase
import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from panda3d.core import *
class Directs(ShowBase):
# rbuttonFrame = DirectFrame(pos = (-1, 0, 0.40))
_LABELS = ["Strongly do not want to continue", "Do not want to continue",
@benregn
benregn / scale_value.py
Created December 29, 2012 08:51
A function to scale a value from a certain number range to different number range
def scale_value(value_to_scale, original_min, original_max, target_min, target_max):
return (((target_max - target_min) * (value_to_scale - original_min))/(original_max - original_min)) + target_min
@benregn
benregn / active.py
Created April 29, 2013 06:13
Navbar active tab template-tag
# http://stackoverflow.com/a/656328/170172
from django import template
register = template.Library()
@register.tag
def active(parser, token):
args = token.split_contents()
@benregn
benregn / hack.sh
Last active November 4, 2023 09:12 — forked from erikh/hack.sh
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@benregn
benregn / django_runserver_plus.sh
Last active August 21, 2016 17:02
function to kill whatever is running on port 8000 and start `runserver_plus` using port 8000
#!/usr/bin/env bash
function start_runserver_plus() {
cd /path/to/project/dir && workon myvenv && python manage.py runserver_plus 0.0.0.0:8000 --traceback -v 3 --threaded
}
function rs() {
# lsof -i :8000 lists processes using the 8000 port, -t option returns only the process ID
d_pid=`lsof -t -i :8000`
if [[ $d_pid ]]; then