Skip to content

Instantly share code, notes, and snippets.

View ischurov's full-sized avatar

Ilya V. Schurov ischurov

View GitHub Profile
@ischurov
ischurov / Untitled63.ipynb
Created March 4, 2017 21:42
nbviewer widget test
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ischurov
ischurov / Untitled5.ipynb
Created February 4, 2017 15:45
parse data from mkrf.ru
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ischurov
ischurov / decode_escaped_cp866.py
Created December 25, 2016 20:36
A helper function useful to decode cp866-encoded filenames in tar archives.
def decode_escaped_cp866(s):
out = []
for token in re.finditer(r"%([0-9A-F]{2})|(.)", s):
if token.group(1) is not None:
out.append(bytes([int(token.group(1), 16)]))
elif token.group(2) is not None:
out.append(token.group(2).encode('utf-8'))
return b"".join(out).decode('cp866')
print(decode_escaped_cp866("%8C%A0%E0%A8%EF - %84%87"))

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)
@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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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>Прежде, чем говорить о дифференциальных уравнения в общем виде, обсудим
несколько простых примеров, в которых они возникают естественным образом.
%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 / 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
@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')