Today my phone has been eating my battery life like crazy. After some google searches I came arround that it is might be caused by a bad file or corrupted sd-card. I also unmounted my sd-card, but so far this was not the solution for my problem...


A quick hack for this problem is to kill the media service via a script.

If your phone is rooted, you can install a program that can run shell scripts like Script Manager - SManager on your phone.

Then run the following script to kill the media service:
#!/system/bin/sh
killall -9 android.process.media
killall -9 mediaserver

Baaaaam! :)

If you have any idea how I find out what file or error is causing my media service to crash, don't hesitate to contact me.


You have an iPhone storyboard and want to support the iPad too? This can be done in a quick way:

  1. Open Xcode
  2. Duplicate the existing storyboard.
  3. Rename them to "MainStoryboard_iPhone.storyboard" and "MainStoryboard_iPad.storyboard"
  4. Right click on the "MainStoryboard_iPad.storyboard" file > "Open as" > "Source code" 
  5. Search & Replace:
    targetRuntime="iOS.CocoaTouch"
    with:
    targetRuntime="iOS.CocoaTouch.iPad"
  6. Done!
You are developing with Sencha Touch and Eclipse? You want to have code completion and outline? ... Here I'll show you how to do it at no charge to you.
This tutorial works also for ExtJS developer, at least I tested it with ExtJS 4.x before. But actually I don't know if the required *.jsb3 file is still included their archives. May someone can confirm this?

Requirements:
  • Working installation of Eclipse with Aptana Studio Plug-in (tested with Eclipse Juno Service Release 2 and Aptana Studio 3.4.0)
  • Unzipped Sencha Touch 2.x.x (tested with Sencha Touch 2.2.1)
  • *.jsb3 file *
* Since .jsb3 file is no more included in the Sencha Touch 2.2.1 archive (I guess they wanna sell you the Sencha Architect instead), you can download it here directly:
Download Sencha Touch .jsb3

For the case you are new to Aptana, I can suggest you to watch the following video tutorial first.

In the next steps I will show you how to install and configure your Spket IDE:
  1. Download and copy the *.jsb3 file into the root directory of your extracted Sencha Touch archive (as a sibling of src)
  2. Start Eclipse.
  3. Goto Help > Install New Software
  4. Click the "add" button
    1. Name: Spket IDE
    2. Location: http://www.agpad.com/update/
  5. Select the Spket IDE Node and click the "Next" button (See Image1). Follow the installation steps.
  6. Restart Eclipse.
  7. In Eclipse, Windows > Preferences or just press  + ,
  8. Select "Spket" > "JavaScript Profile preference" page to display the installed JavaScript Profiles.
  9. Click the "New.." button. In the Name field, type "Sencha Touch" as the name for the new profile. Click "OK".
  10. Click the "Add Library" button. From the Library drop-down list, select "ExtJS". Click "OK".
  11. Click the "Add File" button, choose the *.jsb3 file, which you copied to the Sencha Touch root folder before (See step 1).
  12. Check all the available select boxes in the created profile.
  13. Select the Ext profile created in step 9, click the "Default" button. This makes it to the default profile for all your project.
  14. Click "OK" to save the preferences.
  15. Open your javascript file with the Spket JavaScript Editor. You can set Spket JavaScript Editor as the default editor. "Windows" > "Preferences" or just press  + ,"General" > "Editors" > "File Associations". Select the filetype "*.js". In associated editors select the Spket JavaScript Editor and press the "Default" button. See Image2.
  16. When you type "Ext.de" and press STRTG + SPACE your code should get completed.
  17. Done.



Mac OS X offers you a smart built-in solution to secure your files and folders. It is possible to create an encrypted disk image, it is like a regular disk image but requieres a password to become mounted. How this works, I'd like to show you in the following steps:
  1. Open Disk Utility (press + SPACE and type disk utility).
  2. File > New > Blank Disk Image.
  3. Type a name in the Save As field. This name will be used for the disk image.
  4. Choose a preferred location to save the *.dmg file.
  5. Select a size for the disk image.
  6. Choose as volume format the default Mac OS X Extended (Journaled)
  7. Use "sparse disk image" for a disk image that only uses as much space as it needs, rather than a set amount of space.
  8. Choose 128-bit AES encryption (or 256-bit AES in Mac OS X v10.5 or later, but slower). I would suggest 128-bit AES encryption. 
  9. Click on "Create" button.
  10. Enter a strong password and don't forget to deselect "Remember password (add to keychain)" if you don't want it saved. Because if you do, your created disk image is less secure.




