Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
IF=en0
MAC=`python << EOF
import random
print ":".join("%02X"%x for x in (random.randint(0, 255) for _ in range(6)))
EOF
`
echo "resetting wifi on $IF, rotating mac $MAC"
scselect -n
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z
>>> def f1(y):
... return set(x for x in y)
...
>>> def f2(y):
... return {x for x in y}
...
>>> dis.dis(f1)
2 0 LOAD_GLOBAL 0 (set)
3 LOAD_CONST 1 (<code object <genexpr> at 0x10abecd30, file "<stdin>", line 2>)
6 MAKE_FUNCTION 0
/* Generated by Cython 0.21.1 */
#define PY_SSIZE_T_CLEAN
#ifndef CYTHON_USE_PYLONG_INTERNALS
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 0
#else
#include "pyconfig.h"
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 1
[vagrant@localhost python-gssapi]$ sudo tox
GLOB sdist-make: /home/vagrant/python-gssapi/setup.py
py27 create: /home/vagrant/python-gssapi/.tox/py27
py27 installdeps: nose, nose_parameterized, flake8, git+https://github.com/DirectXMan12/should_be.git, Cython, six
py27 inst: /home/vagrant/python-gssapi/.tox/dist/PythonGSSAPI-1.0.0.zip
ERROR: invocation failed, logfile: /home/vagrant/python-gssapi/.tox/py27/log/py27-2.log
ERROR: actionid=py27
msg=installpkg
cmdargs=[local('/home/vagrant/python-gssapi/.tox/py27/bin/pip'), 'install', '--pre', '/home/vagrant/python-gssapi/.tox/dist/PythonGSSAPI-1.0.0.zip']
env={'LANG': 'en_GB.UTF-8', 'USERNAME': 'root', 'TERM': 'xterm-256color', 'SHELL': '/bin/bash', 'SUDO_COMMAND': '/bin/tox', 'HOSTNAME': 'localhost.localdomain', 'SUDO_UID': '900', 'LC_CTYPE': 'en_GB.UTF-8', 'HISTSIZE': '1000', 'PYTHONIOENCODING': 'utf_8', 'PYTHONHASHSEED': '3968196433', 'LOGNAME': 'root', 'USER': 'root', 'MAIL': '/var/spool/mail/vagrant', 'PATH': '/home/vagrant/python-gssapi/.tox/py27/bin:/sbin:
@sigmaris
sigmaris / saslclient.py
Last active August 29, 2015 14:10
Example SASL code
import argparse
import base64
import struct
import sys
from gssapi import sec_contexts, names
from gssapi.raw.types import NameType, RequirementFlag
SEC_LAYER_NONE = 1
@sigmaris
sigmaris / python3-ldap-gssapi.py
Created September 10, 2014 09:48
Authenticate to LDAP using python3-ldap and python-gssapi
import gssapi
from ldap3 import Connection, SASL_AVAILABLE_MECHANISMS
from ldap3.protocol.sasl.digestMd5 import sasl_digest_md5
from ldap3.protocol.sasl.external import sasl_external
from ldap3.protocol.sasl.sasl import send_sasl_negotiation, abort_sasl_negotiation
SASL_AVAILABLE_MECHANISMS.append('GSSAPI')
def sasl_gssapi(connection, controls):
@sigmaris
sigmaris / file deleted
Last active July 12, 2019 12:56
Deleted Gist
We couldn’t find that file to show.
@sigmaris
sigmaris / echo.py
Created May 12, 2014 19:39
uwsgi websocket test
# Run this with: uwsgi --virtualenv venv --socket /tmp/uwsgi.sock --chmod-socket --plugin gevent --gevent 1000 --gevent-monkey-patch --module echo:application --master --processes 4 --enable-threads
from flask import Flask, request, render_template
import gevent
import logging
from uwsgi_websockets.middleware import ws_middleware
import uwsgi
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
DEBUG:echo:3 is handling a request in <Greenlet at 0x110184550: uwsgi_gevent_request(4539005552L)>
[pid: 99684|app: 0|req: 2/3] 127.0.0.1 () {40 vars in 806 bytes} [Mon May 12 20:34:00 2014] GET / => generated 1383 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 81 bytes (3 switches on core 999)
!!! uWSGI process 99686 got Segmentation Fault !!!
*** backtrace of 99686 ***
0 uwsgi 0x000000010c551ff0 uwsgi_backtrace + 48
1 uwsgi 0x000000010c552533 uwsgi_segfault + 51
2 libsystem_platform.dylib 0x00007fff8a5dc5aa _sigtramp + 26
3 ??? 0x000000010c888050 0x0 + 4505239632
4 Python 0x000000010c76401f PyEval_CallObjectWithKeywords + 93
5 uwsgi 0x000000010c56a4b7 python_call + 23
import gevent
import socket
threadpool = gevent.get_hub().threadpool # this is the default gevent threadpool
urls = ['www.google.com', 'www.example.com', 'www.python.org']
results = threadpool.map(socket.gethostbyname, urls)
# >>> results
# ['173.194.34.179', '93.184.216.119', '185.31.18.175']