Wednesday, September 28, 2011

Friday, September 23, 2011

[Python] Easy Facebook Scripting.

Need a small and neat api for doing Facebook scripting? Look no further!


from urllib import urlretrieve
import imp
urlretrieve('https://raw.github.com/gist/1194123/fbconsole.py', '.fbconsole.py'
fb = imp.load_source('fb', '.fbconsole.py')
fb.AUTH_SCOPE = ['publish_stream']
fb.authenticate()
status = fb.graph_post("/me/feed", {"message":"Hello from my awesome script"})
#Note: Recommend that you download fbconsole.py locally with eg. wget https://raw.github.com/gist/1194123/fbconsole.py

Post a status update:
status = fb.graph_post("/me/feed", {"message":"Hello from my awesome script"})

Fetch likes on a status update:

likes = fb.graph("/"+status["id"]+"/likes")
Delete a status update:
fb.graph_delete("/"+status["id"])
Upload a photo:

fb.graph_post("/me/photos", {"message":"My photo", "source":open("my-photo.jpg")})
Query FQL tables:
friends = fb.fql("SELECT name FROM user WHERE uid IN "
"(SELECT uid2 FROM friend WHERE uid1 = me())")


Source:  Easy Facebook Scripting in Python

Tuesday, September 20, 2011

[Linux]Redshift.

This kinda neat if you have sensitive eyes. Redshift adjusts the color temperature according to the position of the sun.

Introduction:

Redshift adjusts the color temperature of your screen according to your surroundings. This may help your eyes hurt less if you are working in front of the screen at night ...

Installation:

Ubuntu: Packages for Ubuntu.

[Linux] Create your own Cloud service #2.

http://sparkleshare.org/

Another post regarding Cloud service:

http://patrick-henriksson.blogspot.com/2011/09/linux-create-your-own-cloud-service.html

Saturday, September 17, 2011

[Linux]KILL THE CAPS-KEY NOW PLEASE!

The most annoying and useless key, just simply:

setxkbmap -option caps:super




This will map caps-lock to the super key. If you wanna add this feature permanently you could add it to your .profile file.

Friday, September 16, 2011

[Linux]List available upgrades from the terminal.

sudo apt-get update;apt-get -s upgrade
Will list packages that are available for upgrades on Debian-based systems.

[Linux]Enable encrypted home folders in Ubuntu.

Introduktion:

Sometimes you want to keep your sensitive information/data for yourself. And most of the time you will store private documents and files in your home folder. A way of keeping this private is to use encryption for the home folder.

Thursday, September 15, 2011

[Linux]BootUp Manager.

The scripts located in /etc/init.d are part of the bootup sequence of every Debian-like distro. Very often Ubuntu's documentation and guides have suggested - in order to deactivate init scripts - to change the permissions of the scripts in /etc/init.d, making them non-executable.

This will have the following consequences:

Wednesday, September 14, 2011

[Linux]Join a Windows Domain with Ubuntu.

This could be resolved in many different ways(e.g. Samba) but it could also be a real struggle.

[Other]Install Windows 8 developer preview.

Ok, I know! Windows is not my usual topic when it comes to this blog but since i'm a curious person this has to be done :-)

You can try out Windows 8 developer preview in Virtual box by doing following:

Tuesday, September 13, 2011

[Linux] Create your own Cloud service!

With ownCloud!

Features

Current
file management, WebDAV access, sharing, music streaming, users & groups, OpenID, LDAP, unhosted storage

In development
encryption, calendar, contacts, bookmarks, desktop sync client, Android & webOS apps, server-server sync

Planned
file editing, versioning & recovery, connecting to other services

Installation

Monday, September 12, 2011

[Linux] Quick encrypt a file with openssl.

Sometimes you may need to a quick solution for encrypting a file. You can use openssl for this.

Friday, September 9, 2011

[Linux]Mark your Ubuntu server.

Wanna put your Ubuntu server on the map? Then visit this site: http://maps.ubuntu.com/



[Linux]Reboot required?

Doing updates on your Ubuntu installation sometime results in a recommended reboot(for example installing a new kernel). But how do we check if a reboot is required(if you have no access to a GUI or running Ubuntu server)?

Thursday, September 8, 2011

Learn in OOP in the most amusing way.

Having issues trying to understand all that weird concepts when it comes to OOP? Fear(!) not! This is probably the most funny and educating paper I have seen when it comes to approaching OOP.

Dont Fear The OOP.pfd

[Linux] Debugging Bash scripts.

Not a fun but still a necessary task when it comes to bash scripting.

Debugging the entire script:

bash -x myScript.sh


Debugging parts of script:

    set -x : activate debugging.
    set +x : stop debugging.
Example:

#!/bin/bash

echo "Simple example script\n"

set -x
for i in $(seq 3)
do
   echo "Hello World!"
done

set +x
echo "Done debugging!"

exit 0
Alternative:

Replace the shebang with following:

#!/bin/bash -xv
 

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan

Monday, September 5, 2011

[Linux] Create a random password.

cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 10 | head -n 1

tr=type of characters
fold=length of password

Sunday, September 4, 2011

[Linux] Simple sync/backup script.

Just polished my backup script including wake on lan. Just a simple script, but still essential to me.

#!/bin/bash

#function for syncing folders
function sync {
rsync -avrz /folders/to/sync user@host:/destination/folder
rsync -avrx /var/www/data/ ~/Dropbox/wiki/ #makes my wiki pages accessible remotely
}

#function for shutdown remote host, remember to change the rights for the poweroff command(eg. chmod u+s(Set the suid bit) poweroff)
function shutdown {
ssh user@host "poweroff"
}

#wol function, requires the wakeonlan package(on Ubuntu, apt-get install wakeonlan). Or you could use my python script(link).
function wol {
wakeonlan macaddress
}

#check if host is up(my rules: if server is up, only sync. If down start server, sync and then shutdown.
if ping -c 3 host
then
        sync
else
        wol
sync
shutdown
fi

exit 0

Note: Since we are using SSH for remote access it's a good idea to setup SSH login without password, follow this link

Note2: This is added to the crontab for automatic execution once a day.

Note3: I'm using hostname lookup instead of ip(which is assigned by my routers dhcp). This means that if my router suddenly changes the assigned ip(I know it's possible to reserve ip) the script is none dependend on ip. Use avahi-daemon and avahi-autoipd for this feature.

Friday, September 2, 2011

Books - Android Development.

I'm currently struggling to learn the Android Platform. Besides from following my absolutely favorite  The New Boston tutorials I also picked up this excellent book:

Beginning Android Application Development (Wrox Programmer to Programmer)

This usually my learning strategy, always use multiple sources.