I am using the built in GSM (UMTS) modem of my Thinkpad X1 extensively because I am often in places with flaky internet connections. I connect through the standard Network Manager on Ubuntu and everything works fine. There was one major annoyance though. Every time I wanted to top up the SIM balance or book a new package, I needed a phone to send and receive USSD codes. So I took some time to figure out how to do it from the shell. I wrote this down as a help for others and a reminder for myself. Without further ado...
First intsall gammu and picocom.
➜ ~ sudo apt-get install -y gammu picocom| #!/usr/bin/env python | |
| from __future__ import print_function | |
| import base64 | |
| import hashlib | |
| import hmac | |
| import struct | |
| import sys | |
| import time |
$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769
Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:
$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
| // This is an example program that iterates over all | |
| // items in a mongodb collection in a memory safe way | |
| package main | |
| import ( | |
| "labix.org/v2/mgo" | |
| "labix.org/v2/mgo/bson" | |
| "fmt" | |
| ) |
| package test | |
| import ( | |
| "fmt" | |
| "labix.org/v2/mgo" | |
| "labix.org/v2/mgo/bson" | |
| "testing" | |
| ) | |
| const INSERT_COUNT int = 10000 |
In mongodb it's easy to make at upsert, meaning update-or-insert by calling
db.collection.update({criteria}, {updated fields}, true)
The third parameter means - insert a new document if the document doesn't exist yet. So, for example, the following will insert a new document for the user if there's no document for that user yet, and will update it if it already exists:
db.users.update({user_id: '1234'}, {user_id: '1234', name: 'Ran'}, true)
| # LICENSE: public domain | |
| def calculate_initial_compass_bearing(pointA, pointB): | |
| """ | |
| Calculates the bearing between two points. | |
| The formulae used is the following: | |
| θ = atan2(sin(Δlong).cos(lat2), | |
| cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong)) |