Cygwin Portable – (some) Linux power on a USB for Windows

January 29, 2010 6 comments

The Cygwin tools are ports of the popular GNU development tools for Microsoft Windows. They run thanks to the Cygwin library which provides the POSIX system calls and environment these programs expect.

With these tools installed, it is possible to write Windows console or GUI applications that make use of significant parts of the POSIX API. As a result, it is possible to easily port many Unix programs without the need for extensive changes to the source code. This includes configuring and building most of the available GNU software (including the packages included with the Cygwin development tools themselves) as well as lots of BSD tools and packages (including OpenSSH). Even if the development tools are of little to no use to you, you may have interest in the many standard POSIX utilities provided with the package. They can be used from one of the provided Unix shells like bash, tcsh or zsh, as well as from the standard Windows command shell if you have to for some sad reason.

From Cygwin FAQ

If you google Cygwin Portable you will find several solutions:

The one that actually worked for me came from the SourceForge project called CygwinPortable. This version is designed to work with the software bundle PortableApps, but you could use it yourself outside the bundle (see bellow).

To install this software under the bundle just extract the zip file into your PortableAps folder, and on the gui launcher click on Options->Refresh App Icons. You will see two icons appear : one launches cygwin the other launches the setup.

I had some issues getting it to work as i wanted:

Subversion information

it seems the project mantainer packaged the software with svn files, you will need to remove all .svn folders from the exploded contents. I used SVN Cleaner for that.

Outdated setup.exe

The project seems to be unmaintained for some time now. Since that time a new version of cygwin came out which changed how setup.exe and setup.ini work. If you want to update or install new Cygwin packages you will need to download setup.exe from the cygwin page (see bellow for links) and replace the file cygwinsetup.exe in CygwinPortable\App\Cygwin\setup\ with the download one, i would advise you to replace it with a renamed version of the one download if you are using Portable Apps since the portable Apps link runs the original exe file. After doing this you can update and install new cygwin software without a hinch.

Cygwin is locked to the drive you updated it on

After i updated some packages on my cygwin my shell window changed into a normal cmd dos windows, which besides being ugly had the huge disadvantage of not allowing me to copy and paste with a single click. I set out to find a solution and it came in the form of rxvt. %Explain rxvt%. The problem was in my cygwin.bat file.

If you go into CygwinPortable\App\Cygwin you will find a file named cygwin.bat. This batch file is responsible for starting up cygwin. For some reason this file will be changed when you update your cygwin version and (after the setup) it will look something like bellow:

@echo off
F:
chdir F:\Software\Bin\PortableApps\CygwinPortable\App\Cygwin\bin
bash --login -i

the above just runs bash.exe from your cygwin bin dir. And worse it just locked your instalation of cygwin back to the current computer (see the two lines bellow @echo off).

In order to solve this all you have to do is open the cygwin portable zip file you downloaded and replace your cygwin.bat with the one provided in there. This will be able to determine the folder you are running CygwinPortable.exe from and open up your rxvt window.

For those of you wanting to use cygwin outside the PortableApps bundle all the above steps apply, but unfortunally there is some other work you need to do:

  1. All you need to work with cygwin is the folder “CygwinPortable\App\Cygwin” so pull that out
  2. To run cygwin you will need to execute the cygwin.bat file inside that folder. But this file is configured to be run by the CygwinPortable.exe file and not on its own. So to get it to run on is own you will need to change the first line of the script to
for /F %%A in ('cd') do set WD=%%A

Notice i only removed the last part of the line which was telling the batch file where the cygwin base folder was. Since with Portable Apps we run CygwinPortable.exe the base folder would be the file execution folder (\CygwinPortable\) plus “App\Cygwin”. But when running the batch file directly the base folder becomes the batch file execution folder. Ok this part was confusing, if you have any doubts let me know and i’ll revise this part

Enjoy your new powers.

External Links:

Oracle Number to Java Object

January 19, 2010 Leave a comment

Recently i needed to know what should be the JAVA Object to use when mapping against an oracle database.

You can easily find alot of documentation on these mappings by searching google, but if you need to convert data types in the form of Number(p,s) (where p is precision and s is scale) you will have alot more trouble.

I ended up finding a reference to some old bea documentation(which got thrown offline when oracle took over bea) in an objectmix thread. So i put it here if anyone ever needs it:

Column Definition Returned by getObject()
NUMBER(P <=3D 9)
Integer

