This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
http://stackoverflow.com/questions/7632963/numpy-find-first-index-of-value-fast | |
First you need to run: | |
f2py -c -m search search.f90 | |
""" | |
from time import time | |
from matplotlib.pyplot import subplots, show |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!! | |
!! f2py -c -m search search.f90 | |
!! | |
subroutine find_first(needle, haystack, haystack_length, index) | |
!! | |
!! Find the first index of `needle` in `haystack`. | |
!! | |
implicit none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python 3 + numpy | |
from numpy import iinfo, int64 | |
q = iinfo(int64).max // 2**10 | |
q_lim = q + 3 | |
while q < q_lim: | |
print('hello') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mygen(): | |
for k in range(5): | |
a = yield | |
yield a**2 | |
return k | |
r = mygen() | |
for k, x in enumerate(r): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python 3 + numpy | |
from numpy import iinfo, int64 | |
# iinfo(int64).max will give the maximum value of an 8-byte precision integer, | |
# which should be 2^63 - 1 = 9223372036854775807 | |
# (there is one bit for the sign, and a shift by 1 because of zero) | |
# The trick is that a 8-byte float uses 11 bits for the exponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This creates a generator. | |
def mygen(): | |
for k in range(5): | |
# This yields None, and assigns to `a` the value that's sent in after. | |
a = yield | |
# This yields `a**2` and discards any value sent it. | |
yield a**2 | |
# This returns the final value of k, which will be set as the StopIteration | |
# `err.value`, which in this case is not used. (It's 4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Reads a Clementine playlist, and copies all the song files to a directory. | |
arg 1: path to the playlist | |
arg 2: optionally, the output directory | |
You can ignore the BeautifulSoup parser warning (or fi you insist, follow it's directions) | |
""" | |
from bs4 import BeautifulSoup, Tag # pip install beautifulsoup4 | |
from shutil import copy2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Get stacktrace from the clipboard, and open the relevant file/line in the | |
current PyCharm project (useful when using terminal instead of PyCharm run). | |
Arguments: | |
1. The path to the PyCharm launcher script (e.g. "~/pycharm/bin/pycharm.sh") | |
2. [Optional] A json dictionary of path substitutions (e.g '{"/remote/userA": "/home/userA"}') | |
https://www.jetbrains.com/help/pycharm/2016.3/opening-files-from-command-line.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The question is simply: what is the output? | |
Extra: what is `instance.z` after line 8? | |
*/ | |
public class TestQuestion1 { | |
public static void main(String[] args) { | |
SuperCls instance = new SubCls(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
For the question, see | |
https://gist.github.com/mverleg/1088fbb5f21590da6691a6e84547bada | |
OUTPUT: | |
super constructor | |
super b | |
x = 1, y = 3 | |
sub b | |
x = null, y = 3 |
OlderNewer