Archive for the ‘Uncategorized’ Category

30
Dec

Row Locking in MySQL can be performed in two ways.

 
 

1) SELECT … FOR UPDATE

Any lock placed with the FOR UPDATE will not allow other transactions to read, update or delete the row. Other transaction can read this rows only once first transaction get

commit or rollback.

Example:

SELECT * FROM tblTest WHERE id=100 FOR UPDATE;

 

2) LOCK IN SHARE MODE

Any lock placed with LOCK IN SHARE MODE will allow other transaction to read the locked row but it will not allow other transaction to update or delete the row. Other transaction can update or delete the row once the first transaction gets commit or rollback.

Example:

SELECT * FROM tblTest WHERE id=100 LOCK IN SHARE MODE;

 

Here once the first transaction commit or rollback then second transaction which is waiting for first transaction to finish will get an updates row rather than the old one.

 
 

This way we can serve the fresh data to the user and can handle the concurrent request in better way.

30
Dec

//To get a file

local path = system.pathForFile( "data.txt", system.DocumentsDirectory )

//To read from file
local file = io.open( path, "r" )
if file then -- nil if no file found
   local contents = file:read( "*a" )
   print( "Contents of " .. path .. "\n" .. contents )
   io.close( file )
end

//To write in a file
 file = io.open( path, "w" )
   local numbers = {1,2,3,4,5,6,7,8,9}
   file:write( "Feed me data!\n", numbers[1], numbers[2], "\n" )
   for _,v in ipairs( numbers ) do file:write( v, " " ) end
   file:write( "\nNo more data\n" )
   io.close( file )

29
Dec

void CCSpriteFrameCache::addSpriteFramesWithFile:(NSString *plist)

Adds multiple Sprite Frames from a plist file. A texture will be loaded automatically.

The texture name will composed by replacing the .plist suffix with .png.

If you want to use another texture, you should use the  method,

” addSpriteFramesWithFile:texture  ”

 

 

id CCTimer::initWithTarget:selector:( id t, [selector] SEL  s)

Initializes a timer with a target and a selector.

void CCTimer::update:( ccTime  dt)

 

triggers the timer

28
Dec

Sample code to add a horizontal carousel inside a panel in Sencha touch is given below.

 
 

test.views.MenuTypeView = Ext.extend(Ext.Panel, {

fullscreen: true,

layout: ‘card’,

cardSwitchAnimation: ‘slide’,

initComponent: function () {

this.backButton = new Ext.Button({

text        : ‘Home’,

ui                : ‘back’,

handler        : this.backButtonTap,

scope        : this

});

this.saveButton = new Ext.Button({

text        : ‘Save’,

ui                : ‘action’,

handler        : this.saveButtonTap,

scope        : this

});

 
 

 
 

this.carousel = new Ext.Carousel({                 

fullscreen: true,

defaults: {

styleHtmlContent: true

},

 
 

items: [

{

id                : 'idOne',

html         : 'IMAGE-1 MENU ITEMS',

style        : 'background-color: #5E99CC'

}, {

id                : 'idTwo',

html         : 'IMAGE-2 ICON MENU ITEMS',

style        : 'background-color: #759E60'

}, {

id                : 'idThree',

html         : 'IMAGE-3 TABBED BAR ITEMS'

}, {

id                : 'idFour',

html         : 'IMAGE-4 TESTING'

}

 
 

]                

});                 

 
 

 
 

 
 

this.appCarouselPanel = new Ext.form.FormPanel({         

dockedItems        : [{

xtype        : 'toolbar',

title        : 'Select Menu Type',

items        : [

this.backButton,

{xtype: 'spacer'},

this.saveButton

]

}],        

items                :[{

layout: 'hbox',                                        

items: this.carousel

}]

 
 

});

 
 

 
 

 
 

this.items = [this.appCarouselPanel];

test.views.MenuTypeView.superclass.initComponent.call(this);

},

saveButtonTap: function () {

console.log(this.carousel.getActiveItem().getId());

 
 

},

backButtonTap: function () {

 
 

}

});

16
Dec

In video games, hearing the same sample over and over gets extremely fatiguing. One way around that is to subtly vary the playback rate a bit every time. This example varies the pitch by +/- 200 cents from the default value:

Example:

laserSound = audio.loadSound(“laserBlast.wav”)
pitchVariation = (math.random(400) – 200)
laserChannel = audio.play(laserSound, {pitch=pitchVariation})

In music applications, we are constantly changing the pitch and time of the sample, for any variety of reasons.

Note that I am simply talking about varying the playback of the sample rate of the asset – so if an audio sample plays back with {pitch=-1200}, or an octave lower, then it would also playback twice as slowly. To maintain a sample’s duration while varying the pitch, or vice versa, involves some heavy DSP and is probably not worth the effort.

