Pages

Tuesday, June 9, 2015

Fax a PDF from the Mac OS X Command Line

How to Fax a PDF file from the Mac OS X Command Line, including a Cover Sheet

First, you must determine the name of your modem. To do this, at the command prompt type the following and press enter:

$ lpstat -p -d

Results:

printer EPSON_Artisan is idle. enabled since Wed Mar 18 15:12:05 2015
printer USRobotics_Modem is idle. enabled since Fri Feb 20 12:33:49 2015

Choose your modem. Mine was "USRobotics_Modem".


Now, to fax a PDF file to phone number 212-555-1234, type the following all on one line (formatted here for easier reading). I've also included additional fields to auto-generate a cover sheet.

$ sudo lp 
    -d USRobotics_Modem                                 // modem name
    -o phone=2125551234                                 // fax number
    -o faxCoverSheet                                    // include fax cover sheet
    -o faxSubject="ATTN: John Doe. Please Read"         // cover sheet subject
    -o faxCoverSheetMessage="RE: Important File 123456" // message for cover sheet
    "Important File 123456.pdf"                         // path to the file to be faxed


Distilled from the hint and comments in the 2003 article here:
http://hints.macworld.com/article.php?story=20031128150928128

Monday, June 1, 2015

Share RaspberryPi Folder over Samba

Share RaspberryPi Folder over Samba

Setting up a Pi for remote access Samba is pretty straight forward. There are a couple things to do first - like updating your Pi to the latest software, etc., but it's a straight forward process.

1. Update apt-get repositories
pi@apple-pi ~ $ sudo apt-get update

pi@apple-pi ~ $ sudo reboot


2. Attach the disk drive or drives to the Raspberry Pi

pi@apple-pi ~ $ sudo fdisk -l

Disk /dev/mmcblk0: 63.9 GB, 63864569856 bytes
4 heads, 16 sectors/track, 1948992 cylinders, total 124735488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b5098

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880   124735487    62306304   83  Linux

WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.

Note: sector size is 4096 (not 512)

Disk /dev/sdb: 3000.6 GB, 3000592977920 bytes
255 heads, 63 sectors/track, 45600 cylinders, total 732566645 sectors
Units = sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1   732566644  2930266576   ee  GPT

In our case, the external drive we plugged in was from a Linux machine, and uses GNU Parted to map its partition table. It doesn't really matter as all we need is the disk ID information highlighted in RED and ORANGE text.

3. Create a local folder to attach the external drive to
pi@apple-pi ~ $ sudo mkdir /mnt/disk1

pi@apple-pi ~ $ sudo nano /etc/fstab

  GNU nano 2.2.6                        File: /etc/fstab                                                        

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dp$

# user added file systems
/dev/sdb1       /mnt/disk1      ext4    defaults        0       0


Added settings are in GREEN in the above /etc/fstab file.

4. Mount your new drive
pi@apple-pi ~ $ sudo mount -a

5. Now test the newly mounted drive
pi@apple-pi ~ $ ls /mnt/disk1
All Projects
composer.phar
distribution-1.6.0-designer-linux64bit.zip
distribution-1.6.0-runtime.zip
Dropbox
Media

6. Install Samba - which allows you to connect to this folder remotely from Windows, Linux and Mac OS X.
pi@apple-pi ~ $ sudo sudo apt-get install samba samba-common-bin

7. Configure Samba
pi@apple-pi ~ $ sudo nano /etc/samba/smb.conf

At the bottom of the /etc/samba/smb.conf file, add the following code:

  GNU nano 2.2.6                     File: /etc/samba/smb.conf                                        Modified  

#
;   preexec = /bin/mount /cdrom
;   postexec = /bin/umount /cdrom


[jupiter]
        comment= Jupiter Media Library
        path=/mnt/disk1
        browseable=Yes
        writeable=Yes
        only guest=No
        create mask=0777
        directory mask=0777
        public=Yes


jupiter is the name of the file share that people will see if accessed through Finder in Mac OS X, or Windows Explorer or any of the file managers in Linux.

pi@apple-pi ~ $ sudo service samba restart

