Skip to content

Instantly share code, notes, and snippets.

View laike9m's full-sized avatar
🧠
🐍

laike9m laike9m

🧠
🐍
View GitHub Profile
@thirtythreeforty
thirtythreeforty / tcphole.py
Last active August 29, 2015 14:00
A TCP hole puncher
#!/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.
@jabbalaci
jabbalaci / pyvideo_popularity.py
Created April 19, 2015 11:10
pyvideo popularity
#!/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.
@takluyver
takluyver / gist:26fb3b7e365dce527886
Created April 19, 2015 23:32
Pycon videos by views
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)
@vsajip
vsajip / custfmt.py
Created February 9, 2012 20:21
Example of logging formatter factory usage with fileConfig()
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):
@davesque
davesque / vassal.ini
Created January 7, 2013 18:33
Uwsgi ini file for django
[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
@qingniufly
qingniufly / ByteBufferConverter.java
Created March 28, 2017 07:31
Java NIO, ByteBuffer <--> String
// 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));
@bdotdub
bdotdub / redis.markdown
Created November 24, 2010 22:18
Running redis using upstart on Ubuntu

Running redis using upstart on Ubuntu

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:

@kpy3
kpy3 / setupdb.md
Created March 30, 2018 22:16 — forked from danisfermi/setupdb.md
Setup gdb on Mac OS Sierra/High Sierra

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:

@mikeyk
mikeyk / redis_session_backend.py
Created April 8, 2011 18:01
A redis backend for Django Sessions, tested on Django 1.3+
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(

Moved

Now located at https://github.com/JeffPaine/beautiful_idiomatic_python.

Why it was moved

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!