atlas news
    
Peterbe : Python
17  mars     13h58
How do you thousands-comma AND whitespace format a f-string in Python
   Use my large integer:
14  mars     20h24
Leibniz formula for Ï in Python, JavaScript, and Ruby
   Different ways to calculate the value of Ï using the Leibniz formula
14  février     03h09
How to avoid a count query in Django if you can
   Suppose you have a complex Django QuerySet query that is somewhat costly in other words slow . And suppose you want to return: The first N results A count of the total possible results So your implementation might be something like this: def get results queryset, fields, size : count ...
21  septembre     16h11
Pip-Outdated.py with interactive upgrade
   Last year I wrote a nifty script called Pip Outdated.py Pip Outdated.py a script to compare requirements.in with the output of pip list outdated . It basically runs pip list outdated but filters based on the packages mentioned in your requirements.in. For people familiar with Node, it’s like...
22  décembre     13h14
Pip-Outdated.py - a script to compare requirements.in with the output of pip list --outdated
   Simply by posting this, there’s a big chance you’ll say Hey Didn’t you know there’s already a well known script that does this Better. Or you’ll say Hey That’ll save me hundreds of seconds per year The problem Suppose you have a requirements.in file that is used, by pip compile to generate...
22  août     22h47
Join a list with a bitwise or operator in Python
   Use functools.reduce operators.or , my list to join my list with a bitwise OR.
03  avril     19h34
How to sort case insensitively with empty strings last in Django
   Imagine you have something like this in Django: class MyModel models.Models : last name models.CharField max length , blank True ... The most basic sorting is either: queryset.order by ’last name’ or queryset.order by ’ last name’ . But what if you want entries with a blank string...
30  mars     12h33
How to close a HTTP GET request in Python before the end
   Does you server barf if your clients close the connection before it’s fully downloaded Well, there’s an easy way to find out. You can use this Python script: import sys import requests url sys.argv assert x ;: x ; in url, url r requests.get url, stream True if r.encoding is None...
19  octobre     16h44
How to string pad a string in Python with a variable
   I just have to write this down because that’s the rule; if I find myself googling something basic like this more than once, it’s worth blogging about. Suppose you have a string and you want to pad with empty spaces. You have options: gt; gt; gt; s quot;peter quot; gt; gt; gt; s.ljust ...
08  septembre     23h38
TypeScript function keyword arguments like Python
   To do this in Python: def print person name quot;peter quot;, dob : print f quot;name name tdob dob quot; print person prints: name peter dob print person name quot;Tucker quot; prints: name Tucker dob print person dob prints: name peter dob ...