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

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

Bash title random Quote routine

#
#this is a script in my .bash_profile that gets a random
#quote .txt file and assigns it to the terminal title.
#

quote_path="/Users/glynch/Documents/quotes/*"
files=($quote_path)
N=${#files[@]}
((N=RANDOM%N))
randomfile=${files[$N]}
quote=""
while read line; do quote="$quote $line"; done < $randomfile
echo -n -e "\033]0;$quote\007"

itcrowdquote.rb

// Prints a quote from Channel 4's "The IT Crowd"

#!/usr/bin/env ruby

require "rubygems"
require "open-uri"
require "hpricot"
require "htmlentities"

coder=HTMLEntities.new()

doc=open("http://www.channel4.com/entertainment/tv/microsites/I/itcrowd/quote_generator/") { |f| Hpricot(f) }

section=doc/"blockquote"/"p"
(section/"cite").remove()
quote=section.inner_html

# remove leading whitespace
quote=quote.gsub(/^\s+/, "")

# remove trailing whitespace
quote=quote.gsub(/\s+$/, $/)

# remove dash
quote=quote.gsub(/\s\-\s+$/, $/).chomp

# decode HTML entities
quote=coder.decode(quote)

puts quote

SQL quotation for Symbian DBMS

import e32db, time

timestamp = time.time()
distance = 10.5
comment = "I'm fine, thanks!"

# for date/time, int/float, and string respectively

sql = "INSERT INTO events VALUES (#%s#, %d, '%s')" %\
  (e32db.format_time(timestamp),
   distance,
   comment.replace("'", "''") )

- date/time need to be quoted with # and formatted with e32db.format_time
- int/float need no quotation
- string need to be quoted with single quote and repeat the quote if it happen to be inside.
- binary can't be used. You may need to encode it (eg. base64)

One day, I wish to see an easy-to-use SQL abstraction layer for pys60.
An ORM(SQLObject or SQLAlchemy) is even better.
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS