Skip to content

Instantly share code, notes, and snippets.

@martinsam
martinsam / gist:767776
Created January 6, 2011 11:14
Django unique_together work with ForeignKey=None
class FooBar(models.Model):
foo = models.ForeignKey(Foo)
bar = models.ForeignKey(Bar, null=True, blank=True)
class Meta:
unique_together = ('foo', 'bar')
def clean(self):
from django.core.exceptions import ValidationError
if self.foo and FooBar.objects.filter(name=self.bar).exists():
@cjoudrey
cjoudrey / twitter.js
Created November 5, 2011 16:37
Lazy-rendering in PhantomJS
// This example shows how to render pages that perform AJAX calls
// upon page load.
//
// Instead of waiting a fixed amount of time before doing the render,
// we are keeping track of every resource that is loaded.
//
// Once all resources are loaded, we wait a small amount of time
// (resourceWait) in case these resources load other resources.
//
// The page is rendered after a maximum amount of time (maxRenderTime)
# Expand print panel by default
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
# Disable the “Are you sure you want to open this application?” dialog
defaults write com.apple.LaunchServices LSQuarantine -bool false
# Enable subpixel font rendering on non-Apple LCDs
defaults write NSGlobalDomain AppleFontSmoothing -int 2
# Disable press-and-hold for keys in favor of key repeat
@nextroy
nextroy / custom.js
Created June 27, 2012 12:42 — forked from drewjoh/custom.js
Dynamic (AJAX) loaded Bootstrap Modal (Bootstrap 2.0) : Fix for removing the response Modal content
$(document).ready(function() {
// Support for AJAX loaded modal window.
// Focuses on first input textbox after it loads the window.
$('[data-toggle="modal"]').bind('click',function(e) {
e.preventDefault();
var url = $(this).attr('href');
if (url.indexOf('#') == 0) {
$('#response_modal').modal('open');
} else {
@Chrisedmo
Chrisedmo / Mountain Lion tweaks
Created July 30, 2012 14:30
Mountain Lion tweaks (under the hood)
# ~/.osx — http://mths.be/osx
###############################################################################
# General UI/UX #
###############################################################################
# Set computer name (as done via System Preferences → Sharing)
scutil --set ComputerName "MathBook Pro"
scutil --set HostName "MathBook Pro"
scutil --set LocalHostName "MathBook-Pro"
@josephwecker
josephwecker / new_bashrc.sh
Created August 11, 2012 04:36
Replace .bashrc, .bash_profile, .profile, etc. with something much more clean, consistent, and meaningful. Now a repo: https://github.com/josephwecker/bashrc_dispatch
#!/bin/bash
# License: Public Domain.
# Author: Joseph Wecker, 2012
#
# -- DEPRICATED --
# This gist is slow and is missing .bashrc_once
# Use the one in the repo instead! https://github.com/josephwecker/bashrc_dispatch
# (Thanks gioele)
#
# Are you tired of trying to remember what .bashrc does vs .bash_profile vs .profile?
@werkshy
werkshy / start-mysql-in-mem
Created March 29, 2013 14:37
Script to start a second mysql server using ramdisk/tmpfs for unit tests.
#!/bin/bash
DATADIR=/dev/shm/mysql
TMPDIR=/dev/shm/mysql_tmp
MYSQL_SOCKET=/dev/shm/mysql.sock
pkill -9 -f mysql.*datadir.*$DATADIR
mkdir -p $DATADIR
@HLXII
HLXII / EvolveIdle.js
Last active September 8, 2019 02:57 — forked from jaamulberry/EvolveIdle.js
Added autoSmelting (requires the usage of autoPrioritize)
// ==UserScript==
// @name Evolve_HLXII
// @namespace http://tampermonkey.net/
// @version 1.2
// @description try to take over the world!
// @author Fafnir
// @author HLXII
// @match https://pmotschmann.github.io/Evolve/
// @grant GM_log
// @require https://code.jquery.com/jquery-3.3.1.min.js