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 »
4 total  XML / RSS feed 

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

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);}'

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.
« Newer Snippets
Older Snippets »
4 total  XML / RSS feed