16 Apr 2015, 8:15pm
linux:

leave a comment




  • Anzeige
  • Recover deleted photos

    Shit hap­pens… but for Linux users, there is a power tool straight from the US Air Force called “fore­most” to help you recover (aka undelete) your pho­tos eas­ily!
    Note: you’ll need sudo rights to install this soft­ware tool.

    But most impor­tantly: do not write any new data to your device (SD card, flash drive or what­ever)! Oth­er­wise, you’ll over­write what is still there and lose your pho­tos forever.

    The steps:
    Remove or unplug the media/drive/card from your comupter.
    Open a ter­mi­nal window.

    Install the recov­ery software.

    sudo apt-get install foremost

    Cre­ate a folder to put the recov­ered pho­tos in. Impor­tant: don’t put this for­ler on the drive where you want to recover pho­tos from! See above…

    mkdir recovered-photos && cd recovered-photos

    Find the device: copy the fol­low­ing com­mand to your ter­mi­nal and press the [Tab] key twice

    foremost -v -t jpg /dev/sd

    It will say some­thing like this

    sda   sda1  sda2  sda3  sda4  sda5  sda6  sdb

    Now, plug in your drive/card/medium and press [Tab] again, twice.
    It should change to some­thing like this

    sda   sda1  sda2  sda3  sda4  sda5  sda6  sdb  sdc  sdc1

    In my case sdc and scd1 showed up. Thus, sdc1 is the par­ti­tion on the device to recover from. Thus, I my case the full com­mand would be (You need to replace sdc1 with what­ever showed up pre­vi­ously on your own terminal!)

    foremost -v -t jpg /dev/sdc1

    … press return and see the magic hap­pen! Your pho­tos will show up in a sub­folder of recovered-photos. :)

    25 Sep 2014, 7:10pm
    linux:

    leave a comment




  • Anzeige
  • Setting up a linux server to forward all incoming mails

    Typ­i­cal thing when hav­ing a new site up: you want to get whatever@yourdomain.com to end up in you nor­mal inbox, say Gmail.

    Here are the steps!
    Note: If you are logged in as root, you do not need to use “sudo” in front of each command.

    Prepa­ra­tions

    It’s rec­om­mended to have a user account to receive the mail other than root.
    So either choose a user you have cre­ated already or cre­ate a new one:

    sudo adduser [username]

    Does your provider require you to use an SMTP relay? (check the doc­u­men­ta­tion, or ask). You need to know this to continue.

    Install post­fix

    Post­fix is a soft­ware pack­age, a MTA, it han­dles incom­ing mail and forwarding.

    sudo apt-get install postfix

    And answer all con­fig­u­ra­tion ques­tions as below:
    Server con­fig­u­ra­tion type: If you use an SMTP relay, choose “Inter­net with smarthost”, oth­er­wise “Inter­net“
    Sys­tem mail name: [yourdomain.com] (no sub­do­main)
    SMTP relay host: [smtp.yourprivider.com] (only show­ing if you chose “Inter­net with smarthost”)
    Root and post­mas­ter mail recip­i­ent: The created/chosen before (not root)
    Other des­ti­na­tions to accept mail for: keep the sug­gested defaults and add in front [yourdomain.com] and a space
    Force syn­chro­nous updates on mail queue: no
    Local net­works: keep sug­gested
    Use proc­mail for local deliv­ery?: yes
    Mail­box size limit: 0
    Local address exten­sion char­ac­ter: +
    Inter­net pro­to­cols to use: all

    Man­ual configuration

    All edits with sudo if you not logged in as root.
    Edit /etc/postfix/main.cf add fol­low­ing two lines to the end

    virtual_alias_domains = [yourdomain.com]
    virtual_alias_maps = hash:/etc/postfix/virtual

    Create/edit /etc/postfix/virtual and add

    @[yourdomain.com]    [your.email.address@somewhere.com]

    Finally, after edit­ing this file call

    sudo postmap /etc/postfix/virtual

    so that postmap actu­ally applies your changes.

    Notes

    If you for­ward to Gmail, do not use the same address to send test mails that the mails will be for­warded to — Gmail will silently ignore/delete mail where the sender and recip­i­ent are the same and you will think the for­ward­ing does not work.

    26 Dec 2013, 12:25pm
    linux:

    leave a comment




  • Anzeige
  • Scale images for the web — quickly

    Start­ing Gimp just to scale down some pho­tos to send them by mail? Meh.
    How about mark them, right-click, “Send To” -> “Scale for web”?
    No prob­lemo:
    First, get a tool to scale images:

    sudo apt-get install imagemagick

    Now, cre­ate a script that takes a list of images as input, scales them down, and stores them with a pre­fixed file name. Go!

    #!/bin/bash
    pwd > ~/f0.txt
    echo "$@" > ~/f1.txt
    for file in $@
    do
    	convert "$file" -quality 50 -resize 1024x768 "${file%/*}/web-${file##*/}"
    done

    Make sure we chmod +x the script file we just cre­ated.
    Next, let’s inte­grate it into “Send To”. (This is an exam­ple for Thu­nar)
    Cre­ate a .desktop file in the sendto folder, e.g. /usr/share/Thunar/sendto/scale-for-web.desktop with fol­low­ing content:

    # Scale images for the web
    [Desktop Entry]
    Type=Application
    Version=1.0
    Encoding=UTF-8
    TryExec=scale-for-web
    Exec=scale-for-web %F
    Icon=
    Name=Scale for the web
    MimeType=image/jpeg;image/jpg;image/png
    

    Replace both scale-for-web with the name you gave to your script file. Is the script’s folder in $PATH? No idea? Then just put the entire path+filename.
    Now, open Thu­nar, select some images (Jpeg or Png), right-click, “Send To” -> “Scale for the web”, wait a few sec­onds and you’ll see web-....jpg files appear­ing in the same folder. :)

    Ref­er­ences: how to scale images with imageMag­ick, extract path seg­ments, more details on string manipulation

    29 Oct 2013, 4:19pm
    meteor:

    leave a comment




  • Anzeige
  • Serving Static Files with Meteor and Spiderable

    In short: To serve files which are not part of your project’s code (i.e. which are sup­posed to be served with­out being com­piled), put them in the public folder. This folder will be served from /.

    Some more back­ground and details:
    Tried to add a web-font to my project, thus, I put it in /client/webfonts/somefont.woff. But the font didn’t show up. I tested it with wget -O- http://localhost:3000/webfonts/somefont.woff … and *sur­prise* I got the HTML of the default page — not some binary gib­ber­ish that you would expect to find in a font file.

    All file types unknown to meteor get stripped out dur­ing com­pile time. Instead you need to put them in a sep­a­rate folder called public — in my case in /public/webfonts/somefont.woff. Rookie mis­take I guess. :)

    7 Oct 2013, 10:07am
    javascript:

    1 comment




  • Anzeige
  • Callback Method for Twitter’s Typeahead

    When you start using Twitter’s typea­head, e.g. because you switched from Boot­strap 2.3 to 3.0, you will notice that it is NOT a sim­ple drop-in replace­ment for Bootstrap’s orig­i­nal typea­head!
    Before, you gen­er­ated the sug­ges­tions shown to the user by imple­ment­ing a call­back method while cre­at­ing the typea­head like this:

    $(field).typeahead({
      source: function(query, process) { 
        ... return a list of suggestions (see doc for details) 
      }
    });

    Since ver­sion 3, Boot­strap does not pro­vide its own typea­head any more, instead it is using Twitter’s own imple­men­ta­tion which seems to be a good choice at least on the long run. But it does not pro­vide any mean for defin­ing a call­back method to pro­vide the sug­ges­tions — no clue why.
    Instead you can pro­vide a pre­de­fined array locally, a pre­de­fined array that will be loaded on start-up, or a remote ser­vice defined by a URL.
    You will find sev­eral good exam­ples of why you need a call­back method sometimes.

    • You want/have to use a Javascript library to access the service.
    • There is no data­base for the sug­ges­tions, they a gen­er­ated on the fly, e.g.if you want to sug­gest sen­tence com­ple­tion while the user types.
    • You are using Meteor’s col­lec­tions hold­ing your sug­ges­tions, thus, there is no URL you could point to.

    But tak­ing a look into the inter­nals revealed fol­low­ing solu­tion: com­pletely by-pass the inter­nal sug­ges­tion aggre­ga­tion of Twitter’s typea­head by replac­ing the getSuggestions(query, callback) method of the first dataset, which we defined by local: [];.

    (t = $("field")).typeahead({ local: [] });
    t.data("ttView").datasets[0].getSuggestions = function(query, callback) {
      var suggestions = ... gather your suggestions here ...
      var data = [];
      for (suggestion in suggestions) { data.push(this._transformDatum(suggestion)); }
      callback(data)
    }

    (Trans­lated from Cof­fee­script on-the-fly — con­sider as a draft than an out-of-the-box solution.)

    Happy hack­ing. :)

    p.s. for Meteor users: The call­back breaks each time the tem­plate gets re-rendered — despite that you use the pack­age preserve-inputs or <#constant> due to a bug. Some­how, con­stant areas and that par­tic­u­lar pack­age do not get along with each other. Solu­tion: removed the pack­age and use con­stant areas around typea­head input fields works. This should be fixed as soon as the new tem­plate engine gets rolled out.

    2 Jun 2012, 7:32pm
    gwt:

    3 comments




  • Anzeige
  • How to Use JQuery in GWT

    After adding the JQuery script to your project HTML file’s header section

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>

    You will be able to use JQuery in native (JSNI) meth­ods by prepend­ing $wnd., e.g.:

    private native void someMethod() /*-{
    	$wnd.$(function() {
    		$wnd.$('#somediv').doSomething();
    	});
    }-*/;

    With­out $wnd. you will end up with fol­low­ing error: com.google.gwt.core.client.JavaScriptException: (ReferenceError): $ is not defined

    15 May 2012, 12:08pm
    gwt java:

    3 comments




  • Anzeige
  • JUnit-Testing and GAE APIs

    Some issues I encoun­tered when test­ing a new Java library for load­ing mul­ti­ple URLs in par­al­lel on the Google Apps Engine (GAE) (more about that library in another post).

    Here are some of the typ­i­cal errors you might encounter:

    Miss­ing time­out class

    java.lang.NoSuchMethodError: org.mortbay.thread.Timeout

    Con­text menu on project: Prop­er­ties -> Build Path -> Order and Export: move GWT SDK *above* App Engine SDK (cf. here)

    Com­pi­la­tion unit was not seen

    com.google.gwt.junit.JUnitFatalLaunchException: The test class 'com.test.client.MyTest' was not found in module 'com.text.Module'; no compilation unit for that type was seen

    • The test class needs to be within a pack­age that is con­fig­ured in the mod­ule file (*.gwt.xml). You should cre­ate a new source folder (Con­text menu on project -> New -> Source Folder) and cre­ate the whole pack­age struc­ture you use within your project up to client, e.g. com.company.client, and put your GWT tests in it. This way you make sure that the tests are not going to be deployed to GAE later on.
    • If you are test­ing client-side code, your test class needs imple­ment GWTU­nit *and* be run as GWTU­nitTest *not* as JUnitTest ;)

    API pack­age not found

    java.util.concurrent.ExecutionException: com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'urlfetch' or call 'Fetch()' was not found.

    The GAE envi­ron­ment has not been initialized.

    • Set up the required libraries for testing:
      • Con­text menu on project -> Prop­er­ties -> Build Path -> Libraries -> Add Vari­able -> Con­fig­ure Vari­ables -> New…: Set “SDK_ROOT” as name and search you disk for “appengine-api-stubs.jar” and copy the part before “/lib/impl” into the text box named “Path”
      • Select “SDK_ROOT” from the pre­vi­ous dia­log, click “Extend…”, unfold lib and impl and select “…labs.jar”, “…stubs.jar”, and “…api.jar”; unfold “lib/testing” and select “…testing.jar” — done, whew.
    • Add fol­low­ing lines to your test class:
      private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalURLFetchServiceTestConfig());
      @Before public void setUp() { helper.setUp(); }
      @After public void tearDown() { helper.tearDown(); }
    • Have a look in com.google.appengine.tools.development.testing to see all the services/APIs avail­able for test­ing and replace LocalURLFetchServiceTestConfig with the one you need.

    I tried to keep it as brief as pos­si­ble, for more details have a look at this page.

    26 Apr 2012, 9:58am
    gwt java:

    leave a comment




  • Anzeige
  • Multiple Projects and GWT

    When work­ing on sev­eral large scale projects (in Eclipse), it’s con­ve­nient and of course more effi­cient to share and reuse code via com­mon libraries. While those are in an early stage they need to be changed a lot and there­fore it’s handy to link projects in instead of cre­at­ing new jars each time the library has been updated.
    Unfor­tu­nately, this stan­dard approach for Java devel­op­ment in Eclipse does not work that straight for­ward as with plain old Java projects, it requires three steps in total:

    1. Link the library project to all rel­e­vant projects (“Project Pref­er­ences” -> “Java Build Path” -> “Projects” -> “Add…”)
    2. Then, add the client-side code of the library (by adding it as a mod­ule.) There­fore, edit the gwt.xml of your appli­ca­tion and add for exam­ple <inherits name="net.svenbuschbeck.gwt.lib.SuperLib "/> where Super­Lib is the file name of the gwt.xml file in you library project and before that is the pack­age it lies in.
    3. Add the code to the project by link­ing a source folder. Unfor­tu­nately, this is required if you do not want to write an Ant script to com­pile your appli­ca­tion. (If you pre­fer Ant check this out) I don’t like the idea of using such a script because if you for­get to run it each time you make changes, you will end up in confusion—let’s go for the con­ve­nient, auto­matic way then.
      1. Add a folder to your appli­ca­tion project; open the “advanced” sec­tion in the folder cre­ation dia­log, select “Link to alter­nate loca­tion” and pick the source folder (usu­ally “src”) of your library project. (Hint: if you work within a team using a ver­sion­ing sys­tem, you can cre­ate a vari­able for that folder and use this instead. This way, each of your col­leagues can put the library project in a dif­fer­ent folder and accom­mo­date for that by adjust­ing the vari­able :) )
      2. Right click the folder, “Build Path” -> “Use as Source Folder”. Done.

    Sur­pris­ingly, the GWT plu­gin for Eclipse does not honor the project link­ing, thus all the ref­er­ences need to be made explicit or you will end up with lots of the fol­low­ing: ClassNotFoundException.

    28 Feb 2011, 11:10pm
    gwt java:

    leave a comment




  • Anzeige
  • How to Execute Code When the GWT Application Is Going Down

    My goal was to store the UI state of my appli­ca­tion just before it gets ter­mi­nated to be able to restore it next time the way the user left it the other day.

    I tried to add an addAttachHandler to the RootPanel to get informed about the root panel get­ting detached from the DOM so that I can final­ize my appli­ca­tion. Sur­pris­ingly, that does not work in Chrome (tested Chrome and Fire­fox only).

    But besides that this sounds like a bug to me, I found the “proper” way of doing things before the appli­ca­tion ends:

    Window.addWindowClosingHandler(new Window.ClosingHandler() {
    	@Override public void onWindowClosing(ClosingEvent event) { ... } 
    });

    In the end, I think some­thing like Document.addUnloadHandler would be more sug­ges­tive… clos­ing the win­dow or reload­ing a page is both exit­ing the appli­ca­tion by unload­ing the DOM — not clos­ing the window.

    7 Feb 2011, 2:58pm
    java:

    leave a comment




  • Anzeige
  • Java Cookies from the Future Past

    While work­ing with cook­ies in Java/GWT and thus—to set the expire date—with Date, I found a doubt­ful Java behavior.

    My goal was to set a cookie to expire in about one month from today like this:

    Date expires = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 30);
    Cookies.setCookie("myCookie", "myData", expires);

    And kept won­der­ing why the cookie never got stored.

    And finally cre­ated a sim­ple test case like this:

    Date today = new Date();
    Date tomorrow = new Date(today.getTime() + 1000 * 60 * 60 * 24);
    Date nextMonth = new Date(today.getTime() + 1000 * 60 * 60 * 24 * 30);

    And got fol­low­ing dates:

    today=Mon Feb 07 14:27:50 CET 2011
    tomorrow=Tue Feb 08 14:27:50 CET 2011
    nextMonth=Tue Jan 18 21:25:02 CET 2011

    Accord­ing to Java’s cal­cu­la­tion, the cookie was expired already before even being set.

    Took me a bit to under­stand why:
    1000 * 60 * 60 * 24 * 30 = 2,592,000,000 = 0x9A7EC800
    Thus, the first bit got set to one… a clas­si­cal over­flow caus­ing the inte­ger value to become neg­a­tive — just try:

    System.out.println(1000 * 60 * 60 * 24 * 30);

    It will print out -1702967296.

    Fix: Add a lit­tle L will solve the issue by forc­ing the com­piler to cal­cu­late using the scope of long:

    Date nextMonthLong = new Date(today.getTime() + 1000L * 60 * 60 * 24 * 30);

    I guess I will fall for that one again some­time as the error is not obvi­ous in my opin­ion — espe­cially because getTime() returns a long and still, the com­piler sticks with an int for the mul­ti­pli­ca­tion part.

    4 Feb 2011, 10:10pm
    gwt:

    1 comment




  • Anzeige
  • Disable Context Menu in GWT

    To make use of the right mouse but­ton, it is nec­es­sary to dis­able the native browser con­text menu (the popup menu appear­ing on right click). This can be achieved like this:

    RootLayoutPanel.get().addDomHandler(new ContextMenuHandler() {
    
    	@Override public void onContextMenu(ContextMenuEvent event) {
    		event.preventDefault();
    		event.stopPropagation();
    	}
    }, ContextMenuEvent.getType());

    Same should work for RootPanel.

    After that, it is pos­si­ble to make use of the right mouse but­ton for exam­ple like this:

    someWidget.addDomHandler(new MouseMoveHandler() {
    
    	@Override public void onMouseMove(MouseMoveEvent event) {
    		if (event.getNativeButton() == NativeEvent.BUTTON_RIGHT) {
    		...
    2 Feb 2011, 11:41pm
    java projects:

    leave a comment




  • Anzeige
  • Authentication with FlickrJ

    When you know about user­name and pass­word logins, the whole Flickr authen­ti­ca­tion process for web appli­ca­tions seems a lit­tle weird on first sight, nev­er­the­less it is log­i­cal and nec­es­sary after you have done some read­ing (for exam­ple the offi­cial Flickr WebApp Auth HowTo).
    To get started and into cod­ing quickly (using FlickrJ and Java) I rec­om­mend this page. Espe­cially the code exam­ple is excel­lent in my opin­ion! Thanks Andy Sacher!

    17 Jan 2011, 6:38pm
    gwt jobs:

    leave a comment




  • Anzeige
  • Testing GWT Application in Virtual Machine

    I am devel­op­ing on a Mac, but to test my GWT appli­ca­tions for cross-browser com­pat­i­bil­ity in Inter­net Explorer I need to use Win­dows, thus I got Win­dows 7 installed using Par­al­lels. Just by the way, to be able to test in dif­fer­ent Inter­net Explorer ver­sion, I am using a pretty handy appli­ca­tion called IETester.
    But try­ing to access local­host with IE in the vir­tual machine did not work. I got a “404 page not found” error instead of see­ing my app run­ning on the local App Engine instance. Obvi­ously, Par­al­lels does not auto­mat­i­cally for­ward local­host requests to OSX and maybe that is actu­ally a good idea security-wise.
    To fix the issue, you need to run Google App Engine on a pub­lic net­work inter­face, or in other words, bind the App Engine server to all avail­able IP addresses. The down side: every­body know­ing your IP address can see the GWT app now, but oth­er­wise you are not allowed to access it in the viru­tal machine as from your OSX’s point of view, that Win­dows machine is “some other guy access­ing from the out­side”, too. To make GAE acces­si­ble from the out­side, add the para­me­ter “-bindAd­dress 0.0.0.0″ when launch­ing you local GAE. Using Eclipse you can achieve that by right click­ing your project -> Run As -> Run Con­fig­u­ra­tions -> Choose “(x)= Argu­ments” tab; add the option to the top most box titled “Pro­gram argu­ments” in the options area (e.g. before “-port 8888″).

    The first part of the list of argu­ments should look some­thing like that:

    -remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -startupUrl GlocalUiPg2.html -logLevel INFO -codeServerPort 9997 -bindAddress 0.0.0.0 -port 8888 ...

    Now, you can access you app using the OSX’s pub­lic IP address. (You can get to know your IP by hav­ing a look at the net­work pref­er­ences panel.) Launch­ing GAE from Eclipse, you will see a dif­fer­ent link (URL) in the “Devel­op­ment Mode” tab now, con­tain­ing the pub­lic IP already. Using that one in, say, your Fire­fox on Mac, it will ask you now whether you want to allow the debug­ger access. That is also due to the fact, that you are now using a pub­lic address, so it is not clear to your local debug server, whether that request came from the same com­puter or some­one else in the network.

    14 Dec 2010, 11:49am
    java:

    leave a comment




  • Anzeige
  • Casting collections in Java

    Assum­ing two classes A and B as

    class A {}
    class B extends A {}

    It is just log­i­cal that cast­ing B to A works fine:

    A anObjectOfClassA = new B();

    But when it comes to col­lec­tions of As and Bs, a strange phe­nom­e­non appears in Java:

    Collection<B> collectionOfBs = new LinkedList<B>();
    Collection<A> collectionOfAs = (Collection<A>)collectionOfBs; // this line does not compile!

    That is, though the col­lec­tion wrap­per (the java.util.Collection class) is the same and B extends A, cast­ing a col­lec­tion of objects of class B to a col­lec­tion of objects of class A throws an compile-time error.

    But it works using gener­ics (the whole class for the sake of com­plete­ness and reusability):

    import java.util.Collection;
    import java.util.LinkedList;
    
    public class CollectionCastingExample {
    
      class A {}
      class B extends A {}
    	
      Collection<B> collectionOfBs = new LinkedList<B>();
    //  Collection<A> collectionOfAs = (Collection<A>)collectionOfBs;
    	
      Collection<A> collectionOfAs = downCastCollection(collectionOfBs, A.class);
    	
      /**
       * Casts a collection of objects of class B where B extends A to a collection of objects of class A.
       * 
       * @param <T> Base class
       * @param collection Collection of objects of a class extending T 
       * @param aClass Representation of T
       * @return Collection of objects of T casted from given collection of objects of a class extending T.
       */
      @SuppressWarnings("unchecked")
      public static <T> Collection<T> downCastCollection(Collection<? extends T> collection,
          Class<T> aClass) {
        return (Collection<T>) collection;
      }
    }

    Despite the fact that a @SuppressWarnings("unchecked") is required, it avoids iter­at­ing over the whole col­lec­tion of Bs and cast­ing each of them from B to A plus adding them to a new col­lec­tion of As.

    3 Dec 2010, 4:02pm
    gwt:

    2 comments




  • Anzeige
  • Adding a New Service (GWT)

    Adding a new servlet/service to you GWT appli­ca­tion is quite straight for­ward, e.g. by copy­ing the exam­ple “greet­ingSer­vice” or cre­at­ing a new servlet. But it’s easy to over­look a required change/adjustment of your project’s con­fig­u­ra­tion and you might end up with an error mes­sage like “Blocked attempt to access inter­face ‘some.package.SomeService’, which is not imple­mented by ‘some.other.package.SomeOtherServiceImpl’; this is either mis­con­fig­u­ra­tion or a hack attempt”.

    Check list (some should be replaced with what­ever you want to call your new service):

    • Copy or cre­ate files:
      SomeService.java and SomeServiceAsync.java in client pack­age
      SomeServiceImpl.java in server pack­age + change imple­men­ta­tion state­ment to SomeSer­vice
    • Adjust web.xml:
      <servlet>
      	<servlet-name>someServlet</servlet-name>
      	<servlet-class>some.package.SomeServiceImpl</servlet-class>
      </servlet>
      <servlet-mapping>
      	<servlet-name>someServlet</servlet-name>
      	<url-pattern>/[copy base directory name from other service declaration]/some</url-pattern>
      </servlet-mapping>
    • Anno­tate inter­face SomeService.java:
      @RemoteServiceRelativePath("some")
    • Con­nect to your new ser­vice in the client:
      private final SomeServiceAsync someService = GWT.create(SomeService.class);

    Def­i­nitely some pos­si­bil­i­ties to make a mis­takes or miss some­thing here.

    8 May 2010, 11:25am
    linux:

    leave a comment




  • Anzeige
  • Resizing System or Home Partion

    A very con­ve­nient tool for cre­at­ing, mov­ing, and resiz­ing par­ti­tions is GParted. I use it for all my partition-changing-needs — it is really pow­er­ful and yet easy to use! :)

    But it is not pos­si­ble to resize sys­tem rel­e­vant par­ti­tions while the sys­tem is run­ning — makes sense, right? ;)

    But you can down­load GParted as LiveCD ISO file and burn it on a CD. After that, restart your com­puter with the CD in your drive and a small linux will start up directly from CD includ­ing GParted, thus allow­ing you to mod­ify any drive and par­ti­tion there is. :) Do all required changes, click the exit but­ton and you are done. In my case, the com­puter did not reboot auto­mat­i­cally, instead I ended up with a com­mand line inter­face — use the com­mand “sudo reboot” to restart the sys­tem your­self if that happens.

    And just by the way, GParted does also han­dle Win­dows par­ti­tions eas­ily — so there is no need to buy or “get” Par­ti­tion Magic from some­where. But never for­get to backup your data first.

    Yet another hint: GParted works most reli­able if you do one step at a time. So for exam­ple, there are par­ti­tions A and B (A is in front of B) and you wish to give some of the free space in A to B. You need to do fol­low­ing steps: Shrink A, move B left and finally grow B. From my expe­ri­ence, GParted works best if you really do all those steps sep­a­rately, apply each of then, and go for the next one if the last one fin­ished successfully.

    30 Apr 2010, 11:04pm
    linux:

    leave a comment




  • Anzeige
  • Flickering Screen After Upgrade to Kubuntu 10.04

    First of all, I was amazed how smoothly the upgrade went. (K)Ubuntu and I guess other dis­tri­b­u­tions as well have gone quite a far way to become plat­forms for every­body — with a lot of soft­ware but even more tools, helpers and auto­matic back­ground ser­vices — like the nice upgrade service.

    There was only one prob­lem I ran into and I want to share the solution.

    I am run­ning Kubuntu 10.04 (just upgraded today) on a Lenovo IBM ThinkPad R60 (Yes, one of those with both brands on them ;) ) with an ATI Radeon X1400 graph­ics device. But since upgraded, my dis­play started flick­er­ing — not per­ma­nently but unbearable.

    The solu­tion that worked for me (at least par­tially — see below — and this is of cause depend­ing on the graph­ics device type) was to install the pro­pri­etary ATI dri­vers. I know, it is not a good solu­tion, I do not like to use them nei­ther and if any­one out there is read­ing this with a bet­ter solu­tion in mind, let me know it!! :)
    Edit 2011-02-14: Added a new post with an addi­tional, alter­na­tive solu­tion here.

    So what you need to do is  to get your favorite pack­age man­age­ment tool (e.g. Synap­tic or KPack­ageKit) — just hit Alt+F2 and type “pack­age” and pick KPack­ageKit from the list (it will ask you for the super user pass­word). Then, search for “fglrx”. In KPack­ageKit, you will find a result titled “Video dri­ver for the ATI graph­ics accel­er­a­tor”, and some­thing below the title like “fglrx — 2:8.723.1-0ubuntu3” but the ver­sion num­ber should not mat­ter. Click the arrow to the right, hit “Apply” and after reboot­ing, every­thing should per­fectly with­out any configuration.

    Good luck. ;)

    Prob­lems noticed so far: The dri­ver causes “Seg­men­ta­tion Fault” error mes­sages, e.g. when try­ing to open up the dis­play set­tings. That’s ugly, I know. But you can read in sev­eral forum and blog posts, that the sup­port for the for­mer nicely work­ing dri­ver for the ATI X1400 has been dis­con­tin­ued since 10.04, hence, it’s just good luck that the fglrx works some­how — good to know *after* upgrad­ing, right. But still, the flick­er­ing was unbear­able for me, thus, I accept the issues for now. I will keep my eyes peeled hop­ing for a proper solu­tion in the future.

    26 Apr 2010, 9:34pm
    linux:

    leave a comment




  • Anzeige
  • Change hotkey of Kubuntu’s Quick Launch Tool KRunner

    First of all: I love those quick launch tools aka key­stroke launch­ers, they are real time savers — every­one should have one!

    [For those with­out a glue what a key­stroke launcher is:] It is THE tool for launch­ing any kind of soft­ware or even open­ing doc­u­ments. Instead of mov­ing your mouse to you appli­ca­tions menu, click it, search the pro­gram, move the mouse there, maybe pick a sub-folder, move mouse again and finally click — unless you acci­den­tally moved a lit­tle but to far and the menu close again, com­pletely. :( But it is easy to put an end to this (as described below). Instead of doing all that click­ing, you hit a spe­cial key com­bi­na­tion, by default [Alt] and [Space], this will make a small input box show up, now, you only enter the first let­ters of the pro­gram — e.g. “f” will do after a few uses to start Fire­fox (the pro­gram learned that you use it a lot). It might save only a few sec­onds each time, but the sum up and, hey, it is very con­ve­nient, too!

    So here is what you need to do:
    Mac OS: It is already built-in — Just hit Alt+Space and type the name of the pro­gram you want to start (or files or what­ever).
    Win­dows: Get/install Launchy and use it as explained above.
    Kubuntu: built-in as well, BUUUT you have to hit Alt+F2 instead.

    And there it is, some­thing that kept annoy­ing me about Kubuntu for quite a bit. I was hop­ing to get used to it but for what rea­son? Alt+F2 is really not handy com­pared to Alt+Space.
    Finally, based on this old forum post and a few adjust­ments to fit nowa­days Kubuntu, all you need to do is this:

    1. Go to “Set­tings” -> “Key­board and mouse”
    2. Select “Global Key­board Shortcuts”
    3. Pick from the select box “KDE com­po­nent” at the top “Run Com­mand Interface”
    4. Now, you can access “Run Com­mand” — Change it to what­ever you like :)
    28 Feb 2010, 2:05pm
    linux:

    leave a comment




  • Anzeige
  • Moving home to it’s own partion (Ubuntu)

    We are going to move all accounts includ­ing their per­sonal data on a dis­tinct par­ti­tion. This rec­om­mended in case of sys­tem fail­ure to not loose any data.
    I have no idea, why the Ubuntu instal­la­tion wiz­ard does not do this by default — it should!

    This post is based on an arti­cle in Ger­man — I will mainly trans­late it, strip some plush and add some stuff to make life eas­ier and to reduce the risk of data loss. But be aware: to per­form any of those fol­low­ing things, you will need super user rights and you should feel some­what comfy with using the com­mand line. And of course, it might be pos­si­ble in cir­cum­stances unfore­seen, that you lose all your per­sonal data — but there are a lot of backup steps included below.

    Here we go: (con­sole input or state­ments are writ­ten in ital­ics)

    1. Prepa­ra­tion
      1. Cre­ate a backup: rsync –avx –progress /home <your backup destination>
      2. If you do not have a free par­ti­tion yet, I rec­om­mend GParted to cre­ate one (use sudo apt-get install gparted). I rec­om­mend ext3 for com­pat­i­bil­ity issues — but if you use Linux only, you can go for ext4 (please change ext3 to ext4 in step 1.6 in case) — make sure your new par­ti­tion is big enough for your home folder! Try to remem­ber the size (get size: du –sh /home) of /home, you can use it later on to ver­ify your new home location.
      3. Get par­tion name sudo fdisk –l /dev/sda — e.g. /dev/sda7 — I will refer to this name as (name)
      4. Copy your cur­rent file sys­tem con­fig­u­ra­tion: sudo cp /etc/fstab /etc/fstab.new
      5. Get par­tion UUID of new par­ti­tion: sudo blkid — you will find a line about (name) stat­ing a UUID (quite a long hex string), I will refer to it as (uuid) — copy it.
      6. Edit /etc/fstab.new, add a new line at the end as fol­lows (the lay­out should fol­low pre­vi­ous lines — sim­ply copy one and adjust it):
        UUID=(UUID)  /home                ext3         defaults                    0 2
    2. Copy
      1. Sign off / Log out
      2. Switch to con­sole mode by press­ing Ctrl+Alt+F1
      3. Cre­ate a mount point for the new par­ti­tion: sudo mkdir /mnt/tmp
      4. Add par­tion: sudo mount (name) /mnt/tmp
      5. Copy home from the old loca­tion to the new par­ti­tion: sudo rsync –avx –progress /home/ /mnt/tmp
      • Test
          1. Mount copy of home as new home: sudo mount (name) /home
          2. Check size of home folder — should be the same as in step 1.: du –sh /home
          3. Check mount­ing worked: sudo mount| grep /home should print out some­thing like
            (name) on /home
          • Switch
              1. yet another home backup: sudo mv /home /home.bak
              2. cre­ate new home mount point: sudo mkdir /home
              3. cre­ate a backup of fstab: sudo mv /etc/fstab /etc/fstab.bak
              4. put updated ver­sion in place: sudo mv /etc/fstab.new /etc/fstab
              5. reboot and you should be done: sudo reboot

              Ok, that’s that. If every­thing works fine, you can delete the backup home sudo rm –rf /home.bak and the fstab backup sudo rm /etc/fstab.bak. Hope you found it use­ful and I did not put in a mis­take or typo. Gimme feed­back! :)

              5 Aug 2009, 1:12pm
              php:

              leave a comment




            • Anzeige
            • Simple redirection using PHP and HTML meta tag

              Some­thing every­one needs once in a while… maybe you moved a file on your server or you did not install word­press in the root folder of your web­server — like I did nei­ther ;) — a redi­rec­tion or for­ward­ing can be an easy answer.

              The script is rather sim­ple — it redi­rects in three ways to pro­vide a rea­son­able fall back if any of the auto­matic redi­rect­ing fails. To use it on your server, just enter the URL/address/file name/folder you would like the user to be redi­rected to in the sec­ond line of the page/script.

              Put the whole code and markup in a file with file exten­sion “.php”.
              In my case, every user end­ing up at “www.svenbuschbeck.net” should to be for­warded to “www.svenbuschbeck.net/wordpress/home”. So I adjusted the script below like “$url = ‘wordpress/home’”, named the file “index.php” and put it in the root folder. Done :) .
              <?php
              $url = 'put your URL between the parenthesis';
              header("Location: $url");
              ?>
              <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
              <html>
              <head>
              <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
              <meta http-equiv="refresh" content="0;url=<?php echo $url; ?>"/>
              <title>You will be redirected... </title>
              </head>
              <body>
              If you are not redirected automatically, please click <a href="<?php echo $url; ?>">here</a>.
              </body>
              </html>
              16 Apr 2009, 5:46pm
              jobs:

              3 comments




            • Anzeige
            • how to install memchached 1.2.2 from source

              I have installed an instance of mem­chached ver­sion 1.2.2 on one of our servers (Debian etch) today and to keep you from spend­ing a whole after­noon, see my everything-step-by-step instruc­tion below.

              Mem­chached is a dis­trib­uted hash map, which can be used for exam­ple to speed up any kind of web appli­ca­tion, see web­site for details. In our case, we want to use it as tem­po­rary data store. I will report about the expe­ri­ences in a lat­ter post.

              intro­duc­tion

              Always refer to this page for details, but I cre­ated a ver­sion with less text but includ­ing steps to really start from scratch.

              All lines start­ing with # are com­mand lines, i.e. you need to type into a linux shell.
              Out­put of any kind is always sur­rounded by ” even if it is mul­ti­line output.

              con­tent

              a. get libevent (needed to install mem­cached)
              b. get mem­cached and ver­ify instal­la­tion
              c. use and test mem­cached within Java with junit/ant

              a. installing libevent 1.3

              a.1. check for cur­rent ver­sion of libevent

              a.1a.

              Log in as root or get super user rights by call­ing su

              # updat­edb
              # locate libevent

              If there is out­put includ­ing “libevent1” and/or “libevent-1″ (ignore pack­age files like *.deb) -> a.1b, oth­er­wise a.2

              a.1b. remov­ing old libevent version

              # apt-get remove –purge libevent1
              # Y

              # updat­edb
              # locate libevent
              Should now return noth­ing or pack­age files only, i.e. you are ready for installation

              a.2. installing libevent 1.3

              a.2a down­load­ing and unpacking

              # cd /usr/local/src
              # wget http://monkey.org/~provos/libevent-1.3b.tar.gz
              # tar zxvf libevent-1.3b.tar.gz
              # cd libevent-1.3b

              a.2b. con­fig­ur­ing

              # ./configure
              check the out­put, if it con­tains some­thing like “con­fig­ure: error: no accept­able C com­piler found in $PATH” -> a.2c. oth­er­wise a.2d.

              a.2c. com­pil­ing

              # apt-get install gcc

              Redo a.2b.
              I got out­put like “C com­piler can­not cre­ate exe­cuta­bles”, read­ing file ‘config.log’ did not help me at all. Googling finally did, as I found a forum entry, point­ing out a miss­ing lib.
              So try this:

              # apt-get install libc-dev

              Redo a.2b.
              If that did  not solve it… sorry … google on, there is no sense in going on with­out solv­ing this issue. :-/

              a.2d. make it!

              # make && make install

              If you get some­thing like “-bash: make: com­mand not found” -> A.2e, oth­er­wise A.3.

              a.2e.

              # apt-get install make

              Redo a.2d.

              a.3. con­fig­u­ra­tion

              Press the Esc key as you read [esc] in the com­mands below.

              # vim /etc/ld.so.conf.d/libevent-i386.conf
              # i/usr/local/lib/[esc]:wq
              # ldconfig

              b. install mem­chached and ver­ify installation

              b.1. down­load, unpack and install memchached

              # cd /usr/local/src
              # wget http://danga.com/memcached/dist/memcached-1.2.2.tar.gz
              # tar zxvf memcached-1.2.2.tar.gz
              # cd memcached-1.2.2
              # ./configure
              # make && make install

              After installing gcc and libc-dev in sec­tion a, this one went eas­ily for me — if you skipped sec­tion a and run in prob­lems here, please install gcc and libc-dev (see a.2c).

              b.2. ver­ify instal­la­tion of memchached

              b.2a. start mem­chached server

              # mem­cached –u www-data –vv

              Out­put should end with line “<3 server lis­ten­ing”. Per­fect! :)

              b.2b test server

              I will refer to this shell in front of you as server shell below. Now, open another shell on the same machine, I will refer to it a client shell.

              # tel­net local­host 11211

              You should see some­thing like “<7 new client con­nec­tion” on the server shell, switch back to client shell.

              # set test1 1 10000 1
              # a

              You should see “STORED” on client shell and the two fol­low­ing lines on server shell
              ”<7 set test1 1 10000 1
              >7 STORED

              Per­fect!
              You did it, your mem­cached is up and run­ning :)

              c. mem­cached and Java

              I wrote a lit­tle test pack­age using a Java client library for mem­cached from here, together with junit and ant. You can down­load it to have a look how sim­ple using mem­cache is and to ver­ify your instal­la­tion with an included  junit test, auto­mated with an ant build file.