Wednesday, February 15, 2012

[Quick hint] HTML5 Grooveshark

I like to listen to the "Ambient" radio in Grooveshark. For this, I don't need to load the whole site. A nice and lightweight way of doing it is to use the new HTML5 interface of Grooveshark (originally design for mobile devices and currently in beta): http://html5.grooveshark.com.
You can't log in and load a playlist or whole record, but for radio stations is great!

Sunday, October 9, 2011

How to transform images to transparent background

I wanted to change the background on a presentation and found out why I had it with a white background in the first place: The images didn't have a transparent background.


I found this great guide for converting an image to a transparent background one. The guide uses gimp to do get the job done.


Enjoy!

Monday, October 3, 2011

[Hint] How to install OpenMPI on your local computer Edit Delete Tags Autopost


Debian and Ubuntu

These instructions will almost definitely work on Debian lenny, squeeze, and sid, as well as Ubuntu hardy, intrepid, jaunty, karmic, or lucid.
Make sure your package repository is up to date. apt-get update will do this. You must run this command as root - you may have to su, or more likely run it with sudo (it'll look likesudo apt-get update).
Be sure you've installed GCC! apt-get install gcc g++ will install the compilers if you don't have them already.
Then, run apt-get install openmpi-bin openmpi-doc libopenmpi-dev, wrapping the command in sudo if necessary. This will install OpenMPI, all necessary libraries, and the documentation for the MPI calls.
Found these instructions to install MPI. They work on Linux Mint.

Monday, September 19, 2011

[Hint] AWK One-Liners


Very helpful to manipulate text files quickly. I don't know much, but this little list of one-liners makes things pretty clear for some basic tasks.



A Handful of Useful awk One-Liners


Although awk can be used to write programs of some complexity, many useful programs are not complicated. Here is a collection of short programs that you might find handy and/or instructive. To run the program from the command line, on a single file named "filename", type: awk 'program' filename where program is the text in the following examples.

  1. Print the total numnber of input lines:

    END { print NR }

  2. Print the tenth input line:

    NR == 10

  3. Print the last field of every input line:

    { print $NF }

  4. Print the last field of the last input line:

    { field = $NF}
    END { print field }

  5. Print every input line with more than 4 fields:

    NF > 4

  6. Print every input line in which the last field is more than 4:

    $NF > 4

  7. Print the total number of fields in all input lines:

    { nf = nf + NF }
    END { print nf }

  8. Print the total number of lines that contain Beth:

    /Beth/ { nlines = nlines + 1 }
    END { print nlines }


  9. Print the largest first fields and the line that contains it ( assumes some $1 is positive):



    $1 > max { max = $1 ; maxlines = $0 }
    END { print max, maxline)





  10. Print every line that has at least one field:



    NF > 0





  11. Pritn every line longer than 80 characters:



    length($0) > 80





  12. Print the numer of fields in every line, followed by the line itself:



    { print NF, $0 }





  13. Print the first two fields, in opposite order, of every line:



    { print $2, $1 }





  14. Exchange the first two fields of every line and then print the line:



    { temp = $1 ; $1 = $2 ; $2 = temp ; print }





  15. Print every line witg rge first field replaced by the line number:



    { $1 = NR ; print }





  16. Print every line after erasing the second field:



    { $2 = ""; print }





  17. Print in reverse order the fields of every line:



    { for (i=NF ; i>0 ; i=i-1) printf( "%s ", $i)
           printf("n")
    }





  18. Print the sums of the fields of every line:



    { sum = 0
           for ( i=1 ; i<=NF ; i=i+1) sum = sum + $i
           print sum
    }





  19. Add up all fields in all lines and print the sum:



    { for ( i=1 ; i<=NF ; i=i+1 ) sum = sum + $i}
    END { print sum }





  20. Print every line after replacing each field by its absolute value:



    { for (i=1 ; i<=NF ; i=i+1) if ($i<0) $i=-$i
           print
    }




Source: The AWK Programming Language




Sunday, July 24, 2011

[Hint] Smaller font sizes for Eclipse on Linux


The idea of this hint is not to reduce the size of the editor font, but the size of the font in the menus in Eclipse. Great for a smaller screen.



Overwriting the GTKtheme


Although it is theoretically possible to create a new GTK theme from scratch just to launch eclipse, this would require an extraneous amount of work. Or you can create a modified copy of your preferred theme, but this would not easily portable to other machines or to newer versions of GTK. It is much easier to use an existing theme, just overwriting some parameters (the font and size).


Somewhere on your home directory, create a gtkrc file (like: ~/.gtkrc-eclipse) with following content:











style "eclipse" {









        font_name = "Sans Condensed 8"









}









class "GtkWidget" style "eclipse"




Finally, to launch eclipse, use following command line:











GTK2_RC_FILES=/usr/share/themes/Clearlooks/gtk-2.0/gtkrc:/home/user/.gtkrc-eclipse '/opt/eclipse-3.3/eclipse'




(note: the command above shall be written as one line)


or, for a desktop icon:











env GTK2_RC_FILES=/usr/share/themes/Clearlooks/gtk-2.0/gtkrc:/home/user/.gtkrc-eclipse '/opt/eclipse-3.3/eclipse'




(note: the command above shall be written as one line)


Note that GTK loads the gtkrc files in the order that they appear in the GTK2_RC_FILES variable. Files to the right may overwrite configuration from files to the left. In this case, the .gtkrc-eclipse file overwrite the font settings for elements based on GtkWidget (that means, all GTK widgets).


Pros:



  • Affects only eclipse, but on all workspaces.

  • Configures all GUI elements at once.

  • Easily portable to other machines.

  • Reuses work of someone who is surely better in graphical design as you.


Cons:



  • As far, no that I knew.




 


Wednesday, July 20, 2011

How to install CLI Dropbox - Dropbox Wiki




How To Install Dropbox In An Entirely Text Based Linux Environment


../UbuntuServerInstall also contains some notes on getting Dropbox running via the command line.


Prerequisites


  • At least version 2.4 of the C library
  • wget

  • Python 2.x ≥ 2.5 (we do not offer support for Python 3.0)
  • a web browser


Setup process



Short version


  1. Get the latest release tar from the download page:
  2. Files are extracted to .dropbox-dist.

  3. Run dropboxd.


Alternative


I've prepared a repackaged version of dropboxd and dropbox_cli which can be installed once per host (or per system) and which have built-in support for multiple DropBox directories per user. I've added in a "link" command to "dropbox_cli" that gives you 2 minutes to link your DB account to the specified directory. This is taken from the v1.1.6 release. You can find it here:

http://portal.nebiogrid.org/devel/dropbox/


Step-by-step version


  1. Log in to your Linux server so you obtain a shell prompt, and change to your home directory.


    cd




  2. a. Stable 32-bit:


    • wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.x86"




    • Stable 64-bit:


      wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.x86_64"




  3. Sanity check to make sure we're not going to clog our home directory.


    tar -tzf dropbox.tar.gz




  4. Extract


    tar -xvzf dropbox.tar.gz




  5. Make sure the LANG environment variable is set to something other than NULL, e.g. en_US.iso88591. If it is NULL, you'll get a cryptic error.
  6. Run dropboxd:



    ~/.dropbox-dist/dropboxd




  7. You should see output like this:


    This client is not linked to any account... Please visit https://www.dropbox.com/cli_link?host_id=7d44a557aa58f285f2da0x67334d02c1 to link this machine.




  8. <!> dropboxd will create a ~/Dropbox folder and start synchronizing it after this step! Go to the URL given; you should see a success message at the top of your screen.

NOTE: If you want to change the account it is linked to, unlink it from the first account, then kill the running dropbox process, start it up again (with "~/.dropbox-dist/dropboxd &") and obtain the new host_id with dbreadconfig.py . If you don't restart the dropbox client, it will give the same host_id (which for some reason cause me to be unable to change the account it is linked to).


NOTE: Windowless Installs


If you are unable to get a normal browser running on this machine (if its a server for example) then there are two possible solutions:


Using a command-line browser (lynx)


  • Install 'lynx' (if you need to)

  • Get to the client not linked stage of the process above

  • Leave that process running..
  • ... and open a new terminal or screen.
  • Navigate to the dropbox website in lynx. lynx http://dropbox.com/

  • Log in to your dropbox account
  • Now navigate to the link you were provided. To do this; make sure you're not focused in a text-box (using cursor keys) and press g. You can now paste your client link url and hit enter.

  • On this page you will be asked to re-confirm your password... it's quite a long way down the page.
  • Switch back to your other terminal/screen where the linking process is still running and after a second or two it should link!
  • Continue these instructions below to start dropbox hilarious quotes


Really no browser


NOTE: If you do not have or cannot install a browser on the computer on which you wish to install Dropbox, you can create a SOCKS tunnel through SSH from another computer that has a browser and link the client through that.

From computer with browser:  ssh -D 9999 username@ip-address-of-computer-to-install-dropbox-on 

Now enable SOCKS proxy in Firefox (or your browser of choice) with host as 'localhost' and port as '9999' and navigate to the link echoed by dropboxd. Log in to authenticate your client and you're done! Use Google for more help on using SSH as a SOCKS proxy.

Another way without SSH or a browser is to manually type the given link into the web browser on another system. This is the easy workaround which needs no knowledge of networks.


dropboxd didn't give me a link URL!


Run the dbreadconfig.py script to get the URL with the hostid. It's documented here.


Notes on Custom Python Scripts



pyDropboxValues


I have created a (hopefully) 'better' version of dbreadconfig.py here. You can then replace the call to dbreadconfig.py above with pyDropboxValues.py _linkurl. I won't update the instructions above though till I get feedback that my version works correctly. -- AndrewS1 2010-10-15 01:41:03


dbreadconfig.py


  • dbreadconfig.py fails on my machine (gutsy) when importing ctypes. Try deleting all the code which uses ctypes, since you only need that for Windows anyway. -- TrevorB 2009-03-18 01:52:58

  • dbreadconfig.py failed on my Ubuntu 8.04 - I just had to apt-get install gcc and libc6-dev. -- Mario
  • Also, separately, please put each import statement on a different line so that debugging can go much faster, among other reasons (PEP 8). -- jperla
  • If dropboxd just exits without any reason, check that you allow enough size for data seg, stack, virtual memory (ulimit -a). -- tomle
  • Sometimes you need to use python2.6 instead of just python


    python2.6 ~/bin/dropbox.py help




  • dropbox can also be set up on a shared hosting account, the only difference with this here TipsAndTricks/Dropboxwithdaemontools is that rather than creating a new user one has to follow the instruction with the same user available for the hosting account. - luisc


Post-installation


Following on from that, there are a few different options to run the Dropbox client on an ongoing basis. You could put the above line in your server startup scripts, e.g./etc/rc.local, or maybe just a certain user's login scripts.

It is recommended to download the official Dropbox CLI to start the dropbox daemon (as an unprivileged user) and get its status.



$ mkdir -p ~/bin  $ wget -O ~/bin/dropbox.py "http://www.dropbox.com/download?dl=packages/dropbox.py"  $ chmod 755 ~/bin/dropbox.py  $ ~/bin/dropbox.py help




In case you get the following error (after trying to run the Dropbox CLI):



$ ~/bin/dropbox.py help   File "/home/username/bin/dropbox.py", line 91     with open(pidfile, "r") as f:             ^ SyntaxError: invalid syntax




update to Python 2.6 and it will go away. Or better try python2.6 rather than your plain command python as you may already have it installed.

NOTE: For CentOS users, use either the EPEL or IUS repo to install the python26.<arch> RPM. The package installs Python 2.6 in parallel to the distribution default version. This way YUM will not be effected by the newer version. Once installed update the hash-bang line to refer to /usr/bin/python26 or /usr/bin/python2.6.


Changing the dropbox folder location


To move an existing dropbox folder to /foo/bar:



$ dropbox stop $ cp ~/.dropbox/dropbox.db dropbox.db.backup $ wget http://dl.dropbox.com/u/119154/permalink/dropboxdir.py $ chmod +x dropboxdir.py $ mv ~/Dropbox /foo/bar $ ./dropboxdir --setfolder=/foo/bar $ dropbox start




(Do not just create a new empty directory and setfolder to it - when you restart dropbox, it will think you've deleted all your files, and delete them from everywhere else too.)

(The script dropboxdir.py must be located in parent directory to ~/.dropbox-dist/ )

Note that the script above currently only works for Dropbox 0.7.x and not 1.0.x - for Dropbox 1.0 you can use this PHP script or this Python script.


Using symbolic links to move the folder location




$ dropbox stop $ mv ~/Dropbox /target/folder $ ln -s /target/folder/Dropbox ~/ $ dropbox start





Suppress LAN Sync broadcasts


To stop dropbox from sending LAN Sync broadcasts every 30 seconds over port 17500 (http://forums.dropbox.com/topic.php?id=16253) see DropboxAddons/DisableLanSync


Unlink / Relink dropbox account


You shouldn't need to do this, but occasionally it can fix "odd quirks", so is often recommended as a troubleshooting tip on the forums.

To unlink:



$ dropbox stop $ mv ~/.dropbox ~/.dropbox.old




To relink:



$ dropbox start





Running on system startup


Some *nix boxes will let you use "cron" to ensure that dropbox starts up when the machine boots. I've done this by putting



@reboot $HOME/.dropbox-dist/dropboxd




into my crontab. Do "man 5 crontab" in a console window to see if your flavor of cron supports that syntax.

You can also use an init.d or event.d script to automatically run dropboxd.
















Debian/Ubuntu

Fedora/Redhat

Gentoo

init.d scripts

/UbuntuStartup

/FedoraStartup

/GentooStartup

invocation

/etc/init.d/dropbox

service dropbox

/etc/init.d/dropbox

/etc/init.d/dropbox and service dropbox can be called with start, stop, restart and status.

Check below for further instructions once you have downloaded the init.d script for your platform.


Debian/Ubuntu


Click here for a sample init.d script for Debian/Ubuntu and the event.d sample.



$ chmod +x /etc/init.d/dropbox $ update-rc.d dropbox defaults





using upstart


If you want to use the newer upstart init present on Ubuntu installations and are running dropboxd under a sandbox user (say, dropbox), you can place the following script into /etc/event.d, naming it dropbox



start on runlevel 2 start on runlevel 3 start on runlevel 4 start on runlevel 5 stop on shutdown respawn script    # Without next line DB does not sync non ASCII characters (ubuntu 10.04-x86_64, db 0.7.110)    export LANG=en_US.UTF-8    cd /home/dropbox    exec sudo -H -u dropbox ./.dropbox-dist/dropbox end script




After creating the file, run initctl start dropbox and you're set! Alternatively, if only one user of the system is running Dropbox, you can run the script as that user, replacing /home/dropbox with /home/USERNAME and sudo -H -u dropbox with sudo -H -u USERNAME

If gives the error about the job not existing, although this time it says Unknown job: dropbox

Put the content of the script on: /etc/init/dropbox.conf

(The latter version is for Ubuntu 10.4 and, presumably, later versions.)


Fedora/Red hat


Click here for the Fedora/RedHat init.d script. Save it to /etc/init.d/dropbox.

Add the file /etc/sysconfig/dropbox with one line setting the variable DROPBOX_USERS to include all users that want to run dropboxd in quotes and separated by spaces.



$ cat /etc/sysconfig/dropbox DROPBOX_USERS="user1 user2"




Fix file permissions:



$ /bin/chmod 0755 /etc/init.d/dropbox $ /bin/chmod 0644 /etc/sysconfig/dropbox $ /bin/ls -l /etc/init.d/dropbox /etc/sysconfig/dropbox




Fix SELinux permissions:



$ /usr/bin/chcon -u system_u -t initrc_exec_t /etc/init.d/dropbox $ /usr/bin/chcon -u system_u -t etc_t /etc/sysconfig/dropbox $ /bin/ls -lZ /etc/init.d/dropbox /etc/sysconfig/dropbox




For Fedora/RedHat run:



$ chkconfig dropbox on




Verify it worked. You should see dropbox in the list.



$ chkconfig --list | egrep '3:on|5:on' | less





Gentoo


Click here for the Gentoo init.d scripts.



rc-update add dropbox default





openSuse 11.3


Click here for the openSuse init.d scripts.


This is a great hint for working on a remote server, command line only. I did it and it works great, except for the fact that the IT guys don't have Python 2.6 installed on the machine.

Enjoy