Skip to content

Instantly share code, notes, and snippets.

@implementation NSNull (SafeNull)
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
NSMethodSignature *signature = [super methodSignatureForSelector:aSelector];
if (!signature) {
NSLog(@"Warning: Unsuported selector \"%@\" sent to NSNull object.", NSStringFromSelector(aSelector));
return [NSMethodSignature signatureWithObjCTypes:@encode(void)];
}
return signature;
@kenbolton
kenbolton / profiles.models.py
Created February 13, 2013 18:34
Django-Social-Auth and Mezzanine/Cartridge integration from spring 2012. It looks like `mezzanine.accounts`, but the integration with that app is likely incomplete.
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save
from mezzanine.core.fields import RichTextField
from cartridge.shop.models import Product
from social_auth.signals import pre_update
from social_auth.backends.google import GoogleOAuth2Backend
@micahhausler
micahhausler / 0001_initial.py
Last active February 15, 2016 02:03
Custom User Model Switch
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.utils.timezone
import django.core.validators
#### SEE LINE 25!
class Migration(migrations.Migration):
@kennethreitz
kennethreitz / check.sh
Created February 7, 2016 15:48
How to find out why your RST isn't rendering on PyPi
pip install readme-renderer && python setup.py check -rs
@thenewguy
thenewguy / middleware.py
Created January 17, 2016 22:54
static serve middleware based off whitenoise
import mimetypes
import time
from os.path import splitext
from django.contrib.staticfiles.storage import staticfiles_storage
from django.http import HttpResponse, FileResponse, HttpResponseNotAllowed, Http404
from django.core.exceptions import SuspiciousFileOperation
from django.conf import settings
from django.utils.six import text_type
from django.utils.http import http_date
@ArturT
ArturT / Fix OpenSSL Padding Oracle vulnerability (CVE-2016-2107) - Ubuntu 14.04
Last active June 20, 2018 11:46
Fix OpenSSL Padding Oracle vulnerability (CVE-2016-2107) - Ubuntu 14.04
# Based on http://fearby.com/article/update-openssl-on-a-digital-ocean-vm/
$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ wget ftp://ftp.openssl.org/source/openssl-1.0.2h.tar.gz
$ tar -xvzf openssl-1.0.2h.tar.gz
$ cd openssl-1.0.2h
$ ./config --prefix=/usr/
$ make depend
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''Output:
$ py fun_with_progress.py
Start doing things without bar ...
Took: 0:00:13.598943
Start doing things with bar ...
@joshfinnie
joshfinnie / gist:4046138
Created November 9, 2012 14:54
Installing Mezzanine on Heroku

Lately, I have been looking into Python CMSs. There are many out there, but for some reason or another Mezzanine stuck out as one I should try. Installing it is easy enough, but getting it up on running on my new favorite host, Heroku, was a bit of a challege.

Below you will find the steps that I took to get Mezzanine up and running on Heroku. Please let me know in the comments below if anything didn't work for you.

Setting up the Database

Heroku is shortly depricating Django's standard DATABASES dictionary in favor for a package which takes OS Environment Variables and builds the required dictionary for you. This is a good thing because it makes setting up a database on Heroku very easy. The package is called dj_database_url and it makes short work of getting a PostgreSQL database up and running with Mezzanine. Below is the code that you want to put in Mezzanine's DATABASES section:

import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
@rnapier
rnapier / fix-xcode
Last active March 18, 2022 01:17
Links Xcode SDKs from the /SDKs directory (which you maintain yourself)
#!/usr/bin/python
# fix-xcode
# Rob Napier <robnapier@gmail.com>
# Script to link in all your old SDKs every time you upgrade Xcode
# Create a directory called /SDKs (or modify source_path).
# Under it, put all the platform directories:
# MacOSX.platform iPhoneOS.platform iPhoneSimulator.platform
# Under those, store the SDKs:
#! /usr/bin/env python
#-*-coding: utf-8 -*-
import sys
import ctypes
import struct
ELF_MAGIC = [0x7F, ord('E'), ord('L'), ord('F')]
PT_INTERP = 3
ELFCLASS32 = 1