DZone 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


  • submit to reddit

Recent Snippets

                    To create a borderless JButton in swing use the following:

JButton taskButton = new JButton(action);
taskButton.setHorizontalAlignment(JButton.LEADING); // optional

This is useful for "hyperlink" style buttons or "task buttons".
                    To change all .htm files in a folder to .html files:

for f in *.htm; do mv $f `basename $f .htm`.html; done;
                    Go back to your previous directory:

cd -

Go to a new directory and push the current one onto a stack:

pushd /newdirectory

Pop a directory from the stack and go to it:

things = [] #[1,2,3]

if things.each do |thing|
    puts thing
end.empty? then
    puts "no things!"
                    Example of a Auto Attendant menu.

exten => s,1,SetVar(NUMINVALID=0)
exten => s,2,Setvar(NUMTIMEOUTS=0)
exten => s,3,Background(sales_press_one)
exten => s,4,Background(support_press_two))
exten => s,5,ResponseTimeout(5)
exten => s,6,DigitTimeout(2)

exten => t,1,SetVar(NUMTIMEOUTS=$[${NUMTIMEOUTS} + 1])
exten => t,2,Gotoif($[${NUMTRIES} < 2]?s,3)
exten => t,3,Background(vm-goodbye)
exten => t,4,Hangup()

exten => i,1,SetVar(NUMINVALID=$[${NUMINVALID} + 1])
exten => i,2,Gotoif($[${NUMINVALID} < 4]?:10)
exten => i,3,Background(invalid)
exten => i,4,Goto(s,2)
exten => i,10,Playback(vm-goodbye)
exten => i,11,Hangup()
sudo port install ruby
sudo port install rb-rubygems
sudo gem install rails --include-dependencies
sudo ln /opt/local/bin/ruby /usr/local/bin/ruby

Originally from (added --include-dependencies)                
cvs -d login
cvs -d update -P darwinports

or, if you didn't get the source from CVS:

sudo port -d selfupdate
                    if you do not already have a key pair
$ ssh-keygen -t dsa

send your public key to each host you ssh into
$ cat ~/.ssh/ | ssh you@host 'cat - >> ~/.ssh/authorized_keys2'

now you can use ssh-agent and ssh-add to facilitate a "single signon" situation.

useful if you're ssh'ing into a bunch of machines all day.

google ssh-agent for distribution-specific details.                
File.dirname ""
#=> ""

File.basename ""
#=> "stuff.html"

File.split ""
#=> ["", "stuff.html"]

File.join( File.dirname(""), "relative_link.html" )
# => ""

(Originally by Ilmari Heikkinen on the ruby-talk mailing list.)                
                    In your controller:

  layout :my_layout_func



  def my_layout_func
   # anything ruby will work
   # or you could do
   case action_name
    when 'monkey': 'monkey_layout'
    when 'edit'  : 'form_layout'