An array can be declared and filled with the default value using square bracket ([]) initialization syntax. For example, creating an array of 10 integers:
int[] arr = new int[10];
Indices in C# are zero-based. The indices of the array above will be 0-9. For example:
int[] arr = new int[3] {7,9,...
git diff [HEAD|--staged...] --word-diff
Rather than displaying lines changed, this will display differences within lines. For example, rather than:
-Hello world
+Hello world!
Where the whole line is marked as changed, word-diff alters the output to:
Hello [-world-]{+world!+}
You can omit...
To ignore a file foo.txt in any directory you should just write its name:
foo.txt # matches all files 'foo.txt' in any directory
If you want to ignore the file only in part of the tree, you can specify the subdirectories of a specific directory with ** pattern:
bar/**/foo.txt # matches all file...
int a = 1;
int *a_pointer = &a;
To dereference a_pointer and change the value of a, we use the following operation
*a_pointer = 2;
This can be verified using the following print statements.
printf("%d\n", a); /* Prints 2 */
printf("%d\n", *a_pointer); /* Also prints...
Custom views can also take custom attributes which can be used in Android layout resource files. To add attributes to your custom view you need to do the following:
Define the name and type of your attributes: this is done inside res/values/attrs.xml (create it if necessary). The following file...
One way to create a macro is to record it.
Start recording a macro and save it to a register (in this example, we'll use a, but it can be any register you could normally yank text to):
qa
Then run the commands you want to record in the macro (here, we'll surround the contents of a line with <...
public class LogActionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
Log("OnActionExecuting", filterContext.RouteData);
}
public override void OnActionExecuted(ActionExecute...
Load content in webview from the url
Swift
webview.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!))
Objective-C
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
You can create a CALayer and set its frame like this:
Swift:
let layer = CALayer()
layer.frame = CGRect(x: 0, y: 0, width: 60, height: 80)
Objective-C:
CALayer *layer = [[CALayer alloc] init];
layer.frame = CGRectMake(0, 0, 60, 80);
You can then add it as a sublayer to an existing CALayer...
To add a method to a button, first create an action method:
Objective-C
-(void)someButtonAction:(id)sender {
// sender is the object that was tapped, in this case its the button.
NSLog(@"Button is tapped");
}
Swift
func someButtonAction() {
print("Button is tapped...
You can easily transform every component in a clickable button using the MouseArea component. The code below displays a 360x360 window with a button and a text in the center; pressing the button will change the text:
import QtQuick 2.0
Rectangle {
width: 360
height: 360
Rectang...
TRUNCATE TABLE Employee;
Using truncate table is often better then using DELETE TABLE as it ignores all the indexes and triggers and just removes everything.
Delete table is a row based operation this means that each row is deleted. Truncate table is a data page operation the entire data page is...
You can access SharedPreferences in several ways:
Get the default SharedPreferences file:
import android.preference.PreferenceManager;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Get a specific SharedPreferences file:
public static final String PREF_FILE_NAM...
Within a catch block the throw keyword can be used on its own, without specifying an exception value, to rethrow the exception which was just caught. Rethrowing an exception allows the original exception to continue up the exception handling chain, preserving its call stack or associated data:
try...
A shell script is a very versatile way to extend your build to basically anything you can think of.
As an exmaple, here is a simple script to compile protobuf files and add the result java files to the source directory for further compilation:
def compilePb() {
exec {
// NOTICE: grad...
There are few approaches available there:
You can subscribe for keyboard appearance events notifications and change offset manually:
//Swift 2.0+
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(YourVCClas...