Friday, September 23, 2011

Publishing Web Pages with Dropbox and DropPages

dropbox-logoDropbox is more than simply a convenient way to share, store, andsync files. Thanks to some clever individuals in the development community, you can do much more with Dropbox.

One of the more interesting and useful third-party applications for Dropbox is DropPages. It turns Dropbox into a simple web server, letting you publish static web pages quickly and easily. You don’t even have to buy a domain or pay for hosting.

Here’s a look at how to get up and running with DropPages.

What You’ll Need

Obviously, you’ll need a Dropbox account. It’s free, and you get plenty of storage. Especially if you only use your Dropbox account for serving your web pages.

You’ll also need some files called themes. These provide the framework for your web site, and you can download them here. There are only three themes available, but they’re not bad looking.

That said, you can fine tune or create your own theme. How? Well, the themes are formatted withMarkdown, a lightweight markup language that’s similar to Textile (which was covered by Make Tech Easier). Once you learn a bit of Markdown, you can customize your theme.

Once you have all of that, you’re ready to go.

Getting Set Up

Log into Dropbox and create a new folder. Click the New Folder button, and then type a name for the folder in the space that appears.

Creating a new folder in Dropbox

The name of the folder must contain .droppages.com – for example, scottnesbitt.droppages.com. This will be the URL to your web site. When you’re done, click the Create button.

From there, click the Share a Folder button in Dropbox. In the window that opens, click I’d like to share an existing folder and then click the Next button.

Sharing a folder in Dropbox, step 1

Click the folder that you created earlier, and then click the Next button.

Sharing a folder in Dropbox, step 2

In the next window, type server1@droppages.com in the Invite collaborators to this folder field. Doing this shares the file with the DropPages server and turns Dropbox (or, at least, that shared folder) into a basic but workable web server. When you’re done, click the Share folder button.

Sharing a folder in Dropbox, step 3

The request needs to be manually approved by Dave McDermid, the developer of DropPages. That approval can take anywhere from a few hours to a couple of days.

Finally, remember that theme file you downloaded earlier? Extract it into your DropPages folder. Once your share request has been approved, your site will look something like this when you (or someone else) goes to the URL:

A sample site

Final Thoughts

DropPages isn’t high-octane Web publishing. But it’s not meant to be that. If you want to quickly put up a Web page or site, even just for a short while, the combination of DropPages and Dropbox is a great solution. Especially if your needs are simple and you don’t want to fool around with buying a domain, dealing with hosting, and coding web pages.

via Maketecheasier.com

Monday, September 19, 2011

How to Batch Convert Documents at the Command Line

Convert it!There comes a time when you need to convert one or more files to another format. Say, for example, you have a bunch of .rtf files that you want to turn into OpenDocument files. Chances are you don’t need to do that too often, but when the time comes, opening each file in a word processor and saving it can be a real chore.

If you use OpenOffice.org or LibreOffice, then you can save a lot of time by letting a command line utility called JODConverter do the work for you. Don’t let the fact that it’s a command line tool scare you. JODConverter is easy to use and fast. It’s also very effective.

Let’s take a look at how to use it.

Getting Started

Before you go and grab a copy of JODConverter, you’ll need OpenOffice.org or LibreOffice and theJava Runtime Environment for your operating system installed on your computer. Because it’s written in Java, JODConverter runs on Linux, Mac OS, and Windows.

Once you’ve made sure all of that is installed, download a copy of JODConverter. There are two version available: 2.x and 3.0. The main difference between the two version is that version 3.0 supports both LibreOffice and OpenOffice.org. It also seems, from my unscientific observations, to be a bit faster than version 2.x.

Extract the contents of the archive you downloaded to somewhere on your hard drive. For example, if you’re using Linux and downloaded version 3.0 of JODConverter, you can extract the archive to the directory /opt. JODConverter will be installed in /opt/jodconverter-core-3.0-beta-4.

Supported Conversions

JODConverter is very flexible. It can convert between the following formats:

  • Word (.doc) to or from Word OpenDocument Text (.odt)
  • Excel (.xls) to or from OpenDocument Spreadsheet (.ods)
  • PowerPoint (.ppt) to or from OpenDocument Presentation (.odp)