NUMBER(P <=3D 18)
Long

NUMBER(P >=3D 19)
BigDecimal

NUMBER(P <=3D16, S > 0)
Double

NUMBER(P >=3D 17, S > 0)
BigDecimal

Links :

Categories: java, oracle Tags: ,

Why I Hate Weblogic Integration

December 22, 2009 1 comment

This is a running post, as i go along with my current task of trying to use WLI i’m pretty sure i will be adding items to this list:

  • WorkShop – What a bloated and buggy piece of crap. This is probably the worst part till now.
    • I guess its too much to ask for a software to give reasons for not working but eh, here are some i have found:
      • Don’t put your workspace on a path with spaces or strange letters(like ó)
      • If trying to create to create a task plan workshop refuses to responde to next your trying to create the plan in the wrong folder
  • Transformations – grrrrrr… trying to debug these things is the worst thing i’ve had to do. want to know why? because i can’t…
  • It’s really hard to understand why we should even use this crap, and why do people around the world actually consider this as added value….

Extending EJB3 Objects

December 2, 2009 Leave a comment

Small and fast tip.

In order to be able to extend an EJB Entity object (be it a main object or a primary key embbedable) you need to write the MappedSuperclass anotation in the super class.

The following is taken from hibernate documentation :

@MappedSuperclass
public class BaseEntity {
    @Basic
    @Temporal(TemporalType.TIMESTAMP)
    public Date getLastUpdate() { ... }
    public String getLastUpdater() { ... }
    ...
}

@Entity class Order extends BaseEntity {
    @Id public Integer getId() { ... }
    ...
}

Some other notes taken from the documentation :

  • Properties from superclasses not mapped as @MappedSuperclass are ignored;
  • The access type (field or methods), is inherited from the root entity, unless you use the Hibernate annotation @AccessType;
  • Any class in the hierarchy non annotated with @MappedSuperclass nor @Entity will be ignored.

Read the documentation to understand it fully : http://docs.jboss.org/hibernate/stable/annotations/reference/en/html/entity.html chapter 2.2.4.4

Please note that even though i’ve used the Hibernate documentation as a reference this anotation also exists in javax.persistence so it can be used with JPA

Categories: ejb3, java Tags: , ,

Linux File Permissions

November 12, 2009 Leave a comment

I’ve allways struggled with how the linux permissions work. Recently i had another one of those times where i had to change a folders permission recursively so, once again, i googled it. The 5th result is a Google Code University Lab which actually explained it in a way i could get.

This post is a simple sumary of the lab.

When you do an ls -l on your console you will see something like the following

drwxr-xr-x. 2 sapiens sapiens 4096 2009-10-19 14:20 Desktop
drwxr-xr-x. 2 sapiens sapiens 4096 2009-10-07 23:55 Documents
-rwxr-xr-x. 3 sapiens sapiens 4096 2009-11-05 18:42 myStuff.txt

If you look at the start of the line you will notice a bunch of letters, they are actually 10 of them. At first when you are getting into linux these will seem like gibberish to you and you will basicly ignore them, but when you need to actually change the folders permissions you might want to try and learn how to read them.

The letters on that text means the following :

  • d – directory;
  • r – read granted;
  • w – write granted;
  • x – execute granted;
  • – Not granted.

Tha piece of text can be divided in 4 groups (1st group composed of the first caracther, then 3 groups of 3 characters each) :

  1. first letter states wether the file is a folder or not (if it has a ‘d’ its a directory);
  2. the next 3 letters states the permissions for the file Owner
  3. The next 3 letters states the permissions for the Group
  4. the last 3 letters states the permissions for Everyone

So you’ve learned how to read it, but how do you change it well basicly you will be using chmod for that (just man it). As for the arguments you can either write the whole text for the given file or use the short hand.The following table shows you how to use short hand version to give permissions:

Number Read (r) Write (w) Execute (x)
0
1 x
2 w
3 w x
4 r
5 r x
6 r w
7 r w x

Note: The above table was directly taken from the google lab, it also presents a good way to remember this table

 

In order to change a files permission you would write a 3 digit number, using the table above,  that defines the permissions for the groups mentioned above (owner, group, everyone else) for instance:

  • 644 would change a file/folder pemission to be read-only to everyone but the owner which would have full permissions
  • 755 (probably one of the most used) would make the file executable and readable to everyone and full permissions to the file owner.

 

