Skip to content

Instantly share code, notes, and snippets.

View robertlugg's full-sized avatar

Robert M Lugg robertlugg

View GitHub Profile
@robertlugg
robertlugg / jorena_example.rst
Last active June 9, 2018 18:30
A demo of how to use an .rst file

Welcome to the example

Hi Jorena, this is just an example .rst file

If you look on the right of this text box you will see a pushbutton 'RAW'

Press that to see the actual code used to create this file.

A really nice example is https://gist.github.com/dupuy/1855764

@robertlugg
robertlugg / facebook_numpy.csv
Created February 4, 2020 15:08
Numpy usage example
1 2 3 4 5 6 7
2 4 6 8 10 12 14
324 123 345 564 567 345 554
@robertlugg
robertlugg / turtle_demo.py
Created February 15, 2020 19:03
Using Python turtle graphics to draw a shape.
"""
Turtle graphics demo.
Reference: https://www.geeksforgeeks.org/turtle-programming-python/
"""
import turtle
wn = turtle.Screen()
wn.bgcolor("light green")
@robertlugg
robertlugg / ipyo.py
Last active March 5, 2020 16:35
ipywidgets output
# Goal is to capture output from print() to a nice box with scrollbars
# These print statements are proxies for what really does the printing, so I can't change them.
import ipywidgets as widgets
from ipywidgets import HBox, IntSlider, Text, Label, Output
# Attempt #1
a = Output()
with a:
for i in range (50):
print(f"Hello {i}")
@robertlugg
robertlugg / min_max.py
Created March 16, 2020 21:10
Example User entry and determine min and max values.
""" Program to accept list of numbers and return smallest and largest """
def main():
print("Enter numbers. Type 'done' for the number to compute min and max")
smallest = largest = None
while True:
user_entry = input('enter a number ')
if user_entry == 'done':
break
try:
@robertlugg
robertlugg / timer.py
Created April 12, 2020 19:34
Python timer example
import time
while True:
print("How long or 'exit' when finished")
try:
uin = input(">> ")
except Exception:
break
if uin == 'exit':
break
@robertlugg
robertlugg / file_write.py
Created April 14, 2020 17:45
Make directory. Write file.
import os
# User entry of folder name. Make it.
folder = input("Folder name:")
try:
os.makedirs(folder)
except:
pass
# User entry of file base. Build full path.
# Fixed version.
# Minimal changes to get it working
my_string = "This is a bunch of words!"
print(f'{my_string}')
alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
outputStr = ''
for i in my_string:
for idx, j in enumerate(alphabet):
@robertlugg
robertlugg / timer.py
Created April 15, 2020 15:59
Timer that prints on same line. Example of CR without newline.
import time
counter = 0
while counter < 10:
print(f'\r{counter}', end='')
time.sleep(1.0)
counter += 1
print("Done.")

{ "editor.insertSpaces": true, "editor.fontFamily": "JetBrains Mono, Cascadia Code PL, Droid Sans Mono", "editor.fontLigatures": true, "editor.minimap.showSlider": "always", "editor.multiCursorModifier": "ctrlCmd", "editor.renderControlCharacters": true, "editor.renderIndentGuides": true, "editor.renderWhitespace": "boundary", "editor.rulers": [100],