Skip to content

Instantly share code, notes, and snippets.

View MarkusH's full-sized avatar
🐍

Markus Holtermann MarkusH

🐍
View GitHub Profile
@MarkusH
MarkusH / gist:bc3cb7b526dc39470cdc
Created February 14, 2015 23:42
Django migration operations with custom schema editor
class MaterializedViewOperationMixin(object):
def get_schema_editor(self, app_label, schema_editor):
if app_label in {'app1', 'app2'}:
return CustomSchemaEditor()
return schema_editor
class MaterializedViewCreateModel(MaterializedViewOperationMixin, CreateModel):
def database_forwards(self, app_label, schema_editor, from_state, to_state):
schema_editor = self.get_schema_editor(app_label, schema_editor)
@MarkusH
MarkusH / gist:ac611c25d3e240d3277e
Created February 16, 2015 22:07
Prepends the current branch name to the commit message if the branch is named stable/\d.\d.x
#!/bin/sh
branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ ${branch} == stable/* ]] ; then
branch=${branch#stable/}
head -n1 .git/COMMIT_EDITMSG | grep -qP "\[\d\.\d\.x\]"
has_marker=$?
if [[ $has_marker == 0 ]] ; then
echo "[${branch}] " | cat - "${1}" > /tmp/tmpmessage
mv /tmp/tmpmessage "${1}"
@MarkusH
MarkusH / gist:6038ec4e48450fe23051
Created February 24, 2015 03:06
SSH Login Key
$ ssh -i .ssh/id_rsa testsshuser@localhost
PTY allocation request failed
Login at
http://localhost:8000/sshlogin/vbDkI7K4cD7y6cgOuJptjY5gxiDi3QevWZpXE74P5Gqu0YdefDVTFxjBqRGaRSGffhYa321pcNwSw64HvTdFRbVWKrBVnOkvyq83wsoR1Dd43EscUUlwg2V8XNcuACCqzSOgYEoDcySZgYPn1k0RHeBYLCZw2KLcPNa9yL6FKeSCUcG4rzjqe5gU2dYfXtrQ1okLnpK3cFl8fvgc0YL5MZrTIlV3mXHIKyM3V7tHVxZeyOulah6zp3o8plKGpZ/
Shared connection to localhost closed.
@MarkusH
MarkusH / gist:f037f44f60fc78bef98a
Created February 24, 2015 19:10
Referencing custom environments with custom counters
\newcounter{mycounter}
\newenvironment{myenv}[2][]{
\begin{adjustwidth}{30pt}{30pt}\widowpenalties 1 10000
\refstepcounter{mycounter}
\begingroup
\GetTitleStringSetup{expand}%
\subsubsection*{Foo~\arabic{mycounter}: {#2}}%
\ifthenelse{\equal{#1}{}}{}{\label{foo:#1}}\vspace{-7.5pt}
\endgroup
@MarkusH
MarkusH / gist:f55fca3a003723efb2a3
Created April 5, 2015 00:13
Require a user to be a member of a specific group to visit a view
def require_group(group_name):
def wrapper(user):
return user.groups.filter(name=group_name).exists()
return wrapper
@user_passes_test(require_group('Group 1'))
def view1(request):
# ...
@MarkusH
MarkusH / example1.py
Last active August 29, 2015 14:18
Reservoir Sampling
from random import randint
from node import init_list
def get_random(ll):
rand_pos = randint(0, len(ll))
i = 0
node = None
for n in ll:
@MarkusH
MarkusH / main.js
Last active August 29, 2015 14:19
Github Pull-Request line length indicator
/**
* Add a new bookmark with this content.
**/
javascript:$('body').append($('<div style="border: 1px solid red; position: fixed; top: 10px; left: 10px; height: 25px; min-width: 50px" id="line-length"></div>'));$('.blob-code.blob-code-addition').on('mouseover', function(event) {$('#line-length').text(event.target.innerText.length - 1)});

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

#!/usr/bin/env python3
"""
From @pydanny at https://gist.github.com/pydanny/ddf965bbec415084fb6d
Git Integration
===============
1. Move .git/hooks/pre-commit.sample to .git/hooks/pre-commit
2. Add::
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
from smtpd import SMTPServer
import asyncore
import quopri
class DebuggingServer(SMTPServer):