Test-driving the new Mojo programming language. It’s a systems programming language with Python syntax, so we can now use our Python skills for systems programming with a minimal learning hill to climb.
Random Password Generator # Usage: $ mojo build -march native randpass.mojo # $ ./randpass from random import seed, random_ui64 fn generate_random_password() -> String: """Generate 21 character random password.""" let selection: String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#$%&@" var rand_pass: String = "" var password_length = 21 seed() while password_length > 0: rand_pass += selection[random_ui64(0, selection.
Tag: Python
Maybe you also prefer to just check if there’s new mail on the command line, before having to open yet another browser tab and downloading twelve kilograms of Javascript 🤷🏾♂️
#!/bin/env python """ Retrieve number and subjects of unread mail from Gmail. External dependencies: Set a GMAIL_LOGIN environment variable as a json string with Gmail access credentials. An example in Zsh: export GMAIL_LOGIN='{"username":"you@gmail.com", "password":"app_password"}' Usage example: In Zsh: $ chmod +x check_mail.
I have mained Python since 2006, and it has helped me hold down two jobs, and earn a Software Engineering MSc. But that training showed me I need to add another tool to my toolbox. A statically-typed compiled language with no garbage collection.
I chose Rust. In the summer of 2019 after finishing my first year, I skimmed the Rust Book. The Ownership concept was new to me, but overall I liked the feel of the language, Cargo, and that there seemed to be no gotchas.
After a bit of Googling, I found this post which details several methods of getting this done. I only needed an email sent to admins if any management command fails; below is the code I came up with.
Edit manage.py to look something like this (I’ve only included code needed for this functionality):
# ... import sys import traceback from django.core.mail import mail_admins def main(): # ... try: execute_from_command_line(sys.argv) except Exception: mail_admins( subject=f"Command <{' '.
A list of Python “batteries” whose core is written in a systems programming language for speed.
Package Short Description from the Author URL Numpy “The fundamental package for scientific computing with Python … NumPy offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transforms, and more.” https://numpy.org/ Scipy “Fundamental algorithms for scientific computing in Python” https://scipy.org/ ⭐ Pandas “Pandas is a fast, powerful, flexible and easy to use open source data analysis and manipulation tool, built on top of the Python programming language.
Problem You’ve tried to add an object into a set and a TypeError: unhashable type: exception was raised. You were probably using a set becase you needed a collection of objects without duplicates. If that was the case, two ways of solving this come to mind
Solution Implement the __hash__ method for the parent class of that object as per the guidelines in the Python documentation.
Extend the inbuilt data-type list and override it’s append() method: