Skip to content

Instantly share code, notes, and snippets.

@pkmishra
pkmishra / middlewares.py
Last active November 8, 2020 05:26
Scrapy middlewares for random agent list and proxy server usage.
import os
import random
from scrapy.conf import settings
class RandomUserAgentMiddleware(object):
def process_request(self, request, spider):
ua = random.choice(settings.get('USER_AGENT_LIST'))
if ua:
request.headers.setdefault('User-Agent', ua)
class ProxyMiddleware(object):
@pkmishra
pkmishra / .bashrc
Created February 28, 2013 22:12
sample bashrc
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
fi
#enable bash completion
[ -f /etc/profile.d/bash-completion ] && source /etc/profile.d/bash-completion
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
@pkmishra
pkmishra / build.sbt
Created January 16, 2013 23:39
sbt-idea to work with scala 2.10.0
import sbt._
import Defaults._
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
libraryDependencies += sbtPluginExtra(
m = "com.github.mpeltonen" % "sbt-idea" % "1.3.0-SNAPSHOT", // Plugin module name and version
sbtV = "0.12", // SBT version
scalaV = "2.9.2" // Scala version compiled the plugin
)
@pkmishra
pkmishra / snippet-replace-multiple
Created July 26, 2012 19:55
Replace text in multiple files
perl -pi -w -e 's/SEARCH_FOR/REPLACE_WITH/g;' *.extension
@pkmishra
pkmishra / gist:2898254
Created June 8, 2012 21:49
Chaplin- collectionview inside compositeview
For collection view
initialize: ->
console.debug 'CollectionView#initialize'
super({render:false, renderItems:false})
render: ->
super
@renderAllItems()
@pkmishra
pkmishra / jQuery.ajaxQueue.min.js
Created May 12, 2012 02:04 — forked from gnarf/jQuery.ajaxQueue.min.js
jQuery.ajaxQueue - A queue for ajax requests
/*
* jQuery.ajaxQueue - A queue for ajax requests
*
* (c) 2011 Corey Frang
* Dual licensed under the MIT and GPL licenses.
*
* Requires jQuery 1.5+
*/
(function(a){var b=a({});a.ajaxQueue=function(c){function g(b){d=a.ajax(c).then(b,b).done(e.resolve).fail(e.reject)}var d,e=a.Deferred(),f=e.promise();b.queue(g),f.abort=function(h){if(d)return d.abort(h);var i=b.queue(),j=a.inArray(g,i);j>-1&&i.splice(j,1),e.rejectWith(c.context||c,[f,h,""]);return f};return f}})(jQuery)
@pkmishra
pkmishra / MTOMSoapClient.php
Created March 29, 2012 19:57
PHP SOAP client to handle mtom message encoding
/**
* This client extends the ususal SoapClient to handle mtom encoding. Due
* to mtom encoding soap body has test apart from valid xml. This extension
* remove the text and just keeps the response xml.
*/
class MTOMSoapClient extends SoapClient {
public function __doRequest($request, $location, $action, $version, $one_way = 0) {
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
//if resposnse content type is mtom strip away everything but the xml.