Random ramblings about Mac, Python, TeX, programming, and more  |     |          |     |  


Emacs on macOS

December 29, 2023  |  tools, programming, macos

I do almost all my programming and scientific writing in Emacs, and I am a Mac user running a recent version of macOS (usually the latest release available). I try to install most of the third-party software I use with Homebrew. It makes it much easier to install the software I need (including Emacs, BSD make, OpenSSL, Python, and Qt) and keep the software updated (regularly running the command «b …

Last updated: December 29, 2023

Qt for Python (on Mac)

December 13, 2021  |  programming, python

In November 2019, I wrote about this:

Qt for Python (and plotting with Matplotlib)

Since then, Qt 6 and PySide6 has been released (see Qt for Python 6 released). Currently, I install both Python and Qt on my Mac with Homebrew, making the steps much easier than described in the post from 2019:

brew install qt
brew install python

At the moment, Homebrew does not install Python 3.10, the latest a …

Last updated: January 3, 2022

Server side IMAP rules

June 3, 2021  |  tools, python

I'm using several email services, but most of my private email is on an IMAP based service. A lot of the received emails should be automatically moved to a sub-folder on the server without my involvement. In most email clients you can easily create rules to do this. However, I would like to do this even when I have no email clients up and running. For my work email service (Outlook) this can be d …

Last updated: June 8, 2021

Get the notes out of Apple Notes into OneNote (via Evernote) with AppleScript

April 9, 2021  |  tools, programming, macos

I have been using Apple Notes for all my note taking since 2016. For not so interesting reasons, I recently had to change to Microsoft OneNote. But I did not want to leave all my meeting notes behind. I had to find a solution to get all my notes out for Apple Notes. And as many times before, AppleScript (and Python) was part of the solution.

My first attempt was to search for possible tools or rec …

Last updated: April 14, 2021

Differential Privacy (and Python)

March 1, 2021  |  security, programming, python

Differential privacy is an interesting tool when doing privacy aware analytics. This is a topic I have been working on for a while, and one of the great challenges is to implement generic tools for this. However, developers at Google are using this a lot internally, and they have also made their libraries available at GitHub. Since I often prefer Python, I am happy to find a Python wrapper for the …

Last updated: March 5, 2021

MacOS automation with Python and AppleScript

February 21, 2020  |  programming, macos

I prefer to program in Python, but for automation on the Mac, AppleScript is still a great tool. Especially paired with a good AppleScript editor/debugger like Script Debugger. For many projects it would be nice to do most of the scripting in Python, and only do the interaction with the different programs (GUI) in AppleScript. The obvious solution is PyObjC and its ScriptingBridge framework (wrapp …

Last updated: January 27, 2021

Including source code in this blog

January 31, 2020  |  publ, programming, macos, web

I write these blog posts with MarsEdit. And, while I am writing, I preview the blog post with Marked 2 (start Marked 2 and choose Preview → MarsEdit Preview from the menu). And since my writing usually is about programming, the blog posts might contain source code. My approach is similar to how I include source code in papers, and I was writing about it back in 2015. So this is an update on how I …

Last updated: January 31, 2020

Including source code in papers (and exams)

November 17, 2019  |  publ, programming, python

In march 2015, I wrote about using Pygments when including source code in papers (and on the web). I still use Pygments, but I have never updated the description on how I do it now. In most cases, I use Pygments implicit without interacting with the program myself. I leave it to the LaTeX package minted. You still need to install Pygments, but you do not need to interact with it. The minted packag …

Last updated: November 17, 2019

Qt for Python (and plotting with Matplotlib)

November 11, 2019  |  programming, python

To able to develop GUI-based Python programs using Qt you need to install Qt and PySide2 (Python mapping for Qt 5, see Qt for Python). A good place to start is the Qt for Python getting started document.

Install the software

I have Python 3.8 on my Mac. I have also installed numpy and matplotlib with pip (since I have many different Python installations on my Mac, including 2.7, 3.7 and 3.8, I wil …

Last updated: December 13, 2021

Open Emacs from a link in an HTML file on Mac OS X

December 14, 2015  |  os-x, web, programming

Since I do most of my writing in LaTeX, I have all my references (publications I cite when I write papers) in a series of bib-files (for BibTeX). To easier browse and search these references I have created a small Python script that generates a HTML document with all these references. Each reference also includes a link to the bib-file this reference was found in. In the link I include the key of …

Last updated: December 14, 2015

Cryptography with Python 3

May 15, 2015  |  tools, os-x, programming, python, crypto

In 2012 I posted a post on using PyCrypto with Python 3 and some AES and RSA examples. Now, I usually use the cryptography Python library (implemented for both Python 2 and 3). I have ported all my PyCrypto examples from 2012 (see the README file) to the cryptography library.

pycryptex.py / pycryptex-cbc.py

pycryptex.py [src] is a small example using AES to encrypt and decrypt a text:

> python3 pycry …
Last updated: May 15, 2015

Including source code in papers and on the web

March 20, 2015  |  tools, programming, python, publ, web

I've written many papers and a lot of web pages that includes source code. Since Python code was an important part of my Dr. thesis, I even wrote a tool to generate a pretty-printed Python code for LaTeX (this was written in 1997, but since I've been using it ever since it has had a few minor bug fixes since then; however, it needs Python 1.6 and it was the first Python program I ever wrote!). Jus …

Last updated: March 20, 2015

The Swift (short) history

June 3, 2014  |  os-x, programming

The language announced at WWDC yesterday came as a big surprise to almost everyone. At Chris Lattner's Homepage you can find a short summary on the history of the Swift programming language. He started work on the language in July 2010, and it became a major focus for the Apple Developer Tools group 3 years later. Other people started to contribute to the project in late 2011. He mentions Objectiv …

Last updated: June 3, 2014

A new language: Swift from Apple

June 3, 2014  |  os-x, programming, python

I've just developed my first application in Swift, the new language announced by Apple yesterday. I downloaded the Swift book on my iPad during the Keynote, and started programming immediately. When I got hold of Xcode beta 6 I got it running in seconds.

My first impression: Swift is a modern language. It is closely related to popular scripting languages, like Python and Ruby, but is is a compiled …

Last updated: June 3, 2014

How to use Interface Builder to create OS X Cocoa applications with Python

April 20, 2014  |  os-x, programming, python

When programming Python I prefer to use native GUI on OS X. Very Simple OS X Cocoa Application using Python and Interface Builder is a good place to start. The example works with Python 3 on OS X 10.9.2 when PyObjC is installed following the instructions in one of my earlier posts: Python 3 and PyObjC.

Last updated: April 20, 2014

PyGame for Python 3 on OS X Mountain Lion

May 8, 2013  |  os-x, programming, python

These are my steps to install PyGame for Python 3 on OS X Mountain lion:

  1. Download (and unpack) the following:
  • Install the png and jpeg libraries:
  • Last updated: May 8, 2013

    Python 3 and PyObjC

    November 27, 2012  |  os-x, programming, python

    My main programming platform is OS X 10.8 and Python 3 (currently Python 3.3). In earlier blog posts I have discussed installing and using PyCrypto in this environment. My next attempt was to find a GUI solutions for this platform. I usually prefer native approaches when programming, and for OS X the Cocoa framework is the native approach. To get access to this from Python we need a bridge, and th …

    Last updated: November 27, 2012

    AES and RSA PyCrypto examples with Python 3

    November 14, 2012  |  os-x, crypto, programming, python

    Earlier today I wrote about installing PyCrypto for Python 3 on OS X 10.8. I will use the opportunity to provide a few examples using PyCrypto to do AES and RSA encryption and decryption. I have created 3 programs. The first one, pycrypto-mkkey.py [src], generates an RSA key and saves it in two different files. One including the private key and one with only the public key (using the .pub extensio …

    Last updated: November 14, 2012

    PyCrypto with Python 3 on OS X 10.8

    November 14, 2012  |  os-x, crypto, programming, python

    On an updated Mac (in my case 10.8.2) with an updated version of Xcode  (in my case 4.5.2) compiling and installing PyCrypto for Python 3 (in my case 3.3) is not just simply running the setup.py script. The latest release of PyCrypto is 2.6 and it supports Python 3 (it has supported Python 3 since version 2.4). But my earlier attempts using Python 3.2 on OS X 10.8 failed since it couldn't locate t …

    Last updated: November 14, 2012

    Coding fonts

    October 11, 2012  |  tools, fonts, programming

    I consider myself a programmer, and to perform this task I rely on a set of tools. I need a text editor, compilers and/or run-times, build-systems, code repositories, documentation, and sometimes even an IDE. Since the late 80s my text editor of choice has been Emacs (and Aquamacs on OS X), but I am also comfortable with vi (including Vim) and ed. Currently, I am investigating time in newer text e …

    Last updated: January 3, 2022

    Fetch and process information from Cristin

    October 6, 2012  |  publ, web, python

    Yesterday I wrote a small Python script to fetch and generate a publication list for web-pages. I use a web-services (ws) provided by Cristin (Current research information system in Norway). Cristin is a research information system for hospitals, research institutes, and universities and university colleges. From the provided ws I use the method hentVarbeiderPerson (see Brukerdokumentasjon Cristin …

    Last updated: October 6, 2012