28
Nov
Arduino programs can be divided into: structure,values(variables and constants) and functions.
Structure comprises of: Control structures,Arithmetic operators,Comparison operators,Boolean operators,Bitwise operators,Compound operators,comments,etc
Variables comprises of: Constants like HIGH/LOW,true/false,input/output,integer constants,floating point constants
                                   Data types like void,boolean,char,byte,int,string,word,long,double,array,etc
                                   Data type conversion methods like char(),int(),byte(),word(),long(),float()
Functions comprises of: Digital I/O functions-pinMode(), digitalWrite(), digitalRead()
                                    Analog I/O functions-analogReference, analogRead(), analogWrite()
                                    Advanced I/O functions-tone(), noTone(), shiftOut(), shiftIn(), pulseIn()
                                    Time functions-millis(), micros(), delay()
                                    Math functions-min(),max(),abs(),map(),pow(),sqrt() and so on.
Arduino programs are written in C/C++, although users only need define two functions to make a runnable program:
setup() – a function run once at the start of a program that can initialize settings
loop() – a function called repeatedly until the board powers off
Example: To blink an LED
/*
   Turns on an LED on for one second, then off for one second, repeatedly.
 */
void setup() {
  // initialize the digital pin as an output.
  pinMode(13, OUTPUT);
}
void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

, , , , , , , , , , , , , , , , , , ,

31
Oct
NSString*  deviceName= [[UIDevice currentDevice] name];
	NSLog(@"deviceName --->  %@",deviceName);

31
Oct
NSString*  model=[[UIDevice currentDevice] model];
NSLog(@"model --->  %@",model);

29
Sep

The most commonly used layout classes in android are:

  • FrameLayout – designed to display a stack of child View controls. Multiple view controls can be added to this layout. This can be used to show multiple controls within the same screen space.
  • LinearLayout – designed to display child View controls in a single row or column. This is a very handy layout method for creating forms.
  • RelativeLayout – designed to display child View controls in relation to each other. For instance, you can set a control to be positioned “above” or “below” or “to the left of” or “to the right of” another control, referred to by its unique identifier. You can also align child View controls relative to the parent edges.
  • TableLayout – designed to organize child View controls into rows and columns. Individual View controls are added within each row of the table using a TableRow layout View (which is basically a horizontally oriented LinearLayout) for each row of the table.

     
     

    Defining an XML Layout Resource

    The most convenient and maintainable way to design application user interfaces is by creating XML layout resources.  XML layout resources must be stored in the /res/layout project directory (or, in the case of alternative resources, in a specially named sub-directory).

     
     

    The following is a simple XML layout resource, a template with a LinearLayout containing a TextView and an ImageView, defined in XML:

     
     

    <?xml version=”1.0″ encoding=”utf-8″?>  

    <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”  

    android:orientation=”vertical”  

       android:layout_width=”fill_parent”  

       android:layout_height=”fill_parent”  

       android:gravity=”center”>  

       <TextView  

               android:layout_width=”fill_parent”  

           android:id=”@+id/PhotoLabel”  

           android:layout_height=”wrap_content”  

           android:text=”@string/my_text_label”  

           android:gravity=”center_horizontal”  

           android:textSize=”20dp” />  

             <ImageView  

                 android:layout_width=”wrap_content”  

           android:layout_height=”wrap_content”  

           android:src=”@drawable/matterhorn”  

           android:adjustViewBounds=”true”  

           android:scaleType=”fitXY”  

           android:maxHeight=”250dp”  

           android:maxWidth=”250dp”  

           android:id=”@+id/Photo” />  

    </LinearLayout>  

, , , , , , , , , , , , , , , ,

29
Sep

The Android SDK includes a useful logging utility class called android.util.Log. Logging messages are categorized by severity, with errors being the most severe, then warnings, informational messages, debug messages and verbose messages being the least severe. Each type of logging message has its own method. Simply call the method and a log message is created. The message types, and their related method calls are:

 
 

  • The Log.e() method is used to log errors.
  • The Log.w() method is used to log warnings.
  • The Log.i() method is used to log informational messages.
  • The Log.d() method is used to log debug messages.
  • The Log.v() method is used to log verbose messages.
  • The Log.wtf() method is used to log terrible failures that should never happen.

     
     

    Syntax

    Log.i(TAG, ”Informational message!”);  

     
     

    The first parameter of each Log method is a string called a tag. Common practice is to define a global static string to represent the overall application or the specific activity within the application such that log filters can be created to limit the log output to specific data. For example, you could define a string called TAG, as follows:

    private static final String TAG = ”MyTAG”;  

     
     

    Now anytime you use a Log method, you supply this tag. An informational logging message might look like this:

     
     

    You can also pass a Throwable object, usually on Exception, that will allow the Log to print a stack trace or other useful information.

     

    • try {  
    • // …  
    • catch (Exception exception) {  
    •     Log.e(TAG, ”An Exception Encountered. Application Exits.”, exception);  
    • }  

     

     
     

, , , , , , , , , , , , , , , , ,