Category: Linux

GoSnmp – SNMP for GoLang

Today I released soniah/gosnmp – an update of alouca/gosnmp.

Many, many thanks to Andreas Louca for writing alouca/gosnmp. The major difference between his version and soniah/gosnmp is that the latter has tests written. (However the code could do with refactoring). The tests were used to find and correct errors in the following SNMP BER Types:

  • Counter32
  • Gauge32
  • Counter64
  • OctetString
  • ObjectIdentifier
  • IpAddress

Also, this version contains functions for treating the returned snmp values as *big.Int (convenient, as SNMP can return int32, uint32, and uint64 values)

 

git – delete local tracking branches

(Just a summary of Stack Overflow “How do you Remove an Invalid Remote Branch Reference from Git?”).

To delete a local tracking branch (without deleting the remote branch), do:

git branch -rd remote/branch

And of course to delete the remote branch:

git push remote :branch

Occasionally a gc will help, but usually shouldn’t be used:

git gc --prune=now

So, when would you want to use this? Let’s say the repository you’re tracking has a lot of branches (eg the Linux Kernel). You start tracking branch “foo”, do some work with it, merge some of it in to your branch “bar”, then push “bar” up to the remote repository. Or, you’ve got a whole lot of dev branches you’ve merged pushed to your backup repository and also merged into your master branch.

In either case you’ve got a collection of tracking branches you don’t want to see anymore, so clean them up:

% git branch -r
  soniah/dev.a
  soniah/dev.b
  soniah/dev.c
  soniah/dev.d
  soniah/master

% git branch -rd soniah/dev.a
Deleted remote branch soniah/dev.a (was deadbeef).

% git branch -rd soniah/dev.b
Deleted remote branch soniah/dev.b (was deadbeef).

# now remote branches is cleaner:
% git branch -r
  soniah/dev.c
  soniah/dev.d
  soniah/master

git pull -f (git force pull)

Git has a “force push” option (git push -f remote branch), but it doesn’t have a “force pull” option (like git pull -f remote branch).

This works:

% git fetch remote branch
% git reset --hard FETCH_HEAD
% git clean -df

Or, as a function for your bash/zsh config file:

gpuf () {
   # git pull -f $1
   remote=${1:?"need remote to force pull from"}

   current_branch=$(git symbolic-ref -q HEAD)
   current_branch=${current_branch##refs/heads/}
   current_branch=${current_branch:-HEAD}
   if [ $current_branch = 'HEAD' ] ; then
       echo
       echo "On a detached head. Exiting..."
       exit 1
   fi  

   git fetch $remote $current_branch
   git reset --hard FETCH_HEAD
   git clean -df 
}

Linux filename suffixes

When creating files in Linux (and other OS’s) there’s the usual convention of .txt for text files, .c for C files, etc – you just pick them up as you go along.

But there’s actually a manpage that lists the common conventions – “who knew”?

% man suffixes
SUFFIXES(7)                           Linux Programmer's Manual                           SUFFIXES(7)

NAME
       suffixes - list of file suffixes

DESCRIPTION
       It  is  customary to indicate the contents of a file with the file suffix, which consists of a
       period, followed by one or more letters.  Many standard utilities, such as compilers, use this
...
        .asm         │ (GNU) assembler source file
        .au          │ Audio sound file
        .aux         │ LaTeX auxiliary file
...

Network access with Exetel HSPA and Antenna

Update November 2012

On Ubuntu Precise (12.04.1) mobile broadband now “just works”. Plug in the device, right click on Network Manager, follow the configuration wizard for “New Mobile Connection”, choose your provider (eg Exetel) and the correct APN will be filled in (exetel1).

Original Article 2009

I got a Huawei HSPA E1762 USB stick a few months ago for 3G network access, together with Exetel’s $5/month Zero Gig plan (uses the Optus network). Great for when I’m out and about and can’t find a wireless signal to jump onto, or I’m at some client who doesn’t allow laptops onto their network. I’ve been using it regularly and still haven’t gone over about 100M usage, so it’s worked out to be very cheap.

Using Network Manager on Ubuntu Jaunty it mostly “just works” – all I needed to do was set the APN to ‘exetel1′. I’ve also bought an antenna for it from The Antenna Shop – gives me better coverage in shadows in the CBD and out in the country. There’s also other bigger antennas available, as well as car antennas.

antenna

antenna

All-in-all a good buy – thanks Dean for the tip.

Addendum

As per Matt’s comment below, Huawei modems currently have problems on Ubuntu Karmic – Problem with Huawei E1762 Mobile Broadband in Karmic, Bug #413989, Bug # 446146.

Also, if you’re ever prompted to enter an “SP CODE” (ie Mac & Windows), enter “BROADBAND”

Next Page »