How to Concatenate elements of a table together in a string – CORONA ?

In order to concatenate elements of a table together in a string,

Syntax:

	
table.concat (table [, sep [, i [, j]]])

Parameters:
table – The Lua table whose elements will be concatenated.
sep – (Optional) String: The string to insert between concatenated table values. The default value is an empty string (“”).
i – (Optional) Number: The index in the table at which the concatenation should start. The default values is 1.
j – (Optional) Number: The index in the table at which the concatenation should end. The default value is the length of the table.

Example :
tab1 = { 1, 2, “three”, 4, “five” }
print (table.concat(tab1)) –> 12three4five
print (table.concat(tab1, “, “)) –> 1, 2, three, 4, five
print (table.concat(tab1, “, “, 2, 4)) –> 2, three, 4

object:setDrag property in corona

Turns any movieclip into a draggable object when drag is set as true.

The limitX and limitYparameters limit the dragging to either the x or y axis, and the bounds parameter can be used to specify drag boundaries for the object as {left, top, width, height}.

The onPress, onDrag and onRelease parameters take the names of functions to be called when those events occur. All parameters are optional.

myAnim:setDrag{ drag=true, limitX=false, limitY=false, onPress=myPressFunction, onDrag=myDragFunction,
               onRelease=myReleaseFunction, bounds={ 10, 10, 200, 50 }}

To turn off the draggable property again, set “drag” to false:

myAnim:setDrag{ drag=false }

Sending http request to a remote server in sencha

Sending http request to a remote server in sencha:

Ext.Ajax.request({
url: 'ajax_data/simple.json',
success: function(response, opts) {
console.dir(Ext.decode(response.responseText););
},
failure: function(response, opts) {
console.log('request failed : ' + response.status);
}
});

where,

url: The URL to which to send the request, or a function to call which returns a URL string

params:  parameters to the request

 

callback :  The function to be called upon receipt of the HTTP response. The callback is called regardless of success or failure and is passed the following parameters:

options: The parameter to the request call.

success: True if the request succeeded.

response: The XMLHttpRequest object containing the response data.

 

Ext.Ajax.request({ url:'ajax_demo/sample.json', success:function(response, opts){var obj =Ext.decode(response.responseText); console.dir(obj);}, failure:function(response, opts){ console.log('server-side failure with status code '+ response.status);}});

String Object in Javascript

The JavaScript String object is a wrapper for text values. In addition to storing text, the String object includes a property and various methods to

manipulate or gather information about text. String object doesn’t need to be instantiated to be used—for example, you can set a variable to a string, and then all of the String object properties or methods will become available to that variable:

 
 

var myString = “My string”;

 
 

The String object only has one property—length—which is read only. You use the length property to return the length of a string only: You cannot change it externally. The code that follows provides an example using the length property to determine the number of characters in a string:

 
 

var myString = “My string”;

document.write(myString.length);

// Results in a numeric value of 9

 
 

The result of this code is 9, because the space between the two words is also counted as a character.

 
 

There are quite a few methods in the String object that you can use to manipulate and gather information about text. The following is a list of the available methods:

charAt

charCodeAt

concat

fromCharCode

indexOf

lastIndexOf

match

replace

search

slice

split

substr

substring

toLowerCase

toUpperCase

 
 

The chartAt method can be used to retrieve a specific character based on an index that you pass as an argument. The code that follows provides an example of how to return the first character of a string:

 
 

var myString = “My string”;

document.write(myString.chartAt(0);

// Results in M

 
 

If you need the opposite result, there are a couple of methods that return the index of a specified character or set of characters in a string rather than returning a character using an index. These methods are indexOf and lastIndexOf, both of which include two parameters: searchString and start. The searchString parameter is the starting index, and the start parameter tells the method where to begin the search. The difference between these two methods is that indexOf returns the first occurrence, and lastIndexOf returns the last occurrence.

 
 

The charCodeAt method is similar to charAt: The only difference is that it returns the Unicode character. Another Unicode-related method that the String object includes is fromCharCode, which converts Unicode to characters.

Connect to WiFi Network via Terminal

Step 1:
Enable Airport command-line utility.

sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport

Step 2:

List Different Parameters of current WiFi Connection,

airport -I

Step 3:

Run the networksetup tool with proper arguments (SSID and Password)

networksetup -setairportnetwork Airport [SSID] [password]

Notes on mod_rewrite for Apache

Apache’s mod_rewrite document, calls this module as “Swiss Army Knife of URL manipulation!”

 

mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs. Incoming URLs are checked against a series of rules. The rules contain a regular expression to detect a particular pattern. If the pattern is found in the URL, and the proper conditions are met, the pattern is replaced with a provided substitution string or action. This process continues until there are no more rules left or the process is explicitly told to stop.

 

Fig: mod_rewrite control flow.

 

Advantages

  1. mod_rewrite can be used to transform long and complex urls into user friendly or short urls.

    For eg. http://myrurl.php/customer.php?name=shan&id=4562&aadr=561

    Above url can be converted to a more user friendly one as,

    http://myurl.php/customer/shan

     

  2. Security enhancement.

    Consider the above example a potential hacker can try out different urls to hack into the system by giving different parameters and values passed to customer.php, using mod_rewrite we can prevent such threats.

     

    mod_rewrite can be enabled by uncommenting the line,

    LoadModule rewrite_module modules/mod\_rewrite.so

    in apache configuration file httpd.conf.

Pass parameter to NSTimer

To pass parameter to an NSTimer, the parameter should be specified in the field userInfo of the timer. We can pass any number of parameters to NSTimer provided they are wrapped into a collection. Here i am passing two strings to the timer method by wrapping them into an NSMutableDictionary.

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:@”1″ forKey:@”a”];
[dict setObject:@”2″ forKey:@”b”];

