Skip to content

Instantly share code, notes, and snippets.

View vortec's full-sized avatar

Fabian Kochem vortec

View GitHub Profile
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from BeautifulSoup import BeautifulSoup, Tag, CData
>>> s=BeautifulSoup("")
>>> s=BeautifulSoup("<div></div>")
>>> n=s.find('div')
>>> n
<div></div>
>>> n.append(CData('<b>bleh</b>'))
# BeautifulSoup 3.2.0
>>> from BeautifulSoup import BeautifulSoup, CData
>>> s = BeautifulSoup("<div></div>")
>>> n = s.find('div')
>>> n.append(CData('<b>bleh</b>'))
>>> n
<div><![CDATA[<b>bleh</b>]]></div>
>>>
-------------
@vortec
vortec / gist:4709504
Created February 4, 2013 20:31
.strftime('%s') is locale-aware
from pytz import timezone
from datetime import datetime
# From http://en.wikipedia.org/wiki/Eastern_Time_Zone
# "Places that use Eastern Standard Time (EST) when observing standard time (autumn/winter)
# are 5 hours behind Coordinated Universal Time (UTC−05:00)."
us = timezone('US/Eastern')
# GMT during the winter is exactly UTC if I'm not mistaken
uk = timezone('Europe/London')
fkochem at WK-6 in ~/workspace/code/sentry/bin exited 1 workon sentry
$ ./sentry --config=/home/fkochem/.sentry/sentry.conf.py createsuperuser
Traceback (most recent call last):
File "./sentry", line 9, in <module>
load_entry_point('sentry==5.4.1', 'console_scripts', 'sentry')()
File "/home/fkochem/workspace/code/sentry/local/lib/python2.7/site-packages/sentry/utils/runner.py", line 191, in main
initializer=initialize_app,
File "/home/fkochem/workspace/code/sentry/local/lib/python2.7/site-packages/logan/runner.py", line 155, in run_app
management.execute_from_command_line([runner_name, command] + command_args)
File "/home/fkochem/workspace/code/sentry/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
@vortec
vortec / gist:5378491
Created April 13, 2013 13:52
How to recursively unzip a file in Objective C using ZipZap. self.course_data is a NSData object that holds the zip file, coming from a NSURLConnection callback. This is stuff you can ignore.
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
self.progressLabel.text = @"Unpacking...";
connection = nil;
// Save to disk, release memory
NSString *temp_file_path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"/temp.zip"];
[self.course_data writeToFile:temp_file_path atomically:YES];
self.course_data = nil;
// Unzip
@vortec
vortec / gist:5843378
Created June 23, 2013 01:35
Late night implementation of Tornado + Redis PubSub + Websockets. It's late, the code is messy, but it should demonstrate how the general construct works. Feel free to try it on your own after studying it.
import json
import os
import tornado.httpserver
import tornado.web
import tornado.websocket
import tornado.ioloop
import tornado.gen
import tornadoredis
import re
f1 = 'my movie title #12'
f2 = 'my other movie title'
my_regex = re.compile(r'^(?P<movie>.*)( #(?P<version>\d+))$')
result = re.match(my_regex, f1)
if result:
print result.groupdict()
#!/bin/bash
oldrev=$(git rev-parse $1)
newrev=$(git rev-parse $2)
refname="$3"
case "$refname","$rev_type" in
refs/tags/*,tag)
# annotated tag
refname_type="annotated tag"
function="atag"
short_refname=${refname##refs/tags/}
[fkochem@FK] ~/temp $ mkdir blubb †: 0
[fkochem@FK] ~/temp $ cd blubb †: 0
[fkochem@FK] ~/temp/blubb $ git init †: 0
Initialized empty Git repository in /Users/fkochem/temp/blubb/.git/
[fkochem@FK] ~/temp/blubb (git)-[master]$ touch meh †: 0
[fkochem@FK] ~/temp/blubb (git)-[master]$ cat > meh †: 0
this
is
my
awesome
>>> x = {1, 2, 3}
>>> y = [3, 4, 5]
>>> x.intersection(y)
{3}
>>> x & y
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for &: 'set' and 'list'
>>>