Skip to content

Instantly share code, notes, and snippets.

View ischurov's full-sized avatar

Ilya V. Schurov ischurov

View GitHub Profile
@ischurov
ischurov / mkmk-ipynb.py
Created February 8, 2015 12:21
creates a makefile to convert all ipynb-files to html and pdf
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 August 29, 2015 14:15
Template for creating pdfs from ipynb (based on latex_article.tplx). Depends on hse-coursedata.sty which contains data about the particular course
%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 December 12, 2015 09:07
Get all page titles for pages in some category in Wikipedia (presently, names of all personalias are requested from ruwiki)
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 January 2, 2016 00:43
Upload all JPG files in folder to Flickr using `flickrapi`.
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 January 12, 2016 21:48
Send emails according to the list from Google Spreadsheet with SMTP and put them into 'Sent' folder with IMAP.
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
%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 February 15, 2016 09:09
Testcase for bugreport on mathjax node.
<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>Прежде, чем говорить о дифференциальных уравнения в общем виде, обсудим
несколько простых примеров, в которых они возникают естественным образом.
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 November 3, 2016 14:57
This gist provides a function that makes pep-8-friendly multiline representation of long string.
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

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)