I've been trying to understand how to setup systems from
the ground up on Ubuntu. I just installed redis
onto
the box and here's how I did it and some things to look
out for.
To install:
#!/usr/bin/python3 | |
# tcphole.py | |
# By George Hilliard ("thirtythreeforty") | |
# A simple TCP hole puncher for a firewall accepting only ESTABLISHED,RELATED packets | |
# This currently binds to the localhost address, although that's easy to fix by changing | |
# the bind() calls. | |
# This is based on the theory found at http://www.bford.info/pub/net/p2pnat/index.html#sec-tcp. | |
# You may use this software under the terms of the Creative Commons CC-0 license. |
#!/usr/bin/env python3 | |
# encoding: utf-8 | |
""" | |
I saw a similar script on the homepage of Miguel Grinberg (the Flask book guy), | |
but he was using webscraping. Here I use simple API calls instead. | |
The script takes the presentations of a Python conference and orders the | |
presentations in descending order by the number of youtube views. It | |
is an indicator about the popularity of a video. |
Results of running this script: https://gist.github.com/jabbalaci/398429347c96e98aba88 | |
Views Ups Downs Title (Speakers) | |
9,810 166 3 Keynote - Jacob Kaplan-Moss - Pycon 2015 (Jacob Kaplan-Moss) | |
7,044 64 0 Type Hints - Guido van Rossum - PyCon 2015 (Guido van Rossum) | |
4,742 121 0 David Beazley - Python Concurrency From the Ground Up: LIVE! - PyCon 2015 (David Beazley) | |
4,684 66 3 Keynote - Guido van Rossum - PyCon 2015 (Guido van Rossum) | |
4,272 78 1 Dan Callahan - My Python's a little Rust-y - PyCon 2015 (Dan Callahan) | |
2,694 34 0 How to build a brain with Python (Trevor Bekolay) | |
2,391 29 0 Andrew T. Baker - Demystifying Docker - PyCon 2015 (Andrew T. Baker) |
import logging | |
class CustomFormatter(logging.Formatter): | |
def __init__(self, default): | |
self.default = default | |
def format(self, record): | |
if record.levelno in (logging.WARNING, | |
logging.ERROR, | |
logging.CRITICAL): |
[uwsgi] | |
socket = /tmp/example.com.sock | |
; Worker processes | |
master = 1 | |
processes = 4 | |
; Virtualenv and home directory | |
virtualenv = /var/virtualenvs/example.com | |
chdir = /var/www/example.com |
// ByteBuffer to String | |
String s = Charset.forName("UTF-8").decode(byteBuffer).toString(); | |
// String to ByteBuffer | |
ByteBuffer buff = Charset.forName("UTF-9").encode("Hello, World!"); | |
// String to ByteBuffer | |
public static ByteBuffer str_to_bb(String msg, Charset charset){ | |
return ByteBuffer.wrap(msg.getBytes(charset)); |
Here are the steps to installing and setting up GDB on Mac OS Sierra/High Sierra.
Run brew install gdb
.
On starting gdb, you will get the following error:
Unable to find Mach task port for process-id 2133: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
To fix this error, follow the following steps:
from django.contrib.sessions.backends.base import SessionBase, CreateError | |
from django.conf import settings | |
from django.utils.encoding import force_unicode | |
import redis | |
class SessionStore(SessionBase): | |
""" Redis store for sessions""" | |
def __init__(self, session_key=None): | |
self.redis = redis.Redis( |
Now located at https://github.com/JeffPaine/beautiful_idiomatic_python.
Github gists don't support Pull Requests or any notifications, which made it impossible for me to maintain this (surprisingly popular) gist with fixes, respond to comments and so on. In the interest of maintaining the quality of this resource for others, I've moved it to a proper repo. Cheers!