Skip to content

Instantly share code, notes, and snippets.

View miraculixx's full-sized avatar
💭
working on https://github.com/omegaml

miraculixx

💭
working on https://github.com/omegaml
  • Switzerland
View GitHub Profile
@miraculixx
miraculixx / asciidecodeerror.py
Last active November 22, 2021 15:57
Tired of Python's UnicodeDeocodeError, ascii codec can't decode? Here's how to fix it, once and for all.
# Python ascii codec can't decode and unicode mess
#
# check this out https://pythonhosted.org/kitchen/unicode-frustrations.html
# and this http://www.joelonsoftware.com/articles/Unicode.html
#
# The short of it is this
# 1. If you can, always set PYTHONIOENCODING=utf8 before you start your python programs.
# 2. If you can't or you can't ensure this, always use the following lambda _u to get unicode text
# whereever you convert to strings (str.format, str % etc.)
#
@miraculixx
miraculixx / clienttrace.py
Last active August 29, 2015 14:12
Print Django test Client and Tastypie ApiClient traces
class ClientRequestTracer(object):
"""
Trace api calls to a test client
Usage:
self.client = ClientRequestTracer(self.client)
self.api_client = ClientRequestTracer(self.api_client)
Limit the traces by giving parameter traces=[...] list of
strings 'get', 'post', 'put'
@miraculixx
miraculixx / cachereq.py
Created January 10, 2015 01:14
Cacheable URL retriever for Django
"""
(c) 2015 github.com/miraculixx
MIT License
Cacheable URL getter for Django
Uses Django's cache framework to cache responses with the same URL.
Usage:
url = 'http://www.domain.com/static/content'
@miraculixx
miraculixx / github-add-user
Last active January 10, 2022 13:11
batch adding users to github accounts
#!/bin/bash
# Collaborator list, add, remove from a repository
# (c) 2015 miraculixx
# Author: github.com/miraculixx
# MIT License, see below
function help {
echo "Add collaborators to one or more repositories on github"
echo ""
echo "Syntax: $0 -u user -p password [-l] [-D] -r repo1,repo2 <collaborator id>"
@miraculixx
miraculixx / gettox
Last active August 29, 2015 14:13
Get tox on debian Linux
#!/bin/bash
# source: https://wiki.tox.im/Binaries#Linux
sudo sh -c 'echo "deb https://repo.tox.im/ nightly main" > /etc/apt/sources.list.d/toxrepo.list'
wget -qO - https://repo.tox.im/pubkey.gpg | sudo apt-key add -
sudo apt-get install apt-transport-https #for https repos
sudo apt-get update
echo "Tox Repository Installed."
echo "You can now install utox, qtox, toxic, ratox and tox-bootstrapd"
echo "just type: sudo apt-get install utox qtox toxic ratox tox-bootstrapd"
@miraculixx
miraculixx / editor
Created January 31, 2015 09:50
eclipse pydev editor settings
colors
* get the eclipse color theme plugin at http://marketplace.eclipse.org/content/eclipse-color-theme
* set NightLion Aptana Theme
font
* in preferences Colors and Fonts, Text Font
* linux: Monospace size 13
* osx: Menlo size 16-18
@miraculixx
miraculixx / tipstricks.md
Created January 31, 2015 20:02
tastypie ticks and tricks
  • filter on parent/child relationship
class SomeResource(Resource):
    # always use a string with the full path of the resource
    parent = fields.ForeignKey('path.to.module.SomeResource', 
            attribute='parent')
 class Meta:
@miraculixx
miraculixx / crstampit
Last active August 29, 2015 14:14
create stamps on PDFs
# create ./stampit to stamp all PDF files with a given text
# adopted from http://www.commandlinefu.com/commands/view/9984/stamp-a-text-line-on-top-of-the-pdf-pages.
ls *pdf | xargs -L1 -I{} echo 'echo {} && echo "CONFIDENTIAL - ATTN XYZ" | enscript -B -f Courier-Bold12 -o- | ps2pdf - | pdftk {} stamp - output tozip/{}' > stampit
chmod +x stampit
@miraculixx
miraculixx / tips.md
Created February 7, 2015 11:51
linux tips and tricks
@miraculixx
miraculixx / tips.md
Last active August 29, 2015 14:15
python tips and tricks
  • terse parse for keyword arguments
kwparams = lambda kwargs, keys: (kwargs.get(k) for k in keys.split(','))
```

```
def foo(*args, **kwargs): 
    foo, bar = kwparams(kwargs, ('foo,bar'))