Upload to Rackspace Cloud Files in a shell script

I don’t really use much the GUI and always the command line so I don’t really use the Cloud File plugin I created for nautilus.

So here is a shell script to upload to Rackspace Cloud Files and give you back a shortened URL of the public URL file. Great for quick sharing… You have to install the zenity binary first..

[Update: this is now available here https://github.com/chmouel/upcs]

Posted in Rackspace, Scripts | 4 Comments

Unit conversion from zsh

Quick conversion from shell :

Posted in Scripts | 3 Comments

connecting to self signed SSL certificate from Java on Debian/Ubuntu

You want to connect to self signed SSL certificate from Java using the standard HttpsURLConnection and you are getting this error, because the self signed certificate is obviously not recognized by Java :

SEVERE: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
	at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1639)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:215)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:209)

it seems that there is a lot of ‘solutions’ (read hack) or workaround around the web which is resumed well on this stack overflow article.

There is actually a very easy (and secure) way on Debian based systems.

- Go to your https url with Firefox
- Right Click to ‘View Page Info’
- In ‘Security’ tab you will see a button saying ‘View Certificate’
- Click now on the ‘Details’ tab
- Finally click on the ‘Export’ button which offer you to save the PEM certifcate of the website somewhere on your filesystem.

Call it my.self.signed.domain.name.pem or whatever my.self.signed.domain.name should be and put the file in /etc/ssl/certs now you just have to run the command :

sudo update-ca-certificates

and it should add your certificate to the java keystore, you can check it with the command (Enter for Password) :

keytool -list -v -keystore /etc/ssl/certs/java/cacerts
Posted in Java, Programming | Leave a comment

chrometophone and cyrket

Latest Froyo for Android have a nice feature for pushing messages to a Android phone, it’s called Android Cloud to Device Messaging Framework.

Someone at google has developped a nice extensions/apps for sending URL directly from google chrome web browser to your phone, it is called chrometophone and available here.

I often use cyrket for browsing and installing new apps. I thought it could be nice to add support to chrome2phone when sending a cyrknet URL to my Nexus one to popup a market link to install the app sent.

So here is a patch against the android APP or directly the APK to install manually.

Posted in Android | Leave a comment

Using Jython with the vCloud API

Lately I had to do a lot of works with the VMware VCloud product and since the python API did not seem available and I did not have the courage to use the PHP API I had to do most of the API works with Java. I never did any Java before and while I have found Eclipse+Java development surprisingly pleasant and easy to use/learn my favourite are still Emacs+Python.

I have then started to look over Jython to see if I can interact easily with Java via Python and this was actually pretty easy, it took me less than 10mn to convert a Login/Listing-VAPPS script in Jython.

The script is attached at the end of this post (or on github gist here). Don’t forget to adjust the classpath variable mine are defined like that :

commons-codec-1.3.jar
commons-httpclient-3.1.jar
commons-logging-1.1.1.jar
rest-api-schemas-1.0.0.jar
vcloud-java-sdk-0.9.jar
vCloudJavaSDK-samples.jar

Most of them are the ones shipped with the official Java API

Here is the script  the __main__ should get you the logic and a start how to use it :
#!/usr/bin/jython
import sys
 
from org.apache.commons.httpclient.protocol import Protocol
from com.vmware.vcloud.sdk  import VcloudClient, Organization, Vdc
from com.vmware.vcloud.sdk.samples import FakeSSLSocketFactory
 
class VcloudLogin(object):
    """
    VcloudLogin: Login to vcloud class
    """
    vcloudClient = None
    api_version = None
    vcloud_url = None
 
    def __init__(self, vcloud_url, api_version):
        # This is needed if you have a self certified certificate
        # remove it if you have a proper SSL certs.
        self.setup_fake_ssl()
        self.vcloud_url = vcloud_url
        self.api_version = api_version
 
    def setup_fake_ssl(self):
        https = Protocol("https", FakeSSLSocketFactory(), 443)
        Protocol.registerProtocol("https", https)
 
    def login(self, username, password):
        versions = VcloudClient.getSupportedVersions(self.vcloud_url + "/api/versions")
        self.vcloudClient = VcloudClient(versions.get(self.api_version))
        return self.vcloudClient.login(username, password)
 
 
if __name__ == '__main__':
    URL="https://URL"
    API_VERSION="0.9"
    USERNAME="user@organization"
    PASSWORD="password"
 
    vcl = VcloudLogin(URL, API_VERSION)
    organizations_list = vcl.login(USERNAME, PASSWORD)
 
    for org in organizations_list.values():
        for vdcLink in \
                Organization.getOrganizationByReference(vcl.vcloudClient, org).getVdcLinks():
            vdc = Vdc.getVdc(vcl.vcloudClient, vdcLink)
            print "VDC Href: %s\n" % (vdcLink.getHref())
            for vapps in vdc.getVappRefs():
                print "Name: %s URL: %s" % (vapps.getName(), vapps.getHref())
