Using uv to run Python scripts
I’ve been playing around with different Python versions and packages lately and uv provides amazing tooling for running Python code in an isolated virtual environment, but I always have to google the syntax.
https://docs.astral.sh/uv/guides/scripts/
Some common examples:
Start a Python REPL with packages installed:
uv run python –with replicate
Create and run a script:
uv init –script main.py uv add –script main.py replicate uv run main.py
Create an executable:
touch cats chmod +x cats
#!/usr/bin/env -S uv run –script –with replicate import replicate print(replicate.run(“black-forest-labs/flux-schnell”, input={“prompt”: “a cat”})[0].url)
mitmproxy
A “man in the middle” proxy server for debugging http requests. I’ve found this incredibly useful when working with mobile devices. The project even has precompiled binaries for OSX or can be installed with homebrew.
Getting a server running is as simple as:
$ brew install mitmproxy
$ mitmdump -p 8080
Set up the mobile device to use the proxy and visit some webpages you should start seeing requests being logged to the terminal.
Clean up merged branches in git
This will remove all local branches that have been merged into master.
$ git checkout master && git branch --merged | grep -v master | xargs git branch -d
and broken down:
git co master && # Checkout the master branch.
git branch --merged | # List all merged branches one on each line.
grep -v master | # Exclude the master branch.
xargs git branch -d # Each newline from the previous command will be passed as an argument to git branch -d. Which will remove the branch.
Tap vs. Click
I spent a good deal of time recently researching libraries that abstract some of the duplication for handling events on mouse and touch devices. An implementation should ideally allow you to bind listeners to just one event and crucially avoid the 300ms click delay in certain browsers. Also it should trigger the event on touchend and only if the user has not moved from the original element.
During this research I came across a great article and solution (an experimental module in jQuery mobile) to abstracting away the differences between click and touch events and as a bonus this was hands down the best implementation.
It is also available as a standalone file so you don’t have to worry about including the rest of jQuery mobile. Just go to the builder and select only the vmouse checkbox.
There is also an excellent article from Google on creating fast buttons and finally a list of the other libraries I looked into in no particular order (they vary greatly in size and quality):
Reactor.js
An alternative approach to the now popular pub/sub and promise patterns that are common in JavaScript applications. Reactor offers a solution for keeping application state current through the composition of signals and observers.
Reactor is a lightweight library for reactive programming. It provides reactive variables which automatically update themselves when the things they depend on change.
Signals trigger changes in application state and Observers react to these changes. These simple building blocks are then combined to build elegant solutions for common problems such as keeping interface elements up to date.
This pattern has become popular of late in other languages such as Objective-C and .Net.
Lazy.js
Interesting new utility library that builds apon the iterators standardised by underscore.js and applies lazy evaluation so the iterators only do as much or as little as required.
[L]azy evaluation (also known as deferred execution). This can translate to superior performance in many cases, especially when dealing with large arrays and/or “chaining” together multiple methods.
This could be extremely useful under certain circumstances. The event and string examples are particularly interesting.
Modern IE Virtual Machines
Free VM’s for Virtualbox, VMWare etc available from Microsoft.
For anyone stuck trying to open the .sfx files I found the documentation here.
- Locate and verify that you have all the needed files for your chosen VM. You should have at least one .SFX and possible a number of additional .RAR files. The .SFX file contains both the self- extraction code plus the first part of the RAR archive itself.
- Give the SFX file execute permission by typing “chmod +x filename.sfx” at the terminal.
- Execute the SFX executable from the terminal with “./filename.sfx” to expand the virtual machine to the current directory.
History Stuffing
It never fails to amaze me how much impact adding new features can have on browser security.
History Stuffing is a technique used to fill the browsers history. With pushState, you can stuff specific keywords into history, which later the browser will suggest when the user is typing in their location bar.
Hoodie
An interesting new app framework designed to make it very easy to build web applications that work offline by default. Server synchronisation happens transparently in the background (but can be accessed via events) and uses Node and Couchdb.
The project provides authentication, email, admin and other useful modules making it very quick to get a project up and running.
Anima
Nice looking library for building complex animations with support for JavaScript and CSS animations. It also lets you have a fine grained control over the transitions above and beyond CSS’s declarative style.
Anima gives you the ability to use delays and durations normally, even for pure CSS animations. It has two modes: JS and CSS. The first one doesn’t really use CSS transitions or @keyframes. On the contrary, it uses CSS transforms and 3d-transforms together with Javascript to create animation. You have full control over the flow, so you can start, stop, cancel animations and even create event-based stuff. CSS mode allows you to generate pure CSS animations, but it has less control features for now.