Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexandre Macabies zopieux

View GitHub Profile
View gist:8759785
import re
import unicodedata
import difflib
import urlparse
def slugify(value):
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
value = re.sub('[^\w\s-]', '', value).strip().lower()
return re.sub('[-\s]+', '-', value)
View ircbot_url_title.py
#!/usr/bin/env python3
#-*- encoding: utf-8 -*-
# ircbot_url_title.py
# Simple bot which displays urls titles
#
# Copyright (c) 2010 Mick@el and Zopieux
# Copyright (c) 2014 gustavi
#
# This program is free software: you can redistribute it and/or modify
View gist:52c6e643cc6dcf963902
def do_work(i):
# do something very time-consuming here
print("computing stuff for i =", i)
return i < 2
# Test with lists
print( all( [ do_work(i) for i in range(6) ] ) )
# computing stuff for i = 0
# computing stuff for i = 1
# computing stuff for i = 2
@zopieux
zopieux / srtko.py
Created Aug 25, 2014
Find KO chapters in SRT for ~phennequin
View srtko.py
#!/usr/bin/env python
# Usage: python srtko.py <input.srt> <output.txt>
from __future__ import print_function
try:
from itertools import zip_longest
except ImportError:
from itertools import izip_longest as zip_longest
def grouper(iterable, n, fillvalue=None):
@zopieux
zopieux / network.py
Created Sep 27, 2014
Quizz Fever networking
View network.py
def messageToBytes(type, body=None):
data = {'type': type}
if body is not None:
data['body'] = body
try:
return json.dumps(data).encode('ascii') + b"\n"
except ValueError:
raise ValueError("message could not be JSON-encoded")
except UnicodeEncodeError:
raise UnicodeEncodeError("JSON could not be converted to bytes")
@zopieux
zopieux / gdata_oauth2.py
Created Dec 28, 2014
Google API OAuth2 persistent token
View gdata_oauth2.py
# Example with Contacts API
import atom.http_core
import gdata.contacts.client
import gdata.gauth
auth_kwargs = {
'client_id': 'clielnt-id-xxx.apps.googleusercontent.com', # CHANGEME (see API auth console)
'client_secret': 'client-secret-xxx', # CHANGEME (see API auth console)
'scope': 'https://www.google.com/m8/feeds', # CHANGEME (see API reference)
@zopieux
zopieux / result
Last active Aug 29, 2015
pacaur shellcheck analysis
View result
In - line 15:
TEXTDOMAIN='pacaur'
^-- SC2034: TEXTDOMAIN appears unused. Verify it or export it.
In - line 16:
TEXTDOMAINDIR='/usr/share/locale'
^-- SC2034: TEXTDOMAINDIR appears unused. Verify it or export it.
@zopieux
zopieux / compression.sh
Last active Aug 29, 2015
compress/uncompress/listcompress shell functions
View compression.sh
function compress() {
this="$0"
function usage() {
echo "Usage: $this file.{zip,tgz,tbz2,xz,7z,exe} target [target ...]" >&2
}
test $# -lt 2 && ( usage; return 1 )
name="$1"
shift
case "$name" in
*.exe)
View choiceenum.py
import enum
class ChoiceEnum(enum.Enum):
@staticmethod
def tr(func):
label_for = classmethod(lambda cls, member: _(func(member.name)))
return type('ChoiceEnumTr', (), {'label_for': label_for})
@classmethod
def label_for(cls, member):
@zopieux
zopieux / xml.yaml
Last active Aug 29, 2015
YAML for XML for ork
View xml.yaml
identifiers:
- wheel-speed-a:
offset: 0x0b0
- wheel-speed-b:
offset: 0x0b2
frames:
- wheel-speed:
a: luint16
b: luint16