Okay nothing new here, but maybe it inspires you to use "hot" keys more often  :)
  1. CRTL + Q goto last edit location
  2. CRTL + SPACE completes everything
  3. + S removes current line or selected lines
  4. + L goto line number
  5. + ALT + copies current line or selected lines to below
  6. + ALT + copies current line or selected lines to above
  7. ALT + moves current line or selected lines to below
  8. ALT + moves current line or selected lines to above
  9. + SHIFT + 7 Toggle comment*
  10. + goto the beginning of a line
  11. + goto the end of a line
  12. + SHIFT + L brings up a List of shortcut keys
Something missed? - See Windows -> Preference -> General -> Keys.

* You may have to disable the OS X hotkey (  + SHIFT + 7 brings up the help menu).




If you are sitting behind a proxy server you will probably have no internet connection in your Android emulator.

Solution: To configure your specific proxy settings, open Eclipse -> Run Configuration> Android Application > App > Target > Additional Emulator Command Line Options and add:

-http-proxy http://PROXY_PORT:PROXY_PORT

AJAX-Requests for local files are not working on Google Chrome.
XMLHttpRequest cannot load file:///Users/… . Origin null is not allowed by Access-Control-Allow-Origin
To bypass, either use a HTTP server or start Google Chrome with a command-line switch. Open the Terminal and type the command below:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files
If you receive a message like:
XMLHttpRequest cannot load ... Cross origin requests are only supported for HTTP.
Open the Terminal and type the command below:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security

As long as web security is disabled, it is not recommended to surf on public internet pages. In this mode your web browser is vulnerable for any kind of cross-site scripting.

For more information about Google Chrome command-line switches, take a look at Google Chrome command line switches.


Today I had a small problem - how to make hidden files and folders visible in Finder?

After some researches on the web, I found the following solution:

Open the Terminal and run the following command:
defaults write com.apple.finder AppleShowAllFiles TRUE
Before the changes will take effect, you need to restart Finder by running the following command:
killall Finder
Done!

To hide hidden files invisible again, open a Terminal and run the following command:
defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder


You want to use Time Machine over WIFI? - Then you have to buy a Time Capsule or you run a Time Machine at Ubuntu.

Tested with iOS 10.8.2 and Ubuntu Server 12.04

You did an unsuccessful installation before?

For the case that you did, remove Netatalk and all configuration files:
sudo apt-get remove --purge netatalk

Preparing the Ubuntu server...

From the Terminal (press + SPACE and type terminal) you have to run the following command to install Netatalk:
sudo apt-get install netatalk
Note: See also Netatalk HTML documentation for more details.
Configure the afpd server:
sudo vi /etc/netatalk/afpd.conf
Add the following line at the end of this file:
- -tcp -noddp -uamlist uams_dhx.so,uams_dhx2_passwd.so -nosavepassword
Check if CNID_METAD_RUN=yes in "/etc/default/netatalk" file. Otherwise change it. Create a new user for the Time Machine connect:
sudo adduser username
Go to the newly created user directory and create a backup folder there:
cd /home/username/
mkdir time_backup
sudo chown -R username:username time_backup
Configure the newly created backup directory in Netatalk:
sudo vi /etc/netatalk/AppleVolumes.default
At the end of the file you add the following entry:
/home/username/time_backup "My Time Machine Backup" allow:username cnidscheme:dbd volsizelimit:250000 options:usedots,upriv,tm
Make sure that you adjust the directory and username to your needs. With "volsizelimit" you can define the maximum size of the backup. In this case 250 GB.

After you are finished with all the configuration staff you need to restart the Netatalk service:
sudo service netatalk restart
Don't forget to allow afp if you are using ufw - Uncomplicated Firewall:
# Allow network access to the ports 548 and 427
sudo ufw allow 548
sudo ufw allow 427
sudo ufw disable && sudo ufw enable 

Preparing the Mac client...

To allow unsupported network volumes, you have to run the following command in Terminal (press + SPACE and type terminal):
defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
"Connect to your server" (open Finder and press + K) and type the address of your server:
afp://ip_address
Congrats, your Ubuntu server volume should be visible and ready for Time Machine usage now.
From the Terminal (press + SPACE and type terminal) you will run the following commands:
sudo apt-get install apache2
sudo apt-get install php5
sudo /etc/init.d/apache2 restart
Note: Your web folder is in "/var/www". If you restart the Apache HTTP Server you maybe get the following message:
* Restarting web server apache2                                                                                              apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
 ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
