Skip to content

Instantly share code, notes, and snippets.

#Script to set custom iprange for dockers bridge, also starts docker
cat << EOF >> /etc/rc.local
#docker
subnet="10.0.41.1/16"
if ! [[ "$(ip link show docker0)" ]]; then
ip link add docker0 type bridge
ip addr add "$subnet" dev docker0
ip link set docker0 up
iptables -t nat -A POSTROUTING -s "$subnet" ! -d "$subnet" -j MASQUERADE
@Cloudo
Cloudo / paginators.py
Created March 17, 2016 14:45
Django Paginators
from django.core.cache import caches
from django.core.paginator import Paginator
from django.db import connections
class LargeTablePaginator(Paginator):
"""
Overrides the count method to get an estimate instead of actual count when not filtered
"""
def _get_count(self):
"""
@Cloudo
Cloudo / limit.py
Created February 12, 2016 06:49 — forked from hartror/limit.py
Finding safe ways to limit a forked proccess's memory in Python.
#!/usr/bin/env python
import os
import psutil
import resource
import subprocess
import sys
import time
@Cloudo
Cloudo / branch-fu.md
Created December 29, 2015 09:22 — forked from unbracketed/branch-fu.md
Moving commits between branches

Example: Moving up to a few commits to another branch

Branch A has commits (X,Y) that also need to be in Branch B. The cherry-pick operations should be done in the same chronological order that the commits appear in Branch A.

cherry-pick does support a range of commits, but if you have merge commits in that range, it gets really complicated

git checkout branch-B
git cherry-pick X
git cherry-pick Y
@Cloudo
Cloudo / svg2png.js
Created December 14, 2015 14:05 — forked from jcblw/svg2png.js
var svg = document.querySelector( "svg" );
var svgData = new XMLSerializer().serializeToString( svg );
var canvas = document.createElement( "canvas" );
var ctx = canvas.getContext( "2d" );
var img = document.createElement( "img" );
img.setAttribute( "src", "data:image/svg+xml;base64," + btoa( svgData ) );
img.onload = function() {
@Cloudo
Cloudo / get_path.py
Created November 20, 2015 13:10
access deep nested value from python dict
import re
def get_path(dct, path):
for i, p in re.findall(r'(\d+)|(\w+)', path):
dct = dct[p or int(i)]
return dct
function nbsp(s) {
return s.replace(/ /g, '\u00a0');
}
from django.utils.safestring import mark_safe
from django import template
register = template.Library()
@register.filter()
def nbsp(value):
return mark_safe("&nbsp;".join(value.split(' ')))
@Cloudo
Cloudo / FontFix RubyMine
Created October 6, 2015 09:18 — forked from leemour/FontFix RubyMine
Fixing font anti-aliasing for Ubuntu.
# Change Java Runtime:
sudo update-alternatives --config java
# Delete Open-JDK
sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*
# Change fonts - remove hinting:
http://askubuntu.com/questions/32624/ugly-fonts-in-netbeans-how-can-i-make-it-use-the-system-font
# Change RubyMine AntiAliasing first:
@Cloudo
Cloudo / css_resources.md
Last active August 29, 2015 14:19 — forked from jookyboi/css_resources.md
CSS libraries and guides to bring some order to the chaos.

Libraries

  • 960 Grid System - An effort to streamline web development workflow by providing commonly used dimensions, based on a width of 960 pixels. There are two variants: 12 and 16 columns, which can be used separately or in tandem.
  • Compass - Open source CSS Authoring Framework.
  • Bootstrap - Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.
  • Font Awesome - The iconic font designed for Bootstrap.
  • Zurb Foundation - Framework for writing responsive web sites.
  • SASS - CSS extension language which allows variables, mixins and rules nesting.
  • Skeleton - Boilerplate for responsive, mobile-friendly development.

Guides