Drafts

Draft and unpublished posts

0 posts simple view

Pycon 2023

Keynote Speaker - James Powell # [1] I don’t want to be an expert python developer. https://www.youtube.com/watch?v=iKzOBWOHGFE [2] usage of keyword only arguments to prevent pain for users of libraries # [3] # Version 1 def newton(f, x0, fprime, maxiter=100): ... # Version 2 def newton(f, x0, fprime, tol=1e-6, maxiter=100): ... # 🔴 Broke in Version 2 newton(f, x0, fprime, 100) In an alternate timeline the maintainer of newton could have chose to use keyword only arguments to prevent pain for users of libraries, or poor api design due to fear of changing api on users. # Version 1 def newton(f, x0, fprime, *, maxiter=100): ... # Version 2 def newton(f, x0, fprime, *, tol=1e-6, maxiter=100): ... # 🟢 user forced to use keyword only arguments never notices change newton(f, x0, fprime, maxiter=100) References: [1]: #keynote-speaker---james-powell [2]: https://dropper.waylonwalker.com/api/file/8275d2a5-72da-470c-a71d-86019415b303.webp [3]: #usage-of-keyword-only-arguments-...
1 min read

Craftopia

Steam achievements and progress for Craftopia - 0.0% complete with 0/50 achievements unlocked.

5 min
global Field
global BaseModel
from pydantic import BaseModel
from pydantic import Field

Pydantic is a Python library for serializing data into models that can be validated with a deep set of built in valitators or your own custom validators, and deserialize back to JSON or dictionary.

Installation #

To install pydantic you will first need python and pip. Once you have pip installed you can install pydantic with pip.

pip install pydantic

Always install in a virtual environment

Creating a Pydantic model #

To get started with pydantic you will first need to create a Pydantic model. This is a python class that inherits from pydantic.BaseModel.

from pydantic import BaseModel
from pydantic import Field
from typing import Optional

class Person(BaseModel):
    name: str = Field(...)
    age: int

parsing an object #

person = Person(name="John Doe", age=30)
print(person)
name='John Doe' age=30

data serialization #

Pydantic has some very robust serialization methods that will automatically coherse your data into the type specified by the type-hint in the model if it can.

person = Person(name=12, age="30")
print(f'name: {person.name}, type: {type(person.name)}')
print(f'age: {person.age}, type: {type(person.age)}')
1 validation error for Person
name
  Input should be a valid string [type=string_type, input_value=12, input_type=int]
    For further information visit https://errors.pydantic.dev/2.3/v/string_type
person = Person(name="John Doe", age='thirty')
print(f'name: {person.name}, type: {type(person.name)}')
print(f'age: {person.age}, type: {type(person.age)}')
1 validation error for Person
age
  Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='thirty', input_type=str]
    For further information visit https://errors.pydantic.dev/2.3/v/int_parsing

loading from json #

serializing to json #

validation #

Knockout City™

Steam achievements and progress for Knockout City™ - 2.0% complete with 1/50 achievements unlocked.

5 min

Badger

Steam achievements and progress for Badger - 12.5% complete with 5/40 achievements unlocked.

6 min

Frozen Flame

Steam achievements and progress for Frozen Flame - 6.25% complete with 2/32 achievements unlocked.

4 min

MultiVersus

Steam achievements and progress for MultiVersus - 53.57% complete with 15/28 achievements unlocked.

5 min

useful btrfs tools

disk usage # [1] Looking at disk usage on any of these must be done using a tool built for it if you want an accurate measurement. General purpose tools like du will be inaccurate as they do not count things like duplicate copies in snapshots. ❯ sudo btrfs fi usage -T / [sudo] password for waylon: Overall: Device size: 465.26GiB Device allocated: 251.06GiB Device unallocated: 214.20GiB Device missing: 0.00B Device slack: 0.00B Used: 234.44GiB Free (estimated): 227.37GiB (min: 120.27GiB) Free (statfs, df): 227.37GiB Data ratio: 1.00 Metadata ratio: 2.00 Global reserve: 478.88MiB (used: 0.00B) Multiple profiles: no Data Metadata System Id Path single DUP DUP Unallocated Total Slack -- -------------- --------- -------- -------- ----------- --------- ----- 1 /dev/nvme1n1p2 239.00GiB 12.00GiB 64.00MiB 214.20GiB 465.26GiB - -- -------------- --------- -------- -------- ----------- --------- ----- Total 239.00GiB 6.00GiB 32.00MiB 214.20GiB 465.26GiB 0.00B Used 225.82GiB ...
1 min read