The solution to fix it is really simple, you just add the ServerName directive to "/etc/apache2/httpd.conf":
sudo vi /etc/apache2/httpd.conf
Add the line: ServerName localhost

Finally restart the Apache HTTP Server:
sudo /etc/init.d/apache2 restart
done!


Well, there are many ways to access a Mac via remote desktop... I'll explain a very simple way here.

On your Mac, go to Settings -> Sharing -> Screen Sharing and enable the VNC option + a password. Make sure that you have enabled the Screen Sharing itself too.

That's it! Your Mac is ready for a VNC connection now.

If you want to connect to your Mac from another computer, you can use a client like http://www.realvnc.com/.
One of the most important features of style sheets is that they specify how a document is to be presented on different media: screen, beamer, printer, with a speech synthesizer etc.

When you take a look at the ICEfaces TLD Reference you will ascertain, that the media attribute is not supported for ice:outputStyle tag.

When you now say, no problem - I'll take the normal HTML "link"-tag to do the same, you are wrong. When you need components like ice:inputFile, you must define your style sheets with ice:outputStyle. Otherwise your iFrame (where the input file component is placed) will not include the style information from the top site.

Here are the things I would like you to focus on:
  1. Change component class
  2. Change renderer class
  3. Register the custom classes in faces config
  4. Test and Hints

Change component class

At first we need the OutputStyle class from  ICEfaces svn http://www.icefaces.org/main/community/svninfo.iface.

My examples are based on ICEfaces V1.8.2 RC2.

Todo:
  • set a private string member "media"
  • implement public getter and setter methods for media
  • extend the existing saveState and restoreState methods with some "media" stuff. That should be self explanatory.
Here is the new OutputStyle class:

package com.yourcompany.faces.custom.component;

// Version: MPL 1.1/GPL 2.0/LGPL 2.1
//
// "The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations under
// the License.
//
// The Original Code is ICEfaces 1.5 open source software code, released
// November 5, 2006. The Initial Developer of the Original Code is ICEsoft
// Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
// 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
//
// Contributor(s): _____________________.
//
// Alternatively, the contents of this file may be used under the terms of
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
// License), in which case the provisions of the LGPL License are
// applicable instead of those above. If you wish to allow use of your
// version of this file only under the terms of the LGPL License and not to
// allow others to use your version of this file under the MPL, indicate
// your decision by deleting the provisions above and replace them with
// the notice and other provisions required by the LGPL License. If you do
// not delete the provisions above, a recipient may use your version of
// this file under either the MPL or the LGPL License."


import javax.faces.component.UIComponentBase;
import javax.faces.el.ValueBinding;
import javax.faces.context.FacesContext;

public class OutputStyle extends UIComponentBase {

    public static final String COMPONENT_TYPE =
            "com.icesoft.faces.OutputStyleComp";
    public static final String COMPONENT_FAMILY =
            "com.icesoft.faces.OutputStyle";
    public static final String DEFAULT_RENDERER_TYPE =
            "com.icesoft.faces.style.OutputStyleRenderer";

    private String href;
    private String userAgent;
    private String media;

    public OutputStyle() {
        super();
    }

    public String getFamily() {
        return COMPONENT_FAMILY;
    }

    public String getRendererType() {
        return DEFAULT_RENDERER_TYPE;
    }

    public String getHref() {
        if (href != null) {
            return href;
        }
        ValueBinding vb = getValueBinding("href");
        if (vb != null) {
            return (String) vb.getValue(getFacesContext());
        }
        return null;
    }

    public String getUserAgent() {
        return userAgent;
    }

    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }
    
    
    public String getMedia() {
        return media;
    }

    public void setMedia(String media) {
        this.media = media;
    }

    public void setHref(String href) {
        this.href = href;
    }

    public Object saveState(FacesContext context) {
        Object values[] = new Object[5];
        values[0] = super.saveState(context);
        values[1] = href;
        values[2] = userAgent;
        values[3] = media;
        return ((Object) (values));
    }

    public void restoreState(FacesContext context, Object state) {
        Object values[] = (Object[]) state;
        super.restoreState(context, values[0]);
        href = (String) values[1];
        userAgent = (String) values[2];
        media = userAgent = (String) values[3];
    }
}

Change renderer class

Now we need the OutputStyleRenderer class from svn.

Todo:
  • Correct the import directive for OutputStyles so that are custom component is pointed
  • Enhance the encodeEnd method with the new media attribute logic.
  • extend the existing saveState and restoreState methods with some "media" stuff. That should be self explanatory.
Here is the whole OutputStyleRenderer class:
package com.yourcompany.faces.custom.renderer;

