This file contains hidden or 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
!ls | |
import subprocess, sys | |
!pip install {library} | |
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pkg_name']) | |
from IPython.core.interactiveshell import InteractiveShell | |
InteractiveShell.ast_node_interactivity = "all" |
This file contains hidden or 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
import requests | |
import lxml.html as lh | |
import pandas as pd | |
header = { "User-Agent"; #.... | |
r = requests.get(url, headers=header) | |
df = pd.read_html(r.text)[0] | |
###################################### |
This file contains hidden or 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 fib(n): | |
v1, v2, v3 = 1, 1, 0 # initialise a matrix [[1,1],[1,0]] | |
for rec in bin(n)[3:]: # perform fast exponentiation of the matrix (quickly raise it to the nth power) | |
calc = v2*v2 | |
v1, v2, v3 = v1*v1+calc, (v1+v3)*v2, calc+v3*v3 | |
if rec=='1': v1, v2, v3 = v1+v2, v1, v2 | |
return v2 |
This file contains hidden or 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
# | |
# Source: http://blog.rtwilson.com/conda-revisions-letting-you-rollback-to-a-previous-version-of-your-environment/ | |
# Changes to Anaconda distribution and packages | |
conda list --revisions | |
# Revert to a previous revision |
This file contains hidden or 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
import numpy | |
def sieve8(n): | |
"""Return an array of the primes below n.""" | |
prime = numpy.ones(n//3 + (n%6==2), dtype=numpy.bool) | |
for i in range(3, int(n**.5) + 1, 3): | |
if prime[i // 3]: | |
p = (i + 1) | 1 |
This file contains hidden or 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
# R Function to Shift Vectors | |
# http://clarkrichards.org/r/timeseries/2016/02/09/a-function-to-shift-vectors/ | |
# | |
shift <- function(x, lag) { | |
n <- length(x) | |
xnew <- rep(NA, n) | |
if (lag < 0) { | |
xnew[1:(n-abs(lag))] <- x[(abs(lag)+1):n] | |
} else if (lag > 0) { |
This file contains hidden or 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
### Keybase proof | |
I hereby claim: | |
* I am mbadros on github. | |
* I am mbadros (https://keybase.io/mbadros) on keybase. | |
* I have a public key ASAw2MSDq8rPTnECkZ4ZbR5BGa-SWaPvKrvxtllX0kVnogo | |
To claim this, I am signing this object: |
This file contains hidden or 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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |