Skip to content

Instantly share code, notes, and snippets.

View twidi's full-sized avatar
🕶️

Stéphane "Twidi" Angel twidi

🕶️
View GitHub Profile
@kevingessner
kevingessner / gist:9509148
Last active April 27, 2023 15:45
Responsive emails that really work -- From Etsy's Code As Craft blog: http://codeascraft.com/2014/03/13/responsive-emails-that-really-work
<html>
<head>
<style type="text/css">
table table {
width: 600px !important;
}
table div + div { /* main content */
width: 65%;
float: left;
}
@aaugustin
aaugustin / HOWTO.md
Last active December 3, 2019 20:18
Connecting a Django application to a Microsoft SQL Server database from Debian GNU/Linux
  1. Install and register the FreeTDS driver for unixODBC.

     apt-get install tdsodbc
     odbcinst -i -d -f /usr/share/tdsodbc/odbcinst.ini
    
  2. (Optional) Test the DSN-less connection with pyodbc.

     apt-get install python-pyodbc
    

>>> import pyodbc

@minddust
minddust / spaceless_except_pre.py
Last active January 1, 2016 20:19
Django spaceless with preserved pre formatting
"""Copyright (c) 2013-2014 Stephan Groß, under MIT license."""
from __future__ import unicode_literals
import re
from django import template
from django.template import Node
from django.utils import six
from django.utils.encoding import force_text
from django.utils.functional import allow_lazy
@nvie
nvie / ormtools.py
Created November 29, 2013 08:59
Really useful helper that I use constantly to force myself to write more efficient Django queries.
from contextlib import contextmanager
from django.conf import settings
from django.db import connection
@contextmanager
def no_queries_allowed():
"""This is a helper method that makes it easier during development, by
throwing an exception when any queries are made within its block. Using
@jdp
jdp / redis-movekeys.sh
Created August 22, 2013 22:24
Move keys matching pattern from one database to another
#!/bin/sh
#
# Usage: ./redis-movekeys.sh [-h host] [-p port] [-n src] [-m dest] pattern
#
# Move keys matching pattern from the src Redis database to the
# dest Redis database.
set -e
HOST="localhost"
@jdp
jdp / redis-delkeys.sh
Created August 21, 2013 19:19
Delete keys matching a pattern from Redis
#!/bin/sh
#
# Usage: ./redis-delkeys.sh [-h host] [-p port] [-n db] pattern
#
# Matches keys with the KEYS command matching pattern
# and deletes them from the specified Redis DB.
set -e
HOST="localhost"

Build your own private, encrypted, open-source Dropbox-esque sync folder

Prerequisites:

  • One or more clients running a UNIX-like OS. Examples are given for Ubuntu 12.04 LTS, although all software components are available for other platforms as well (e.g. OS X). YMMV
  • A cheap Ubuntu 12.04 VPS with storage. I recommend Backupsy, they offer 250GB storage for $5/month. Ask Google for coupon codes.

Software components used:

  • Unison for file synchronization
  • EncFS for folder encryption
@davidbgk
davidbgk / tests.py
Last active December 17, 2015 19:29
An attempt to create generic class-based tests for Django
class GenericViewTest(TestCase):
def setUp(self):
self.client = Client()
def assertGet(self, num_queries):
with self.assertNumQueries(num_queries):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.context = response.context
@mlorant
mlorant / get_thumbnail.py
Last active December 15, 2015 15:19
Just a little function to get thumbnail of video on Youtube or Dailymotion, based on the watch URL. Works with every youtube links, thanks to a great regex, found on stackoverflow, again. Useful when you want to do video list, without displaying every video embed on the same page.
import re
# List of format available on Youtube
YOUTUBE_CHOICES = ("default", "hqdefault", "0", "1", "2")
# Default image if no thumbnail is found
NO_PREVIEW = "/static/img/no_preview.png"
def get_video_thumbnail(url, version="hqdefault"):
@mattmcc
mattmcc / models.py
Created March 27, 2013 00:24
Quick & dirty "read-only" model for using SQL views
class ViewManager(models.Manager):
def bulk_create(self, *args, **kwargs):
raise NotImplementedError
def create(self, *args, **kwargs):
raise NotImplementedError
def get_or_create(self, *args, **kwargs):
raise NotImplementedError