Because Samba Username/Passwords are different than the actual system's login credentials, you need to set the pi password for Samba. I recommend you make it the same as your existing pi password.
pi@apple-pi ~ $ sudo smbpasswd -a pi
Provide the new password for Samba, with the username of pi.

8. Setup autofs
pi@apple-pi ~ $ sudo apt-get install autofs

pi@apple-pi ~ $ sudo nano /etc/auto.master

Add the following to the bottom of the /etc/auto.master file
# User added configurations
/media/ /etc/auto.ext-usb --timeout=20,defaults,user,exec,uid=1000

pi@apple-pi ~ $ sudo reboot







Friday, November 12, 2010

Installing CouchDB on Ubuntu


Finally got CouchDB installed and running on Ubuntu 10.4. Using the standard apt-get command only got me to version 0.10 of CouchDB, and I wanted to get to the most recent (1.1 as of right now). To do this, I used the following - with a few minor changes - that I poached from here. Also note that I had already installed 0.10 using apt-get, so the following is only really upgrading to 1.1 from 0.10.

sudo apt-get install build-essential erlang

svn co http://svn.apache.org/repos/asf/couchdb/trunk couchdb
cd couchdb
./bootstrap
./configure
make
sudo make install
make clean
make distclean
sudo -i
adduser --system --home /usr/local/var/lib/couchdb --no-create-home --shell /bin/bash --group --gecos "CouchDB Administrator" couchdb
chown -R couchdb:couchdb /usr/local/var/lib/couchdb
chown -R couchdb:couchdb /usr/local/var/log/couchdb
chown -R couchdb:couchdb /usr/local/var/run
chown -R couchdb:couchdb /usr/local/etc/couchdb
chmod -R 0770 /usr/local/var/lib/couchdb
chmod -R 0770 /usr/local/var/log/couchdb
chmod -R 0770 /usr/local/var/run
chmod -R 0770 /usr/local/etc/couchdb
cp /usr/local/etc/init.d/couchdb /etc/init.d/
update-rc.d couchdb defaults
Start it up with:
sudo /etc/init.d/couchdb start

Wednesday, August 26, 2009

Backing up your files using rsync and ssh

Backing up your important files is something everyone should be doing regularly. There are obviously lots of options - like backing up to a CD or DVD, a network share, a USB drive or a server somewhere.

Rsync is a tool that comes standard on Unix/Linux/Mac machines, and provides command line capability to backup files from one location to another.

For this example, we'll be backing up our files to a remote server, and we'll use ssh to securely connect to that server, and rsync will send the files across that ssh connection.

You can build a shell scrip to backup all the various directories you'd like, or use some fancy exclude statements to select the content you want. At some point I'd like to use the exclude statements, but I have a few other projects going right now and I don't have too much time to play with it - so I'm going to just use a shell script.

First thing to do is install the latest version of rsync.

Get the latest version from the rsync site:

cd ~/Desktop
curl -O http://rsync.samba.org/ftp/rsync/rsync-3.0.6.tar.gz
tar -xzvf rsync-3.0.6.tar.gz
rm rsync-3.0.6.tar.gz
curl -O http://rsync.samba.org/ftp/rsync/rsync-patches-3.0.6.tar.gz
tar -xzvf rsync-patches-3.0.6.tar.gz
rm rsync-patches-3.0.6.tar.gz
cd rsync-3.0.6

Apply patches relevant to preserving Mac OS X metadata:
patch -p1 <patches/fileflags.diff
patch -p1 <patches/crtimes.diff
Configure, make, install:
./prepare-source
./configure
make
sudo make install
This should install the latest version of rsync. This first step is not necessary, as long as you have a copy of rsync already installed - but it's always good to use the latest version.

Now, you need to correctly craft your rsync command. Below is a breakdown of the different pieces to the command.

rsync [options] [directory_to_backup] [username@server]:[destination_directory]

The usual option flags are -av, which are 'archive mode' and 'verbose'. There is a third option flag -n, which means 'dry run', which will do everything except actually copy the files. It's usually best to use this -n option when you're developing your command, so you make sure you're copying the right files.

