Skip to content

Instantly share code, notes, and snippets.

Avatar

Ilya V. Schurov ischurov

View GitHub Profile
@ischurov
ischurov / mkmk-ipynb.py
Created Feb 8, 2015
creates a makefile to convert all ipynb-files to html and pdf
View mkmk-ipynb.py
import glob
import re
import os.path
import sys
published_dir=sys.argv[1] if len(sys.argv)>1 else "published"
ipynb=glob.glob("*.ipynb")
bns=map(lambda f: os.path.splitext(f)[0], ipynb)
@ischurov
ischurov / ruarticle.tplx
Last active Aug 29, 2015
Template for creating pdfs from ipynb (based on latex_article.tplx). Depends on hse-coursedata.sty which contains data about the particular course
View ruarticle.tplx
%custom IPython Notebook / NBConvert template
%based on latex_article.tplx from ipython notebook
%modified by Ilya V. Schurov <ilya at schurov.com>
%license: BSD-like (see http://ipython.org/ipython-doc/stable/about/license_and_copyright.html for details)
% Default to the notebook output style
((* if not cell_style is defined *))
((* set cell_style = 'style_ipython.tplx' *))
((* endif *))
@ischurov
ischurov / getnames.py
Last active Dec 12, 2015
Get all page titles for pages in some category in Wikipedia (presently, names of all personalias are requested from ruwiki)
View getnames.py
import requests
url = "https://ru.wikipedia.org/w/api.php"
query = {'action':'query',
'list':'categorymembers',
'cmtitle':'Категория: Персоналии по алфавиту',
'cmstartsortkeyprefix':'А',
'format':'json',
'cmlimit':500
}
@ischurov
ischurov / flickr-upload.py
Last active Jan 2, 2016
Upload all JPG files in folder to Flickr using `flickrapi`.
View flickr-upload.py
import flickrapi # we're using http://stuvel.eu/flickrapi
import glob
api_key="xxx"
api_secret="xxx"
# get your own on https://www.flickr.com/services/api/
flickr = flickrapi.FlickrAPI(api_key, api_secret)
flickr.authenticate_via_browser(perms='write')
@ischurov
ischurov / send-invites.py
Created Jan 12, 2016
Send emails according to the list from Google Spreadsheet with SMTP and put them into 'Sent' folder with IMAP.
View send-invites.py
import imaplib
import time
from email.mime.text import MIMEText
from email.utils import formataddr
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
import json
import pandas as pd
View Simple example of using odeint to solve two-dimensional ode
%matplotlib inline
# to use in Jupyter
from scipy.integrate import odeint
import numpy as np
def f(Z, t):
# x = Z[0], y = Z[1]
return [Z[1], -Z[0]]
t = np.linspace(0, 10)
@ischurov
ischurov / testcase-mathjax-node-ee.html
Created Feb 15, 2016
Testcase for bugreport on mathjax node.
View testcase-mathjax-node-ee.html
<div style='visibility: hidden; display: none;'>
\[
\newcommand{\ph}{\varphi}
\]
</div>
<h1 id="label_chap_notion_of_ODE"><span class="section__number">1. </span>Понятие дифференциального уравнения </h1><h2 id="label_h2_number_1"><span class="section__number">1. </span>Примеры моделей, приводящих к дифференциальным уравнениям
</h2>Прежде, чем говорить о дифференциальных уравнения в общем виде, обсудим
несколько простых примеров, в которых они возникают естественным образом.
View get_uik_data.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ischurov
ischurov / repr_long_str.py
Created Nov 3, 2016
This gist provides a function that makes pep-8-friendly multiline representation of long string.
View repr_long_str.py
def repr_long_str(s, maxlen=70, correction=-1, doprint=False):
assert maxlen > 3
cur = 0
out = []
while cur < len(s):
end = cur + maxlen - 2 + correction
while len(repr(s[cur:end])) > maxlen + correction:
end -= 1
out.append(repr(s[cur:end]))
correction = 0
View answer on removing empty elements.markdown

This is due to fact that you modify your list when iterating it. You can check what's going on with pythontutor.com visualizer or add some print statements like this:

    templist = ['', 'hello', '', 'hi', 'mkay', '', '']
    
    for i, element in enumerate(templist):
        print("Step", i)
        print('element is', repr(element), 'and templist is', templist)
        if element == '':
            print("element is empty")
            templist.remove(element)