Never been to TextSnippets 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 (or not, you can keep them private!)

About this user

Mark James Adams http://raysend.com/mark/

« Newer Snippets
Older Snippets »
13 total  XML / RSS feed 

Postgresql dump SS archive script

Dump, bzip, and upload a postgres database to strongspace. Via Ubernostrum

#!/usr/bin/bash

FILENAME=b_list-`/usr/xpg4/bin/date +%Y%m%d`.sql.bz2
cd /home/myuser/dumps
/opt/local/bin/pg_dump -U db_username db_name | /usr/bin/bzip2 > $FILENAME
/usr/bin/scp $FILENAME me@strongspace:/my/backup/dir/

Install RdbiPgSQL package for R on OS X

Connecting R to Postgres on OS X is a little bit of a hassle given where OS X looks for the libraries to link to.

Assuming you've installed Postgres via MacPorts, add shell variables for your Postgres lib and include directories to ~/.profile

export PG_LIB_DIR=/opt/local/lib/postgresql82
export PG_INCLUDE_DIR=/opt/local/include/postgresql82


Add a link from the OS X SDK directory to /opt

$ sudo ln -s /opt/ /Developer/SDKs/MacOSX10.4u.sdk/opt


Then install RdbiPgSQL as you would normally.

If the install fails because R isn't picking up the PG_LIB_DIR, _INCLUDE_DIR variables, keep a lookout for the lines in the install error output that look like


The downloaded packages are in
        /tmp/RtmpTakYpZ/downloaded_packages


In Terminal, change to this directory, replacing the 'RtmpTakYpZ' string with whatever directory the error output gives. Then run the R install command on the package file:

$ cd /tmp/RtmpTakYpZ/downloaded_packages
$ sudo R CMD INSTALL RdbiPgSQL_1.10.0.tar.gz 




Change OS X font smoothing in one application

E.g, Light font smoothing style in Textmate.

$ defaults write com.macromates.textmate AppleFontSmoothing -int 1

Webdav upload utility

Command line utility to upload files to a webdav server.

Requires net_digest_auth.rb (snippet)

NB: Does not handle MKCOL, so the directory where you place the file must already exist.

Usage

$ ruby upload.rb cert.yml source destination


where cert.yml is a file of the form

username: USERNAME
password: PASSWORD


source is the path to the file to upload

destination is the URL of a directory on a webdav server to upload to.

# upload.rb
# Command line webdav upload script. Based off of 
# http://theexciter.com/articles/bingo

require 'net_digest_auth'
require 'yaml'
require 'uri'

abort("Usage: #{$0}    ") unless ARGV.size==3

auth = YAML.load_file(ARGV[0])
username = auth['username']
password = auth['password']

src = ARGV[1]
dst = ARGV[2]

if File.exists?(src)
  url = URI.parse(dst)
  Net::HTTP.start(url.host) do |http|
    res = http.put(url.request_uri, 'hello') # try putting something so
                                             # the server will return a
                                             # www-authenticate header
    req = Net::HTTP::Put.new("#{url.path}#{File.basename(src)}")
    req.digest_auth(username, password, res)
    response = http.request(req, File.open(src).read)
    puts response.code + " " + response.message
  end
else
  puts "No such file #{src.inspect}"
end

Authenticated Digest for Net:HTTPHeader

Allows authenticated requests to be made.

Based off of http://theexciter.com/articles/bingo and updated for Ruby 1.8.6

Use by calling

    req.digest_auth(username, password, res)


on an HTTP request object before asking for a response.

# net_digest_auth.rb
require 'digest/md5'
require 'net/http'

module Net
  module HTTPHeader
    @@nonce_count = -1
    CNONCE = Digest::MD5.new.update("%x" % (Time.now.to_i + rand(65535))).hexdigest
    def digest_auth(user, password, response)
      # based on http://segment7.net/projects/ruby/snippets/digest_auth.rb
      @@nonce_count += 1

      response['www-authenticate'] =~ /^(\w+) (.*)/

      params = {}
      $2.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }

      a_1 = "#{user}:#{params['realm']}:#{password}"
      a_2 = "#{@method}:#{@path}"
      request_digest = ''
      request_digest << Digest::MD5.new.update(a_1).hexdigest
      request_digest << ':' << params['nonce']
      request_digest << ':' << ('%08x' % @@nonce_count)
      request_digest << ':' << CNONCE
      request_digest << ':' << params['qop']
      request_digest << ':' << Digest::MD5.new.update(a_2).hexdigest

      header = []
      header << "Digest username=\"#{user}\""
      header << "realm=\"#{params['realm']}\""
      
      header << "qop=#{params['qop']}"

      header << "algorithm=MD5"
      header << "uri=\"#{@path}\""
      header << "nonce=\"#{params['nonce']}\""
      header << "nc=#{'%08x' % @@nonce_count}"
      header << "cnonce=\"#{CNONCE}\""
      header << "response=\"#{Digest::MD5.new.update(request_digest).hexdigest}\""

      @header['Authorization'] = header
    end
  end
end

wdiff wrapper for svn

#/bin/sh

wdiff $6 $7

Refresh rate in Vienna

Change the default refresh rate in seconds for the Vienna RSS reader to whatever you want. Anything less than 1800 seconds might be considered bad netiquette, but it's useful if you're only subscribed to internal feeds (e.g., activeCollab, Connector).

defaults write uk.co.opencommunity.vienna2 CheckFrequencyInSeconds 60

load/unload postgres (via ports) launch deamon

Enable or disable the automatic launch of the postgresql server installed via macports. Starts or stops the daemon and modifies the launchd manifest.

launchctl load -w /opt/local/etc/LaunchDaemons/org.darwinports.postgresql81-server/org.darwinports.postgresql81-server.plist

launchctl unload -w /opt/local/etc/LaunchDaemons/org.darwinports.postgresql81-server/org.darwinports.postgresql81-server.plist

twitter from the command line

Replace username/password with your info. The message is posted as the status text.

curl -u username:password -d status="" http://twitter.com/statuses/update.xml

Bar graph of file, folder sizes on TxD

From besonen.

Prints an ordered list of file and folder sizes in human readable form, with a bar graph to show the relative size of each item.

du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf("%6.1f\t%s\t%25s  %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}'

start postgres

Postgres was installed through darwinports, so

/opt/local/lib/postgresql81/bin/pg_ctl -D /opt/local/var/db/postgresql81/defaultdb/ start

shell/vim .rc's for Japanese support (UTF-8)

Get Japanese (and other multibyte, ascii-unfriendly languages) working in the Terminal.

.inputrc (bash)
set convert-meta off
set meta-flag on
set output-meta on


.cshrc (tcsh)
set dspmbyte=utf8


.vimrc
:set enc=utf-8
:set fenc=utf-8


And don't forget 'ls -w' or 'ls -v' to display files and directories.

Preferences: Uncheck 'Emulation > Escape non-ASCII characters';

More at Apple Support - Topic: Displaying foreign characters in the Terminal command line.

CSS for printing Instiki pages with @media rule

Insert in your Stylesheet tweaks to get black---instead of gray--text when pages are printed.

@media print {
    body {
        color: black;
        background-color: white;
        font-size: 10pt;
    }

    h1, h2, h3, h4, h5, h6 {
        color: black;
    }

    a, a:link, a:active, a:visited {
        color: black;
        border-bottom: thin dotted;
        text-decoration: none;
    }

 h1#pageName, .newWikiWord a, a.existingWikiWord, .newWikiWord a:hover, #TextileHelp h3 { 
      color: black; 
    }
}


« Newer Snippets
Older Snippets »
13 total  XML / RSS feed