For this example, on my Mac in my home directory, I have a folder called 'pyscripts' which holds some python scripts I've written for different purposes. I'd like to backup that folder to a server I have access to. I've created a directory on the server in my home directory there, called 'backup'.

Username: raj
Server: my.server.com
Source Directory: ~/pyscripts/
Destination Directory: ~/backup/pyscripts/

With that in mind, here is the command I'm going to use:

/usr/local/bin/rsync -av ~/pyscripts/ raj@my.server.com:/home/raj/backup/pyscripts/

This will copy all the files from my local ~/pyscripts/ folder, to my backup folder.

Pretty simple really.

But... The one hitch.

We have to be present to supply our password for ssh. Later, I'll figure out how to use public and private keys to automatically log into the server, so I can truly automate the backup process.

Wednesday, August 12, 2009

URL Files - Adding links in SharePoint Document Libraries

On occasion, you may wish to add a shortcut to a file hosted somewhere else, in one of your document libraries in SharePoint. As an example, if you have a collection of documents that a project manager needs to fill out and return to you, but some of those documents are hosted elsewhere.

The easiest thing to do is to create a small text file (using notepad or your favorite editor) with the .url extension. Then add the link information in the body of the file.

For example:

[InternetShortcut]
URL=http://www.google.com/
WorkingDirectory=
ShowCommand=
IconIndex=
IconFile=
Modified=
HotKey=


Make sure you save the file with the .url extension instead of the standard .txt extension - or this won't work.

Upload your new .url file to a SharePoint document library, and give it whatever name and title you like.

Tuesday, July 28, 2009

10 Useful Code Snippets for Web Developers

This is a great article. I've copied the content here (so I don't lose it) but it was originally published here: http://woork.blogspot.com/2009/07/10-useful-code-snippets-for-web.html






1. CSS Print Framework
Hartija is an universal Cascading Style Sheets Framework for web printing. To use this framework download the CSS file here and use this line of code into your web pages:

<link rel="stylesheet" href="print.css" type="text/css" media="print">


2. CSS @font-face
This snippet allows authors to specify online custom fonts to display text on their webpages without using images:

@font-face {
font-family: MyFontFamily;
src: url('http://');
}


3. HTML 5 CSS Reset
Richard Clark made a few adjustments to the original CSS reset released from Eric Meyers.


4. Unit PNG Fix
This snippet fixes the png 24 bit transparency with Internet Explorer 6.


5. Tab Bar with rounded corners
This code illustrates how to implement a simple tab bar with rounded corners:



6. PHP: Use isset() instead of strlen()
This snippet uses isset() instead strlen() to verify a PHP variable (in this example $username) is set and is at least six characters long. (via Smashing Magazine).

<?php
if (isset($username[5])) {
// Do something...
}
?>


7. PHP: Convert strings into clickable url
This snippet is very useful to convert a string in a clickable link. I used this snippet for several tutorials; for example take a look at this link Simple PHP Twitter Search ready to use in your web projects where I used this snippet to convet into a clickable link all textual links contained in a tweet.

<? php
function convertToURL($text) {
$text = preg_replace("/([a-zA-Z]+:\/\/[a-z0-9\_\.\-]+"."[a-z]{2,6}[a-zA-Z0-9\/\*\-\_\?\&\%\=\,\+\.]+)/"," <a href=\"$1\" target=\"_blank\">$1</a>", $text);
$text = preg_replace("/[^a-z]+[^:\/\/](www\."."[^\.]+[\w][\.|\/][a-zA-Z0-9\/\*\-\_\?\&\%\=\,\+\.]+)/"," <a href="\\" target="\">$1</a>", $text);
$text = preg_replace("/([\s|\,\>])([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-z" . "A-Z]*\@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})" . "([A-Za-z0-9\!\?\@\#\$\%\^\&\*\(\)\_\-\=\+]*)" . "([\s|\.|\,\<])/i", "$1<a href=\"mailto:$2$3\">$2</a>$4",
$text);
return $text;
}
?>


8. jQuery: Ajax call
This is the most simple way to implement an Ajax call using jQuery. Change formId and inputFieldId with the ID of the form and input field you have to submit:

