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...
To find all the files of a certain extension within the current path you can use the following find syntax. It works by making use of bash's built-in glob construct to match all the names having the .extension.
find /directory/to/search -maxdepth 1 -type f -name "*.extension"
To find ...
Since Git 1.7.12 it is possible to rebase down to the root commit. The root commit is the first commit ever made in a repository, and normally cannot be edited. Use the following command:
git rebase -i --root
Note that you cannot overload a function based on its return type. For example:
// WRONG CODE
std::string getValue()
{
return "hello";
}
int getValue()
{
return 0;
}
int x = getValue();
This will cause a compilation error as the compiler will not be able to work out wh...
Filters can either be defined in a method and then added to Jinja's filters dictionary, or defined in a method decorated with Flask.template_filter.
Defining and registering later:
def format_datetime(value, format="%d %b %Y %I:%M %p"):
"""Format a date time to (Defau...
It is also possible to write a context manager using generator syntax thanks to the contextlib.contextmanager decorator:
import contextlib
@contextlib.contextmanager
def context_manager(num):
print('Enter')
yield num + 1
print('Exit')
with context_manager(2) as cm:
# the ...
Intents can be used to broadcast messages to other components of your application (such as a running background service) or to the entire Android system.
To send a broadcast within your application, use the LocalBroadcastManager class:
Intent intent = new Intent("com.example.YOUR_ACTION"...
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...
This code selects data out of a table:
SELECT Column1, Column2, Column3 FROM MySourceTable;
This code creates a new table called MyNewTable and puts that data into it
SELECT Column1, Column2, Column3
INTO MyNewTable
FROM MySourceTable;
To move data you first insert it into the target, then delete whatever you inserted from the source table. This is not a normal SQL operation but it may be enlightening
What did you insert? Normally in databases you need to have one or more columns that you can use to uniquely identify rows so we w...
public class Dog : RealmObject
{
public string Name { get; set; }
public int Age { get; set; }
}
var realm = Realm.GetInstance();
realm.Write(() =>
{
var mydog = realm.CreateObject<Dog>();
mydog.Name = "Rex";
mydog.Age = 1;
});
var pups = real...
It is a common practice to place multiple <div> inside another <div>. This is usually referred to as "nesting" elements and allows for further dividing elements into subsections or aid developers with CSS styling.
The <div class="outer-div"> is used to group to...
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...
The shift operators allow programmers to adjust an integer by shifting all of its bits to the left or the right. The following diagram shows the affect of shifting a value to the left by one digit.
Left-Shift
uint value = 15; // 00001111
uint doubled = value << 1; // Resu...
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...