Tuesday, October 29, 2013

Strip HTML entities with Postable

Postable is a great little page for translating HTML code in your text into non-interpretable characters so that you can easily blog about code without parts of it disappearing because it gets interpreted as HTML tags.
Just enter the code snippet into the field. Press Make it friendly and copy/paste the result into your blog.
Great! :)

http://www.elliotswan.com/postable/

Note: It is run through PHP, so no guarantees that your text isn't stored somewhere. But then again, you're about to blog it right?

Sources: http://www.elliotswan.com/2006/03/24/allow-me-to-introduce-you-to-my-new-little-app-postable/

Linux command to take screenshot

On newer versions of KDE when you press the PrintScreen button, a dialog pops up asking you if you want to copy or save a screenshot.

You can also do screenshots from Gimp: Open Gimp, select File -> Create -> Screen Shot...

To be cool or on older versions of Linux you might want to be able to take screen shot using a command line terminal (virtual terminal, you still need to be in X Windows).

Enter the following command:
import -window root <location to put image>
e.g.
import -window root ~/screenshot.jpg

So then you can easily press Alt + F2, enter the command above. Then you won't get the terminal window in your screenshot.
On my system, once you have done so once, the next time you start entering the text it autocompletes.

Note: You need ImageMagick installed as import is included in that package.

Source: http://www.linuxforums.org/forum/newbie/10213-print-screen-available-linux.html

Wednesday, July 31, 2013

Batch Cropping Photos

Like most people nowadays I take a lot of photos, using either my phone or a digital camera. As I don't trust electronic storage mediums and also I like paper copies, I want to have many of the photos printed.

The problem is that photos taken by modern cameras/phones don't match good old paper photo width and height (aspect ration). The solution is to crop (i.e. cut away parts of the image) that are not essential, to fit my photos to the paper.

This is relatively easily done, you can
1. Let your paper photo provider cut out a default selection (the center part of the photo usually), which is mostly ok except when the interesting part isn't centered in your image. Or
2. You go through each image an select the part you want and crop it manually, either using a program like Picasa or Photoshop, or a program provided by your photo service (like JapanPhoto CEWE which is horrible to use and navigate)

This works ok for a few images, but once you pass 100s of photos, it takes too much time.

