Highlight

2024-03-18

Don't forget to check your integer type!

"""PIL/Pillow Image.fromarray() doesn't check your array value types!"""

from PIL import Image
import numpy as np


im = Image.new("RGB", (2, 1))
im.putpixel((0, 0), (255, 0, 0))
im.putpixel((1, 0), (0, 255, 0))

a = np.array(im)
print("Good shape:", a.shape, a)
print("See?")
Image.fromarray(a, "RGB").show()

a = np.array([[[255, 0, 0], [0, 255, 0]]])
print("Bad shape:", a.shape, a)
print("Where'd the green pixel go?")
Image.fromarray(a, "RGB").show()

a = np.uint8(a)
print("Fixed shape:", a.shape, a)
print("If the green pixel disappeared, you forgot to cast to uint8.")
Image.fromarray(a, "RGB").show()

Coal ash contains more energy than was gained from burning the coal.

https://www.world-nuclear.org/information-library/facts-and-figures/heat-values-of-various-fuels.aspx

Natural uranium, in FNR 28,000 GJ/kg [so 28e9 J/g]
Hard black coal (IEA definition) >23.9 MJ/kg
Hard black coal (Australia & Canada) c. 25 MJ/kg [so 25e3 J/g and 207.25 g/mol according to https://pubchem.ncbi.nlm.nih.gov/compound/1-Anthrylmethanolate]
Sub-bituminous coal (IEA definition) 17.4-23.9 MJ/kg
Sub-bituminous coal (Australia & Canada) c. 18 MJ/kg
Lignite/brown coal (IEA definition) <17.4 MJ/kg
Lignite/brown coal (Australia, electricity) c. 10 MJ/kg


mass / molar mass = moles

moles * avogardo = number of molecules


number / avogadro = moles

moles * molar mass = mass


1e6 / 6.022140857e24 * 207.25 = 3.4414672e-17 g of coal = 8.603668e-13 J (25e3 J/g * 3.4414672e-17 g)

1 / 6.022140857e24 * 238.02891 = 3.952563e-23 g of uranium = 1.1067176e-12 J (28e9 J/g * 3.952563e-23 g)

1 / 6.022140857e24 * 232.03806 = 3.8530826e-23 g of thorium = 1.0788631e-12 J (28e9 J/g * 3.8530826e-23)


https://pubs.usgs.gov/fs/1997/fs163-97/FS-163-97.html

"2,000 coal samples from the Western United States and approximately 300 coals from the Illinois Basin. In the majority of samples, concentrations of uranium fall in the range from slightly below 1 to 4 parts per million (ppm). Similar uranium concentrations are found in a variety of common rocks and soils, as indicated in figure 2. Coals with more than 20 ppm uranium are rare in the United States. Thorium concentrations in coal fall within a similar 1–4 ppm range"


So at 1 ppm uranium and 1 ppm thorium, a coal power plant releases only (8.603668e-13 / (1.1067176e-12 + 1.0788631e-12)) = 0.3936559286 = 39% of the available energy in coal.

2020-05-29

Keep your system and project tidy with a Python virtual environment folder


cees@cees-XPS-13-9380:~/code/space-monitor$ python3 -m venv venv
cees@cees-XPS-13-9380:~/code/space-monitor$ source venv/bin/activate
(venv) cees@cees-XPS-13-9380:~/code/space-monitor$ which python3
/home/cees/code/space-monitor/venv/bin/python3
(venv) cees@cees-XPS-13-9380:~/code/space-monitor$ python3 -m pip install logdna
Processing /home/cees/.cache/pip/wheels/af/ce/e9/fccf04ebc826e8cff5ec031f8ecc0c3b4092b44bc692f22a3f/logdna-1.5.3-py3-none-any.whl
Collecting requests
  Using cached requests-2.23.0-py2.py3-none-any.whl (58 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2020.4.5.1-py2.py3-none-any.whl (157 kB)
Collecting idna<3,>=2.5
  Using cached idna-2.9-py2.py3-none-any.whl (58 kB)
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
  Using cached urllib3-1.25.9-py2.py3-none-any.whl (126 kB)
Collecting chardet<4,>=3.0.2
  Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Installing collected packages: certifi, idna, urllib3, chardet, requests, logdna
Successfully installed certifi-2020.4.5.1 chardet-3.0.4 idna-2.9 logdna-1.5.3 requests-2.23.0 urllib3-1.25.9
(venv) cees@cees-XPS-13-9380:~/code/space-monitor$ python3 -m pip freeze > requirements.txt
(venv) cees@cees-XPS-13-9380:~/code/space-monitor$ cat requirements.txt 
certifi==2020.4.5.1
chardet==3.0.4
idna==2.9
logdna==1.5.3
requests==2.23.0
urllib3==1.25.9
(venv) cees@cees-XPS-13-9380:~/code/space-monitor$ python3 -m pip install -r requirements.txt
Requirement already satisfied: certifi==2020.4.5.1 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (2020.4.5.1)
Requirement already satisfied: chardet==3.0.4 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (3.0.4)
Requirement already satisfied: idna==2.9 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (2.9)
Requirement already satisfied: logdna==1.5.3 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 4)) (1.5.3)
Requirement already satisfied: requests==2.23.0 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 5)) (2.23.0)
Requirement already satisfied: urllib3==1.25.9 in ./venv/lib/python3.7/site-packages (from -r requirements.txt (line 6)) (1.25.9)
(venv) cees@cees-XPS-13-9380:~/code/space-monitor$ deactivate
cees@cees-XPS-13-9380:~/code/space-monitor$ 

2020-02-27

Autocue / Teleprompter

ms. px. (from here):

2019-05-07

Free Planning Poker

2015-10-14

My Firefox won't paste text! A workaround using AutoHotkey.

In Firefox I often find myself unable to paste into Facebook or YouTube comment boxes. I've been a Mozilla fan since 3.0, but bugs like these make Firefox a pain. Here's a workaround that works in my 64-bit Windows 7:
  1. Install AutoHotkey.
  2. Save this script as "type_clipboard.ahk":
    ; http://www.autohotkey.com/board/topic/76296-type-out-text-in-clipboard/
    ; ctrl+win+v
    ^#v::
        sendraw %clipboard%
    return
  3. Run the script and press Ctrl+Win+V to have AutoHotkey type your clipboard text into Firefox.