Skip to content

Instantly share code, notes, and snippets.

View martin-martin's full-sized avatar
⛰️
hill view from the balcony

Martin Breuss martin-martin

⛰️
hill view from the balcony
View GitHub Profile
@martin-martin
martin-martin / venv.txt
Created March 5, 2021 11:24
File and folder contents of a Python virtual environment
.
├── bin
│   ├── Activate.ps1
│   ├── activate
│   ├── activate.csh
│   ├── activate.fish
│   ├── dmypy
│   ├── easy_install
│   ├── easy_install-3.8
│   ├── mypy
@martin-martin
martin-martin / tag.py
Created February 3, 2021 10:31
tag decorator
def tag(msg,tag):
def wrapping():
return f'<{tag}> {msg} </{tag}>'
return wrapping
string = input('Please, type in a sentence: ')
tg = input('Please, type in an HTML tag you want: ')
a = tag(string, tg)
print(a())

If you go to the command line in Mac OS X and enter:

defaults write com.apple.finder AppleShowAllFiles TRUE

All system files that are usually hidden (e.g. all .git folders) will then be shown by default in the Finder. Hide the system files by executing the same command, but set TRUE to FALSE. Finally, enter:

killall Finder

You can combine logical operators in a conditional statement. Here's an example:

>>> color = 'white'
>>> age = 10
>>> if age <= 14 and (color == 'white' or color == 'green'):
...     print(f'This milk is {age} days old and looks {color}')
... else:
...     print(f'You should better not drink this {age} day old milk...')
... 

Let's look at a new scenario. In the following code snippet, you will create a conditional statement that will check your age and let you know how you can participate in elections depending on that factor:

>>> age = 10
>>> if age < 18:
...     print('You can follow the elections on the news')
... elif age < 35:
...     print('You can vote in all elections')
... elif age >= 35:
... print('You can stand for any election')
@martin-martin
martin-martin / 09_04_files_exceptions.py
Created July 31, 2020 08:46
Reading book files and printing the first character
import os
warpeace=[]
with open ("books/war_and_peace.txt", "r") as store:
warpeace.append(store.readlines())
print(warpeace[0])
with open ("books/crime_and_punishment.txt", "w") as overwrite:
overwrite.write("")
for book in os.listdir(r"books/"):
with open (f"books/{book}", "r") as x:
import random
num = random.randint(1, 10)
guess = None
while guess != num:
guess = input("guess a number between 1 and 10: ")
guess = int(guess)
@martin-martin
martin-martin / file1.txt
Created May 7, 2020 14:09
Created via API
Demo
@martin-martin
martin-martin / tirta_empul.py
Last active March 2, 2020 14:59
Rules of the Balinese Tirta Empul water ritual in code
# encoding the Tirta Empul water ritual in code
pools = [range(1, 14), range(1, 3), range(1, 5)]
def cleanse(f_num, p_num):
print(f"you are now at fountain {f_num} of pool {p_num}.")
print("make a wish")
print("splash your face " * 3)
print("take a sip of water " * 3)
print("hold your head under the fountain")
@martin-martin
martin-martin / data.json
Created October 16, 2019 07:34
example headings from find-a-tender
{
"https://enoticetest.service.xgov.uk/Notice/Published/109876-2019?p=1":{
"h2":[
" Find a Tender\n",
"Network Rail Infrastructure Ltd",
"Share this notice",
"Review services",
"Concerned about something you've seen here?",
"Saved to watch notices list",
"Sign in to watch this notice",