<script type="text/javascript">
$(document).ready(function(){
$("form#formId").submit(function() {
inputField = $('#inputFieldId').attr('value');
$.ajax({
type: "POST",
url: "yourpage.php",
cache: false,
data: "inputField ="+ inputField,
success: function(html){
$("#ajax-results").html(html);
}
});
return false;
});
});
</script>


9. CSS Layouts Collections
This page contains a collection of over 300 grids and CSS layout ready to use in your projects. Take a look, it's very useful.


10. Simple versatile multilevel navigation Menu
Several months ago I found this simple code (HTML + CSS + JavaScript for jQuery) to implement a versatile multilevel navigation menu (please send me the original source if you find it!). I think it's the simpler and faster way to do that. The result is something like this:


The only thing you have to do is to create nested &ltul> lists into a main list with id="nav", in this way:

<ul id="nav">
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a>
<ul>
<li><a href="#">Link 3.1</a></li>
<li><a href="#">Link 3.2</a></li>
<ul>
</li>
</ul>


...and use this basic CSS code (you have to modify it to customize the layout of this menu with the style of your site!):

#nav, #nav ul{
margin:0;
padding:0;
list-style-type:none;
list-style-position:outside;
position:relative;
line-height:26px;
}
#nav a:link,
#nav a:active,
#nav a:visited{
display:block;
color:#FFF;
text-decoration:none;
background:#444;
height:26px;
line-height:26px;
padding:0 6px;
margin-right:1px;
}
#nav a:hover{
background:#0066FF;
color:#FFF;
}
#nav li{
float:left;
position:relative;
}
#nav ul {
position:absolute;
width:12em;
top:26px;
display:none;
}
#nav li ul a{
width:12em;
float:left;
}
#nav ul ul{
width:12em;
top:auto;
}
#nav li ul ul {margin:0 0 0 13em;}
#nav li:hover ul ul,
#nav li:hover ul ul ul,
#nav li:hover ul ul ul ul{display:none;}
#nav li:hover ul,
#nav li li:hover ul,
#nav li li li:hover ul,
#nav li li li li:hover ul{display:block;}

...and this is the JavaScript code for jQuery you have to copy in the tag <head> of the pages that use this menu:

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
function showmenu(){
$("#nav li").hover(function(){
$(this).find('ul:first').css({visibility:"visible", display:"none"}).show();
}, function(){
$(this).find('ul:first').css({visibility:"hidden"});
});
}

$(document).ready(function(){
showmenu();
});
</script>







Thanks again to Antonio Lupetti for putting this together.

Tuesday, July 21, 2009

Customizing the Content Query Web Part (CQWP)


One of the nicest webparts available in SharePoint 2007 is the Content Query Web Part (a.k.a. CQWP). This web part allows you to query data from any list on the same site collection, and display those list items. This works great if you want to show corporate news on a team’s site, or in my case, show blog entries on various sites throughout the organization.

The scenario: a senior leader has started a blog dedicated to the new project management system that’s being rolled out. Obviously people can subscribe via RSS to the blog, but we also want to display the most recent entry on a project team’s SharePoint site. To do so, we’re going to use the CQWP, and customize the item style, so that we’re displaying the content how we want it to appear.

The setup - create a blog site in SharePoint, and create a web part page (or use an existing one) that is not on the blog site, to host the CQWP.

First, the CQWP.

Edit your host page, and add a Content Query Web Part to one of the zones.

cqwp_01.png

After it’s added, click ‘Modify Shared Web Part’ to open the tool pane.

Expand the Query section, and choose “Show items from the following list”, then click “Browse” and navigate to your blog site, and select the “Posts” list.

cqwp_02.png

Scroll down and expand the “Presentation” section, and locate “Styles” section. Choose “Title and Description” from the “Item Style” pull down.

cqwp_03.png

Click Apply, then OK to get back to your page.

cqwp_04.png

Notice that the CQWP is only showing the title of the blog post, not the body.