The utility can also handle conversions from RTF and WordPerfect, older OpenOffice.org files, and can even convert all supported formats to PDF.

Doing a Basic Conversion

Now that everything is installed, you’re ready to go. The first thing you need to do is start OpenOffice.org in the background. To do that, open a terminal window and then type the following command:

soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" &

Stay in the terminal window and change to the directory containing the files that you want to convert. Then, run the following command:



java -jar [path to JODConverter]/lib/[.jar file] source_file output_file

The path and the name of the .jar file will be different depending on the version of JODConverter that you’re using. If, for example, you’re using version 3.0, here’s a sample path:



java -jar opt/jodconverter-core-3.0-beta-4/lib/jodconverter-core-3.0-beta-4.jar source_file output_file

Let’s say you have a Word file named Secure_Email_Report.doc that you want to convert to OpenDocument format. Just run the following command:



java -jar [path to JODConverter]/lib/[.jar file] Secure_Email_Report.doc Secure_Email_Report.odt

Doing Batch Conversions


Using JODConverter to convert a single file is a waste. You can just as easily do the deed in OpenOffice.org or LibreOffice. But converting large numbers of files is where JODConverter shines. And that’s easy to do.


How? Just run this command:



java -jar [path to JODConverter]/lib/[.jar file] *.input_type -o output_type

In the command above, input_type is the extension of the files that you want to convert andoutput_type is the extension of the target format. For example:



java -jar [path to JODConverter]/lib/[.jar file] *.doc -o pdf

This converts all Word files (*.doc) in a directory to PDF files. All you need to do is substitute the extensions of the files types that you want to convert from and to.


Scripting the Conversion


Typing that long string at the command line can be a chore. And if you only use JODConverter infrequently, it’s easy to forget the path and name of the .jar file that you need to include in the command.


To get around that problem, you can write a script or a batch file. If you’re running Linux, for example, here’s a good tutorial on shell scripting.


But you don’t even need to do that. If you have Python (a popular scripting language and interpreter) installed on your computer, you can download and use a script named DocumentConverter.py.


To use the script, just type:



python DocumentConverter.py input_file output_file

The script doesn’t seem to work with batch conversion, though.


Final Thoughts


If you’re looking for a fast and efficient way to convert multiple documents to another format, then JODConverter is definitely worth a look. It’s fast, it’s efficient, and it’s flexible. On top of that, it’s fairly easy to use. Even if you only convert documents once in a blue moon, JODConverter is a good addition to your toolkit.

More Useful and Interesting Bash Prompts

morebashprompts-smallA while back, we listed 8 Useful and Interesting Bash Prompts. That turned out to be one of our most popular articles, and still generates user response and feedback. This time we’ve found a few more gems, as well as some handy tips and tricks for having the coolest shell prompt on the proverbial block.

Using These Prompts

Some of the following prompts are one-liners, and can be pasted directly into your terminal for (temporary) use. To make them permanent, you’ll have to paste the code into your .bashrc or.bash_profile.

The larger, more complex prompts such as Twtty should be saved to their own script file (such as myprompt.sh), and you place a line like

source myprompt.sh

in your .basrc file to “import” them.


Twtty Prompt


This is a two-line prompt that holds quite a bit of information including username, hostname, workingdirectory, time, and command history number. Because of the technical and visual complexity, it’s best to place this prompt script in its own file, then source it from your .bashrc or .bash_profile as described above.


morebashprompts-twtty



