Skip to content

Instantly share code, notes, and snippets.

🙃
wat

Ionel Cristian Mărieș ionelmc

🙃
wat
View GitHub Profile
View gist:727856
administrator@ubuntu:~/projects/sandbox$ ve-cpython/bin/python json-bench.py && ve-pypy/bin/pypy json-bench.py
Running: json-bench.py
test_cpickle
test_cpickle warmup: 3.89885687828
test_cpickle RUN: 4.03457689285
test_demjson
test_demjson warmup: 143.255517006
test_demjson RUN: 156.608139992
test_cjson
test_cjson warmup: 3.51447200775
@ionelmc
ionelmc / gist:2047741
Last active Oct 1, 2015
webserver in a line
View gist:2047741
python -c "import SimpleHTTPServer, SocketServer, BaseHTTPServer; SimpleHTTPServer.test(SimpleHTTPServer.SimpleHTTPRequestHandler, type('Server', (BaseHTTPServer.HTTPServer, SocketServer.ThreadingMixIn, object), {}))" 9090
# short
python -c "from SimpleHTTPServer import test, BaseHTTPServer as b, SimpleHTTPRequestHandler as h; from SocketServer import ThreadingMixIn as t; test(h, type('Server', (b.HTTPServer, t, object), {}))" 9090
# shorter
python -c "import SimpleHTTPServer as h, SocketServer as s, BaseHTTPServer as b; h.test(h.SimpleHTTPRequestHandler, type('S', (b.HTTPServer, s.ThreadingMixIn, object), {}))" 9090
# this variant disables dns reverse lookups
python -c "import SimpleHTTPServer as h, SocketServer as s, BaseHTTPServer as b; h.test(type('H', (h.SimpleHTTPRequestHandler, object), {'address_string': lambda self: str(self.client_address[0])}), type('S', (b.HTTPServer, s.ThreadingMixIn, object), {}))" 9090
@ionelmc
ionelmc / cmd-proxy.py
Created Aug 14, 2012
Command line http proxy (for benchmarking)
View cmd-proxy.py
#!/usr/bin/env python
import os
import tornado.httpserver
import tornado.ioloop
import tornado.web
import subprocess
import shlex
import fcntl
import errno
from cStringIO import StringIO
@ionelmc
ionelmc / gist:3754670
Created Sep 20, 2012
Test the damn imports
View gist:3754670
find src -name \*.py | sed 's/\//./g;s/\.py$//g;s/\.__init__$//;s/^src\.//' | while read -r line; do
echo Importing $line '\033[1;31m'
PYTHONPATH=src DJANGO_SETTINGS_MODULE=xxx.settings python -c "import $line"
echo -n '\033[0m'
done
@ionelmc
ionelmc / admin.py
Created Oct 16, 2012
terse admin.py
View admin.py
from django.contrib import admin
from .models import SomeModel, OtherModelWithFKToSomeModel
def register(model):
def decorator(klass):
admin.site.register(model, klass)
return klass
return decorator
def inline(model, klass=admin.TabularInline, **options):
return type(
@ionelmc
ionelmc / create-mysql-ramdisk-instance.sh
Last active Aug 21, 2017
Mysql instances (ramdisk, linux)
View create-mysql-ramdisk-instance.sh
#!/bin/bash -xe
# source: http://www.ducea.com/2009/01/19/running-multiple-instances-of-mysql-on-the-same-machine/
i=$1
port=$[3306+$i]
#mysqladmin -S /var/run/mysqld/mysqld$i.sock shutdown || true
kill -9 `cat /var/run/mysqld/mysqld$i.pid` || true
umount /var/lib/mysql$i || true
rm -rf /var/lib/mysql$i
mkdir /var/lib/mysql$i
View gist:4021120
class RegistrationBackend(SimpleBackend):
def register(self, request, **kwargs):
name, email, password = kwargs['name'], kwargs['email'], kwargs['password1']
username = generate_id(name, '', email)
UserProfile.objects.create(
user=User.objects.create_user(username, email, password),
name=name
)
View active_page.py
from django.template import Library
register = Library()
@register.simple_tag(takes_context=True)
def active_page(context, page_name):
active = active_class(context, page_name)
return ' class="%s" ' % active if active else active
@register.simple_tag(takes_context=True)
def active_class(context, page_name):
@ionelmc
ionelmc / windows-network-type-fixup.py
Created Nov 17, 2012
windows-network-type-fixup.py
View windows-network-type-fixup.py
import win32com.client
NETWORK_CATEGORIES = {
1: "PRIVATE",
0: "PUBLIC",
2: "DOMAIN"
}
m = win32com.client.Dispatch("{DCB00C01-570F-4A9B-8D69-199FDBA5723B}")
more = 1
pos = 1
connections = m.GetNetworkConnections()
View maze.py
python -c "while 1:import sys,random;sys.stdout.write(random.choice('\/'))"
You can’t perform that action at this time.