Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Peter Cooperx http://www.petercooper.co.uk/

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

See your most used shell commands

Found here.

   1  
   2  history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr

Implementation of 'which' in pure Ruby

Written by someone called 'erikh' on #rubyonrails on irc.freenode.net.

   1  module Which
   2   
   3    #
   4    # Searches the path, or a provided path with given separators
   5    # (path_sep, commonly ":") and a separator for directories (dir_sep,
   6    # commonly "/" or "\\" on windows), will return all of the places
   7    # that filename occurs. `filename' is included as a part of the
   8    # output.
   9    #
  10    # Those familiar with the which(1) utility from UNIX will notice the
  11    # similarities.
  12    #
  13   
  14    def which(filename, path=ENV["PATH"], path_sep=File::PATH_SEPARATOR, dir_sep=File::SEPARATOR)
  15      dirs = path.split(/#{path_sep}/)
  16   
  17      locations = []
  18   
  19      dirs.each do |dir|
  20        newfile = "#{dir}#{dir_sep}#{filename}"
  21        # strip any extra dir separators
  22        newfile.gsub!(/#{dir_sep}{2,}/, "#{dir_sep}")
  23        p = Pathname.new(newfile)
  24        if p.exist? and p.executable?
  25          locations.push(newfile)
  26        end
  27      end
  28   
  29      return locations
  30    end
  31   
  32    module_function :which
  33  end

Adding DSO modules to Apache 2.0.53 on UNIX

For some reason all the Apache docs tell you to run apxs over a .so file. I never had any .so files, but I found this to work (if you have the .c file for your module).

   1  /usr/local/apache2/bin/apxs -c mod_foo.c
   2  /usr/local/apache2/bin/apxs -i -a -n foo mod_foo.la

It seems that the apxs compilation process puts the .so file in a folder called .libs/ which is invisible to a regular ls, but the above works too.
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS