HomeHome ArchiveArchive

A RingBuffer in Ruby

I needed a ring buffer in Ruby, and since a web search didn’t yield anything I did it myself. Here you go, use as you wish:


Simple RingBuffer implementation
================================

see class RingBufferTest below for usage examples
=================================================

class RingBuffer \< Array

alias\_method :array\_push, :push
 alias\_method :array\_element, :[]

def initialize( size )
 @ring\_size = size
 super( size )
 end

def push( element )
 if length == @ring\_size
 shift \# loose element
 end
 array\_push element
 end

\# Access elements in the RingBuffer
 \#
 \# offset will be typically negative!
 \#
 def [](offset%20=%200)
 return self.array\_element( - 1 + offset )
 end
end

Usage example and unit test for the Ring Buffer
===============================================

require 'test/unit'
class RingBufferTest \< Test::Unit::TestCase

\# Usage example (and test)
 def test\_ring\_buffer

    rb = RingBuffer.new 2               # create RingBuffer with 2 elements

    rb.push 'Apple'                     # put 'Apple' into RingBuffer
    rb.push 'Pear'
    assert( rb[] == 'Pear' )            # the most recent element in the RingBuffer
                                        # is the 'Pear'

    assert( rb[0] == 'Pear' )           # same as before

    assert( rb[-1] == 'Apple' )         # get the second most recent element - it
                                        # shold be 'Apple'

    rb.push 'Mango'
    assert( rb == ['Pear', 'Mango'] )   # the 'Mango' has pushed the 'Apple' out of
                                        # the RingBuffer

end
end

update failed: dynamic update temporarily disabled (REFUSED)

The bind DNS server’s error messages I encounter are usually not very helpful. This is one of them. It means that the zone you (or some nsupdate client) is trying to update is currently frozen. What you need to do is thus to unfreeze it by issuing a:

rndc unfreeze your.dynamically.updatable.zone

Changing photo orientation in gqview

It’s taken a long time but slowly gqview is being recognized as one of the best open source image displaying programs. It’s fast, it’s easy to use, it’s been steadily evolving over the years, it can do a lot but it gets out of your way.

One thing that can not yet be done directly in gqview is rotating images (especially photos) by setting the relevant EXIF flag. However there’s a way to do it by using an underestimated feature of gqview: its configurable editors.

So how can you rotate photos in gqview without needing to rewrite them by ‘physically’ rotating them? You modify its ‘Orientation’ EXIF flag. Here’s how:

  • install renrot (in Debian-like systems: ‘apt-get install renrot’)
  • in gqview go to Edit->Preferences->Editors, choose a “Menu Entry”, set “Menu Name” to “Rotate 90C” and “Command Line” to “%Vchmod +w %p; renrot –no-rename –tag Orientation: 1 -r 90 –only-orientation %p”
  • and you’re done

Now you can select a photo and then Edit->Rotate 90C. Voilà, the ‘Orientation’ EXIF flag is modified by “applying” a 90C rotation, and since gqview understands that flag you’ll see your photo displayed as you want it.

GIS Knoppix

Introduction

GIS-Knoppix is a bootable Linux CD with pre-installed GIS software. It is based on Knoppix.

Software

  • Linux with KDE and many applications
  • GRASS 6.2 Raster/vector GIS, image processing system, and graphics production system
  • PostgreSQL 8.1.4.2 Postgres database with PostGIS extension
  • MySQL 5.0.21 MySQL database with spatial extensions
  • QGis 0.8 Viewer and data analysis for vector and raster data with PostGIS support

Versions

Version: FOSS4G2006

  • GRASS 6.2 Raster/vector GIS, image processing system, and graphics production system
  • PostgreSQL 8.1.4.2 Postgres database with PostGIS extension
  • MySQL 5.0.21 MySQL database with spatial extensions
  • QGis 0.8 Viewer and data analysis for vector and raster data with PostGIS support

Version: 1.2

  • Linux with KDE and many applications
  • GRASS 6.0.0beta with Spearfish dataset Raster/vector GIS, image processing system, and graphics production system
  • UMN MapServer 4.4.1 Environment for building spatially enabled Internet applications
  • PostgreSQL 7.4.6 / PostGIS Postgres database with PostGIS extension
  • MySQL 4.1.9 MySQL database with spatial extensions
  • QGis 0.6 Viewer and data analysis for vector and raster data with PostGIS support
  • TerraView 2.0 Viewer and data analysis for vector with DB support
  • Jump 1.1.2 Workbench for viewing, editing, and processing spatial datasets
  • Thuban 1.0.0 Interactive geographic data viewer
  • MapLab 2.0.1 Suite of web-based tools to create and manage MapServer applications and map files
  • MapDesk 0.7 Viewer/editor for UMN Mapserver
  • Interlis Compiler and UML editor for Interlis formats
  • and other software GPSdrive, GPSMan, …

Changes from version 1.1 to 1.2:

  • Various updates including GRASS 6, Mapserver 4.4.1
  • New packages: QGis, drawmap, dgpsip
  • Update to Knoppix 3.4

Changes from version 1.0 to 1.1:

  • Added PostGIS, MySQL 4.1, TerraView, Jump, Thuban, Interlis, MapDesk
  • Spearfish data set for GRASS
  • Based on Knoppix 3.3
  • Many updates: Mapserver 4.0.1, OpenOffice 1.1, etc.

Download

The ISO images of version 1.2 are available for downloading (700MB):

Other GIS Live CD’s