Skip to content

Instantly share code, notes, and snippets.

View macloo's full-sized avatar
💭
Teaching some Python

Mindy McAdams macloo

💭
Teaching some Python
View GitHub Profile
@macloo
macloo / radio-test.html
Created December 16, 2015 16:53
Radio buttons that are not visible as radio buttons (Bootstrap)
<div class="row">
<div class="col-xs-12 text-center">
<h2>Select version:</h2>
<div class="btn-group" data-toggle="buttons">
<label id="esv" class="btn btn-primary active">
<input type="radio" autocomplete="off">ESV
</label>
<label id="kjv" class="btn btn-primary">
<input type="radio" autocomplete="off">KJV
</label>
@macloo
macloo / date_string.js
Last active December 17, 2015 02:29
JavaScript for date string
// produce a data string in this format: 2015-12-17 01:31:39
function getDate() {
var date = new Date();
timestamp = date.getUTCFullYear() + '-' +
('00' + (date.getUTCMonth() + 1)).slice(-2) + '-' +
('00' + date.getUTCDate()).slice(-2) + ' ' +
('00' + date.getUTCHours()).slice(-2) + ':' +
('00' + date.getUTCMinutes()).slice(-2) + ':' +
('00' + date.getUTCSeconds()).slice(-2);
# testing for a prime number - use of modulo (modulus)
# also, a good example (for beginners) of use of a while loop
# journalism students often ask how one would use modulo - this shows them one case
n = 0
print "\nWe will test a number to find out whether it is prime."
print "Try it with 25. Then try it with 7 or 13."
n = raw_input("Enter a whole number: ")
def testfor100(a):
@macloo
macloo / modulo.py
Created December 17, 2013 16:15
Simple example of using modulo (modulus) to test for a prime number.
# testing for a prime number - use of modulo (modulus)
# also, good example of a for loop
n = 0
print "\nWe will test a number to find out whether it is prime."
print "Try it with 25. Then try it with 7 or 13."
print "Then try it with any number you like (but not too large a number!)."
n = raw_input("Enter a number: ")
n = int(n)
@macloo
macloo / lists.py
Last active December 31, 2015 15:39
Introductory script for adding items to a list in Python.
# some things we do with lists
userlist = [] # makes an empty list
q = "n"
x = "a"
while q == "n":
e = raw_input("Add an element: ")
userlist.append(e)
q = raw_input ("Do you want to quit? (y/n) > ")
import sys
scores = {"A": 1, "C": 3, "B": 3, "E": 1, "D": 2, "G": 2,
"F": 4, "I": 1, "H": 4, "K": 5, "J": 8, "M": 3,
"L": 1, "O": 1, "N": 1, "Q": 10, "P": 3, "S": 1,
"R": 1, "U": 1, "T": 1, "W": 4, "V": 4, "Y": 4,
"X": 8, "Z": 10}
# Get the Scrabble rack from the command line.
if len(sys.argv) < 2:
@macloo
macloo / argv_test1.py
Last active January 3, 2016 17:08
These tiny, simple files are derived from Zed Shaw's free online book _Learn Python the Hard Way_. These files accompany Zed's exercises 15 - 17. I wrote a quiz for students to test themselves - see the URL at the top of each file here. There are 4 Python files and 2 text files.
# see http://bit.ly/mmpython2 for the quiz
# compare the way this runs to the way argv_test2.py runs
# to run:
# python argv_test1.py first.txt
from sys import argv
script, filename = argv
txt = open(filename)
@macloo
macloo / functions1.py
Created January 18, 2014 17:32
These tiny, simple files are derived from Zed Shaw's free online book _Learn Python the Hard Way_. These files accompany Zed's exercises 18 and 19, in which he introduces functions. I wrote a quiz for students to test themselves - see the URL at the top of each file here.
# this is the answer to questions 16 and 17 in Practice with Python, Part 2 - Self-Quiz
# see http://bit.ly/mmpython2 for the quiz
def myname():
print 'Mindy'
print 'McAdams'
def anyname(a, b):
print a
print b
@macloo
macloo / transact.php
Last active January 26, 2016 14:31
Doing transactions in PHP for MySQL
<?php
// $conn comes from a separate database connection file
// this is a partial, nonworking file
try {
// Let's begin a transaction
mysqli_begin_transaction($conn, MYSQLI_TRANS_START_READ_ONLY);
// There can be a set of queries
// If any one fails, an exception should be thrown
@macloo
macloo / passwords.php
Created January 26, 2016 14:37
Encrypting passwords with PHP for MySQL
<?php
// this is a partial, nonworking file
$salt1 = "qm&h*";
$salt2 = "pg!@";
$first_name = "Bill";
$last_name = "Smith";
$username = "bsmith";
$password = "secret";
$token = hash('ripemd128', "$salt1$password$salt2");