Enabling Quectel EM05-G Modem on Linux

5.00 avg. rating (94% score) - 2 votes

My new Thinkpad has a Quectel EM05-G modem. For some reason it refused connect, even though it showed up in Gnome settings on Ubuntu 22.10. I checked with “mmcli -m 0 and it said “sim missing” as its state.

After some Googling it appeared the modem ships in some kind of a locked state, so it only works in Windows. I checked with “mbimcli”:

It was easy to unlock:

After this, Gnome was able to enable the mobile broadband connection without problem.

 

Tunneling SSH over HTTPS with stunnel

0.00 avg. rating (0% score) - 0 votes

I was faced with a firewall denying access to the outside world using ssh. All I had was http/https access via a proxy server which required authentication. I had an Ubuntu jump host outside the network connected to the internet with a free 443 port. I tried accessing that with httptunnel and proxytunnel, but could get neither to work with this proxy server.

The solution that worked in this particular case was stunnel. It can wrap any TCP connection into an https session which was not rejected by the proxy server I was facing.

Continue reading Tunneling SSH over HTTPS with stunnel

Methods for Both Classes and Instances in Python

0.00 avg. rating (0% score) - 0 votes

I came across a situation where it would be nice for a Python class to have a method which works for both the class and its instances, and when called in an instance context, to know on which instance it was invoked. Python does not support this directly, but as it is a very flexible language, it can be done. To make it work somewhat nicely requires just a few lines of not so obvious code.

Continue reading Methods for Both Classes and Instances in Python

Enable vi editing mode in IPython 5

0.00 avg. rating (0% score) - 0 votes

Create default profile and set editing mode to ‘vi’:

 

Flask-SQLAlchemy and PostgreSQL Unit Testing with Transaction Savepoints

5.00 avg. rating (91% score) - 1 vote

PostgreSQL provides us two very powerful features which are helpful with unit testing: transactional DDL and transaction savepoints. In this article I will show you how to use those with Flask-SQLAlchemy unit tests.

Transactional DDL means you can create tables inside a transaction, run tests against them, and roll back your changes after you are done. The database will be left in the same state as it was when you started. If you started with an empty database, nothing will be left in the database afterwards.

Savepoints allow you to roll back a part of a transaction without affecting what has happened before that savepoint was created. You can run a single test inside a savepoint and roll back just the changes that single test made without affecting the changes your set-up code has done before the savepoint.

That means you can create a large number of tables and other database objects in the beginning of your test suite and then run individual tests inside nested transaction using savepoints. There is no need to drop and re-create the whole database schema for each test. Continue reading Flask-SQLAlchemy and PostgreSQL Unit Testing with Transaction Savepoints

Ubuntu 14.04 Active Directory Authentication

5.00 avg. rating (91% score) - 1 vote

In a post a couple of years ago I gave an example on how to configure an Ubuntu 12.04 server to authenticate to Active Directory. Things used to be hard back then. Now we have the realmd realm enrollment manager to do the hard work of joining the host to an Active Directory domain, and the System Security Services Daemon or SSSD to do the actual authentication and authorization work whenever it is needed. And things are much easier to configure and get running. Continue reading Ubuntu 14.04 Active Directory Authentication

OpenStreetMap Nominatim Server for Geocoding

5.00 avg. rating (98% score) - 9 votes

Here’s how to install the OpenStreetMap Nominatim service on your own server. It can be used to geocode and reverse geocode addresses and map coordinates. You will also get a web interface which loads map tiles from openstreetmap.org while doing geocoding requests using your own server. Continue reading OpenStreetMap Nominatim Server for Geocoding

Remove Unwanted Files From Git History

4.50 avg. rating (87% score) - 2 votes

Here’s an example of how to remove every *.pyc file from every commit in Git history. It is adapted from this Git help page.

Rewrite history

Run git filter-branch, forcing (--force) Git to process—but not check out (--index-filter)—the entire history of every branch and tag (--tag-name-filter cat -- --all), removing the specified files ('git rm --cached --ignore-unmatch *.pyc') and any empty commits generated as a result (--prune-empty). Continue reading Remove Unwanted Files From Git History

Adding Git version control to web sites

3.00 avg. rating (63% score) - 5 votes

Here’s a little script I made to make it easy to put a number of existing web sites residing under /var/www under version control by Git. Regarding security, it is obviously not a good idea to initialize the Git repository directly under the site directory, since from there it might be served by the web server to the outside world. And that is not what I want. Instead what I want is to have the Git working directory directly in the site directory that is served, and the repository somewhere else. That is perfectly possible with Git, just by setting one or two environment variables. Continue reading Adding Git version control to web sites

Upsert Methods for PostgreSQL

3.62 avg. rating (73% score) - 8 votes

Update: PostgreSQL 9.5 has been released with INSERT .. ON CONFLICT UPDATE support.


PostgreSQL has no “upsert” or “replace” or “insert .. on duplicate key update” or “merge into” construct to conditionally either insert a new row, or if a row with the key already exists, to either update the existing row with the new values, or first delete the old row and then insert a new one. This has been discussed many times in the posgresql developers mailing lists, and plans to implement the SQL standard MERGE operation have been devised. But there is still no such functionality in PostgreSQL as of version 9.3. Here are some examples on how to implement the functionality in different ways, using either a function, a trigger function or a rule. None of them are perfect. There are trade-offs to be made. Continue reading Upsert Methods for PostgreSQL

SQLAlchemy Declarative Class Reflector

3.00 avg. rating (63% score) - 5 votes

SQLAlchemy has a nice reflection facility which takes for example a database table name as argument and produces a Table object out of it for manipulation. However, those objects do not behave like the objects produced by declarative classes, which are easier to work with. Here’s a little class that helps to bridge that gap by reflecting proper declarative classes from database tables. It has only been tested with PostgreSQL, but it may work with other databases as well. Continue reading SQLAlchemy Declarative Class Reflector

Editing Tabular Data in Vim

3.33 avg. rating (68% score) - 6 votes

Helpful settings for editing tabular data:

Noexpandtab disables expanding of inputted tabs to spaces. Adjust the number of spaces to your liking. Tabstop sets the visual appearance of tab stops (here 16 spaces). Continue reading Editing Tabular Data in Vim

Developer Mode for the Samsung Galaxy S4

3.43 avg. rating (70% score) - 7 votes

From: Developer Mode for the Samsung Galaxy S4

Get to the phone’s settings by tapping ‘menu’ from the home screen and then tapping ‘settings’

  • tap on ‘more’
  • tap on ‘software information’
  • tap on ‘About Device’
  • find the build number, and tap it 7 times
  • on the 7th tap, a prompt should appear alerting you that Developer Options has been unlocked

You may also wish to:

And after that you must accept the USB connection by tapping OK in the prompt on the device after you connect it.