Skip to content

Instantly share code, notes, and snippets.

Michael Floering hangtwenty

Block or report user

Report or block hangtwenty

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hangtwenty
hangtwenty / centos_cx_Oracle
Last active Jan 6, 2020
CentOS 6: Set up Oracle Instant Client and Python package cx_Oracle
View centos_cx_Oracle
#!/bin/bash
# INSTALL ORACLE INSTANT CLIENT #
#################################
# NOTE: Oracle requires at least 1176 MB of swap (or something around there).
# If you are using CentOS in a VMWare VM, there's a good chance that you don't have enough by default.
# If this describes you and you need to add more swap, see the
# "Adding a Swap File to a CentOS System" section, here:
# http://www.techotopia.com/index.php/Adding_and_Managing_CentOS_Swap_Space
@hangtwenty
hangtwenty / quick_punycode_encode_decode_example.py
Last active Dec 24, 2019
[Regarding Python 2 - in Python 3 just use normal strings that are always Unicode.] // quick example of encoding and decoding a international domain name in Python (from Unicode to Punycode or IDNA codecs and back). Pay attention to the Unicode versus byte strings
View quick_punycode_encode_decode_example.py
# INCORRECT! DON'T DO THIS!
>>> x = "www.alliancefrançaise.nu" # This is the problematic line. Forgot to make this a Unicode string.
>>> print x
www.alliancefrançaise.nu
>>> x.encode('punycode')
'www.Alliancefranaise.nu-h1a31e'
>>> x.encode('punycode').decode('punycode')
u'www.Alliancefran\xc3\xa7aise.nu'
>>> print x.encode('punycode').decode('punycode')
www.alliancefrançaise.nu
@hangtwenty
hangtwenty / _socket_toggle.py
Last active Dec 18, 2019
Disable the internet in Python. With py.test hooks. (Disable socket.socket.) GREAT for unit testing.
View _socket_toggle.py
from __future__ import print_function
import socket
import sys
_module = sys.modules[__name__]
def disable_socket():
""" disable socket.socket to disable the Internet. useful in testing.
.. doctest::
@hangtwenty
hangtwenty / fix_typo_for_django_cached_template_loader.md
Last active Dec 5, 2019
TypeError: __init__() missing 1 required positional argument: 'loaders'
View fix_typo_for_django_cached_template_loader.md

Django's Cached Template Loader

Quick tip on fixing an error that may confuse you. Namely, because in the settings file, we have to give string names - so errors are somewhat abstracted from your input.

Basically, when you give the argument to TEMPLATES["OPTIONS"]["loaders"],

  • the argument is a list of loaders;
  • for the cached loader, the first argument is the cached loader,
  • but it needs 1+ args - what it's caching.
  • You pass this as a tuple of the loader, and its args.
@hangtwenty
hangtwenty / tupperware.py
Last active Nov 18, 2019
recursively convert nested dicts to nested namedtuples, giving you something like immutable object literals
View tupperware.py
from UserDict import IterableUserDict
import collections
__author__ = 'github.com/hangtwenty'
def tupperware(mapping):
""" Convert mappings to 'tupperwares' recursively.
@hangtwenty
hangtwenty / README.md
Last active Nov 6, 2019
Quick note - how to fix django-livereload-server import error. https://github.com/tjwalch/django-livereload-server
View README.md

Error:

ImportError: cannot import name 'livereload_port' from 'livereload'

Cause:

You have both livereload and django-livereload-server installed. Most likely, one was installed before the other, and having both is an accident.

@hangtwenty
hangtwenty / README.md
Created Nov 6, 2019
Quick note - how to fix django-livereload import error
View README.md

Error:

ImportError: cannot import name 'livereload_port' from 'livereload'

Cause:

You have both livereload and django-livereload installed. Most likely, one was installed before the other, and having both is an accident.

@hangtwenty
hangtwenty / README.md
Created Nov 6, 2019
Quick note - how to fix django-livereload import error
View README.md

Error:

ImportError: cannot import name 'livereload_port' from 'livereload'

Cause:

You have both livereload and django-livereload installed. Most likely, one was installed before the other, and having both is an accident.

@hangtwenty
hangtwenty / README.md
Created Nov 6, 2019
Quick note - how to fix django-livereload import error
View README.md

Error:

ImportError: cannot import name 'livereload_port' from 'livereload'

Cause:

You have both livereload and django-livereload installed. Most likely, one was installed before the other, and having both is an accident.

View aligning-images.md

Aligning images

left alignment

This is the code you need to align images to the left:

<img align="left" width="100" height="100" src="http://www.fillmurray.com/100/100">
You can’t perform that action at this time.