Skip to content

Instantly share code, notes, and snippets.

@oiwn
oiwn / n?
Created April 10, 2011 14:57
rules = (
Rule(SgmlLinkExtractor(allow='&after=', restrict_xpaths="//p[@class='nextprev']"),
callback='parse_next_page',
follow=True,
),
)
def parse_next_page(self, response):
xpath = "//a[@class='comments']/@href"
requests = [Request(comment.extract() + "?limit=500",
@oiwn
oiwn / gist:3379472
Created August 17, 2012 14:55
Memory and cpu optimization for Selenium
# Memory and cpu optimization
profile.set_preference('browser.sessionhistory.max_total_viewers', 0)
#profile.set_preference('browser.cache.memory.enable', False)
#profile.set_preference('browser.cache.offline.enable', False)
#profile.set_preference('browser.cache.disk.enable', False)
profile.set_preference('browser.safebrowsing.enabled', False)
profile.set_preference('browser.shell.checkDefaultBrowser', False)
profile.set_preference('browser.startup.page', 0)
profile.set_preference('dom.ipc.plugins.enabled.timeoutSecs', 15)
profile.set_preference('dom.max_script_run_time', 10)
# -- coding: utf-8 --
import os
import pdb
#import random
from scrapy import log, signals
from scrapy.stats import stats
from scrapy.xlib.pydispatch import dispatcher
from scrapy.exceptions import IgnoreRequest
from scrapy.conf import settings
from scrapy.utils.job import job_dir
@tornado.gen.engine
def async_request(self, callback, server_url, method=u'GET', body=None, **kwargs):
"""
Make async request to server
:param callback: callback to pass results
:type callback: func
:param server_url: path to required API
:type server_url: unicode
:param method: HTTP method to use, default - GET
:type method: unicode
@oiwn
oiwn / gist:8746888
Created February 1, 2014 02:00 — forked from afeld/gist:5704079

TODO: make gem for this

This was tested using Rails 3.2 and Rails 4.0 on Ruby 2.0.0.

Bower

  1. Set the install directory for Bower components:

// .bowerrc

----- Esc -----
Quick change directory: Esc + c
Quick change directory history: Esc + c and then Esc + h
Quick change directory previous entry: Esc + c and then Esc + p
Command line history: Esc + h
Command line previous command: Esc + p
View change: Esc + t (each time you do this shortcut a new directory view will appear)
Print current working directory in command line: Esc + a
Switch between background command line and MC: Ctrl + o
Search/Go to directory in active panel: Esc + s / Ctrl + s then start typing directory name
import re
import htmlentitydefs
def convert_html_entities(s):
""" Convert codes like DŽ inside html document
into unicide characters
"""
matches = re.findall("&#\d+;", s)
if len(matches) > 0:
hits = set(matches)
# coding: utf8
"""
Descriptive HTTP status codes, for code readability.
See RFC 2616 and RFC 6585.
RFC 2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
RFC 6585: http://tools.ietf.org/html/rfc6585
"""
from __future__ import unicode_literals
@oiwn
oiwn / gist:361ea24e7c0829f616d6
Created February 9, 2015 17:18
Set active button/element after route changed.
.directive( 'whenActive', function ( $location ) {
return {
scope: true,
link: function ( scope, element, attrs ) {
scope.$on( '$routeChangeSuccess', function () {
if ( $location.path() == element.attr( 'href' ) ) {
element.addClass( 'active' );
}
else {
element.removeClass( 'active' );
# -*- coding: utf-8 -*-
"""
Download files:
```
http://fssprus.ru/opendata/7709576929-iplegallist/data-20150415-structure-20140318.csv
http://www.fssprus.ru/opendata/7709576929-iplegallist/structure-20140318.csv
wget [url] -O [filepath]