External Links :

VirtualBox Share Folders with Guest Machine

November 2, 2009 1 comment

VirtualBox has a nifty feature that allows you to share folders with your guest machines. This will make a specific folder of you host machine avaible to your guest.

Though the menu option is clearly visible its actually hard to understand how this all works, especially if (like me :D) you are expecting it to magicly appear on your guest OS.

The initial sharing operation is as simple as can be :

  • Just jump to Shared folders menu option;
  • Add a new Folder (choose if its temporary or not);
  • Give the path to the folder and the share name.

Now the way you access this in your guest machine depends on the Operating System you are running. Mind that you will need to install the Guest Additions in order to share folders.

For windows guest the folder will be avaible automaticly but you will need to navigate to your network places and find “VirtualBox Shared Folders”. I had to go to Network Places -> Entire Network -> VirtualBox Shared Folders, and your share should be there.
For Linux Guest (works with Ubuntu and Fedora) you will need to mount the share in order for it to be acessible. So you will do the following :

  1. Create a directory where you wish to mount your share (let’s name it myshare);
  2. execute the command sudo mount.vboxsf MyShare /path/to/myshare.

Note that mount.vboxsf has no spaces. Above MyShare would be the name you gave your shared folder in the VirtualBox GUI. After that your share will be mounted on /path/to/myshare.

References :

Categories: Linux, Virtual Box Tags: , ,

How to Sign oAuth requests

October 15, 2009 1 comment

In the development of Piculet, my new hobbie project, i’ve had to implement the oAuth Authorization process. The Twitter App documentation gives you a rough sketch of how to do this, and the services spec points you off to the official oAuth Specification.

Let’s just say it’s a bit confusing. After surfing the web i’ve found some example code and a class with oAuth utility methods which i used in the implementation see external links at the end.

I advise you read and examine the code mentioned in the article here. The small  application the author provides will give you some insight on how it all works and how you can achieve the oAuth calls. Unfortunally this isn’t explained in the article itself hence this post.

Authorization process

The authorization process, according to twitter is :

  1. The application uses oauth/request_token to obtain a request token from twitter.com.
  2. The application directs the user to oauth/authorize on twitter.com.
  3. After obtaining approval from the user, a prompt on twitter.com will display a 7 digit PIN.
  4. The user is instructed to copy this PIN and return to the appliction.
  5. The application will prompt the user to enter the PIN from step 4.
  6. The application uses the PIN as the value for the oauth_verifier parameter in a call to
  7. oauth/access_token which will verify the PIN and exchange a request_token for an access_token.
  8. Twitter will return an access_token for the application to generate subsequent OAuth signatures.

Seems simple enough.

Signing oAuth Requests

When you register your application with twitter it gives you a consumer key that identifies your application and a consumer secret which will be used to generate your oAuth signature. This is where i bungled up, at first i thought the consumer key would be the signature to use, lets just say i should’ve read the oAuth Spec first.

Let’s take the request token call as an example. In order to obtain the request token for your application you will need to generate the following :

  1. Signature
  2. Nonce
  3. Timestamp

The oAuthBase class mentioned above will help you with this. All you need to do is provide it with your consumer key and secret, the url your calling in this case that would be : http://twitter.com/oauth/requet_token and the queryString – in this case this is empty
All you need to do is call the method  GenerateSignature to generate your signature and prepare your url.
The following code generates the url to call request_token :

    OAuth.OAuthBase oAuth = new OAuth.OAuthBase();
    string queryString="";
    string tstamp=oAuth.GenerateTimeStamp();
    string sig = oAuth.GenerateSignature(new Uri(http://twitter.com/oauth/requet_token),
                                     consumerKey, consumerSecret,,null, null,"GET",tstamp ,nonce,
                                     out url, out queryString);
    queryString += "&oauth_signature=" + HttpUtility.UrlEncode(sig);
    return url+"?"+queryString;

Now all you need to do is call that url and get your request_token.

All calls from here on end can be signed in the same manner. Only difference is that after the authorization procedure you get an access token, which you will need to provide  the GenerateSignature method in order to sign your urls.

Sidenote on Using oAuthBase

I ran into a problem when trying to use the oAuthBase class with mono and monodevelop.

Problem came from the compiler not finding the HttpUtility anywhere. This is a class that is inside the System.Web namespace. I solved this by adding System.Web to the project references.

External Links