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:2390284
Last active March 10, 2024 11:47
Python String Generator of "Random" English Nouns. #python #password
import random
"""
Returns a "random" 4 word phrase from a list of words.
"""
nouns = [
@bergantine
bergantine / gist:1171682
Last active July 11, 2023 01:42
Python Image Encoding in Data URI Scheme Base 64. #python #base64
data_uri = open("sample.png", "rb").read().encode("base64").replace("\n", "")
# HTML Image Element
img_tag = '<img alt="" src="data:image/png;base64,{0}">'.format(data_uri)
print img_tag
# CSS Background Image
css = 'background-image: url(data:image/png;base64,{0});'.format(data_uri)
print css
@bergantine
bergantine / models.py
Last active December 8, 2022 19:13
Django choice field and natural language display of that choice in templates. #django #djangotemplate
{% comment %}
Display the language representation of that choice instead of the numerical representation.
{% endcomment %}
{% for member in object_list %}
{{ member.get_team_display|lower }}
{% endfor %}
@bergantine
bergantine / Vagrantfile
Last active August 30, 2022 19:31
Vagrant config for basic Python development
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
@bergantine
bergantine / Vagrantfile
Last active July 13, 2022 04:15
Vagrant box for Zurb development.
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64-2"
# The url from where the 'config.vm.box' box will be fetched if it
@bergantine
bergantine / gist:4035311
Last active June 24, 2022 14:02
Django: Specify Test Database. #django #test #database
# Useful if dev settings are pointed at the production or staging database on a remote host
# In the dev settings, after the `DATABASES` configuration, add a second wrapped in an `if` statement
import sys
if 'test' in sys.argv:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
@bergantine
bergantine / gist:1119284
Last active June 4, 2022 16:42
Python Random Password Generator (One Liner). #python #password
python -c "from random import choice; print ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789%^*(-_=+)') for i in range(32)])"
@bergantine
bergantine / Readme.md
Last active November 18, 2021 12:11
Vagrant config for Apache + mod_ssi
@bergantine
bergantine / genpass.py
Last active May 18, 2021 07:13
Safari-style #python #password Generator
from random import choice
def genCode(len):
return ''.join([choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') for i in range(len)])
print '%s-%s-%s-%s' % (genCode(3), genCode(3), genCode(3), genCode(3))
@bergantine
bergantine / gist:1165817
Last active February 9, 2021 04:20
JavaScript hasClass(), addClass(), removeClass(). #javascript
// class manipulation from http://www.openjs.com/scripts/dom/class_manipulation.php
function hasClass(ele,cls) {
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {