Skip to content

Instantly share code, notes, and snippets.

View svschannak's full-sized avatar

Sven Schannak svschannak

View GitHub Profile
class ICalFeed(Feed):
# comments
feed_type = feedgenerator.DefaultFeed
def __call__(self, request, *args, **kwargs):
"""
Copied from django.contrib.syndication.views.Feed
Supports file_name as a dynamic attr.
"""
# views.py
class EventFeed(ICalFeed):
"""
A simple event calender
"""
product_id = '-//example.com//Example//EN'
timezone = 'UTC'
file_name = "event.ics"
.. automodule:: app_name.views
    :members:
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
django.setup()
@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
@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 / 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 / start_ipython_in_venv.sh
Created June 21, 2016 11:52
Start IPython with the current venv
python -m IPython notebook
@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 / 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)