Skip to content

Instantly share code, notes, and snippets.

# NOTE: I have no reason for indenting this like I do.
# But writing scrappers can get boring sometimes, you know.
# -^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^
foo = un(first_or_value(tr.select('//*[preceding-sibling::font/a[contains(., "Bajar")]]')))
# -^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^
if 'nominal' in foo: l.add_value('tipo', 'nominal')
elif 'numerica' in foo: l.add_value('tipo', 'numerica')
else : raise ValueError(u'Not "nominal" nor "numerica" in %s' % foo)
# -^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^-^v^
# Problema:
module Foo
@hello = 42
class Bar
# Desde acá quiero llegar a @hello.
end
end
$.ajax({
method: 'GET',
url: '/search.json',
data: 'q=' + escape(_mq_input.val()),
traditional: true,
dataType: 'json', // response's
complete: function(xhr, status) {
if (xhr.getResponseHeader('content-type') || '' == 'application/json')
var data = JSON.parse(xhr.responseText);
if ((status == 'success' || status == 'notmodified') && data['status'] == 'OK') {
@k0001
k0001 / gist:656921
Created October 31, 2010 18:06
.irbrc
require 'irb/completion'
require 'wirble'
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
Wirble.init
Wirble.colorize
@k0001
k0001 / gist:653592
Created October 29, 2010 13:47
nginx config: userdir php.
location ~ ^/~(.+?)/(.+?\.php)$ {
root /home/$1/www/$2;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/~(.+?)(/.*)?$ {
alias /home/$1/www$2;
}
@k0001
k0001 / gist:651160
Created October 28, 2010 11:29
jsonindent
cat <<EOF | sudo tee /usr/bin/jsonindent > /dev/null
#!/usr/bin/env python
import sys
import json
json.dump(json.load(sys.stdin), sys.stdout, indent=1)
sys.stdout.write('\n')
EOF
sudo chmod 0755 /usr/bin/jsonindent
/**
* Check wether the given ``answer`` produces the right output for
* the current level.
*
* Returns ``null`` on success. Otherwise returns the wrong output.
*/
Soret.check_answer = function(regex, repl) {
var user_output = Soret.sub(regex, repl);
if (user_output != Soret.get_expected_output())
# -*- coding: utf8 -*-
import re
import sys
import json
import logging
import random
from pprint import pprint
from django.db.models import ObjectDoesNotExist
from django.db.models import Q
import os
_HERE_DIR = os.path.dirname(os.path.abspath(__file__))
_ROOT_DIR = os.path.join(_HERE_DIR, '..')
BOT_NAME = 'mscrap'
BOT_VERSION = '1.0'
SPIDER_MODULES = ['mscrap.spiders']
(MSCRAP)k@del ~/q/mscrap_git/mscrap/mscrap % cat exporters.py
# -*- coding: utf8 -*-
from scrapy.contrib.exporter import JsonLinesItemExporter
class TypedJsonLinesItemExporter(JsonLinesItemExporter):
"""
Like JsonLinesItemExporter but each line adds the item type.