Skip to content

Instantly share code, notes, and snippets.

View bergantine's full-sized avatar

J*Bergantine bergantine

  • London, United Kingdom
View GitHub Profile
@bergantine
bergantine / gist:1566412
Last active September 29, 2015 07:27
Style an HTML5 Form Element Placeholder. #html5 #form #input #placeholder #css
// from http://stackoverflow.com/questions/2610497/change-an-inputs-html5-placeholder-color-with-css
input::-webkit-input-placeholder
color: #fff
input:-moz-placeholder
color: #fff
@bergantine
bergantine / gist:2029226
Last active October 1, 2015 17:17
Time the execution of a method in Python using timeit.Timer.timeit(). #python
"""
Look up all Users associated with a particular badge.
"""
import timeit
s = """\
from profiles.models import Badge, UserProfile
@bergantine
bergantine / projectAppDelegate.m
Created March 13, 2012 18:51 — forked from mwbrooks/projectAppDelegate.m
In PhoneGap-iOS, open external links in the external browser (Safari.app). #ios #objectivec #phonegap
/**
* Note: the following function should already exist in your application delegate file.
* Replace it with the following implementation.
*
* Thanks to @purplecabbage for implementation.
*/
// ...
/**
@bergantine
bergantine / strict_mode.js
Created March 17, 2012 19:09
Wrap multiple functions to use JavaScript strict mode. #javascript
(function() {
// http://www.nczonline.net/blog/2012/03/13/its-time-to-start-using-javascript-strict-mode/
"use strict";
function doSomething() {
// this runs in strict mode
}
function doSomethingElse() {
// so does this
@bergantine
bergantine / gist:2312432
Last active October 2, 2015 20:18
Display exceptions in a Python try / except statement. #python #exception #except #try #sys #traceback
import sys
import traceback
try:
# do something
except:
traceback.print_exc(file=sys.stdout)
@bergantine
bergantine / gist:2312438
Last active October 2, 2015 20:18
Return only unique values from a Python iterable. #python
def unique(s):
"""Return a list of the elements in s, but without duplicates.
For example, unique([1,2,3,1,2,3]) is some permutation of [1,2,3],
unique("abcabc") some permutation of ["a", "b", "c"], and
unique(([1, 2], [2, 3], [1, 2])) some permutation of
[[2, 3], [1, 2]].
For best speed, all sequence elements should be hashable. Then
unique() will usually work in linear time.
@bergantine
bergantine / gist:2312446
Last active October 2, 2015 20:18
jQuery plugin template. #jquery #plugin #javascript
// based on http://blog.jeremymartin.name/2008/02/building-your-first-jquery-plugin-that.html
(function($){
$.fn.PLUGIN-NAME = function(options) {
var defaults = {
VARIABLE: PARAMETER,
VARIABLE2: PARAMETER
// i.e. minTrail: 20
};
@bergantine
bergantine / gist:2321617
Last active October 2, 2015 21:08
Temp Share: createDatabase() Function. #demo #javascript #database
function createDatabase() {
try {
var shortName = dataConfig.database;
var version = dataConfig.databaseVersion;
var displayName = dataConfig.database;
var maxSize = dataConfig.databaseMaxSize;
db = openDatabase(shortName, version, displayName, maxSize);
db.transaction(function(transaction) {
transaction.executeSql(
@bergantine
bergantine / gist:2367995
Last active October 3, 2015 01:58
Bitbucket Wiki TOC in Creole. #bitbucket #wiki #toc #creole
<<toc / 3>>
@bergantine
bergantine / gist:3056393
Last active October 6, 2015 21:37
Django Template Current Date (used primarily in Copyright notices). #djangotemplate
{% now "Y" %}