// Version: MPL 1.1/GPL 2.0/LGPL 2.1
//
// "The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations under
// the License.
//
// The Original Code is ICEfaces 1.5 open source software code, released
// November 5, 2006. The Initial Developer of the Original Code is ICEsoft
// Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
// 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
//
// Contributor(s): _____________________.
//
// Alternatively, the contents of this file may be used under the terms of
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
// License), in which case the provisions of the LGPL License are
// applicable instead of those above. If you wish to allow use of your
// version of this file only under the terms of the LGPL License and not to
// allow others to use your version of this file under the MPL, indicate
// your decision by deleting the provisions above and replace them with
// the notice and other provisions required by the LGPL License. If you do
// not delete the provisions above, a recipient may use your version of
// this file under either the MPL or the LGPL License."

import com.icesoft.faces.context.DOMContext;
import com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer;
import com.icesoft.faces.renderkit.dom_html_basic.HTML;
import com.icesoft.faces.util.CoreUtils;
import com.yourcompany.faces.custom.component.OutputStyle;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Element;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import java.beans.Beans;
import java.io.IOException;

public class OutputStyleRenderer extends DomBasicRenderer {

    private static Log log = LogFactory.getLog(OutputStyleRenderer.class);
    private static final String IE_EXTENTION = "_ie";
    private static final String IE_7_EXTENTION = "_ie7";
    private static final String IE_8_EXTENSION = "_ie8";
    private static final String SAFARI_EXTENTION = "_safari";
    private static final String SAFARI_MOBILE_EXTENTION = "_safarimobile";
    private static final String CSS_EXTENTION = ".css";
    private static final String DT_EXTENTION = "_dt";
    private static final String OPERA_EXTENTION = "_opera";
    private static final String OPERA_MOBILE_EXTENTION = "_operamobile";

    private static final int DEFAULT_TYPE = 0;
    private static final int IE = 1;
    private static final int SAFARI = 2;
    private static final int DT = 3;
    private static final int IE_7 = 4;
    private static final int SAFARI_MOBILE = 5;
    private static final int OPERA = 6;
    private static final int OPERA_MOBILE = 7;
    private static final int IE_8 = 8;

    public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
            throws IOException {
        validateParameters(facesContext, uiComponent, OutputStyle.class);
        try {
            DOMContext domContext =
                    DOMContext.attachDOMContext(facesContext, uiComponent);
            if (!domContext.isInitialized()) {
                OutputStyle outputStyle = (OutputStyle) uiComponent;
                Element styleEle = buildCssElement(domContext);
                String href = outputStyle.getHref();
                styleEle.setAttribute(HTML.HREF_ATTR, getResourceURL(facesContext,href));
                
                String media = outputStyle.getMedia();
                
                if(media != null) styleEle.setAttribute("media", getResourceURL(facesContext,media));
                
                domContext.setRootNode(styleEle);
                int browserType = browserType(facesContext, uiComponent);
                if (browserType != DEFAULT_TYPE) {
                    if (href.endsWith(CSS_EXTENTION)) {
                        int i = href.indexOf(CSS_EXTENTION);
                        if (i > 0) {
                            String start = href.substring(0, i);
                            Element ieStyleEle = buildCssElement(domContext);
                            String extention = IE_EXTENTION;
                            if (browserType == SAFARI) {
                                extention = SAFARI_EXTENTION;
                            }
                            if (browserType == DT) {
                                extention = DT_EXTENTION;
                            }
                            if(browserType == IE_7){
                                extention = IE_7_EXTENTION;
                            }
                            if(browserType == IE_8){
                                extention = IE_8_EXTENSION;
                            }
                            if(browserType == SAFARI_MOBILE){
                                extention = SAFARI_MOBILE_EXTENTION;
                            }
                            if(browserType == OPERA){
                                extention = OPERA_EXTENTION;
                            }
                            if(browserType == OPERA_MOBILE){
                                extention = OPERA_MOBILE_EXTENTION;
                            }
                            // W3C spec: To make a style sheet preferred, set the rel attribute to "stylesheet" and name the style sheet with the title attribute
                            ieStyleEle.setAttribute(HTML.TITLE_ATTR, extention);
                            String hrefURL = CoreUtils.resolveResourceURL(facesContext, start + extention + CSS_EXTENTION);
                            ieStyleEle.setAttribute(HTML.HREF_ATTR, hrefURL);
                            styleEle.getParentNode().appendChild(ieStyleEle);
                        } else {
                            throw new RuntimeException(
                                    "OutputStyle file attribute is too short. " +
                                    "Needs at least one character before .css. Current Value is [" +
                                    href + "]");
                        }
                    } else {
                        throw new RuntimeException(
                                "OutputStyle file attribute must end in .css. " +
                                "Current Value is [" + href + "]");
                    }
                }

            }
            domContext.stepOver();
        } catch (Exception e) {
            log.error("Error in OutputStyleRenderer", e);
        }
    }