Posted in Cloud, Programming | 1 Comment

When Oracle dbstart/dbshut does not do anything

If like me you are surprised by the fact that dbstart or dbshut does not do anything when launching it, just make sure to edit the /etc/oratab and have the last char as Y and not N. Like if it is like this :

orcl:/u01/app/oracle/product/11.2.0/dbhome_1:N

change it to this :

orcl:/u01/app/oracle/product/11.2.0/dbhome_1:Y
Posted in Oracle | 1 Comment

Howto use backtrack4 from hard disk with Grub2

If you want to boot backtrack4 from time to time on your Linux desktop/laptop but don’t want to carry it on a USB drive (or CDROM) on you then this guide may help.

I am using Debian unstable on my laptop but I am sure you can adapt it to anything you want. I am using another partition (/dev/sda6) as my backtrack partition but it’s possible to copy the full thing in / as well on your main partition.

Download backtrack4 from backtrack website :

http://www.backtrack-linux.org/downloads/

  • mount the iso image locally :

sudo mount -o loop bt4-final.iso /mnt

  • copy the content of the iso to the root of the chosen partition (mounted in /media/part6 for me) :

cd /mnt;sudo rsync –progress -avu * /media/part6/

  • Configure grub :

sudo su -
cat < /etc/grub.d/50_Backtrack
#!/bin/sh
exec tail -n +3 $0
menuentry “Backtrack” {
linux (hd0,6)/boot/vmlinuz BOOT=casper boot=casper nopersistent rw quiet vga=0×317
initrd (hd0,6)/boot/initrd.gz
}
EOF
chmod +x /etc/grub.d/50_Backtrack

  • Update grub

sudo update-grub

And you should be able to boot the Backtrack menu, make sure this point to the right partition for me it’s (hd0,6) because my backtrack copied CD is on /dev/sda6 but your mileage may differ.

Posted in Linux | 3 Comments

Get Facebook albums with python

Since I haven’t see much script like this around the web here is a quick script to suck bunch of albums from facebooks (your own) nothing fancy just something to get you started with pyfacebook.

#!/usr/bin/python
import os
import urllib
from facebook import Facebook
 
# see http://developers.facebook.com/get_started.php
# Your API key
API_KEY="YOUR_API_KEY"
# Application secret key
SECRET_KEY="YOUR_SECRET_KEY"
 
cnx = Facebook(API_KEY, SECRET_KEY)
cnx.auth.createToken()
cnx.login()
cnx.auth.getSession()
 
def choose_albums(cnx):
    cnt = 1
    ret={}
    bigthing=cnx.photos.getAlbums(cnx.uid)
 
    for row in bigthing:
        ret[cnt] = row['name'], row['aid'], row['link']
        print "%d) %s - %s" % (cnt, row['name'], row['link'])
        cnt += 1
    ans = raw_input("Choose albums (separated by ,): ")
    return [ret[int(row)] for row in ans.split(', ') ]
 
chosen_albums = choose_albums(cnx)
for album in chosen_albums:
    name, aid, _ =  album
    print "Album: ", (name)
    ddir = "fbgallery/%s" % name
    if not os.path.exists(ddir):
        os.makedirs(ddir)
    for photo in cnx.photos.get(aid=aid):
        url = photo['src_big']
        dest="%s/%s.jpg" % (ddir, photo['pid'])
        if not os.path.exists(dest):
            print "Getting: ", url
            urllib.urlretrieve(url, dest)
Posted in Python | 4 Comments

Twitter notification of replies by Email

I don’t check very often my twitter to know when someone replies and I find it hard to figure out what’s going on when i check a couple of days after even using a client showing only the reply (my client of choice lately is the Emacs twittering mode client)

I have made a script who’s checking your direct reply and email it to you. This is to setup via a cron on a server who has a mail server configured locally. You can get it from here :

http://github.com/chmouel/twitter-reply-notification

Posted in Python | Leave a comment

Customize face at point in Emacs

It’s probably interesting only for the hardcore Emacs users but the last CVS version of emacs (2009-12-17) get a nifty new improvement if you need to customize a face property.

If you point on the text where you want to customize it will detect it automatically which face point you are on and ask you if this is what you want to customize (after launching the command M-x customize-face). No guessing around with list-face-displays anymore.

I am just mentioning that because it does not seems to me mentioned in the CHANGES file.

Posted in Emacs | 8 Comments