Skip to content

Instantly share code, notes, and snippets.

View saghul's full-sized avatar

Saúl Ibarra Corretgé saghul

View GitHub Profile
import Image
imageFile = "zFlowers.jpg"
im1 = Image.open(imageFile)
width = 500
height = 420
im2 = im1.resize((width, height), Image.BICUBIC)
@saghul
saghul / pydmesg
Created August 21, 2010 20:00
pydmesg: dmesg with human readable timestamps
#!/usr/bin/env python
# coding=utf8
# Copyright (C) 2010 Saúl ibarra Corretgé <saghul@gmail.com>
#
"""
pydmesg: dmesg with human-readable timestamps
"""
CREATE VIRTUAL TABLE enrondata1 USING fts3(content TEXT); /* FTS3 table */
CREATE TABLE enrondata2(content TEXT); /* Ordinary table */
SELECT count(*) FROM enrondata1 WHERE content MATCH 'linux'; /* 0.03 seconds */
SELECT count(*) FROM enrondata2 WHERE content LIKE '%linux%'; /* 22.5 seconds */
try:
import cjson as jsonlib
jsonlib.dumps = jsonlib.encode
jsonlib.loads = jsonlib.decode
except ImportError:
try:
from django.utils import simplejson as jsonlib
except ImportError:
try:
import simplejson as jsonlib
saghul@hal:~$ ipython
Python 2.6.6rc1+ (r266rc1:83691, Aug 5 2010, 17:07:04)
Type "copyright", "credits" or "license" for more information.
IPython 0.10 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
typedef struct {
PyObject_VAR_HEAD
/* Vector of pointers to list elements. list[0] is ob_item[0], etc. */
PyObject **ob_item;
/* ob_item contains space for 'allocated' elements. The number
* currently in use is ob_size.
* Invariants:
* 0 <= ob_size <= allocated
* len(list) == ob_size
typedef struct {
long hash; /* cached hash code for the entry key */
PyObject *key;
} setentry;
/*
This data structure is shared by set and frozenset objects.
*/
Log into email server:
saghul@hal:~$ openssl s_client -connect mail.example.com:993
Get server capabilities:
. capability
* CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT IDLE CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS AUTH=PLAIN
. OK Capability completed.
@saghul
saghul / gist:676079
Created November 14, 2010 10:58
Sharing content through HTTP in one line
saghul@hal:~$ cd Downloads/
saghul@hal:~/Downloads$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
@saghul
saghul / gist:707898
Created November 20, 2010 15:31
lambda example 1
In [1]: f = lambda x: x+1
In [2]: f(1)
Out[2]: 2
In [3]: f(3)
Out[3]: 4