This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Module(): | |
module_state = {} | |
def Class(val): | |
def get_val(): | |
return val | |
class_state = {'get_val': get_val} | |
return class_state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Example In action: http://jsfiddle.net/r8wcY/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import json | |
class Jsonable(object): | |
def date_handler(self, obj): | |
return obj.isoformat() if isinstance(obj, (datetime.datetime, datetime.date)) else None | |
def save_json(self, file_name): | |
with open(file_name, 'w') as output: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import types | |
import re | |
buffer_regex = re.compile(r'^([\t\s]*)\w') | |
def dedent(code): | |
replace_chunk = '' | |
for line in code.split('\n'): | |
matches = buffer_regex.search(line) | |
if matches: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://littletutorials.com/2008/06/23/inheritance-not-for-code-reuse/ | |
def mixin(mixin_cls): | |
def mixin_decorator(cls): | |
if not hasattr(cls, '__mixed__'): | |
cls.__mixed__ = [] | |
for name, val in mixin_cls.__dict__.items(): | |
if not name.startswith('__') and not name.endswith('__'): | |
if not hasattr(cls, name): | |
setattr(cls, name, val) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section: screens | |
master-control: | |
ubuntu: | |
mac: | |
end | |
section: links | |
master-control: | |
down(65, 100) = ubuntu(0, 100) | |
down(0, 30) = mac(0, 100) | |
ubuntu: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function create_offer(){ | |
$merchant = new Merchant(); | |
$merchant->where('id', 1);//TODO get currently logged in merchant | |
$merchant->get(); | |
$this->load->library('form_validation'); | |
$this->form_validation->set_rules('description', 'Description', 'required'); | |
$this->form_validation->set_rules('from_time', 'From Time', 'required'); | |
$this->form_validation->set_rules('to_time', 'To Time', 'required'); | |
$this->form_validation->set_rules('deal', 'Deal', 'required'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Take your boring old prompt from this: | |
# matthew-morrisons-macbook:~$ | |
# and cd into a git repo and add the current branch to the prompt for a more glorious experience: | |
# matthew-morrisons-macbook:django-media-masher(master)$ | |
# then use `workon` to select a virtualenv and it will be added your prompt for additional glory: | |
# (media-masher)matthew-morrisons-macbook:django-media-masher(master)$ | |
# then freely switch branches and virtualenvs and have your prompt always reflect what you're | |
# currently working with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@patch('quote_options.models.LiabilityLimit.objects.filter') | |
@patch('quote.models.Q') | |
def should_filter_with_q_object_in_get_liability_limits(self, q_object, limit_filter): | |
manager_instance = Mock(spec=quote_models.LiabilityManager()) | |
policy = mock.Mock() | |
q_instance = mock.Mock() | |
q_or_method = mock.Mock() | |
q_or_method.return_value = q_instance | |
q_instance.__or__ = q_or_method |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageChops | |
def trim(im, border): | |
bg = Image.new(im.mode, im.size, border) | |
diff = ImageChops.difference(im, bg) | |
bbox = diff.getbbox() | |
if bbox: | |
return im.crop(bbox) | |
def create_thumbnail(path, size): |