Saturday, December 15, 2012

Jailbreaking Windows Phone 7.5 HTC Titan

I have a HTC Titan (X310e) which suddenly turned into garbage when it would only show a garbled home screen after having the screen turned off once (Everything looked fine after reboot). Also all my email "apps" were missing and I could not access anything social (People, or settings about People og social networks).

After lots of Googling, I gave up on finding a solution online. I decided to delete everything on the phone and jailbreak it (since vanilla WP7 didn't have any backup functions anyways).

I followed this tutorial: forum.xda-developers.com/showpost.php?p=26842868&postcount=46
So thanks to dragonide from XDA Developers.

The tutorial was good, but I'll add some minor details that might be useful:
  • Download files from:
    DFT__HSPL_WP7SG1.rar: http://htcfanboys.com/download/cotulla/?action=view&file=10777
    DFT Eternity 24 langs Freedom V1 Pearl Edition.7z: http://forum.xda-developers.com/showthread.php?t=1684907
    RUU_ETERNITY_Radio_Signed_17.5006.08.27_17.08.50.06.7z: http://www.mediafire.com/download.php?6i5r5a5amkwx8h
  • Turn off your phone and disconnect it from the computer.
  • Remove your SIM card.
  • Hold volume up and down then press power. continue holding the volume buttons.
  • When you see green text on white background with for example version PI39100
    Radio 17.0...
    ..., you are in SPL. It should also say "Serial" about 2/3 of the way down the screen
  •  Connect to computer with USB. you might have to try different USB ports. Check"Safely Remove Hardware and Eject Media" in the system tray; My phone came up as Titan USB Sync on some ports, in that case flashing failed with 264 and 266 errors. (See http://forum.xda-developers.com/wiki/index.php?title=Elf_RUU_Error_Codes for explanation of errors). When it came up as Qualcomm CDMA Technologies MSM on a port, flashing worked fine.
  • Unpack DFT__HSPL_WP7SG1.rar using for example 7-Zip (http://www.7-zip.org/), just right click the file and select open archive.
  • Run \DFT_HSPL_WP7SG1\1_SPL205\TITAN\ROMUpdateUtility.exe and follow instructions (takes about 1 min).
  •  You should see the progress bar in parallel on both the computer and the phone.
  • When complete, the phone reboots. Hold the volume buttons until you enter SPL. Notice that it now says "HSPL2.5.160015.3 (137079)" and "Radio-16.23.06.10" (Radio was 17... before flashing on my phone).
  • Run \DFT_HSPL_WP7SG1\2_HSPL\DFT_HSPL_WP7SG1_INSTALL.exe and follow instructions (install HSPL) (takes about 1 min).
  • Phone will reboot after flashing. When rebooting, hold volume to enter SPL.
  •  Unpack DFT Eternity 24 langs Freedom V1 Pearl Edition.7z.
  •  Run \DFT Eternity 24 langs Freedom V1 Pearl Edition\ROMUpdateUtility.exe and follow instructions (takes about 10 min).
  • After completing flashing the phone will reboot and probably hang/freeze on boot (just showing the HTC logo). Reboot phone (just hold the power button or remove the battery). Hold volume buttons to enter SPL.
  • Unpack RUU_ETERNITY_Radio_Signed_17.5006.08.27_17.08.50.06.7z
  • Run \RUU_ETERNITY_Radio_Signed_17.5006.08.27_17.08.50.06\ROMUpdateUtility.exe (takes less than 1 minute).
  • After flashing, the phone reboots, hold volume buttons to enter SPL and check that Radio is now 17.5006.08.27
  • Turn off the phone (remove the battery).
  • Put your SIM card back in.
  • Power on the phone like normal and go through the Windows Phone 7 setup process.
  • Enjoy jailbroken WP7.
Note: My system is a Windows 7 machine, things may differ on your system.

Images of what you should expect to see (sorry for the blur):











Thanks to Sources:
http://windowsphone.stackexchange.com/questions/173/what-are-the-options-for-developer-unlocking-a-wp7-device
http://windowsphonehacker.com/articles/hspl_and_first_custom_roms_out_for_htc_titan_radar-06-01-12
http://forum.xda-developers.com/showthread.php?t=1684912
http://forum.xda-developers.com/showthread.php?t=1684907
http://forum.xda-developers.com/showthread.php?t=1684912&page=11
http://forum.xda-developers.com/showpost.php?p=26842868&postcount=46
http://forum.xda-developers.com/wiki/index.php?title=Elf_RUU_Error_Codes
http://forum.xda-developers.com/wiki/ActiveSync

Thursday, November 15, 2012

Wednesday, November 14, 2012

Play 2 Framework Limit Request Data

My form had more fields than I wanted to save (lists of multiple models). And I only wanted to validate and save one data set (list of models) at a time.

To solve this I added one submit button per list of models and a name tag, with the id of my model list, to each submit button:

<input type="submit" name="@modellist.id" value="Save Model @modellist.id">

In my controller I now wanted to remove all the fields that were irrelevant before validation (So I wouldn't get any errors on those fields). From all the submitted models I wanted to fetch all models that matched my submit button's modelid:

(Note: To accomodate the lists of models, I have created a class which contains a map of all models submitted by the form, so thats why I'm working with maps. If you have a simpler setup this idea might be more easily done)

Form<ModelMap> modelMapForm = form(ModelMap.class);

// Remove unwanted models depending on which submit button has been pressed.
DynamicForm requestData = form().bindFromRequest(); // Doesn't try to match values to a "model"
Form<ModelMap> filledModelMapForm = ModelMapForm.bindFromRequest();
ModelMap allModelMap = filledModelMapForm.get();
ModelMap wantedModelMap = new ModelMap();
for (int modelid : modelids) {
    // Check if modelid is in POST data, if yes than that button was pressed and we want that data.
    if (requestData.get(""   modelid) != null) {
        for (Map.Entry<String, Model> entry : allModelMap.models.entrySet()) {
            if (entry.getKey().endsWith(""   modelid)) {
                wantedModelMap.models.put(entry.getKey(), entry.getValue());
            }
        }
    }
}
// Place wanted values in filledModelMapForm for validation and saving
filledModelMapForm = filledModelMapForm.fill(wantedModelMap);
// Place all values in allModelMapForm so that they are shown in case of errors
Form<ModelMap> allModelMapForm = ModelMapForm.bindFromRequest();

if (filledAnswerMapForm.hasErrors()) {
    allModelMapForm.reject("Error, please correct it.");
    return badRequest(view.render(<other values>, allModelMapForm));
}
else {
    ModelMap saveModelMap = filledModelMapForm.get();
    // Process form...
}


Maybe this solves your problem or helps you solve it. :) If you find a more elegant way, please don't hesitate to tell me below.

Source: https://groups.google.com/forum/?fromgroups=#!topic/play-framework/TRzjAwVvVEM

Tuesday, October 30, 2012

Copy all text in a Gnome terminal

Shamelessly copied from arsane on superuser.com (Thanks)

Instead of dragging mouse to select all text:

1. Triple click the last line of current terminal(do not release the mouse).
2. Press SHIFT+HOME key which will lead us to the first line.
3. Drag mouse to the first line.
4. Right click , edit->copy.

See http://superuser.com/a/80175.

Apache Felix LinkageError

I was getting java.lang.LinkageError when running Felix. I had a big trouble finding out what the problem really was.

Finally, I found that javax.activation was being loaded by two modules differently (See http://frankkieviet.blogspot.no/2009/03/javalanglinkageerror-loader-constraint.html and http://stackoverflow.com/questions/4270950/compile-time-vs-run-time-dependency-java).

I couldn't exclude javax.activation from any of my modules (tried to explicitly ignore it from my pom.xml files (Maven), but that didn't work).

In the end I discovered that felix automatically loads some packages on startup. This is specified in the org.osgi.framework.system.packages.extra variable in config.properties (In the conf folder).
Just adding javax.activation;version=1.1.1 (The version I wanted) there fixed it.
Now Felix loads the package, and my waring modules fetch it from there instead of trying to load it themselves.

Sources: http://devangelist.blogspot.no/2011/04/osgi-bundle-lifecycles.html,
http://stackoverflow.com/questions/6097279/java-lang-linkageerror-loader-constraint-violation-in-grails-project,
http://fusesource.com/forums/message.jspa?messageID=14613,
http://fusesource.com/forums/thread.jspa?messageID=7682

Play 2 Framework as a Windows Service

I wanted to run Play2 as a Windows Service, but had problems getting it to work with the usual methods (SC.exe) (See http://www.herikstad.net/2012/10/run-as-windows-service.html for others).

Ended up using RunAsSvc from PirmaSoft. Here is how:


1. In command prompt. Go to your project folder. Run play dist. This will create a ZIP file in the dist folder of your project.
3. Unzip the ZIP file in a location of your choice-
4. Download RunAsSvc from http://www.pirmasoft.de/runassvc.php and unzip it in a location of your choice.
5. Run RunAsSvc.exe as an Administrator
 5.1 Choose a Name for your service
 5.2 Choose a Description for your service
 5.3 In "Path to executable" browse to your Java/bin folder (e.g. C:\Program Files\Java\jre7\bin) and choose java.exe
 5.4 In "Parameters" Enter: -Dhttp.port=80 -cp "./lib/*;" play.core.server.NettyServer . (you only need the -Dhttp.port=80 flag if you want to set the port to something other than 9000).
 5.5 Set the working directory to the locations where you unzipped the project ZIP file.
 5.6 Press OK and check that you now can find your service in the Service panel (services.msc) and that you can open your webpage in your browser.

To delete the service, go to "Add/Remove Programs" and find PirmaSoft RunAsSvc - <your service name> and select uninstall.

If the service won't run, check that there is no RUNNING_PID file in the folder where you unzipped the ZIP file.

To see the process in Task Manager: Select "Show processes from all users", it will be a java.exe running as SYSTEM.

Sources:  https://groups.google.com/forum/?fromgroups=#!topic/play-framework/xykhfyVu_Y0,
http://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute,
http://stackoverflow.com/questions/10894615/play-framework-bat-windows-java-process,
http://stackoverflow.com/questions/9941689/how-to-change-http-port-that-play2-is-listening-on

Run as Windows Service

Sometimes you want to be able to run a program in the background, and to keep it running even though you are not logged in. Some programs give you the possibility to set them up as services, here are some ways to install any program as a service:

1. Using SC to install it yourself (sc "MyServiceName" binPath= "C:\myservice\my.exe", note the space after binPath)
2. Using instsrv.exe and srvany.exe
3. More types (For 1,2, and 3: http://www.msfn.org/board/topic/83272-how-to-run-a-program-as-a-service/)
4. Adding the script as a Startup Script in Group Policy (http://techsupt.winbatch.com/ts/T000001048F90.html) (gpedit.msc)
5. Using the nice little tool RunAsSvc from Pirmasoft (http://www.pirmasoft.com/runassvc.php)
6. Using YAJSW (Yet Another Java Service Wrapper) (http://yajsw.sourceforge.net/#mozTocId212903)
7. Using JSW (Java Service Wrapper) (http://wrapper.tanukisoftware.com/doc/english/download.jsp)

Source: http://www.msfn.org/board/topic/83272-how-to-run-a-program-as-a-service/

Wednesday, October 24, 2012

JBoss Wrapper PropertyNotFoundException

After setting up JBoss to be run through a Java Service Wrapper from Tanuki Software (http://wrapper.tanukisoftware.com/doc/english/integrate-simple-nix.html) I got the following exception:

Caused by: javax.el.PropertyNotFoundException: /page.xhtml @20,20 value="#{objectname.fieldname}": Target Unreachable, identifier 'objectname' resolved to null

Turns out this is because the wrapper.conf file field wrapper.app.parameter.2 can't handle the bind address (-b 192.168.1.50) flag if used exactly as in the command line.

To fix, remove the space between the -b and the IP address:
wrapper.app.parameter.2=-b192.168.1.50

Solutions source: https://community.jboss.org/thread/93706

Tuesday, October 2, 2012

Installing xlrd module in Portable Python

Portable Python is a neat project to put python on a USB stick (or wherever) to not have to install it on your machine. xlrd is an excellent Python module for reading Excel files.
To make the xlrd module available in your Portable Python installation (so you can use it in a script using import xlrd) you just have to copy the source files:
1. Install Portable Python to a location of your choice. http://www.portablepython.com/
2. Download xlrd http://pypi.python.org/pypi/xlrd
3. Extract the xlrd tar.gz file
4. Copy the files found in xlrd folder (e.g.xlrd-0.8.0.tar.gz\dist\xlrd-0.8.0.tar\xlrd-0.8.0\xlrd\) to the App\lib directory of the Portable Python installation.
I suggest you create a directory for the files (e.g. Portable Python 2.7.3.1\App\Lib\xlrd).
5. Start using xlrd in scripts run using Portable Python

Source: https://groups.google.com/d/topic/portablepython/IXqu0Y1Hcug/discussion

Sunday, September 30, 2012

Connect to MS SQL Server using Python

Steps to take to connect to a MS SQL Server using Python. In this case using the python ODBC module pyodbc.
1. Download pyodbc from http://code.google.com/p/pyodbc/downloads/list, get the newest 32-bit version (even if you have 64-bit OS), since you need to have a paid license to use the 64-bit version. The 32-bit version is free.
2. Check what ODBC client you have for MS SQL Server. Go to Control Panel -> Administrative Tools -> Data Sources (ODBC) -> Drivers tab (on Windows 7). You will hopefully see a list of drivers to choose from. I had SQL Server and SQL Server Native Client 10.0. You will need the whole name in the next step.
3. Here is a sample program to fetch data from a table:
# -*- coding: utf-8 -*-
import pyodbc

CONNECTION_STRING="""
Driver={SQL Server Native Client 10.0};
Server=localhost\sqlexpress;
Database=MYDB_DB;
Trusted_Connection=yes;
"""

db = pyodbc.connect(CONNECTION_STRING)
c = db.cursor()
c.execute ('SELECT * FROM users')
rs = c.fetchall()
for r in rs:
    print r[0]

Notice how we put the driver name from step 2. into the Driver parameter, the Server parameter should point to your server and the Database should be the name of your database. The triple quotations is just to let us have the connection string on multiple lines in the code, you could use a single quotation mark and have it all on the same line.

Sources: http://community.activestate.com/forum/how-instal-pyodbc-module, http://stackoverflow.com/questions/289978/whats-the-simplest-way-to-access-mssql-with-python-or-ironpython, http://code.google.com/p/pyodbc/wiki/GettingStarted, http://stackoverflow.com/questions/10558354/using-microsoft-access-database-mdb-with-python-on-ubuntu

Tuesday, September 18, 2012

Python writing UTF-8 files

Some steps to take to create UTF-8 files with Python:
1. use codecs module to read and write files:
import codecs
f = codecs.open('file.txt', mode="w", encoding="utf-8-sig")
2. Don't mix strings and unicode. (Always prefix "strings" with u (e.g. u"hello world"))
3. Start your python script with # -*- coding: utf-8 -*- in case you might have any unicode characters in your code or in hardcoded "strings" in your script.

4. Also read http://lobstertech.com/python_unicode.html and http://www.evanjones.ca/python-utf8.html for more info on using UTF-8/unicode with Python.

Other sources:
http://docs.python.org/howto/unicode.html
http://www.carlosble.com/2010/12/understanding-python-and-unicode/

Transact SQL Arithmetic overflow error

Getting
Arithmetic overflow error converting numeric to data type numeric.
when trying to insert into your MS SQL (Transact SQL) table?

Most probably this is caused by the datatype of your field. If the type is for example numeric(18,18) this does not mean that you can have 18 digits before the decimal point and 18 after. It actually means that you can have a total of 18 digits (specified by the first value) and 18 digits after the decimal point.

As you might realize this means you can't have any values larger or equal than 1.0 in your field.

So, if that's what your're trying to do, change the field type to for example numeric(18,5) which will give you 5 digits in front of the decimal point and 13 after.

Source: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=35602

Thursday, August 23, 2012

.NET XAML binding more than one property

When making views using XAML and with .NET you might sometimes want to combine more than one property into a textblock (e.g. for example showing the breadcrumbs of your location in a textblock). Something like the following for example:
Location1.Title + "." + Location2.Title + "." + Location3.Title

There are several ways of doing this.

One is creating a custom converter for MultiBinding that creates the string for you, pretty well explained here:
http://msdn.microsoft.com/en-us/library/system.windows.data.multibinding.converter.aspx
Which seems to be the common suggestion, but it involves writing a lot of code for just one field. And you might have to do this often!

Alternatively you can just combine a bunch of textblocks:
<textblock text="{Binding Path=Location1.Title}" />
<textblock text=", " />
<textblock text="{Binding Path=Location2.Title}" />
<textblock text=", " />
<textblock text="{Binding Path=Location3.Title}" />
Which is ok, but gets messy.

Or, you can (Since .NET 3.5 SP1) use MultiBinding property StringFormat:
<TextBlock Margin="5,0,0,0">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}, {1}, {2}">
<Binding Path="Location1.Title"/>
<Binding Path="Location2.Title"/>
<Binding Path="Location3.Title"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>

Note the empty bracket at the start of the StringFormat. When the XAML reader sees an opening bracket it reads this as the start of a markup extension (Binding). The empty bracket is an escape sequence to prevent the XAML reader from trying to interpret the {0} as a binding.
Note2: A space character will also work (" {0}, {1}, {2}").

Sources: http://stackoverflow.com/questions/505397/built-in-wpf-ivalueconverters, http://stackoverflow.com/questions/9001974/strange-multibinding-stringformat-issue, http://msdn.microsoft.com/en-us/library/ms744986.aspx

Friday, August 3, 2012

MySQL VS Oracle SQL

Listed below are ways to achieve the same in Oracle SQL as in MySQL:

The equivalent of LIMIT in MySQL is ROWNUM in Oracle SQL:
MySQL: SELECT * FROM table LIMIT 10;
Oracle SQL: SELECT * FROM table WHERE ROWNUM <= 10

Solution found at: http://www.delphifaq.com/faq/databases/oracle/f594.shtml

Thursday, July 26, 2012

Stop Firefox download window from blinking

The window that opens when you download a file in Firefox may sometimes be annoying, either because it pops up when you're trying to do something else or that the button/window on the windows taskbar starts to blink.

Firefox lets you disable these features through its advanced properties. Enter about:config into the address bar of Firefox, accept the "I'll be careful, I promise!" warning. Then enter one of the following in the Search field at the top:

browser.download.manager.flashCount - set to 0 (zero) to disable blinking in windows taskbar.

browser.download.manager.showWhenStarting - set to false to prevent the download window from showing at all (it won't open if it's not already open) when you start a download.

browser.download.manager.focusWhenStarting - set to false to keep the download window from stealing focus/showing when a download starts.

Almost directly copied from http://superuser.com/questions/63762/is-there-way-to-disable-download-bar-blinking-in-firefox, thanks to Adam Ryan. :)

Tuesday, May 29, 2012

Windows Phone 7 podcast workaround

In any other country than the U.S., podcasts are not available in the WP7 marketplace. To get podcasts you can either use a third party app (like Simply Podcast which streams your podcasts when you requests them) or use the Zune software on your computer.

This might sound horrible, "I have to connect my phone to my computer to get podcast like some ipod". However, once you've added the podcast to your phone in the Zune software you can then go to Music+Videos on your phone, select Subscribe and have your phone automatically download the latest episodes when it is connected to a Wifi network.

Just slightly annoying. :)

Tuesday, March 27, 2012

Android SMS & MMS Backup

If you want to backup your SMSes and MMSes from your Android phone I found 2 apps to do this:

SMS Backup & Restore by Ritesh Sahu - Excellent for backing up your SMSes to an XML with included XSL file for easy reading in a webbrowser.
Save MMS by Andrew Schwimmer - Let you save MMS images one by one, ok if you don't have more than maximum a couple of hundred MMS images to save.

They both save data to your SD card which you can then copy when connecting your mobile to a computer or just pop in the SD card in a pc with a card reader.

Thx to for SMS backup: http://androidforums.com/htc-droid-incredible/281188-sms-mms-back-up.html,

WP7 Marketplace app not available

When first trying to use the Windows Phone 7.5 Marketplace you might get the message "This might be because your phone software needs to be updated, the application is exclusive to a different mobile provider, or the app is not available in your region". Especially if you live outside of the US or UK.

To fix make sure your regional settings on the phone (Settings -> system -> region + language) are set to the same as your Windows Live ID that you are using for your phone.
Apparently you might also want to set region settings for Zune.net (I did not have to do this).

Read this on http://answers.microsoft.com/en-us/winphone/forum/wp7-sync/market-place-not-availavle-for-your-region-yet/74c7a9fd-34cd-4bd7-8349-59f07fcf923a#1a7f23cc-80ef-473a-9f94-e2d7fcac7379

Wednesday, March 21, 2012

MySQL specify index without FORCE INDEX

Here's a blog post from Shlomi Noach which displays some useful steps to consider when optimizing MySQL querie where MySQL chooses an inefficient index.
It helped me. Especially the part about tricking MySQL to not use an index, without using USE INDEX or FORCE INDEX (which can be very bad if you have a dynamic query or your tables change/grow, something they usually do).

http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index

Note that Solution #7: Make MySQL think the problem is harder than it really is can also be applied to GROUP BY. e.g. GROUP BY id, type, level

Tuesday, March 6, 2012

Notepad++ Replace using Regex

One of the best features of Notepad++ is the search and replace. You can either use normal search, extended (so you can search for newlines (\n) and tabs (\t)), or regular expressions.

Regex is great for massaging data into the form you want to input into another program.

One case I often have is long lists of output from a PHP script using var_dump() which I want to paste into an Excel spreadsheet. But I need to remove the preceding "string '" and the trailing "' (length=<length of string>)" for the data to make sense.

To remove the starting "string '", just use a normal search (since the string is the same on all lines). To remove the ending we need to use regex since the <length of string> value can vary, using the regular expression search \' \(length=.* should do the trick.