How to connect to Rackspace Cloud Files via ServiceNET

If you are a Rackspace customer and you are are planning to use Rackspace Cloud Files via it’s internal network (ServiceNet) so you don’t get billed for the bandwidth going over Cloud Files this is how you can do.

The first thing is to make sure with your support team if your servers are connected to ServiceNet and if you have that connection then there is a small change to do in your code.

The second thing is to use the just released 1.5.0 version on GitHUB for PHP :

http://github.com/rackspace/php-cloudfiles/tree/1.5.0

and for python :

http://github.com/rackspace/python-cloudfiles/tree/1.5.0

(you need to click on the download link at the top to download the tarball of the release).

Afer this is just a matter to set the argument servicenet=True, for example in PHP :

$user='username';
$api_key='theapi_key';
 
$auth = new CF_Authentication($user, $api_key);
$auth->authenticate();
$conn = new CF_Connection($auth, $servicenet=true);

In Python you can do like this :

username='username'
api_key='api_key'
 
cnx = cloudfiles.get_connection(username, api_key, servicenet=True)
Posted in Programming, Python, Rackspace | 4 Comments

Rackspace Cloud Files helper scripts

Since working a lot with Rackspace Cloud Files I have put some quick
scripts using the python-cloudfiles API to do some ls rm and cp of containers or objects..

It’s really a collection of quickly written stuff put in the same file
but at least if not useful for you it would give you an idea how the
python-cloudfiles works. It is all available here :

http://github.com/chmouel/cloud-files-helper

Posted in Programming, Rackspace | Leave a comment

Emacs transparency with mouse wheel

Emacs is playing fancy on the latest version (since emacs 23) it has now support for transparency at least on Linux when you have a composited Windows Manager.

As explained on the Emacs wiki here everything is controlled by this frame parameter like this :

 (set-frame-parameter (selected-frame) 'alpha '(85 50))

I have automated the thing to allow the transparency to increase or decrease when combined with the alt key just put this code somewhere in your $HOME/.emacs or $HOME/.emacs.d/init.el :

(defun my-increase-opacity()
  (interactive)
  (let ((increase (+ 10 (car (frame-parameter nil 'alpha)))))
    (if (> increase 99)(setq increase 99))
    (set-frame-parameter (selected-frame) 'alpha (values increase 75)))
)
 
(defun my-decrease-opacity()
  (interactive)
  (let ((decrease (- (car (frame-parameter nil 'alpha)) 10)))
    (if (< decrease 20)(setq decrease 20))
    (set-frame-parameter (selected-frame) 'alpha (values decrease 75)))
)
 
(global-set-key (kbd "M-<mouse-4>") 'my-increase-opacity)
(global-set-key (kbd "M-<mouse -5>") 'my-decrease-opacity)
</mouse>
Posted in Emacs | 2 Comments

rsync like backup to Rackspace Cloud File with duplicity

It seems that there is no much documentation about how to do rsync like backup with duplicty so here it is :

#!/bin/bash
UPLOAD_TO_CONTAINER="backup" #adjust it as you like
export CLOUDFILES_USERNAME=Your Username
export CLOUDFILES_APIKEY=API_KEY_YOU_GOT
export PASSPHRASE=The Passphrase for your encrypted backup
 
duplicity /full/path cf+http://${UPLOAD_TO_CONTAINER}

This should take care to upload the backup files to the backup container. It does that incrementally and detect the changes to your file system to upload. There is much more option for duplicity look at the manpage for more info.

Posted in Rackspace, Scripts | 22 Comments

Upload to Rackspace Cloud files from GNOME nautilus

After seeing this script http://overhrd.com/?p=106 which allow to upload files with the file manager (finder) of MacosX to Rackspace Cloud Files, I have made a nautilus script that doe the same for us Gnome/Unix users.

Available here :

http://github.com/chmouel/nautilus-rackspace-cloud-file/tree/master

Screensho uploading to Rackspace Cloud File form Nautilus

Posted in Programming, Rackspace, Scripts | Leave a comment

python syntax warning in emacs

One of the best feature to have with Emacs when doing python development is to have a real time syntax error/warning check highlighted in your code to avoid many errors or superfluous code.

This code is taken from the brillant Emacswiki python page.

You need to install pyflakes first which should be available on your linux distro by default in a package or for the other OS you may follow the procedure from the pyflakes webpage.

and add this configuration to your .emacs :

(when (load "flymake" t)
(defun flymake-pyflakes-init ()
  (let* ((temp-file (flymake-init-create-temp-buffer-copy
                     'flymake-create-temp-inplace))
         (local-file (file-relative-name
                      temp-file
                      (file-name-directory buffer-file-name))))
    (list "pyflakes" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
             '("\\.py\\'" flymake-pyflakes-init)))

make sure pyflakes is in your path and enable flymake-mode by default if you like for all python mode :


(add-hook 'python-mode-hook 'my-python-mode-hook)

go by M-x customize flymake as well if you like to customise some variables.

Posted in Emacs, Python | Leave a comment

emacs daemon and Xdefaults

It does not seems that emacs started with –daemon read the .Xdefauls resource it seems that the only way setting it is by the default-frame-alist variable.

I have my setup like this :

(setq default-frame-alist '((font-backend . "xft")
                            (font . "Inconsolata-14")
                            (vertical-scroll-bars)
                            (left-fringe . -1)
                            (right-fringe . -1)
                            (fullscreen . fullboth)
                            (menu-bar-lines . 0)
                            (tool-bar-lines . 0)
                            ))

PS: inconsolata font can be installed from the package ttf-inconsolata

Posted in Emacs | 7 Comments

Network manager and iwl3945 not showing network

So if you have network-manager not detecting wireless networks it is probably because lately the driver need to be set as up to get the thing going.

On my Debian I have added this to make it works :

echo "/sbin/ip link set wlan0 up"|sudo tee /etc/default/NetworkManager

Posted in Debian | Tagged | Leave a comment

Better output from sqlite3 command line

That weird output from sqlite3 command line is annoying you as well ? Just set this up to get something better :

cat < <EOF>~/.sqliterc
.mode "column"
.headers on
.explain on
EOF
Posted in Programming | Leave a comment

Update Emacs/VIM tags with inotify

When you use the tags interface for Emacs or with VIM you have to generate your tag file everytime you have a new class or things get changed.  Would not be cool to have inotify monitoring your project directory and run the etags command to generate it.

With incron you have cron that can watch some portion of the filesystem and generate an action if certain event appears.  So after installed (aptitude/urpmi) it I have configured this incrontab entry :

/home/chmouel/git/myproject IN_CLOSE_WRITE /home/chmouel/update-ctags.sh py $@ $@/$#

The script update-ctags.sh takes 3 argument one is the type of file to update when it’s changed it accept multipe of them if you delimit with a pipe ie: py|inc|php|c and the two others are identifier from incron to give the base directory and the full path which is something you should not have to change.

The update-ctags is simple as follow which could be hacked for your convenience :

#!/bin/bash
 
ACCEPTED_EXTENSION="$(echo $1|sed 's/|/ /g')"
BASE_DIR=$2
FILE_EXT=${3##*.}
 
[[ -z ${FILE_EXT} ]] &amp;&amp; exit
 
processing=
for extension in $ACCEPTED_EXTENSION;do
    [[ $extension == $FILE_EXT ]] &amp;&amp; processing=true
done
 
find ${BASE_DIR} ! -wholename './.git/*'  -a ! -wholename './.svn/*' -a ! -name '*.pyc' -a ! -name '*~' -a ! -name '*#' -print0| xargs -0 etags -o ${BASE_DIR}/TAGS 2&gt;/dev/null &gt;/dev/null
/home/chmouel/git/swift-container IN_CLOSE_WRITE /home/chmouel/updatectags.sh py $@ $@/$#
Posted in Emacs | 1 Comment