Skip to content

Instantly share code, notes, and snippets.

View svschannak's full-sized avatar

Sven Schannak svschannak

View GitHub Profile
@svschannak
svschannak / uri.js
Created May 4, 2016 06:27 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@svschannak
svschannak / ubuntu_openvpn_setup.sh
Created June 10, 2016 09:06
Install scripts for using openvpn config files in ubuntu network
sudo apt-get install openvpn network-manager-openvpn network-manager-openvpn-gnome
sudo apt-get install network-manager-vpnc
sudo /etc/init.d/networking restart
@svschannak
svschannak / selenium_multiprocess.py
Last active March 15, 2021 04:35
Multiprocessing with Selenium and Python for website crawling
from multiprocessing import Pool, cpu_count
def run_parallel_selenium_processes(datalist, selenium_func):
pool = Pool()
# max number of parallel process
ITERATION_COUNT = cpu_count()-1
count_per_iteration = len(datalist) / float(ITERATION_COUNT)
@svschannak
svschannak / ipython_error.sh
Created June 21, 2016 11:51
Error if you use the wrong python version with IPython
AttributeError: 'Unicode' object has no attribute 'tag'
@svschannak
svschannak / start_ipython_in_venv.sh
Created June 21, 2016 11:52
Start IPython with the current venv
python -m IPython notebook
@svschannak
svschannak / simple_wsgi.py
Created July 17, 2016 14:00
Very simple wsgi server for oauth callbacks
from wsgiref.simple_server import make_server
from cgi import parse_qs, escape
def show_get_params(environ, start_response):
subject = parse_qs(environ.get('QUERY_STRING', ''))
start_response('200 OK', [('Content-Type', 'text/html')])
return ['''%(subject)s''' % {'subject': subject}]
srv = make_server('localhost', 3000, show_get_params)
srv.serve_forever()
@svschannak
svschannak / react-draft-update.js
Created September 26, 2016 07:58
Draft.js Update editor content
componentWillReceiveProps(newProps){
this.setState({
editorState: createEditorState(newProps.current_content),
})
}
@svschannak
svschannak / find_match_for_dataframes.py
Last active October 13, 2016 15:56
Pandas Find Match for 2 dataframes and add column with right index
def find_match_for_dataframes(df1, df2, cols_to_compare=[], name_of_new_row="found_in_row"):
copy_df2 = df2
df1[name_of_new_row] = ""
for idx, item in df1.iterrows():
for idx_comp, comp_item in copy_df2.iterrows():
# check if all conditions are successful
# returns True if the list is empty
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
django.setup()
.. automodule:: app_name.views
    :members: