Skip to content

Instantly share code, notes, and snippets.

@pr4v33n
pr4v33n / xd13.cpp
Created September 21, 2011 01:51
lvalue
#include <iostream>
using namespace std;
int main()
{
char s[]="this is a character array";
@pr4v33n
pr4v33n / arch.log
Created August 21, 2011 14:22
Archlinux
.asoundrc
---------
pcm.!default {
type hw
card 2
device 0
}
ctl.!default {
type hw
card 2
@pr4v33n
pr4v33n / translate.js
Created July 28, 2011 13:21
En to Jp phonetic translation
// Paste the line below in Adress bar to translate
javascript:void((function(){var en=prompt("Name in english:");var ma={'a':'ka','b':'tu','c':'mi','d':'te','e':'ku','f':'lu','g':'ji','h':'ri','i':'ki','j':'zu','k':'me','l':'ta','m':'rin','n':'to','o':'mo','p':'no','q':'ke','r':'shi','s':'ari','t':'chi','u':'do','v':'ru','w':'mei','x':'na','y':'fu','z':'zi'};var jn='';for(var i=0;i<en.length;++i){ch=en.charAt(i).toLowerCase();if(ch in ma){jn+=ma[ch];}else{jn+=ch;}}alert(jn);})())
@pr4v33n
pr4v33n / prevtop.py
Created July 27, 2011 11:06
prevtop
def before_top_post(request):
data = ''
post_id = request.GET['post_id']
post = Post.objects.get(id=post_id)
posts = get_top_posts(request)
cond = lambda p: p.id != post.id
before_matched = itertools.takewhile(cond, posts)
skip = sum(itertools.imap(cond, before_matched))
if skip > 0:
matched = next(itertools.islice(posts, skip-1, None), None)
@pr4v33n
pr4v33n / nexttop.py
Created July 27, 2011 10:21
gen expr
def next_top_post(request):
data = ''
post_id = request.GET['post_id']
post = Post.objects.get(id=post_id)
posts = get_top_posts(request)
matches = itertools.dropwhile(lambda p: p.id != post.id, posts)
matched = next(itertools.islice(matches, 1, None), None)
arrows = get_top_arrows(matched)
next_post = profile_post_to_html(request,matched,'top')
data = {'post':next_post, 'arrows':arrows}
@pr4v33n
pr4v33n / temp.py
Created July 27, 2011 09:24
generator
mposts = ((p.id, posts[i+1] if (i+1) != len(posts) else None) for i, p in enumerate(posts) if p.id == post.id)
for (id, next_post) in mposts:
print('Matched post id:', id)
print('Next post id:', next_post.id)
@pr4v33n
pr4v33n / apptrace.log
Created July 20, 2011 19:51
Apptrace import error
>>> import apptrace.middleware
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/apptrace-0.2.2-py2.5.egg/apptrace/middleware.py", line 18, in <module>
from instruments import Recorder
File "/usr/lib/python2.5/site-packages/apptrace-0.2.2-py2.5.egg/apptrace/instruments.py", line 23, in <module>
from django.utils import simplejson
ImportError: No module named django.utils
@pr4v33n
pr4v33n / #pocoo.log
Created July 4, 2011 17:33
Middleware
(03:47:50 PM) h0x5f3759df: Hi, is there any way for me to pass info from my app to my custom middleware?
(04:19:03 PM) mitsuhiko: h0x5f3759df: hard
(04:19:10 PM) mitsuhiko: h0x5f3759df: what does the middleware do?
(04:19:24 PM) h0x5f3759df: It does some profiling
(04:19:34 PM) h0x5f3759df: I want to restrict the profiling to a subset of users
(04:19:39 PM) h0x5f3759df: *admins
(04:20:43 PM) mitsuhiko: h0x5f3759df: the thing is that the middleware starts executing before the application does and stops afterwards
(04:20:49 PM) mitsuhiko: but at one point in the middle there will be the application
(04:30:57 PM) mitsuhiko: h0x5f3759df: i would probably try not doing that in the middleware :)
@pr4v33n
pr4v33n / irc.log
Created July 1, 2011 14:49
Armin on wsgi request context
(06:39:05 PM) h0x5f3759df: How would i access the request context in my custom wsgi middleware?
(06:39:13 PM) mitsuhiko: h0x5f3759df: you can't
(06:39:37 PM) mitsuhiko: at least not reliably
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<pubDate>Monday, 13. June 2011 12:39AM</pubDate>
<title>GroupBachat.com Deals Feed</title>
<link>http://www.groupbachat.com/</link>
<description>Current Deals</description>
<language>en-gb</language>
<copyright>Groupbachat 2011</copyright>