Wednesday, March 28, 2012

WP7: Isolated Storage

To store app data so that it can be restored when app is tombstoned/deactivated and then restored. stored in key/value pairs


IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings;
 if (!setting.Contains("rounds")) // check if key exists
 {
     setting.Add("rounds", rounds); // if not, create new key
}
 else
{
      setting["rounds"] = rounds; // if exists, just change the value
}

Reference: http://create.msdn.com/en-US/education/quickstarts/Isolated_Storage

Tuesday, March 27, 2012

WP7: Canvas, Random, 2D Array & Timer



// create a rectangle and fill it with color
Rectangle r = new Rectangle();
 r.Width = r.Height = 50;
r.Fill = new SolidColorBrush(Colors.Orange);
 r.Stroke = new SolidColorBrush(Colors.Black);
 r.StrokeThickness = 3;
// add to canvas
canvas1.Children.Add(r);
// set position

Canvas.SetLeft(r, x);
 Canvas.SetTop(r, y);


// random generator
Random rand = new Random();
int n = rand.Next(maxNumber); // integer :0 to less than maxNumber


// 2D Array
int[,] containers = new int[w, h];

for (int i = 0; i < w; i++ )
 {
       for (int k = 0; k < h; k++)
      {
           containers[i, k] = -1;
       }
 }


// Timer
using System.Windows.Threading;
DispatcherTimer timer = new DispatcherTimer();

timer.Interval = TimeSpan.FromSeconds(5); 
timer.Tick += new EventHandler(timer_Tick);


void timer_Tick(object sender, EventArgs e)
{
     // do something 
 }

Monday, March 26, 2012

WP7: Button MouseDown and Rotate

Interesting that the Button control in silverlight does not support mousedown event.
however, to capture touch down event on the button, has to change the ClickMode of the Button control to "Press" instead of "Release"
and then capture the mousedown event using the "Click" event

Reference: http://www.silverlightshow.net/items/Tip-How-to-handle-the-MouseLeftButtonDown-and-MouseLeftButtonUp-events-of-the-Button-control.aspx

Rotation done using the following:
<Button.RenderTransform>
   <RotateTransform Angle="180" CenterX="100" CenterY="25"/>
</Button.RenderTransform>

Friday, March 09, 2012

Create User accounts in Mac OS X

Reference: http://serverfault.com/questions/20702/how-do-i-create-user-accounts-from-the-terminal-in-mac-os-x-10-5


# Find out the next available user ID
MAXID=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1)
USERID=$((MAXID+1))

# Create the user account
dscl . -create /Users/$USERNAME
dscl . -create /Users/$USERNAME UserShell /bin/bash
dscl . -create /Users/$USERNAME RealName "$FULLNAME"
dscl . -create /Users/$USERNAME UniqueID "$USERID"
dscl . -create /Users/$USERNAME PrimaryGroupID 20
dscl . -create /Users/$USERNAME NFSHomeDirectory /Users/$USERNAME

dscl . -passwd /Users/$USERNAME $PASSWORD

# Add user to group
dseditgroup -o edit -t user -a $USERNAME $GROUP

# Create the home directory
createhomedir -c -u $USERNAME

Wednesday, March 07, 2012

Phonegap: HTML5 vs DOM/CSS

Tested and compared using HTML5 canvas drawing and DOM elements with CSS
strangely, when tested on an android 4 device, HTML5 canvas drawing cause the app to black out after a while.
using DOM elements and CSS2, seems ok.
performance pretty similar