python language
Python docs / Tutorial / Data Structures / Stdlib / Pathlib / Argparse / Errors and Exceptions / Built-in Exceptions / unittest / Markdown
mmmnnnmmm - Gwern - Matt Might - tim rodenbröker - The Coding Train - CG Cookie
Python docs / Tutorial / Data Structures / Stdlib / Pathlib / Argparse / Errors and Exceptions / Built-in Exceptions / unittest / Markdown
"Hello, World!" is the traditional first program for beginning programming in a new language or environment.
The objectives are simple:
def hello():
return 'Hello, World!'
You have five tasks, all related to cooking
Define an EXPECTED_BAKE_TIME
constant that returns how many minutes the lasagna should bake in the oven.
According to your cookbook, the Lasagna should be in the oven for 40 minutes:
>>> import lasagna
>>> lasagna.EXPECTED_BAKE_TIME
40
Implement the bake_time_remaining()
function that takes the actual minutes the lasagna has been in the oven as an argument and returns how many minutes the lasagna still needs to bake based on the EXPECTED_BAKE_TIME
.
>>> from lasagna import bake_time_remaining
>>> bake_time_remaining(30)
10
Implement the preparation_time_in_minutes()
function that takes the number of layers you want to add to the lasagna as an argument and returns how many minutes you would spend making them.
Assume each layer takes 2 minutes to prepare.
>>> from lasagna import preparation_time_in_minutes
>>> preparation_time_in_minutes(2)
4
Implement the elapsed_time_in_minutes()
function that has two parameters: number_of_layers
(the number of layers added to the lasagna) and elapsed_bake_time
(the number of minutes the lasagna has been baking in the oven).
This function should return the total number of minutes you've been cooking, or the sum of your preparation time and the time the lasagna has already spent baking in the oven.
>>> from lasagna import elapsed_time_in_minutes
>>> elapsed_time_in_minutes(3, 20)
26
Go back through the recipe, adding notes and documentation.
def elapsed_time_in_minutes(number_of_layers, elapsed_bake_time):
"""
Return elapsed cooking time.
This function takes two numbers representing the number of layers & the time already spent
baking and calculates the total elapsed minutes spent cooking the lasagna.
"""
"""Functions used in preparing Guido's gorgeous lasagna.
Learn about Guido, the creator of the Python language: https://en.wikipedia.org/wiki/Guido_van_Rossum
"""
EXPECTED_BAKE_TIME = 40
def bake_time_remaining(elapsed_bake_time):
"""Calculate the bake time remaining.
:param elapsed_bake_time: int - baking time already elapsed.
:return: int - remaining bake time (in minutes) derived from 'EXPECTED_BAKE_TIME'.
Function that takes the actual minutes the lasagna has been in the oven as
an argument and returns how many minutes the lasagna still needs to bake
based on the `EXPECTED_BAKE_TIME`.
"""
return EXPECTED_BAKE_TIME - elapsed_bake_time
def preparation_time_in_minutes(number_of_layers):
"""
Return minutes spent making the recipe
This function takes a number representing the number of layers added to the lasagne
"""
preparation_time = 2
return preparation_time * number_of_layers
def elapsed_time_in_minutes(number_of_layers, elapsed_bake_time):
"""
Return elapsed cooking time.
This function takes two numbers representing the number of layers & the time already spent
baking and calculates the total elapsed minutes spent cooking the lasagna.
"""
return preparation_time_in_minutes(number_of_layers) + elapsed_bake_time
Introduction to Bluefin Linux / Codecs and Multimedia Support / bazzite-arch for steam and gaming / Bluefin Administration Guide / Latest documentation / MLBox, Ollama, Alpaca, mods, Pytorch / Nvidia 555 drivers incoming, important information! - Bluefin and Aurora
Sculpting a Python function - by Nobody has time for Python
Data Classes in Python 3.7+ (Guide) – Real Python
Make your own Tower Defense Game with PyGame • Inspired Python
Malcolm Gladwell and William Cohan on What Really Happened to GE
Life Lessons After 10 Years of BetterExplained.com – BetterExplained
‘Story Of Your Life’ Is Not A Time-Travel Story · Gwern.net
What “Drive My Car” Reveals on a Second Viewing | The New Yorker
'Drive My Car' and 'Uncle Vanya': How Intertextuality Enriches a Film
Creating Isometric RPG Game Backgrounds - using Stable Diffusion techniques to create 2D game environments
Great game development is actively harmed by this assumption. Pre-allocating resources at an early stage interrupts the exploratory iteration needed to find the fun in a game. A written plan that stretches months into the future is like a stake through the heart of a good game process. Instead of quickly pivoting to amplify a delightful opportunity found during play testing, you end up blindly barreling towards completion on a some ineffectual paper fantasy.
A Skeleton Key to Ali Smith's Artful — The Airship, from the Wayback machine
The most beautiful thing about Ali Smith’s book Artful — at once a series of real-life Oxford lectures and a metafictional post-love story — is the way she carries us through her unnamed narrator's emotional progression
The Guardian review, theliterarysisters, #AliSmith
Google - We Have No Moat, And Neither Does OpenAI, discussion at Hacker News
Leaked internal document claims open-source will outcompete Google and OpenAI the uncomfortable truth is, we aren’t positioned to win this arms race and neither is OpenAI. While we’ve been squabbling, a third faction has been quietly eating our lunch.
Development notes from xkcd's Gravity and Escape Speed #gamedev
Escape Seed is a large space exploration game created and drawn by Randall Munroe.
This was one of the most ambitious — and most delayed — April Fools comics we’ve ever shipped. The art, physics, story, game logic, and render performance all needed to work together to pull this off. We decided to take the time to get it right.
The game is a spiritual successor to last year’s Gravity space exploration comic. Our goal was to deepen the game with a bigger map and more orbital mechanics challenges to play with.
Andreas Fragner - Writing summaries is more important than reading more books
Ted Chiang's essay - Will A.I. Become the New McKinsey?, comments from Schneier on Security. previously, Ted Chiang - ChatGPT Is a Blurry JPEG of the Web
Out of Sir Vidia’s Shadow, Paul Theroux @LRB
** TODO **
Civilization IV needs xml dll's to work with steam proton.
$ protontricks 8800 vcrun2003 msxml3 corefonts lucida tahoma fontsmooth=rgb
document first play through as Rome/Julius-caesar on Warlord difficulty
Disco Elysium has stopped working. The game freezes on loading. A solution is to install a custom build of proton, GloriousEggroll/proton-ge-custom. It has FFmpeg enabled for FAudio, patches from wine-staging and Vulkan for Direct3D (VKD3D).
Download a release
mkdir -v ~/.steam/root/compatibilitytools.d/
tar -xf Proton-7.2-GE-2.tar.gz -C ~/.steam/root/compatibilitytools.d/
** TODO **
** ref **
Crossing the Blood Meridian: Cormac McCarthy and American History
The 'Dead-Internet Theory' Is Wrong but Feels True - The Atlantic
An app can be a home-cooked meal
Ian Rankin on Patricia Highsmith’s hunger for love and thought
Arundhati Roy, novelist with a sting
Benyamin on how he became a writer
The Truth, by Stanisław Lem | The MIT Press Reader by Stanisław Lem, translated by Antonia Lloyd-Jones
Lem's 1964 story, published in English for the first time, tells the tale of a scientist in an insane asylum theorizing that the sun is alive.
The meditative empathy of Susanna Clarke’s Piranesi - Vox by Constance Grady
There is something meditative about watching Piranesi live, the purity of his life and the kindness of it. And Piranesi’s kindness is possible in part because he lives in such communion with the House, which is his world. He respects the House and knows how to live within it, and in turn the House blesses him with its bounties.
The Sellout won the Booker Prize. This blistering passage on white male privilege shows why. - Vox by Constance Grady
In the end we found it impossible to ignore the impassioned pleas of the Lost City of White Male Privilege, a controversial municipality whose very existence is often denied by many (mostly privileged white males). Others state categorically that the walls of the locale have been irreparably breached by hip-hop and Roberto Bolaño’s prose ...
9 Fictional Friendships that Explore Male Intimacy - Electric Literature by Jackson Frons
At the fulcrum of Roberto Bolaño’s kaleidoscopic epic Savage Detectives, are the poets Ulises Lima and Arturo Belano, the author’s alter ego. The mysterious leaders of the Visceral Realists, drift through Spain, Israel, North Africa, and Mexico sharing an unspoken and often inscrutable bond as they phase in and out of contact
‘Heartbreak is part of doing anything you want to do’ | Paul Beatty | The Guardian, Kate Kellaway interviews Paul Beatty
You are wary of other people’s questions. What questions do you ask yourself?
I don’t ask myself big questions. I’ve a friend who was struggling, saying: “I don’t know why I am here… what is the purpose?” I said: “There is no purpose.” If there were a purpose, then I would be frozen.
Considering the Novel in the Age of Obama by Christian Lorentzen
Environmental despoliation, economic regression, and enthroned sexism and bigotry are already on the cards. For all the turmoil on our streets and abroad, literary historians may look back at the Obama years as a time of tranquility ...
Joan Didion: Only Disconnect Off Center: Essays by Barbara Grizzutti Harrison (1980).
I am disinclined to find endearing a chronicler of the 1960s who is beset by migraines that can be triggered by her decorator's having pleated instead of gathered her new diningroom curtains. These, and other assorted facts -- such as the fact that Didion chose to buy the dress Linda Kasabian wore at the Manson trial at I. Magnin in Beverly Hills -- put me more in mind of a neurasthenic Cher than of a writer who has been called America's finest woman prose stylist.
A Premature Attempt at the 21st Century Canon | Vulture by Vulture Editors
A panel of critics tells us what belongs on a list of the 100 most important books of the 2000s … so far.
The World According to Peter Thiel - Erik Torenberg's Thoughts
His claim is that we've had this narrow cone of progress around the world of bits—around software & IT — but not atoms. The iPhones that distract us from our environment also distract us from how strangely old & unchanged our current environment is. If you were to be in any room in 1973, everything would look the same except for our phones. This explains his old Founders Fund tagline: “We wanted flying cars, instead we got 140 characters.”
Zooming out, people don’t understand how important economic growth is. It’s the only thing sustaining the planet. Without it, we go into a malthusian war. Indeed: The only way our societies have worked for at least 250 years is by economic growth. Parliamentary democracies are built on an ever-expanding pie that they can continue subdividing. Once the pie is no longer expanding, everything turns zero-sum.
Cyberdecks For High-Tech Low-Lifes - The Dork Web
The term “Cyberdeck” was first coined in Gibson’s 1984 literary masterpiece, Neuromancer. He rewrote parts of Neuromancer several times after the release of Ridley Scott’s Blade Runner. Blade Runner was based on Philip K. Dick’s 1968 novel Do Androids Dream of Electric Sheep. Scott, Dick, Brunner’s The Shockwave Rider, Goddard’s Alphaville and work by futurists such as Syd Mead and Moebius make the title of “father of Cyberpunk” hard to hang on Gibson alone. But he’s clearly a very important character in the development of Cyberpunk culture.
Just as Shakespeare brought in new words to describe new worlds, 1980s Gibson is Cyberpunk’s Great Bard. The Cyberdeck is just one of Gibson’s literary gifts. It’s the tool that lets Console Cowboys jack into the Matrix of Cyberspace and start hacking.
The anthropologist in an economist world - Altered States of Monetary Consciousness
Anthropology starts from the recognition that a person - in the first instance at least - cannot exist apart from a group. Put differently, anthropology assumes that a human network always precedes its individual members, and that care and reproduction precede any form of solo heroics. Human babies don’t survive long if they are left to fend for themselves, and - even if they miraculously survived without others - they would not be able to speak language, which would make all future social interaction, relationships and trade near-impossible.
The age-old strategy of buying cheap shares is faltering - Hacker News
the article is behind paywall, but the discussion at HN is interesting (premii)
Why You Should Use Component-Based Design in Unity
Let’s say that any weapon will have a component for damage, range, and projectiles (optional). Using Unity’s UI, you could create a weapon by dragging these components onto any GameObject and customizing the values of each one. Then, if the way projectiles are handled changes further into development, all you need to do is change one script, and all your weapons’ functionalities will be updated instead of just those defined at one level of a tree.
Yay is a command-line tool to install and manage software from the Arch User Repository. It is included in the community repository of Manjaro Linux.
> pacman -Ss yay
community/yay 10.0.4-1
Yet another yogurt. Pacman wrapper and AUR helper written in go.
> sudo pacman -S yay
> man yay
> yay --help
# upgrade system
> yay -Syyu
# remove stale packages
> yay -Qdt
> yay -R $(yay -Qdtq | xargs)
# cleanup
> yay -Sc --noconfirm
# edit PKGBUILD
> mkdir ~/AUR_local && cd ~/AUR_Local
> yay --getpkgbuild julius-game
:: Querying AUR...
:: Downloaded PKGBUILD (1/1): julius-game
> ls julius-game/
total 12K
-rw-r--r-- 1 user0 user0 173 Sep 22 11:04 julius-game.desktop
-rw-r--r-- 1 user0 user0 145 Sep 22 11:04 julius-game.install
-rw-r--r-- 1 user0 user0 1.4K Sep 22 11:04 PKGBUILD
> cd julius-game
> vi PKGBUILD
> makepkg -si
# show foreign packages
# i.e those not belonging to official repos
# yay -Q --foreign
> yay -Qm
# info about AUR package
> yay -Si ktlint
:: Querying AUR...
Repository : aur
Name : ktlint
Keywords : None
Version : 0.38.1-1
Description : An anti-bikeshedding Kotlin linter with built-in formatter
URL : https://ktlint.github.io/
AUR URL : https://aur.archlinux.org/packages/ktlint
....
The World According to Peter Thiel - Erik Torenberg's Thoughts
His claim is that we've had this narrow cone of progress around the world of bits—around software & IT — but not atoms. The iPhones that distract us from our environment also distract us from how strangely old & unchanged our current environment is. If you were to be in any room in 1973, everything would look the same except for our phones. This explains his old Founders Fund tagline: “We wanted flying cars, instead we got 140 characters.”
Zooming out, people don’t understand how important economic growth is. It’s the only thing sustaining the planet. Without it, we go into a malthusian war. Indeed: The only way our societies have worked for at least 250 years is by economic growth. Parliamentary democracies are built on an ever-expanding pie that they can continue subdividing. Once the pie is no longer expanding, everything turns zero-sum.
Cyberdecks For High-Tech Low-Lifes - The Dork Web
The term “Cyberdeck” was first coined in Gibson’s 1984 literary masterpiece, Neuromancer. He rewrote parts of Neuromancer several times after the release of Ridley Scott’s Blade Runner. Blade Runner was based on Philip K. Dick’s 1968 novel Do Androids Dream of Electric Sheep. Scott, Dick, Brunner’s The Shockwave Rider, Goddard’s Alphaville and work by futurists such as Syd Mead and Moebius make the title of “father of Cyberpunk” hard to hang on Gibson alone. But he’s clearly a very important character in the development of Cyberpunk culture.
Just as Shakespeare brought in new words to describe new worlds, 1980s Gibson is Cyberpunk’s Great Bard. The Cyberdeck is just one of Gibson’s literary gifts. It’s the tool that lets Console Cowboys jack into the Matrix of Cyberspace and start hacking.
The anthropologist in an economist world - Altered States of Monetary Consciousness
Anthropology starts from the recognition that a person - in the first instance at least - cannot exist apart from a group. Put differently, anthropology assumes that a human network always precedes its individual members, and that care and reproduction precede any form of solo heroics. Human babies don’t survive long if they are left to fend for themselves, and - even if they miraculously survived without others - they would not be able to speak language, which would make all future social interaction, relationships and trade near-impossible.
The age-old strategy of buying cheap shares is faltering - Hacker News
the article is behind paywall, but the discussion at HN is interesting (premii)
Why You Should Use Component-Based Design in Unity
Let’s say that any weapon will have a component for damage, range, and projectiles (optional). Using Unity’s UI, you could create a weapon by dragging these components onto any GameObject and customizing the values of each one. Then, if the way projectiles are handled changes further into development, all you need to do is change one script, and all your weapons’ functionalities will be updated instead of just those defined at one level of a tree.
Fast inverse square root, sometimes referred to as Fast InvSqrt() or by the hexadecimal constant 0x5F3759DF, is an algorithm that estimates 1/sqrt(x), the reciprocal (or multiplicative inverse) of the square root of a 32-bit floating-point number x floating-point
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
return y;
}