Subnautica

Steam achievements and progress for Subnautica - 5.88% complete with 1/17 achievements unlocked.

4 min

Poly Bridge

Steam achievements and progress for Poly Bridge - 9.09% complete with 2/22 achievements unlocked.

4 min

devops philosophy

How to keep a secret - https://changelog.com/shipit/58 Kelsey Heightower Fundamentals - https://changelog.com/shipit/44 What does good devops look like - https://changelog.com/shipit/28 Docs are not optional - https://changelog.com/shipit/17 Dave Farley the foundations of Continuous Delivery - https://changelog.com/shipit/5

Steep

Steam achievements and progress for Steep - 0.0% complete with 0/41 achievements unlocked.

5 min

extending vim with shell commands

Vimconf 2022 The pitch # [1] Extending vim does not need to be complicated and can be done using cli tools that you might already be comfortable with. Examples, setting up codeformatters with autocmds, using lf/ranger as a tui file manager, generating new files using a template framework like cookiecutter/copier/yeoman, using ag to populate your quickfix. run a command # [2] vimconf!!<esc>!!figlet formatters # [3] local settings = require'waylonwalker.settings' M.waylonwalker_augroup = augroup('waylonwalker', { clear = true }) M.format_python = function() if settings.auto_format.python then vim.cmd('silent execute "%!tidy-imports --black --quiet --replace-star-imports --replace --add-missing --remove-unused " . bufname("%")') vim.cmd('silent execute "%!isort " . bufname("%")') vim.cmd('silent execute "%!black " . bufname("%")') end end autocmd({ "BufWritePost" }, { group=M.waylonwalker_augroup, pattern = { "*.py" }, callback = M.format_python, }) File Navigation # [4...
1 min read
from kedro.pipeline import node

node(
    input="raw",
    output="int",
    func=my_func,
    tags=["one"],
)

Upon first running an aws cli command using localstack you might end up with the following error.

Unable to locate credentials. You can configure credentials by running "aws configure".

Easy way #

The easy easiest way is to leverage a package called awscli-local.

pipx install awscli-local

Leveraging the awscli #

If you want to use the cli pro

pipx install awscli

aws config --profile localstack
# put what you want for the keys, but enter a valid region like us-east-1

alias aws='aws --endpoint-url http://localhost:4566 --profile localstack'
npx create-react-app todoreact
import React,{useState,useEffect} from 'react';
import './App.css';

function App() {
  const [data,setData]=useState([]);
  const [newName,setNewName]=useState([]);
  const getData=()=>{
    fetch('/api'
    ,{
      headers : {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
       }
    }
    )
      .then(function(response){
        return response.json();
      })
      .then(function(myJson) {
        setData(myJson)
      });
  }
  useEffect(()=>{
    getData()
  },[])

  const addItem= async () => {
    const rawResponse = await fetch('/api/add/', {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },

    body: JSON.stringify({"name": newName})
    });
    const content = await rawResponse;

    console.log(content);
    getData()
  }




  return (
    <div className="App">
     {
       data && data.length>0 && data.map((item)=><p>{item.id}{item.priority}{item.name}<button>raise priority</button></p>)
     }
    <input type='text' value={newName} onChange={(e) => (setNewName(e.target.value))} />
    <button onClick={addItem} >add item</button>
    </div>
  );
}

export default App;

Hatch allows you to specify direct references for dependencies in your pyproject.toml file. This is useful when you want to depend on a package that is not available on PyPI or when you want to use a specific version from a Git repository. Often used for unreleased packages, or unreleased versions of packages.

docs

[project]
dependencies = ['markata', 'markata-todoui@git+https://github.com/waylonwalker/markata-todoui']

[tool.hatch.metadata]
allow-direct-references=true