Skip to content

Instantly share code, notes, and snippets.

View pdbartsch's full-sized avatar

Paul Bartsch pdbartsch

  • UC Santa Barbara
  • 93455
View GitHub Profile
# https://www.practicepython.org/exercise/2014/02/26/04-divisors.html
import math
invar = input("Please enter an integer. Then I'll return a list of all divisors of that number: ")
def divisors(n):
divisors = [ x for x in range(1,n+1) if n % x == 0]
print(*divisors, sep=', ')
try:
# deal with float inputs
# https://www.practicepython.org/exercise/2014/02/15/03-list-less-than-ten.html
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
def less_than_ten(a):
for n in a:
if n < 10:
print(n)
less_than_ten(a)
# https://www.practicepython.org/exercise/2014/02/05/02-odd-or-even.html
# in case floats are input force them to int
num = int(float(input("Please enter a whole number. ")))
check = int(float(input("Please enter another whole number. ")))
# set message depending on if num / check leaves a remainder
if num % check == 0:
message = str(num) + ' can be divided evenly by ' + str(check) + ' and the result is ' + str(int(num/check))
else:
# https://www.practicepython.org/exercise/2014/01/29/01-character-input.html
import datetime
import math
name = input("Hey Bud! What's your name? ")
# by converting to float before forcing to int I avoid errors when user inputs decimal
age = int(float(input("Hi! "+ name +" How old are you? ")))
# round up to make sure number isn't 0
mult = math.ceil(float(input("Please enter a number. ")))
@pdbartsch
pdbartsch / code.py
Last active January 29, 2019 16:16
The code running lights and sounds on my outlaw class pinewood derby police car 2019 using Adafruit's Hallowing and CircuitPython
import time
import array
import math
import board
import pulseio
import digitalio
import touchio
import audioio
import busio
import adafruit_lis3dh
@pdbartsch
pdbartsch / code.py
Last active January 2, 2019 22:00
Play the star spangled banner using Circuit Python and the Circuit Playground Express from Adafruit! I went to search for the notes to the song online and found that Ryan Aebi had already converted them to frequency in Hz , so he saved me a ton of time.
'''
star spangled banner on Circuit Playground Express using Circuit Python
'''
from adafruit_circuitplayground.express import cpx
# color palette for NeoPixels
red = (30, 00, 0)
white = (255, 255, 255)
@pdbartsch
pdbartsch / code.py
Created December 30, 2018 18:40
Simple example to illustrate my problem using an Adafruit Hallowing with CircuitPython. When using the built in red led on pin 13, the light remains off until I ask it to turn on with the capacitive touch pad. When using an external led through any GPIO pin (including 13) my led is on by default and then blinks as expected when touching the touc…
import board, digitalio, touchio, time
led = digitalio.DigitalInOut(board.D9)
#led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
touch = touchio.TouchIn(board.TOUCH4)
while True:
if touch.value:
@pdbartsch
pdbartsch / GitHooks.md
Last active July 9, 2018 23:36
git hooks

question:

When using VS Code I often forget to push changes after a commit. Any extensions or hacks to just push with each commit?

answer

git hooks

The hooks are all stored in the hooks subdirectory of the Git directory. In most projects, that’s .git/hooks.

  • create an executable file called post-commit with no file extension in the hooks directory with the following 2 lines
  1. #!/bin/sh
  2. git push origin master
@pdbartsch
pdbartsch / ChangeRemoteOrigin.md
Last active May 11, 2018 17:11
How to change remote origin

Move a repository from one web host to another

  • cd \local\repository\directory
  • show current remote and the name of the remotes: git remote -v
  • take the name of the remote you'd like to remove (e.g. origin or destination) and plug it into the next command
  • git remote rm origin will remove a remote named 'origin' but substitute your remote name here

Push the repo to new host:

  • git remote add origin https://user@example.com/userName/remoteRepoName.git
  • git push -u origin master
@pdbartsch
pdbartsch / html5shiv-printshiv.js
Created July 6, 2017 23:17
UCSB Get Latitude & Longitude
/**
* @preserve HTML5 Shiv 3.7.2 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
*/
!function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x<style>"+b+"</style>",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=y.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=y.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),y.elements=c+" "+a,j(b)}function f(a){var b=x[a[v]];return b||(b={},w++,a[v]=w,x[w]=b),b}function g(a,c,d){if(c||(c=b),q)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():u.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||t.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),q)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createE