Create the timer.
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(myTimerMethod:) userInfo:dict repeats:NO];
[dict release];

implement the timer method.

-(void)myTimerMethod:(NSTimer*)myTimer
{
//cast the userInfo of the timer to a variable of object we assigned earlier.
NSMutableDictionary *dict = [myTimer userInfo];
NSLog(@”cur dict is:%@”,[dict objectForKey:@”a”]);
NSLog(@”cur dict is:%@”,dict);
}

Tween Animation in Android

Tween Animation

 

A tween animation can perform a series of simple transformations (position, size, rotation, and transparency) on the contents of a View object. So, if you have a TextView object, you can move, rotate, grow, or shrink the text. If it has a background image, the background image will be transformed along with the text. The animation package (android.view.animation) provides all the classes used in a tween animation.

 

A sequence of animation instructions defines the tween animation, defined by either XML or Android code. As with defining a layout, an XML file is recommended because it’s more readable, reusable, and swappable than hard-coding the animation. In the example below, XML is used.

 

The animation instructions define the transformations that you want to occur, when they will occur, and how long they should take to apply. Transformations can be sequential or simultaneous – for example, you can have the contents of a TextView move from left to right, and then rotate 180 degrees, or you can have the text move and rotate simultaneously. Each transformation takes a set of parameters specific for that transformation (starting size and ending size for size change, starting angle and ending angle for rotation, and so on), and also a set of common parameters (for instance, start time and duration). To make several transformations happen simultaneously, give them the same start time; to make them sequential, calculate the start time plus the duration of the preceding transformation.

 

The animation XML file belongs in the res/anim/ directory of your Android project. The file must have a single root element: this will be either a single <alpha>, <scale>,<translate>, <rotate>, interpolator element, or <set> element that holds groups of these elements (which may include another <set>). By default, all animation instructions are applied simultaneously. To make them occur sequentially, you must specify the startOffset attribute, as shown in the example below.

 

The following XML simultaneously spin and rotate a View object.

 

<set android:shareInterpolator=”false”>

<scale

android:interpolator=”@android:anim/accelerate_decelerate_interpolator”

android:fromXScale=”1.0″

android:toXScale=”1.4″

android:fromYScale=”1.0″

android:toYScale=”0.6″

android:pivotX=”50%”

android:pivotY=”50%”

android:fillAfter=”false”

android:duration=”700″ />

<set android:interpolator=”@android:anim/decelerate_interpolator”>

<scale

android:fromXScale=”1.4″

android:toXScale=”0.0″

android:fromYScale=”0.6″

android:toYScale=”0.0″

android:pivotX=”50%”

android:pivotY=”50%”

android:startOffset=”700″

android:duration=”400″

android:fillBefore=”false” />

<rotate

android:fromDegrees=”0″

android:toDegrees=”-45″

android:toYScale=”0.0″

android:pivotX=”50%”

android:pivotY=”50%”

android:startOffset=”700″

android:duration=”400″ />

</set>

</set>

 

Some values, such as pivotX, can be specified relative to the object itself or relative to the parent. Be sure to use the proper format for what you want (“50″ for 50% relative to the parent, or “50%” for 50% relative to itself).

 

You can determine how a transformation is applied over time by assigning an Interpolator. Android includes several Interpolator subclasses that specify various speed curves: for instance, AccelerateInterpolator tells a transformation to start slow and speed up. Each one has an attribute value that can be applied in the XML.

 

With this XML saved as star_jump.xml in the res/anim/ directory of the project, the following code will reference it and apply it to an ImageView object from the layout.

 

ImageView imgView;

Animation tweenAnimation;

 

imgView = (ImageView) findViewById(R.id.imgView);

tweenAnimation = AnimationUtils.loadAnimation(this, R.anim.star_jump);

imgView.startAnimation(tweenAnimation);

 

As an alternative to startAnimation(), you can define a starting time for the animation with Animation.setStartTime(), then assign the animation to the View with View.setAnimation().