Now obviously, we want to display the body of the post which is Rich HTML, and we want to show what day/time the post was submitted. To get that to work, we need to know the internal field name SharePoint uses for the Body field of a blog post, and the Published field of a blog post. Then we’ll edit the XSL Item Style sheet to include the new fields.

Getting the internal field names

So the two fields besides Title we want to display are Body and Published. To find the internal field name of those fields, do the following:

  • Navigate to the Blog site

  • Click ‘View All Site Content’ on the left hand navigation bar

  • Select the ‘Posts’ list

  • Click the ‘Settings’ button, then choose ‘List Settings’

  • On the List Settings page, you’ll see a section called Columns

  • Click on the column you want to add - 'Body'

  • Now, look at the address bar, and find where it shows the field name “&Field=Body”

    cqwp_05.png


  • Repeat the steps above for 'Published', and you’ll notice that the internal column name for 'Published' is 'PublishedDate'



Now that we have the internal column names, we need to decide what type of fields they are. In the XSL sheet, we must choose one of these field types for each field.


  • Text

  • Note

  • Number

  • Currency

  • Integer

  • Boolean

  • DateTime

  • Threading

  • Lookup

  • Choice

  • URL

  • Counter

  • DisplayOnly (DisplayOnly field type has no storage of its own)

  • RichHTML

  • Image



In this example, Body is going to be “RichHTML” and PublishedDate is going to be “DateTime”.

Editing the CQWP

Now that we have the field names and their types, we need to edit the CQWP to make sure the part is pulling in all the fields we need.

Go to your web part, and on the menu select ‘Export’. Pick a file name for your part, and choose a location to save it.

Edit the .webpart file using Notepad or some other text editor, and locate the line that reads:

<property name="CommonViewFields" type="string" />

Replace this line with the line below:

<property name="CommonViewFields" type="string">Body, RichHTML;PublishedDate, DateTime</property>

If you want the webpart to pull more fields, just keep adding them separated by a semi-colon.

Save the part, and go pack to your web part page.

Remove the CQWP that is there, and then import the .webpart file you just edited.

Click ‘Add Web Part’, then select “Advanced Web Part Gallery and Options”

cqwp_06.png
cqwp_07.png

After you’ve imported and added your part, you won’t see anything different. We’ve told the CQWP to pull in our extra fields, but we still need to edit the XSL stylesheet to display those fields.

Editing the XSL Stylesheet

Open SharePoint Designer, and open the root site of your site collection.

Choose the ‘Style Library’ document library from the root site, open the XSL Style Sheets folder, and edit ITEMSTYLE.XSL. This unghosts the page, but we can reset it if we want at any time.

Each <xsl:template> element is a “style” to display an item in the CQWP. Copy any of the styles, and paste it after the last closing </xsl:template> element and before the closing <xsl:stylesheet> tag.

Edit the name and match attributes of your new template:

<xsl:template name=”MyCustomStyle” match=”Row[@Style=’MyCustomStyle’]” mode=”itemstyle”>

Now, in the last section of your newly created <xsl:template>, add a value-of xsl tag to display the fields you want appropriately.

<xsl:value-of select=”@PublishedDate” />

<xsl:value-of select=“@Body” disable-output-escaping=”yes” />

NOTE: Notice the disable-output-escaping=“yes” attribute of the @Body element. This tells the webpart to output HTML rather than raw text. - so if you put HTML into the body of your post, it will display as HTML.

Save the file. Return to the site (in the browser) and refresh the page. Open the Web Part Tool Pane for the CQWP and expand Presentation, then under Styles change the Item Style to the new custom style in the drop down. Select Apply.

With closer inspection of the ITEMSTYLE.xsl, you’ll notice that each <xsl:template> is wrapped in HTML - simply change that HTML to however you want to display your item, and you’re good to go.


~~~~~ Credit ~~~~~

I couldn’t have figured this out with out having read these three posts... Big thanks to the authors.
http://www.heathersolomon.com/blog/articles/CustomItemStyle.aspx

http://blogs.msdn.com/ecm/archive/2006/10/25/configuring-and-customizing-the-content-query-web-part.aspx

http://www.sharepoint-tips.com/2007/01/showing-description-of-page-in-content.html