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:989602
Last active September 25, 2015 21:47
SCSS Mixix Example. #sass #scss #demo
// example of string interpolation in a mixin
// matches a particular color and image together following a naming scheme for the images
$green: #7bd939;
$orange: #de712c;
@mixin sectionhead($color, $name) {
.section-head {
background-color: $color;
background-image: url('../../images/masthead-' + $name + '.jpg');
@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 / gist:1147298
Last active September 26, 2015 19:27
Python offline manifest file creator. #html5 #python #offline #manifest
#! /usr/local/bin/python
"""
Creates a file in the same directory named offline.manifest,
or if that file already exists, replaces its contents with project files.
To ignore files of a particular type add their file extension to the ignore list.
"""
import os
@bergantine
bergantine / gist:1157441
Last active September 26, 2015 20:48
Django filter stack to cleanup WYSIWYG output. #djangotemplate
{{ value|removetags:"br div p span style"|safe|linebreaks }}
@bergantine
bergantine / gist:1163864
Last active October 2, 2020 13:49
Send an email when memory hits a certain limit (Bash CRON script for Linux). #bash #cron #linux #ops
# check memory usage every 15 minutes and if usage matches 90% of allocation, send an email
# where _username_ is the username (works on Mac if -u parameter is changed to -U)
# where [email protected]_ is who should be emailed
# where MAX is the allocated memory (must be an integer)
# where LIMIT is the point at which you want to be emailed (must be an integer)
*/15 * * * * USAGEF=`ps -u _username_ -o rss,command | grep -v peruser | awk '{sum+=$1} END {print sum/1024}'`; USAGEI=${USAGEF/.*}; MAX=120; LIMIT=108; if [ $USAGEI -gt $LIMIT ]; then echo Usage \($USAGEI\) is approaching or over the maximum allocation \($MAX\) | mail -s "Server is approaching max allocation of memory." [email protected]_; fi
@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) {
@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 / CSS
Last active September 26, 2015 22:57
JavaScript to retrieve the unicode of a character for CSS (from Rogie King). #css #unicode #rogieking #javascript
content: "\2318";
@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 / gist:1445036
Last active September 28, 2015 13:27
Responsive JS. #javascript #responsive
window.onresize = function() {
responsiveLoad();
}
window.onload = function() {
responsiveLoad();
}
function responsiveLoad() {
console.log('resized');