Archive for the “HOW TO” Category

Embedded Fonts in Pdf

 

It is often that we need to submit paper or report electronically in portable document format (p.d.f.) that requires the fonts are embedded so that it is easily distributed or printed in various machines and p.d.f. version. It is usual for us to encounter the problem of emmbeded fonts simply because we use our own p.d.f converter. It may be from the pdf driver such as cutepdf, primopdf or our ghost script p.d.f converter.

Here is some "hacking techniques" to debug the problem of embedded fonts (in linux, taken from [1]).  Suppose your non-working p.d.f file is text.pdf

 

(1) convert to ps (postscript file):
pdftops text.pdf

(2) convert back to pdf using prepress settings:
ps2pdf14 -dPDFSETTINGS=/prepress text.ps

(3) check new text.pdf for horrendous formatting errors due to double conversion, and embedded fonts as above.

 

http://axiom.anu.edu.au/~luke/embedded_fonts.html

 

Sep 2, 2009 Posted Under: HOW TO, Portable Document, UNIX   Read More

Get ASP.NET control’s ID to be used by JavaScript function

 

Sometime we want to use javascript to be used in our ASP.NET (or any server side scripting language). The problem will occur if we want to get/store value from javascript to ASP.NET UI component (example asp:TextBox). Since the rendered ID of the ASP.NET component is generated in the runtime, so it’s difficult to set the ASP.NET component’s ID to the javascript in development process.

I suggest to assign the ASP.NET component’s ID to javascript in the code-behind file. In this article, I will explain how to add javascript pop-up calendar into the ASP.NET page.

In the ASP.NET page:

<asp:TextBox ID="StartDate" runat="server" CssClass="NormalTextBox" ReadOnly="false" Width="80"/>    

……

<asp:ImageButton ID="imageButtonStartDate" runat="server" ImageUrl="~/images/calendar.png"/>

The image button will be used as a trigger to show the pop-up calendar.  In code-behind, in the Page_Load() method, we need to do:

Registering the javascript into the ASP.NET

String moduleDir = this.TemplateSourceDirectory;

Page.ClientScript.RegisterClientScriptInclude("scw", moduleDir + "/JS/scw.js");

Add the action into the image button, choose OnClientClick

imageButtonStartDate.OnClientClick = "scwShow(" + StartDate.ClientID + ",event); return false;";

The scwShow method need to get the ASP.NET TextBox’s component ID. StartDate is the ID of the ASP.NET TextBox component. Use ClientID to get the ID of the TextBox.

Aug 28, 2009 Posted Under: .NET, HOW TO   Read More

Auto Increment in PostgreSQL

First of all, create a sequence:

CREATE SEQUENCE question_sequence;

Then create the table:

CREATE TABLE question (
    ID INTEGER NOT NULL PRIMARY KEY DEFAULT nextval(’question_sequence’),
    QUESTION_TEXT CHARACTER VARYING(250),
    QUESTION_LEVEL CHARACTER VARYING(50)
);

 

Aug 13, 2009 Posted Under: HOW TO   Read More

Back-up File with Rsync

 

Description

Rsync is a command in unix/linux terminal that enables us to transfer just the differences between two folders interconected to some networks. The italic word just gives us a clue on how to transfer files efficiently. One application of this usability is for speeding up back-up processes, i.e. no need for transfer a big chunk of folder that we have in both ends but only the differences between them.

How does it work?

We can straightly use it from the linux terminal. Ex: in ubuntu open applications -> accessories –> terminal 

 

Local machine:  rsync [OPTION...] SRC... [DEST]

Access via remote shell:
  Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
  Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

Access via rsync daemon:
  Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
        rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
  Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
        rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST

For Frequent Back-up

For frequent back-up, it will be convenient if we can make a shell command file containing the necessary instructions for back up. With just calling that command, the back-up will be done in few seconds/minutes (depending on the folder size). Here is an example (case study).

Remote server for backup: www.backupdomain.com, folder: $HOME/test, username: user

Local folder: $HOME/Documents/test

We can create the shell command file as follows.

