Skip to content

3rd March 2021

Coding

Python

Code Styling

  • Improvement: Don't use try-except to initialize dictionaries.

    Instead of:

    try:
        dictionary['key']
    except KeyError:
        dictionary['key'] = {}
    

    Use:

    dictionary.setdefault('key', {})
    

Python Snippets

  • New: Add date management snippets.

    import datetime
    d = "2013-W26"
    r = datetime.datetime.strptime(d + '-1', "%Y-W%W-%w")
    

    import calendar
    
    >> calendar.month_name[3]
    'March'
    
    * Get ordinal from number

    def int_to_ordinal(number: int) -> str:
        '''Convert an integer into its ordinal representation.
    
        make_ordinal(0)   => '0th'
        make_ordinal(3)   => '3rd'
        make_ordinal(122) => '122nd'
        make_ordinal(213) => '213th'
    
        Args:
            number: Number to convert
    
        Returns:
            ordinal representation of the number
        '''
        suffix = ['th', 'st', 'nd', 'rd', 'th'][min(number % 10, 4)]
        if 11 <= (number % 100) <= 13:
            suffix = 'th'
        return f"{number}{suffix}"
    

Operative Systems

Linux

Vim Plugins

mkdocs

  • New: Document the Navigation object and the on_nav event.

    Useful if you develop MkDocs plugins, it holds the information to build the navigation of the site.

Arts

Writing

Grammar and Orthography

Writing Style

  • New: Analyze interesting books on writing style.

    • The elements of style by William Strunk Jr and E.B White
    • On writing well by William Zinsser
    • Bird by bird by Anne Lamott
    • On writing by Stephen King
  • New: Explain how to end a letter.

    Use Sincerely in doubt and Best if you have more confidence. Add a comma after the sign-off and never use Cheers (it's what I've been doing all my life (◞‸◟;) ).