Skip to content

Instantly share code, notes, and snippets.

@IanHopkinson
IanHopkinson / lxml_examples.py
Created November 24, 2015 19:42
Examples of xpath queries using lxml in python
#!/usr/bin/env python
# encoding: utf-8
import lxml.etree
import lxml.html
import requests
xml_sample = """<?xml version="1.0" encoding="UTF-8"?>
<foo:Results xmlns:foo="http://www.foo.com" xmlns="http://www.bah.com">
<foo:Recordset setCount="2">
@dmitric
dmitric / mdx_video.py
Created August 19, 2013 07:40
A dead simple python markdown extension to embed youtube or vimeo videos in markdown. Using oembed is a terrible idea if you have lots of links on a page, and the other implementations I saw were sloppy. You can still use regular links to vimeo and youtube too.
# -*- coding: utf-8 -*-
from markdown import Extension
from markdown.util import etree
from markdown.inlinepatterns import Pattern
SOURCES = {
"youtube": {
"re": r'youtube\.com/watch\?\S*v=(?P<youtube>[A-Za-z0-9_&=-]+)',
"embed": "//www.youtube.com/embed/%s"
},
@douglasmiranda
douglasmiranda / gist:5408278
Created April 17, 2013 22:26
Leading zeros in django templates
{{ variable|stringformat:"02d" }}
@acdha
acdha / active_value_filter.py
Created August 31, 2012 20:14
Django admin list_filter which filters out values which are not used in the current queryset
from django.contrib.admin import FieldListFilter
from django.utils.translation import ugettext as _
class ActiveValueFilter(FieldListFilter):
"""list_filter which displays only the values for a field which are in use
This is handy when a large range has been filtered in some way which means
most of the potential values aren't currently in use. This requires a
queryset field or annotation named "item_count" to be present so it can
@jonathanmoore
jonathanmoore / gist:2640302
Created May 8, 2012 23:17
Get the share counts from various APIs

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

@spartanroc
spartanroc / BibTeXKeyOnly.js
Created May 5, 2011 06:17
New Features and Improvements on Zotero's Support of BibTeX Export
{
"translatorID": "12345",
"label": "BibTeX CiteKey-only Exporter",
"creator": "Simon Kornblith and Richard Karnesky with tweaks by Tan",
"target": "bib",
"minVersion": "2.1.9",
"maxVersion": "",
"priority": 200,
"inRepository": false,
"translatorType": 3,