Create an empty git repo or reinitialize an existing one
git init
## Error handling in Python is done through the use of exceptions that are caught in try blocks and handled in except blocks. If an error is encountered, a TRy block code execution is stopped and transferred down to the except block, as shown in the following syntax: | |
try: | |
f = open("test.txt") | |
except IOError: | |
print "Cannot open file." | |
## In addition to using an except block after the try block, you can also use the finally block. The code in the finally block will be executed regardless of whether an exception occurs. | |
f = open("test.txt") |
Create an empty git repo or reinitialize an existing one
git init
Key/Command | Description |
---|---|
Tab | Auto-complete files and folder names |
Ctrl + A | Go to the beginning of the line you are currently typing on |
Ctrl + E | Go to the end of the line you are currently typing on |
Ctrl + U | Clear the line before the cursor |
Ctrl + K | Clear the line after the cursor |
Ctrl + W | Delete the word before the cursor |
Ctrl + T | Swap the last two characters before the cursor |
# -*- coding: utf-8 -*- | |
from pyqtgraph.Qt import QtGui, QtCore | |
import numpy as np | |
from numpy import arange, sin, cos, pi | |
import pyqtgraph as pg | |
import sys | |
class Plot2D(): | |
def __init__(self): | |
self.traces = dict() |
Matplotlib is a plotting library. It relies on some backend to actually render
the plots. The default backend is the agg
backend. This backend only renders
PNGs. On Jupyter notebooks the matplotlib backends are special as they are
rendered to the browser. Generally you will not need to explicitly set the
backend on a Jupyter notebook. This does introduce a discrepancy between code
that runs in Jupyter and code that runs as a script natively in the Python
interpreter. So you need to understand that the 2 environments are not the same
import numpy as np | |
from scipy.io.wavfile import write | |
# Samples per second | |
sps = 44100 | |
# Frequency / pitch of the sine wave | |
freq_hz = 440.0 | |
# Duration |
# See for tiao.io/posts/notebooks/save-matplotlib-animations-as-gifs/ more information and notes below | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import animation, rc | |
from IPython.display import HTML, Image | |
# equivalent to rcParams['animation.html'] = 'html5' | |
rc('animation', html='html5') | |
fig, ax = plt.subplots() |
def mode(xs): | |
""" | |
This returns the mode of the values in xs. xs is a standard | |
Python list with discrete values, which can be of any hashable | |
value. | |
Fo this problem, think about using a dictionary in some way. | |
What could be the keys? The values? Also remember that dictionaries | |
are UNORDERED--in other words, there is no guaranteed order. |
def median(xs): | |
""" | |
When given a standard Python list of numbers, this function will | |
return the median value. There are a few cases to consider: | |
1. xs is an empty list: return None | |
2. A list with one element: returns that element | |
3. A list with an odd number of elements: Returns the middle value. |
#!/bin/bash | |
# put this in ec2 ubuntu user-data | |
mkdir /home/ubuntu/script/ | |
cat <<'EOF' >> /home/ubuntu/script/slack.sh | |
#!/bin/bash | |
ip=`/usr/bin/curl -s -w '\n' http://169.254.169.254/latest/meta-data/public-ipv4` | |
instance=`/usr/bin/curl -s -w '\n' http://169.254.169.254/latest/meta-data/instance-id` |