    private Element buildCssElement(DOMContext domContext) {
        Element styleEle = domContext.createElement("link");
        styleEle.setAttribute(HTML.REL_ATTR, "stylesheet");
        styleEle.setAttribute(HTML.TYPE_ATTR, "text/css");
        return styleEle;
    }

    private int browserType(FacesContext facesContext, UIComponent uiComponent) {
        int result = DEFAULT_TYPE;
        String useragent = ((OutputStyle)uiComponent).getUserAgent();
        if(useragent != null){
            return _browserType(useragent);
        }

        Object o = facesContext.getExternalContext().getRequest();
        if (o != null) {
            if (o instanceof HttpServletRequest) {
                HttpServletRequest request = (HttpServletRequest) o;
                useragent = request.getHeader("user-agent");
                if(useragent == null){
                    useragent = ((OutputStyle)uiComponent).getUserAgent();
                }
                if(useragent == null){
                 if (log.isDebugEnabled()) {
                  log.debug("Not able to find user agent. Returning default");
                 }
                    return DEFAULT_TYPE;
                }
                if(((OutputStyle)uiComponent).getUserAgent() == null){
                    ((OutputStyle)uiComponent).setUserAgent(useragent.toLowerCase());
                }
                String user = useragent.toLowerCase();
                result = _browserType( user);

            } else {
             if (log.isDebugEnabled()) {
              log.debug(
                        "OutputStyleRenderer: Request is not HttpServletRequest. Its [" +
                        o.getClass().getName() + "]");
             }
            }
        } else {
         if (log.isDebugEnabled()) {
          log.debug(
                    "IceStyleReader: facesContext.getExternalContext().getRequest() is null");
         }
        }
        return result;
    }

    private int _browserType(String user) {
        int result = DEFAULT_TYPE;
        if (Beans.isDesignTime()) {
            result = DT;
        } else {
            if (user.indexOf("opera") < 0 && user.indexOf("msie") != -1) {
                result = IE;
                if(user.indexOf("msie 7") != -1){
                    result = IE_7;
                }
                if(user.indexOf("msie 8") != -1){
                    result = IE_8;
                }
            } else if (user.indexOf("safari") != -1) {
                result = SAFARI;
                if(user.indexOf("mobile") != -1) {
                    result = SAFARI_MOBILE;
                }
            } else if (user.indexOf("opera") != -1) {
                result = OPERA;
                if(user.indexOf("240x320") != -1) {
                    result = OPERA_MOBILE;
                }
            }
        }
        return result;
    }
}

Register the custom classes in faces config

The last step is to register our new logic in the faces-config.

<component>
  <description>Links one or more theme CSS files into the page</description>
  <display-name>Output Style</display-name>
  <component-type>com.icesoft.faces.OutputStyleComp</component-type>
  <component-class>com.yourcompany.faces.custom.component.OutputStyle</component-class>
  <component-extension>
   <base-component-type>com.sun.faces.Component</base-component-type>
   <component-family>com.icesoft.faces.OutputStyle</component-family>
   <renderer-type>com.yourcompany.faces.custom.renderer.OutputStyleRenderer</renderer-type>
  </component-extension>
</component>

<render-kit>
  <render-kit-id>ICEfacesRenderKit</render-kit-id>
  <render-kit-class>com.icesoft.faces.renderkit.D2DRenderKit</render-kit-class>
  <renderer>
   <component-family>com.icesoft.faces.OutputStyle</component-family>
   <renderer-type>com.icesoft.faces.style.OutputStyleRenderer</renderer-type>
   <renderer-class>com.yourcompany.faces.custom.renderer.OutputStyleRenderer</renderer-class>
  </renderer>
 </render-kit>

Test and Hints

When all changes are done the new tag should be avalaible now. Simply type in your template:

<ice:outputStyle href="/css/yourStyle.css" media="all"/>
<ice:outputStyle href="/css/yourPrintStyle.css" media="print"/>

Hint: When you want to use the media attribute in an iFrame component like ice:inputFile too, you need to modifiy some more things. In this case you've to modify the class InputFile and a re-build of the ICEfaces libs is essential.