Skip to content

Instantly share code, notes, and snippets.

View zopieux's full-sized avatar

Alexandre Macabies zopieux

View GitHub Profile
# -*- coding: utf-8 -*-
import smtplib
from email.mime.text import MIMEText
from email.header import Header
import urllib.request as urllib
from bs4 import BeautifulSoup
from random import choice
def randomWikipediaPage():
@zopieux
zopieux / bb_webhook_to_irc.py
Last active August 31, 2022 23:57
Bitbucket webhooks to IRC broker
#!/usr/bin/env python3
# coding: utf-8
# This launches a webserver listening on HTTP_HOST and a IRC client to display the messages.
# Configuration using capital variables below.
# Dependencies: Python 3, pypeul (Python 3 branch)
from http.server import BaseHTTPRequestHandler, HTTPServer
from pypeul import IRC, Tags
import json
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)
#!/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
@zopieux
zopieux / gist:52c6e643cc6dcf963902
Created July 31, 2014 16:55
Lists vs. iterators
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 August 25, 2014 16:14
Find KO chapters in SRT for ~phennequin
#!/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 September 27, 2014 19:14
Quizz Fever networking
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 December 28, 2014 14:48
Google API OAuth2 persistent token
# 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 August 29, 2015 14:16
pacaur shellcheck analysis
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 August 29, 2015 14:16
compress/uncompress/listcompress shell functions
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)