#!/bin/bash
STRING:"Backup is done"
rsync -avz –delete -e ssh ~/Documents/test  use@backupdomain.com:~/test
echo $STRING
exit 0

save the above shell command in executable .sh file and just invoke the command whenever it is necessary. We may want to put the command in the cron-job for scheduled backup..

Note that the option –delete means that the backup will delete the file that does not exist at the sender side.

 

Reference: 

[1] http://www.samba.org/ftp/rsync/rsync.html

Jul 19, 2009 Posted Under: HOW TO, UNIX   Read More

How To: Handle compressed (tar.gz) file using tar

Syntax

tar -[option] [compressed file]

For reference purposes, the following list is a description of the tar options used to extract compressed file :

x (extract)
tar will extract from the passed filename (as opposed to creating a new file).

v (verbose)
tar will print verbose output as files are extracted. You may omit this flag if you do not wish to see each file as it is unpacked.

z (zipped)
tar will use gunzip to decompress the source. This option assumes that you are using the GNU tools; other versions of tar may not support the z flag. In the event that you are not using the GNU tools, you will need to manually unzip the file using gunzip before you can unpack it with tar.

f (file)
tar will use the filename following the f parameter to determine which file to extract.

 

Jul 6, 2009 Posted Under: HOW TO, UNIX   Read More

How To: Checking version of installed MySQL Server

In order to check the version of installed MySQL Server, we can use following command

mysql -V

The result in our machine is

mysql version 14.12 Distrib 5.0.26, for pc-linux-gnu (86_64) using readline 5.0

 

Jul 5, 2009 Posted Under: HOW TO, UNIX   Read More

How To: SSH Tunneling to connect local pgAdmin to remote PostgreSQL

 

Case: There is a need to use pgAdmin in local machine to connect to the postgresql remotely. One option is use SSH tunneling from local machine to remote machine.

Assumption made:

in remote machine, the postgresql run in port 5432 (default port)

SSH can be use to encrypt the network connection between clients and a PostgreSQL server. First make sure that an SSH server is running properly on the same machine as the PostgreSQL server and that you can log in using ssh as some user.

To create tunnel between our machine and remote machine using SSH, we could use command:

ssh -L [local port]:[localhost]:[remote port] [user]@[remote machine domain]

example:

ssh -L 5454:localhost:5432 user007@some-domain.com

you will be prompted to enter the password of the user007 in the some-domain.com

Open the pgAdmin and add new server. Set host to localhost, port 5454, SSL is not required, set maintained DB to blank.

Jul 5, 2009 Posted Under: HOW TO, UNIX   Read More

How To: vi Text Editor

 

A text editor is a program used to create and modify the text files. Two principal Unix text editor are vi and emacs. Powerful, mature, full-featured program, by far, the most widely used editors.

Starting vi

To start vi, the basic syntax is:

vi [-rR] [file]

Command mode and input mode

When working with vi, data is kept in a storage called an editing buffer. If we can to edit file using vi, vi copies the contents of the file to the editing buffer. We are not working with the original, we use the copy instead.

Command Mode

Whichever typed keys will be interpreted as commands.

Input Mode

Everything key typed to the editor, will be inserted directly into a buffer.

Inserting Text

There are tweleve commands to change to input mode. Half of these commands are for entering new data; the other half are for replacing existing text.

Here are the commands:

Command     
Description
i change to input mode: insert before cursor position
a change to input mode: insert after curson position
I change to input mode: insert at start of current line
A change to input mode; insert at end of the current link
o change to input mode: open bellow current line
O change to input mode; open above current line

 

Deleting Text

There are several ways to delete data from the editing buffer, using both vi and ex commands. The vi commands are:

Command Description
x delete character at cursor
X delete character to left of cursor
D delete from cursor to end of line
dmove delete fro cursor to move
dd delete the entire current line

 

 Writting Data to a File

There are several command to write data to a file. The commands are:

Command Description
:w write data to original file
:w file

write data to a new file

:w! file overwrite an existing file
:w>> file append data to specified file

Find sometext

/sometext

Jul 2, 2009 Posted Under: HOW TO, UNIX   Read More