Archive for category Code

Freshmeat.net Finally Updates Site

Freshmeat 3.0 Screen Cap

Freshmeat 3.0 Screen Cap

Freshmeat.net has updated its site after many years of stagnation. It is such a shame because they were very well positioned to have really good marketshare any they mostly sat on their laurels. For example they should have been on top of the code search business. Maybe they will take over the extension/addon business from dysfunctional services like Addons Mozilla Org (AMO) [shakes fist]. AMO is a very well designed site/service with a crappy moderation process behind it (and I have personal experience).

The old design was an example of good design at the time with a not overcrowded feeling and convenient but mellow quick link icons. I In any case, my biggest dislike with the old site was the search. It may have been ok in a pre-Google world but if you cannot beat Googles search you need to embed it.

Freshmeat 3.0 Design Close-up

Freshmeat 3.0 Design Close-up

In this new design the listings are nice and compact. Textual buttons appear on mouse over to remove some clutter (I kind of liked the icons as opposed to text for repetition). Unfortunately they have removed a quick way to visit the homepage or full change log. They replaced some of the info effectively with a more modern tag construct but other info is missing. The search is much better but the language of a listing does not display in the results. The language was pretty important to me when browsing for a library. I have not seen if there is a good set of syntax for the search. Google codesearch like lang:c license:MIT syntax would be nice.

, , ,

No Comments

Gtk Pie Chart Widget

I needed a pie chart widget for a project so I made one. I used cairo for rendering of course. This API has add_segment and remove_segment functions but I will change that to take a tree model. There are almost no options or style at this point which would obviously be important but I have got the basic outline down I think. I am considering writing an entire charting widget set. There are several packages focused on plotting but they are not presentation oriented.

Code Follows:

Read the rest of this entry »

, , , , , ,

4 Comments

DMS to Decimal By Request

This is a function from my library that can be used to decode a degrees-minutes-seconds (DMS) string to a decimal degrees.
Enjoy.

/* ------------------------------
   Function: geo_dms_to_deg
     Parse a degrees-minutes-seconds (DMS) value string into a double floating
     point in degrees.
 
   Parameters:
     str     - [in]  string containing an angle in DMS
     end_ptr - [out] a pointer to the character following the last in the DMS
     packed  - [in]  boolean whether to expect the DMS to lack delimiters
     value   - [out] value in degrees
 
   Returns:
     true on success, false on failure
   ------------------------------ */
int geo_dms_to_deg( const char *str, const char **endptr, int packed, double *value ) {
  int d = -1, m = -1, s = -1, pos = 0;
  char ps[20] = "", *ps_ptr;
  float p = 0.0, fraction;
 
  if( packed ) {
    char format[64] = "";
 
    pos = strspn( str, "0123456789" );
    if( pos < 5 || pos > 7 )
      return( 0 );
 
    snprintf( format, 64, "%%%dd%%2d%%2d%%n", pos - 4 );
    if( sscanf( str, format, &d, &m, &s, &pos ) != 3 )
      return( 0 );
  } else if( sscanf( str, "%d:%d:%d.%[0123456789]%n", &d, &m, &s, ps, &pos ) == 4 ) {
    p = 0.0;
    fraction = 0.1;
    for( ps_ptr = ps; *ps_ptr != '\0'; ps_ptr++ ) {
      p += (*ps_ptr - '0')*fraction;
      fraction *= 0.1;
    }
  } else if( sscanf( str, "%d:%d:%d%n", &d, &m, &s, &pos ) == 3 ) {
    /* empty */
  } else if( sscanf( str, "%d:%d%n", &d, &m, &pos ) == 2 ) {
    s = 0;
  } else if( sscanf( str, "%d%n", &d, &pos ) == 1 ) {
    s = 0;
    m = 0;
  } else {
    return( 0 );
  }
  if (d < 0) return 0;
  if (m < 0 || m >= 60) return 0;
  if (s < 0 || s >= 60) return 0;
 
  *endptr = &str[pos];
 
  if( value )
    *value = d + m/60.0 + (p + (float)s)/3600.0;
 
  return( 1 );
}

, , , ,

No Comments

Dos2unix in Emacs, Sometimes Macros Are Nice

No CRLF
This is just a generic search and replace. Really you could make a macro for any search and replace you do on a regular basis.

;;; A interactive function for replacing all dos
;;; carriage returns (^M) with Unix 
;;; line feeds in a selected buffer. 
(defun dos2unix (buffer)
  "Automate M-% C-q C-m RET C-q C-j RET"
  (interactive "b buffer to convert" )
  (goto-char (point-min))
  (while (search-forward (string ?\C-m) nil t)
    (replace-match "" nil t)))

, , , , , ,

3 Comments

Bad Behavior has blocked 138 access attempts in the last 7 days.