I luckily found a great program written to help with just this thing, JPEGCrops (http://ekot.dk/programmer/JPEGCrops/). And it's free!

JPEGCrops lets you add all the images you want to crop (only JPEGs though, it crashes with PNG), select the aspect ratio (e.g. 10x15 for regular photos in Norway), and move the box around inside each image to quickly and easily select which portion you want. The program is very fast both in loading images as well as cropping. You can also select an alternative output folder so that you don't mess up your full scale images.


The program is version 0.7.5 beta so could crash in some cases (like when trying PNG, so don't do that) and doesn't seem to be in active development. But it does just what is needed and I'm very happy with the result.

If the link goes away, contact me and I'll send you a copy. :) Thanks to Toke Eskildsen for such a great program! :)

Note: If you want to select a different aspect ratio for all your images, you can change the default by going to File -> Preferences -> Default Aspect. Then all images added after that should have the new aspect ratio set.

Note2: I use FujiDirekte (http://www.fujidirekte.no/), a Norwegian photo printer which I'm very happy with, they also have quite reasonable prices I've found from my investigations. Very easy and useable online interface for ordering. They even notice which aspect ratio I probably want for each photo. For example if I have cropped some images to 10x15 and some to 13x18, those sizes are listed correctly while they are "wrong" for other size, so the 10x order option for a 13x18 cropped image would be 10x17 or something. Not matching any of the aspect ratios I have cropped to.

Thursday, June 20, 2013

Dynamics 2.0 ROM on HTC Titan WP7

My Marketplace app didn't work, so I figured I'd install a Custom ROM on my HTC Titan phone. After a bit of googling I found:

Dynamics 2.0 (http://forum.xda-developers.com/showthread.php?t=1691921)
Eburon (http://forum.xda-developers.com/showthread.php?t=1731921)
HTC Titan 7.8 Sianto Edition AL (http://forum.xda-developers.com/showthread.php?t=1908624)

Also I found that I already had DFT Eternity 24 langs Freedom V1 Pearl Edition (http://forum.xda-developers.com/showpost.php?p=26842868&postcount=46) installed from my jailbreaking

I decided to try Dynamics 2.0. Here's how I did it:
 
  1. Get the prerequisites. 
    1. Details: http://forum.xda-developers.com/showthread.php?t=1521763
      Download: http://forum.xda-developers.com/attachment.php?attachmentid=923630&d=1330440102 (1MB) 
    2. Download and Install: 
      1. Windows Mobile Device Center (WMDC) (https://www.microsoft.com/en-us/download/details.aspx?id=14) (Might already be installed if you have Windows 7 or newer). 
      2. Microsoft Visual Studio Express 2012 (https://www.microsoft.com/visualstudio/eng/downloads#d-2012-express)
        or
        Microsoft Visual Studio Express 2010 (https://www.microsoft.com/visualstudio/eng/downloads#d-2010-express) (?MB) with Microsoft Visual Studio Express 2010 Service Pack 1 (https://www.microsoft.com/en-us/download/details.aspx?id=23691) (450MB)
        If you already have it installed and the trial has expired, don't worry a license is free, all you have to do is register. I used VS Express 2010. 
      3. Windows Phone 7.1 SDK (https://www.microsoft.com/en-us/download/details.aspx?id=27570) (500MB) 
  2. Backup user content. 
    1. Download WPBackup
      Details: http://forum.xda-developers.com/showthread.php?t=2010135
      Download: rhiffsta.ch/ultrashot/WPBackup_v1.0.rar
      or
      http://uploaded.net/file/xkg2k12x
       
    2. Run backup 
      1. Usage instructions: http://forum.xda-developers.com/showthread.php?t=2010135&page=12#118 
      2. Unpack the rar file to a location of your choice. 
      3. Start Zune (can't remember if I had to quit Zune before backing up or not, might want to try that if WPBackup doesn't start). 
      4. Connect your phone and sync it with Zune.  
      5. Start WMDC on your phone (don't quit it while backing up). Press Run and get IP, doesn't matter what it is, if you don't get an IP follow the instructions on the forum (worked fine for me on the first try). 
      6. Start WPBackup. If no program window shows, you are missing some prerequisite or Zune or WMDC. 
      7. Press connect in WPBackup 
      8. Follow instructions in WPBackup to backup whatever you want. 
  3. Install Dynamics ROM. 
    1. Download ROM and instructions.
      Details: http://forum.xda-developers.com/showthread.php?t=1691921 and http://dl.xda-developers.com/attachdl/9b7772b952cedc1d300ace97fe037123/51c218cf/1/5/0/5/9/4/5/release_2.0_en.txt
      Download: rhiffsta.ch/ultrashot/Dynamics_2.0_Titan.rar (450MB) 
    2. Install ROM 
      1. Disconnect your phone from the USB cable and turn it off. Press both volume buttons and then while pressing, turn the phone on. Wait for the SPL to show (bootloader showing statistics). 
      2. Connect the USB cable and wait for the text 'Serial' to change to 'USB' on the phone. 
      3. Make sure that the phone is connected as Qualcomm CDMA Technologies MSM on your PC. 
      4. Unpack the rar file to a location of your choice. 
      5. Start TitanAdvancedRUU.exe and select regular RUU and  Dynamics_2.0_Titan.nbh, then press Next. 
      6. Check the 'I've read the readme' box and press next. 
      7. Check 'I completed the steps indicated above' and press next.
      8. Press the 'Update' button. You should get a view saying "From Image Version: To Image Version: 4.06.401.03". 
      9. Press Next. 
      10. Press Next. 
      11. Wait for the ROM to be installed. The phone will reboot and let you go through the standard WP7 setup. 
  4. Restore backup 
    1. Start Zune and set up phone there. 
    2. Start WMDC on your phone, press run. 
    3. Start WPBackup on your computer, press connect. 
    4. Select restore. Select what you want to restore (Restore seems to work even though it says "Please, setup Live account first!"). 
    5. Restore 
      1. Install the apps you want from the restore (your phone will show the Marketplace page for each app), then go back to WMDC and press OK in WPBackup. 
    6. Reboot phone
Note: You should restore the backup before setting up any accounts such as Facebook, Gmail, or Yahoo. If you don't, restored contacts and SMSes that are duplicates of the ones downloaded from your accounts will be read only and show up twice (in the case of contacts). Very annoying.

Good luck! Hopefully it will work smoothly for you. :) If you have problems, just add a comment or ask at the forums. :)

Below are some screenshots from my process.

















Wednesday, June 19, 2013

BusyBox Limited echo

BusyBox is a program incorporating the functionality of several GNU tools/programs, like for example df, grep, find, mv, and echo. This binary is usually used on embedded devices instead of a full fledged GNU/Linux install. Thus you can call it BusyBox/Linux.

However, as this program is not the exact same code as in GNU/Linux there are differences between them, and some things are not supported. One such difference is that the echo command is a bit limited. There is a flag -e which tells the program to "enable interpretation of backslash escapes". For example change swap foreground and bacground colors with:
echo -e "\e[7m" and echo -e "\e[0m"

Except this won't work on BusyBox (at least in version 1.12.1), echo doesn't accept \e and \x escape sequences. Instead you have to use the octal equivalent so the above would be:

echo -e "\033[7m" and echo -e "\033[0m".

Found at http://osdir.com/ml/linux.busybox/2003-07/msg00201.html .

Tuesday, May 21, 2013

Passing arguments to program when using GDB command line

If you have a program that takes input parameters on start and you want to debug it using GDB in the command line, here is how to pass parameters to the program:
  1. Start GDB with given program
    gdb myProgram.a
  2. Set break points etc. 
  3.  Start debugging and give parameters you would usually give to program here
    run param1 param2 
Alternatively you can specify arguments directly when calling gdb with --args flag:
gdb --args myProgram.a param1 param2

Cheatsheet for GDB command line: http://www.yolinux.com/TUTORIALS/GDB-Commands.html

Source: http://bytes.com/topic/c/answers/833755-how-do-i-pass-argument-gdb

Wednesday, May 15, 2013

Remote Desktop Windows To Linux

There are probably a ton of ways to do this, but here is one.:)
Use X11VNC on Linux and a standalone TightVNC client to connect to the Linux machine from Windows.
  1.  Install X11VNC on Linux (Ubuntu)
    sudo apt-get install x11vnc
  2. Run the VNC server on Linux
    x11vnc
    or
    x11vnc -forever
    to keep listening for new connections after the first client has disconnected.
    WARNING: X11VNC runs without password as default, you should set a password if you intend to let the server run in the background or for longer periods.
  3. Download standalone (or installer if you have the rights to install) of TightVNC:
    Latest version, installer only:
    http://www.tightvnc.com/download.php
    Old version, standalone:
    http://www.tightvnc.com/download-old.php
    http://www.tightvnc.com/download/1.3.10/tightvnc-1.3.10_x86_viewer.zip
  4. Connect to your Linux machine (use ifconfig to get IP-address) using the TightVNC viewer.
Consider adding x11vnc-forever to your /etc/rc.local and make it executable to start a VNC server when your computer boots.

Wednesday, May 8, 2013

Google Test check for derived class pointer

I have a function that creates an object of a derived/child Derived class and passes this object as a pointer to a function accepting a pointer of the base/parent Base class.

Now I wanted to test this using the Google Test Framework in conjunction with Google Mock:

TEST_F(myClassToBeTestedTest, functionToBeTestedTest)
{
    EXPECT_CALL(myClassMock, myFunc(::testing::A<Derived *>()));
    myClassToBeTested.functionToBeTested();
}


This did not compile with the following error:

mytestclasstest.cpp:X:Y: error: no matching function for call to 'MyClassMock::gmock_myFunc(testing::Matcher<Derived*>)'
mytestclasstest.cpp:X:Y: note: candidate is:
myclassmock.h:X:Y: note: testing::internal::MockSpec<void(Base*)>& 'MyClassMock::gmock_myFunc(const testing::Matcher<Base*>&)

...

Googling a bit I found http://stackoverflow.com/questions/5056538/google-mock-using-testingan which explained that Google Test needed const and &. However I couldn't get this to make sense for my type argument. E.g. EXPECT_CALL(myClassMock, myFunc(const ::testing::A<Derived *>() &)); doesn't work.

After more searching (and annoyance at google for removing :: and <>) I ended up with creating my own custom matcher using "Using Predicates as Matchers" from http://code.google.com/p/googlemock/wiki/CookBook#Using_Predicates_as_Matchers together with http://stackoverflow.com/questions/500493/c-equivalent-of-instanceof to check if object is type of Derived:

int IsDerived(Base * base)
{
    Derived * derived = dynamic_cast<Derived *>(base);
    return derived != NULL ? 1 : 0;
}

TEST_F(myClassToBeTestedTest, functionToBeTestedTest)
{
    EXPECT_CALL(myClassMock, myFunc(::testing::Truly(IsDerived)));
    myClassToBeTested.functionToBeTested();
}

Wednesday, April 10, 2013

HTC Titan Wp 7.5 Disables cellular data after screensaver

My HTC Titan suddenly startet turning off my cellular data (3G) after I turned off the screen for a little while (immediately turning the screen back on and it would still be enabled so it seems to be some kind of timeout).

Workaround for this problem:
1. Turn the phone off and then on again.
OR
2. Go to settings -> Flight Mode -> Turn flight mode on -> Turn flight mode off -> enter PIN code (if asked).

Will add solution to problem if I can find any.

Thursday, February 28, 2013

Termios to get Ncurses cbreak without Ncurses

In my C++ program I wanted to capture keypresses in command line without waiting for newline/enter being entered.
Ncurses has a command cbreak() which does this, but I wasn't using Ncurses.

I finally found termios.h library and tcgetattr()/tcsetattr() commands:


#include <termios.h>

int main(int argc, char* argv[])

{
    struct termios m_old_term_config;
    struct termios m_new_term_config;

    // Get current terminal configuration
    tcgetattr(STDIN_FILENO, &m_old_term_config);

    // Make a copy to restore later
    m_new_term_config = m_old_term_config;

    // Disable line by line input and echo
    m_new_term_config.c_lflag &= ~(ICANON | ECHO);

    // Or only disable line by line input
    //m_new_term_config.c_lflag &= ~ICANON

    tcsetattr(STDIN_FILENO, TCSANOW, &m_new_term_config);

    /* Run program without line by line input and echoing  */

    // Restore old terminal configuration when closing program
    tcsetattr(STDIN_FILENO, TCSANOW, &m_old_term_config);
}



Sources: http://linux.die.net/man/3/termios
http://en.wikibooks.org/wiki/Serial_Programming/termios