function prompt_command {
  TERMWIDTH=${COLUMNS}
  # Calculate the width of the prompt:
  hostnam=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
# "whoami" and "pwd" include a trailing newline
usernam=$(whoami)
cur_tty=$(tty | sed -e "s/.*tty\(.*\)/\1/")
newPWD="${PWD}"
# Add all the accessories below ...
let promptsize=$(echo -n "--(${usernam}@${hostnam}:${cur_tty})---(${PWD})--" \
| wc -c | tr -d " ")
let fillsize=${TERMWIDTH}-${promptsize}
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="${fill}-"
let fillsize=${fillsize}-1
done
  if [ "$fillsize" -lt "0" ]
then
let cut=3-${fillsize}
newPWD="...$(echo -n $PWD | sed -e "s/\(^.\{$cut\}\)\(.*\)/\2/")"
fi
}   PROMPT_COMMAND=prompt_command   function twtty {   local GRAY="
\[\033[1;30m\]"
local LIGHT_GRAY="
\[\033[0;37m\]"
local WHITE="
\[\033[1;37m\]"
local NO_COLOUR="
\[\033[0m\]"   local LIGHT_BLUE="\[\033[1;34m\]"
local YELLOW="
\[\033[1;33m\]"   case $TERM in
xterm*)
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
;;
*)
TITLEBAR="
"
;;
esac   PS1="
$TITLEBAR\
$YELLOW-$LIGHT_BLUE-(\
$YELLOW\$usernam$LIGHT_BLUE@$YELLOW\$hostnam$LIGHT_BLUE:$WHITE\$cur_tty\
${LIGHT_BLUE})-${YELLOW}-\${fill}${LIGHT_BLUE}-(\
$YELLOW\${newPWD}\
$LIGHT_BLUE)-$YELLOW-\
\n\
$YELLOW-$LIGHT_BLUE-(\
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \"+%a,%d %b %y\")\
$LIGHT_BLUE:$WHITE\$$LIGHT_BLUE)-\
$YELLOW-\
$NO_COLOUR "   PS2="$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR "
}

One important thing to note about this prompt is that the horizontal bar scales to fit the width of your terminal, and that the working directory line will truncate itself when it gets too large.


If you have any problems with the above code snippet, the plain text version can be downloaded here.


High-Performance Minimalist Prompt


All the complexities of a fancy prompt like Twtty do take up extra CPU cycles, and while it’s certainly not going to grind your system to a halt, it can add up. If you want something that packs a lot of info without slowing you down, I suggest this:


morebashprompts-minimal



PS1="[\d | \T -> \w ...\$?]\n#"

One interesting thing to note here is the use of the variable $? at the end. This signifies the exit status of the last command entered. 0 means all is well, any other number usually indicates an error.


Rob’s Prompt


This is one of the more popular prompts floating around the Internet. The code is small and simple, yet it gives many of the features found in the larger, more complex examples.


morebashprompts-robs



PS1="\[\033[0;33m\][\!]\`if [[ \$? = "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi\`[\u.\h: \`if [[ `pwd|wc -c|tr -d " "` > 18 ]]; then echo "\\W"; else echo "\\w"; fi\`]\$\[\033[0m\] "; echo -ne "\033]0;`hostname -s`:`pwd`\007"

MegaFancyPrompt


The name is entirely deserved – this prompt is quite large and extremely fancy. It’s got color, titlebar control, user-awareness, proxy detection, screen detection, job count, and more. In short, just about every feature found in the other prompts we’ve mentioned can be found here, and quite a few others. If you want it ALL in your prompt, this is it.


morebashprompts-megafancy


Note: Not all features are visible at all times, so while it may not look like much in the screenshot, you can check out the full (documented, commented) script file here for details on how to get the visible parts you want.



COLOR_WHITE='\033[1;37m'
COLOR_LIGHTGRAY='033[0;37m'
COLOR_GRAY='\033[1;30m'
COLOR_BLACK='\033[0;30m'
COLOR_RED='\033[0;31m'
COLOR_LIGHTRED='\033[1;31m'
COLOR_GREEN='\033[0;32m'
COLOR_LIGHTGREEN='\033[1;32m'
COLOR_BROWN='\033[0;33m'
COLOR_YELLOW='\033[1;33m'
COLOR_BLUE='\033[0;34m'
COLOR_LIGHTBLUE='\033[1;34m'
COLOR_PURPLE='\033[0;35m'
COLOR_PINK='\033[1;35m'
COLOR_CYAN='\033[0;36m'
COLOR_LIGHTCYAN='\033[1;36m'
COLOR_DEFAULT='\033[0m'
  # Function to set prompt_command to.
function promptcmd () {
history -a
local SSH_FLAG=0
local TTY=$(tty | awk -F/dev/ '{print $2}')
if [[ ${TTY} ]]; then
local SESS_SRC=$(who | grep "$TTY " | awk '{print $6 }')
fi
  # Titlebar
case ${TERM} in
xterm
* )
local TITLEBAR='\[\033]0;\u@\h: { \w } \007\]'
;;
* )
local TITLEBAR=''
;;
esac
PS1="${TITLEBAR}"
  # Test for day change.
if [ -z $DAY ] ; then
export DAY=$(date +%A)
else
local today=$(date +%A)
if [ "${DAY}" != "${today}" ]; then
PS1="${PS1}\n\[${COLOR_GREEN}\]Day changed to $(date '+%A, %d %B %Y').\n"
export DAY=$today
fi
fi
  # User
if [ ${UID} -eq 0 ] ; then
if [ "${USER}" == "${LOGNAME}" ]; then
if [[ ${SUDO_USER} ]]; then
PS1="${PS1}\[${COLOR_RED}\]\u"
else
PS1="${PS1}\[${COLOR_LIGHTRED}\]\u"
fi
else
PS1="${PS1}\[${COLOR_YELLOW}\]\u"
fi
else
if [ ${USER} == ${LOGNAME} ]; then
PS1="${PS1}\[${COLOR_GREEN}\]\u"
else
PS1="${PS1}\[${COLOR_BROWN}\]\u"
fi
fi
  # HTTP Proxy var configured or not
if [ -n "$http_proxy" ] ; then
PS1="${PS1}\[${COLOR_GREEN}\]@"
else
PS1="${PS1}\[${COLOR_LIGHTRED}\]@"
fi
  # Host
  if [[ ${SSH_CLIENT} ]] || [[ ${SSH2_CLIENT} ]]; then
SSH_FLAG=1
fi
if [ ${SSH_FLAG} -eq 1 ]; then
PS1="${PS1}\[${COLOR_CYAN}\]\h "
elif [[ -n ${SESS_SRC} ]]; then
if [ "${SESS_SRC}" == "(:0.0)" ]; then
PS1="${PS1}\[${COLOR_GREEN}\]\h "
else
local parent_process=`cat /proc/${PPID}/cmdline`
if [[ "$parent_process" == "in.rlogind*" ]]; then
PS1="${PS1}\[${COLOR_BROWN}\]\h "
elif [[ "$parent_process" == "in.telnetd*" ]]; then
PS1="${PS1}\[${COLOR_YELLOW}\]\h "
else
PS1="${PS1}\[${COLOR_LIGHTRED}\]\h "
fi
fi
elif [[ "${SESS_SRC}" == "" ]]; then
PS1="${PS1}\[${COLOR_GREEN}\]\h "
else
PS1="${PS1}\[${COLOR_RED}\]\h "
fi
  # Detached Screen Sessions
local DTCHSCRN=$(screen -ls | grep -c Detach )
if [ ${DTCHSCRN} -gt 2 ]; then
PS1="${PS1}\[${COLOR_RED}\][scr:${DTCHSCRN}] "
elif [ ${DTCHSCRN} -gt 0 ]; then
PS1="${PS1}\[${COLOR_YELLOW}\][scr:${DTCHSCRN}] "
fi
  # Backgrounded running jobs
local BKGJBS=$(jobs -r | wc -l )
if [ ${BKGJBS} -gt 2 ]; then
PS1="${PS1}\[${COLOR_RED}\][bg:${BKGJBS}]"
elif [ ${BKGJBS} -gt 0 ]; then
PS1="${PS1}\[${COLOR_YELLOW}\][bg:${BKGJBS}] "
fi
  # Stopped Jobs
local STPJBS=$(jobs -s | wc -l )
if [ ${STPJBS} -gt 2 ]; then
PS1="${PS1}\[${COLOR_RED}\][stp:${STPJBS}]"
elif [ ${STPJBS} -gt 0 ]; then
PS1="${PS1}\[${COLOR_YELLOW}\][stp:${STPJBS}] "
fi
  # Bracket {
if [ ${UID} -eq 0 ]; then
if [ "${USER}" == "${LOGNAME}" ]; then
if [[ ${SUDO_USER} ]]; then
PS1="${PS1}\[${COLOR_RED}\]"
else
PS1="${PS1}\[${COLOR_LIGHTRED}\]"
fi
else
PS1="${PS1}\[${COLOR_YELLOW}\]"
fi
else
if [ "${USER}" == "${LOGNAME}" ]; then
PS1="${PS1}\[${COLOR_GREEN}\]"
else
PS1="${PS1}\[${COLOR_BROWN}\]"
fi
fi
PS1="${PS1}{ "
  # Working directory
if [ -w "${PWD}" ]; then
PS1="${PS1}\[${COLOR_GREEN}\]$(prompt_workingdir)"
else
PS1="${PS1}\[${COLOR_RED}\]$(prompt_workingdir)"
fi
  # Closing bracket } and $\#
if [ ${UID} -eq 0 ]; then
if [ "${USER}" == "${LOGNAME}" ]; then
if [[ ${SUDO_USER} ]]; then
PS1="${PS1}\[${COLOR_RED}\]"
else
PS1="${PS1}\[${COLOR_LIGHTRED}\]"
fi
else
PS1="${PS1}\[${COLOR_YELLOW}\]"
fi
else
if [ "${USER}" == "${LOGNAME}" ]; then
PS1="${PS1}\[${COLOR_GREEN}\]"
else
PS1="${PS1}\[${COLOR_BROWN}\]"
fi
fi
PS1="${PS1} }\$\[${COLOR_DEFAULT}\] "
}   # Trim working dir to 1/4 the screen width
function prompt_workingdir () {
local pwdmaxlen=$(($COLUMNS/4))
local trunc_symbol="..."
if [[ $PWD == $HOME* ]]; then
newPWD="~${PWD#$HOME}"
else
newPWD=${PWD}
fi
if [ ${#newPWD} -gt $pwdmaxlen ]; then
local pwdoffset=$(( ${#newPWD} - $pwdmaxlen + 3 ))
newPWD="${trunc_symbol}${newPWD:$pwdoffset:$pwdmaxlen}"
fi
echo $newPWD
}
  # Determine what prompt to display:
# 1. Display simple custom prompt for shell sessions started
# by script.
# 2. Display "bland" prompt for shell sessions within emacs or
# xemacs.
# 3 Display promptcmd for all other cases.
  function load_prompt () {
# Get PIDs
local parent_process=$(cat /proc/$PPID/cmdline | cut -d \. -f 1)
local my_process=$(cat /proc/$$/cmdline | cut -d \. -f 1)
  if [[ $parent_process == script* ]]; then
PROMPT_COMMAND=""
PS1="\t - \# - \u@\H { \w }\$ "
elif [[ $parent_process == emacs* || $parent_process == xemacs* ]]; then
PROMPT_COMMAND=""
PS1="\u@\h { \w }\$ "
else
export DAY=$(date +%A)
PROMPT_COMMAND=promptcmd
fi
export PS1 PROMPT_COMMAND
}
  load_prompt

Bonus – Finding the Right Colors


As you may have noticed, most of these prompts use color, and the color is often represented in a coded form like ‘\033[1;30m’, which is quite difficult to read or remember. An easy way to see all your available colors, and preview what they’ll look like, is to simply paste the following snippet into your browser:



for i in `seq 1 7 ; seq 30 48 ; seq 90 107 ` ; do 
echo -e "\e[${i}mtest\e[0m$i"
done

Which will output each color code with its number.


morebashprompts-colortest


Conclusion


There are, of course infinite variations that could be packed into your prompt. Nearly any kind of textual data can be added in, and bash’s developers have had decades to add in functionality. Some readers have even commented about running custom Python or Ruby scripts from within the prompt. Whatever you do, make it functional.


via maketecheasier.com