Load Jquery in Chrome developer console

If you for some reason need to load chrome in the developer console and that page doesn’t include Jquery this is what you will need to do:

For http page:

var scriptElem = document.createElement(‘script’);
scriptElem.src = “http://code.jquery.com/jquery.js”;
document.getElementsByTagName(‘head’)[0].appendChild(scriptElem);

 

For https page:

var scriptElem = document.createElement(‘script’);
scriptElem.src = “https://code.jquery.com/jquery.js”;
document.getElementsByTagName(‘head’)[0].appendChild(scriptElem);

 

Now you can start Jquery.

 

jquery-in-chrome-console

Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Errors running builder ‘Android Pre Compiler’ on project

If you have this error

Errors running builder ‘Android Pre Compiler’ on project ‘XXX’

Than you might be running ADT 21
This is one possible workaround until the fix
  • Open properties of project in Eclipse
  • Then Resources -> Resource filters. Click the “Add…” button -> Check “Exclude all”, “Files and folders”, “All children”.
  • In the text entry box input “.svn” (without quotes).
  • Restart Eclipse.
Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Eclipse fix black toolip in Ubuntu 12.04+

After Install Ubuntu 12.04 I’ve realize that in Eclipse tooltips were with a black background. After a little googling I’ve found the solution.

Edit file /usr/share/themes/Ambiance/gtk-2.0/gtkrc
This file is used by theme Ambiance in ubuntu. If you use another theme you will have a diferent file path. Note themes are instaled here /usr/share/themes
After edit this file locate in the first lines:
tooltip_fg_color
tooltip_bg_color
These are the foreground and background colors of tooltips. Change the color to the values that you like. After a restart you will have the eclipse black tooltip fixed.
Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Path.combine in Java

In Dotnet and in particular in C# you can to Path.Combine

public static string Combine(
string path1,
string path2
);

This is a simple way to do something similar in Java:

public final class Path {
private Path() { }
public static String combine(final String... paths){
if(paths == null || paths.length == 0) {
return null;
}

File file = new File(paths[0]);
final int len = paths.length;
for (int i = 1; i < len; i++) {
file = new File(file, paths[i]);
}

return file.getPath();
}
}

Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Alpha numeric input filter

In Android you should know that it’s possible to specify input filters in EditText.
You should also know that it’s possible to create custom input filters. In this post I wil show how to create an Alpha numeric input filter.

First create a class that implements InputFilter

In this class you will have to implement the filter method.

In this method you will have to see if chars in source argument are valid. Every time a char is not valid you will have to return “” and ever time a char is valid you will have to return null.

this is a sample of what should be done:

public class AlphaNumericFilter implements InputFilter {
private Context _context;

public AlphaNumericFilter(Context context) {
this._context = context;
}

@Override
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {

for (int i = start; i < end; i++) {
if (!Character.isLetterOrDigit(source.charAt(i))) {
return “”;
}
}
return null;
}
}

To use it it’s simple.

For a EditText just do this:
this._editText = (EditText) findViewById(R.id.edit_text);
this._editText.setFilters(new InputFilter[]{ new AlphaNumericFilter(MyActivity.this)});

For a EditTextPreference just do this:
this._editText = (EditTextPreference) prefs.findPreference(“edit_text”);
this._editText.getEditText().setFilters(new InputFilter[]{new AlphaNumericFilter(MyPreferenceActivity.this) });;

Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Removing Xml declaration where saving a xml document

In .Net in order to remove the Xml Declaration that exists on the top of a xml document you will need to do something like this:

XmlDocument doc = new XmlDocument(); 

doc.LoadXml(message); 
 ... 
//save and don't generate xml declaration 
XmlWriterSettings writerSettings = new XmlWriterSettings(); 
writerSettings.OmitXmlDeclaration = true; 
StringBuilder stringBuilder = new StringBuilder(); 
using (XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, writerSettings)) { 
 doc.Save(xmlWriter); 
string newMessage = stringBuilder.ToString();
Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter