Skip to content

Instantly share code, notes, and snippets.

@rogfrich
rogfrich / exercise.js
Created March 25, 2021 21:37
JAMstack exercises - JS
function task1() {
var taskImage = document.getElementsByTagName('img')[0];
taskImage.src = "http://placekitten.com/g/200/200"
var taskHeader = document.getElementById('taskHeader')
taskHeader.style.color = 'red'
}
function task2() {
@rogfrich
rogfrich / page.html
Created March 25, 2021 21:36
JAMstack_exercises_HTML
<!DOCTYPE html>
<html>
<head>
<title>JAMstack</title>
</head>
<body>
<div id="task1wraper">
<h1 id="taskHeader">Task 1</h1>
@rogfrich
rogfrich / venvs.sh
Created January 17, 2021 22:07
Sample zsh / Bash script with aliases and a function to manage Python venvs
# This script is an example of how to simplify the creation, activation and deactivation of Python virtual environments.
alias we="which python"
alias ae='deactivate &> /dev/null; source ./venv/bin/activate'
alias de="deactivate"
# Function to create an environment and optionally set a custom prompt
ce() {
if [ -z "$1" ] # If the first parameter is an empty string (i.e no parameter supplied)
then
@rogfrich
rogfrich / Ex37.py
Created September 14, 2020 15:47
My solution to exercise 37 in "Exercises for Programmers: 57 Challenges to Develop Your Coding Skills" by Brian P Hogan.
"""
Exercises for Programmers: 57 Challenges to Develop Your Coding Skills.
Exercise 37: Password Generator.
Requirements:
- Create a program to generate a secure password.
- Prompt for length, number of special characters, and the number of numeric chars.
Constraints:
- Store characters used to generate passwords in lists.
@rogfrich
rogfrich / logparse.py
Last active July 29, 2021 10:21
My solution for the Real Python "Python Practice Problems" Exercise 4: Log Parser (https://realpython.com/python-practice-problems)
""" log parser
Accepts a filename on the command line. The file is a linux-like log file
from a system you are debugging. Mixed in among the various statements are
messages indicating the state of the device. They look like:
Jul 11 16:11:51:490 [139681125603136] dut: Device State: ON
The device state message has many possible values, but this program only
cares about three: ON, OFF, and ERR.
Your program will parse the given log file and print out a report giving
how long the device was ON, and the time stamp of any ERR conditions.
"""
"""
A series of examples of list operations for Dad!
EXAMPLE 1
Start with a list of three lists: [[1,2,3], [4,5,6], [7,8,9]]
End with new lists for each position in the old list.
"""
# a list of lists, each three items long.
old_list = [
"""
Specification:
A function initDeck which creates a list Deck of 52 entries containing the numbers 1-52. Needs to be recallable so delete or overwrite Dec.
Second function Deal which randomises the order of list Deck, then in a loop 1-13 creates or overwrites a two-dimensional array Hand[0-3][0-12] by copying the value in the next entry in Deck.
Master routine to call both and print out the values in Hand.
Deck and Hand to be global.
"""
import random
def init_deck():
"""
@rogfrich
rogfrich / deal2.py
Last active March 21, 2020 16:44
Object oriented card dealing app for Dad. The same thing as deal.py, but in a more object oriented way.
import random
import sys
class Deck:
def __init__(self, number_of_cards):
self.number_of_cards = number_of_cards
self.reset()
def reset(self):
self.cards = []
@rogfrich
rogfrich / deal.py
Created March 21, 2020 16:08
Card dealing app for Dad
"""
Specification:
A function initDeck which creates a list Deck of 52 entries containing the numbers 1-52. Needs to be recallable so delete
or overwrite Dec.
Second function Deal which randomises the order of list Deck, then in a loop 1-13 creates or overwrites a two-dimensional
array Hand[0-3][0-12] by copying the value in the next entry in Deck.
Master routine to call both and print out the values in Hand.
Deck and Hand to be global.
"""
import random
@rogfrich
rogfrich / Ex20.py
Last active April 20, 2019 10:47
Solution for Ex20 on www.practicepython.org
"""
Write a function that takes an ordered list of numbers (a list where the elements are in order from smallest to
largest) and another number. The function decides whether or not the given number is inside the list and returns
(then prints) an appropriate boolean.
Extras: Use binary search.
NOTE: I created an option to compare the time taken by three different search methods.
"""
import random, time, sys