Skip to content

Instantly share code, notes, and snippets.

View dazcona's full-sized avatar
🤹‍♂️
Juggling with Data

David Azcona dazcona

🤹‍♂️
Juggling with Data
View GitHub Profile
@dazcona
dazcona / show_image.py
Created August 23, 2019 15:59
Display matplotlib RGB images
# Display matplotlib RGB images
# https://www.pyimagesearch.com/2014/11/03/display-matplotlib-rgb-image/
# matplotlib: pyplot and mpimg to load and display our images
# plt.axis("off"): to remove the axes of the figure
# OpenCV: images are stored in BGR order rather than RGB!
# Matplotlib
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
@dazcona
dazcona / remote-notebook.md
Last active August 22, 2019 12:18
Remote Access to IPython Notebooks via SSH

Remote Access to IPython Notebooks via SSH

Start your notebook on the remote host:

remote_user@remote_host$ ipython notebook --no-browser --port=8889

Remote connect from your local machine:

local_user@local_host$ ssh -N -f -L localhost:8888:localhost:8889 remote_user@remote_host
@dazcona
dazcona / sum.py
Created February 20, 2019 12:29
Sum two numbers from standard input
#!/usr/bin/env python
# read from input
a = int(raw_input()) # first
b = int(raw_input()) # second
print a + b
@dazcona
dazcona / say_hello.py
Created February 20, 2019 12:27
Function that prints Hello!
#!/usr/bin/env python
def say_hello():
print("Hello, World!")
say_hello()
@dazcona
dazcona / hello.py
Created February 20, 2019 12:22
Hello World!
#!/usr/bin/env python
print "Hello, World!"
@dazcona
dazcona / read-json.py
Created November 9, 2018 14:58
Read JSON file
import json
from pprint import pprint
with open('data.json') as f:
data = json.load(f)
pprint(data)
@dazcona
dazcona / write-json.py
Created November 9, 2018 14:52
Write a JSON file
import json
data = [
{
'greeting': 'Hi!'
'name': 'David'
},
{
'greeting': 'Hello'
'name': 'Peter'
@dazcona
dazcona / smallest-from-index.py
Created November 7, 2018 17:21
Smallest from position i (part of selection sort)
# Assume an existing non-empty list a, and a position i.
# Find p, the position of the smallest element in a[i:N].
# The only difference is that:
# instead of starting at position 0, we start at position i
p = i
j = i + 1
while j < len(a):
if a[j] < a[p]:
@dazcona
dazcona / smallest-list.py
Created November 7, 2018 17:18
Find the smallest element in a list (part of selection sort)
# Assume an existing non-empty list a.
# Find p, the position of the smallest element in a.
# The smallest element could be at any position.
# Therefore, we will have to examine every position.
# Therefore, we use our do-something-n-times pattern.
p = 0
j = 1
while j < len(a):
@dazcona
dazcona / fragments.py
Created November 7, 2018 17:16
Python fragments
#!/usr/bin/env python
# Assume an existing list of strings a.
# Write a Python fragment which writes each string in a to standard output, one per line.
# Explanation
# When you run this locally, the output will be "dog", "cat" and "mouse", one per line.
# However, when you run this code from another pgoram, the output will depend upon the value of a provided by that program.
if __name__ == "__main__":