Sunday, 28 September 2014

Reading a terminfo file

The terminfo/termcap configure various terminals in linux

The infocmp can be used to dump the compiled current terminal configurations into the terminfo format.

Sample output of infocmp

#       Reconstructed via infocmp from file: /usr/share/terminfo/c/cygwin
cygwin|ansi emulation for Cygwin,
        am, hs, mir, msgr, xon,
        colors#8, it#8, pairs#64,
        bel=^G, bold=\E[1m, clear=\E[H\E[J, cr=^M, cub=\E[%p1%dD,

Here's how to read the output

# - comment
the first line of | separated fields are the aliases of the terminal (ends with comma)
3 kinds of settings - all comma separated.
simple words  - boolean variables (eg. am = auto margin)
word#number - sets variable to numbers - eg. colors#8
word=string - sets variable to string

Reference:
http://docstore.mik.ua/orelly/unix/upt/ch41_11.htm

Monday, 22 September 2014

Where does Visual Studio pick up framework assemblies from

From this link : C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework

Visual Studio doesn't use the dlls it finds in the installed framework directories (i.e. %windir%\Microsoft.Net\Framework\v3.0 v4.0 etc. directories). 



Tuesday, 16 September 2014

Android LinearLayout: Adding a button beside an EditText

To layout an EditText and Button side-by-side like so:

Use the following:
LinearLayout
     orientation:horizontal
EditText
    layout_width="0dp"
    layout_weight="1"
Button
    layout_width="wrap_content"


With this the button has enough width to display its contents and then ensure that the edit box fills the rest of the width of the parent.

What does layout_weight do? 

In a LinearLayout, it specifies how to assign the remaining space across different views. Whatever space each view needs (based on wrap_content, explicit width, etc.) would be used first, then any extra space that is available will be assigned to all the views in proportion to their weights.

See here for more details.



Andriod: Creating a Toast with data from the parent Activity of an onClickListener

We'll often register an inner class as an onClickListener. Inside this if there's a need to access the parent Activity use this:
getBaseContext()

Making a Toast message:
Toast.makeText(Context, text, Toast.LENGTH_LONG).show();


Code sample:

        addTask.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = ((EditText)findViewById(R.id.task_text)).getText().toString();
                Toast.makeText(getBaseContext(),text, Toast.LENGTH_LONG).show();
            }
        });

Saturday, 13 September 2014

Android AVD Creation: Missing Snapshot and Host GPU options

From:   http://stackoverflow.com/questions/23883415/android-emulator-shnapshot-option-is-missing

The Creation window had to be manually expanded to reveal the hidden options

Just increase the size of this window and it becomes this:

Android Studio: Location of the SDK


If you install Android Studio (and you don't already have the Android SDK?), Android Studio will install the Android SDK inside the Android Studio install directory like so:
<android_studio_install_location>\sdk

Once you download the Intel Hardware accelerated execution manager from the SDK manager, you need to install it - it will be here: 
<android_studio_install_location>\sdk\extras\intel\Hardware_Accelerated_Execution_Manager

Friday, 12 September 2014

.Net Build Error: The "exists" function only accepts a scalar value, but its argument "$(PackageSourceManifest)" evaluates to "[same path];[same path]" which is not a scalar value.

From: http://stackoverflow.com/questions/18006428/vs2012-exists-only-accepts-scalar-values

The solution which worked for me:
Open your .csproj file and look for any duplicated import tag.
In my case the .csproj had two lines like this:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio
\v10.0\WebApplications\Microsoft.WebApplication.targets" />
Remove one of them fixed the problem.

Thursday, 11 September 2014

Finding out which version of .Net Framework you have installed

From: http://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx

To find .NET Framework versions by viewing the registry (.NET Framework 1-4)

  1. On the Start menu, choose Run.
  2. In the Open box, enter regedit.exe.
    You must have administrative credentials to run regedit.exe.
  3. In the Registry Editor, open the following subkey:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP
    The installed versions are listed under the NDP subkey. The version number is stored in the Version entry. For the .NET Framework 4 the Version entry is under the Client or Full subkey (under NDP), or under both subkeys.

To find .NET Framework versions by viewing the registry (.NET Framework 4.5 and later)

  1. On the Start menu, choose Run.
  2. In the Open box, enter regedit.exe.
    You must have administrative credentials to run regedit.exe.
  3. In the Registry Editor, open the following subkey:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full
Note Note
If the Full subkey is not present, then you do not have a the .NET Framework 4.5 or later installed.
Check for a DWORD value named Release. The existence of the Release DWORD indicates that the .NET Framework 4.5 or newer has been installed on that computer.

The value of the Release DWORD indicates which version of the .NET Framework is installed.
Value of the Release DWORD
Version
378389
.NET Framework 4.5
378675
.NET Framework 4.5.1 installed with Windows 8.1
378758
.NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2
379893
.NET Framework 4.5.2

Copied Android Studio project still refers to old layout files


I recently copied a HelloWorld Android Studio app from one location to another. Changes I made to the layout in the new project were just not being picked up. A Ctrl+B on the resource which was being used to refer to the layout opened up the layout file from the old HelloWorld project.

It turns out that there was a variable RES_FOLDERS_RELATIVE_PATH in the app.iml file which was pointing to file://$MODULE_DIR$/../../HelloWorld/app/src/main/res  (the old res folder) - after closing Android Studio and manually changing this to refer to file://$MODULE_DIR$/src/main/res, and removing the .idea\workspace.xml file and things started working as expected.

Wednesday, 10 September 2014

Git: Getting the contents of a file as of a particular SHA


http://stackoverflow.com/questions/7685433/how-to-get-files-and-content-by-sha-of-commit

git show f414f31:Documentation/help.txt

.. where the path Documentation/help.txt is relative to the top level of the working tree, regardless of whether you're in a subdirectory or not. 

Git: Fixing merge conflicts when you want to resolve by taking theirs


git checkout --theirs foo/bar.java
git add foo/bar.java
see: http://stackoverflow.com/questions/10697463/resolve-git-merge-conflict-accepting-their-changes

Git: cherry-pick the last commit on another branch

git cherry-pick `git log -1 --format='%H' <branchname_to_cherry_pick_from>`

# This assumes you are running this in git bash and that you have checked out the branch that you want to cherry-pick into.

Tuesday, 9 September 2014

Unicode - what programmers need to know

From: http://www.joelonsoftware.com/articles/Unicode.html

Unicode represents a letter as a Unicode code point (represented as U+nnnn) - this doesn't say how the letter is stored in memory - only what its conceptual representation is. This can then be stored using some encoding (UTF-8, UTF-16, etc).

UTF-8 uses 1 byte to represent all letters below ASCII 128
UCS-2  alias UTF-16 uses 2 bytes - these can then be big-endian or little-endian and uses an initial FE FF (unicode byte order mark) to indicate which endian it is.

The Unicode code points can be encoded in any encoding scheme you want - could be ASCII, Hebew ANSI, OEM Greek, etc. But if the unicode code point has no visual representation in the encoding scheme of the reader, then you get a little ? or a ? in a rhombus.

A string without an encoding specified doesn't make sense. 

Wednesday, 3 September 2014

Android Notes: Lessons from HelloWorld

Basic Setup

  • Install Android Studio
  • Get the required SDK - I got the latest SDK for 4.4
  • Gradle build tool is bundled with Android Studio? (Maybe, I don't know)
  • Create the Android Virtual Devices (emulator) for testing - use the AVD manager (the AVD manager can also be launched from inside Android Studio, as can the SDK Manager)
    • You may need to install the correct CPU/ABI for the emulator from the SDK Manager.
  • Launch the AVD - you will probably need to set the RAM on the emulator to a low value (200MB) for the device emulator to launch in a decent time. 

Basic development process


  • Write code - target a particular version of the Android SDK
  • Launch emulator
  • Run code. this will:  
    • compile and create an APK
    • install the APK in the emulator
    • launch the app

Structure of an Android HelloWorld App


public class Greetings extends Activity 
  • An Activity represents a screen in the UI
  • Contains a bunch of on* methods (onCreate, onCreateOptionsMenu, ...) which will be invoked when specific events happen.
AndroidManifest.xml
  • Declares various components (including Activities) which are to be a part of the application.
  • Various important pieces:
    • uses-sdk  - which sdk the application can work with (max, min,...)
    • application - defines the application, contains the various components like activities, services, etc.
    • activity (inside application) - defines a screen
    • intent-filter (inside activity, can it be in other places?) - defines what events the activity will listen for?
The res/ Directory
  • Contains various resources needed by the application
  • drawable-* : different images to be drawn, based on screen resolution
  • layout - contains layouts for various activities - how to layout the screen
  • menu?
  • values/strings.xml - different strings to be used in the application
R  Generated class
  • Generated during build - do not hand edit. 
  • Contains various strings/resources/etc. - can be used in the application.