Tutorial by Examples: c

Given the text: foo: bar I would like to replace anything following "foo: " with "baz", but I want to keep "foo: ". This could be done with a capturing group like this: s/(foo: ).*/$1baz/ Which results in the text: foo: baz Example 1 or we could use \K,...
Date and LocalDate objects cannot be exactly converted between each other since a Date object represents both a specific day and time, while a LocalDate object does not contain time or timezone information. However, it can be useful to convert between the two if you only care about the actual date i...
Header file UIColor+XYZPalette.h: @interface UIColor (XYZPalette) +(UIColor *)xyz_indigoColor; @end and implementation UIColor+XYZPalette.m: @implementation UIColor (XYZPalette) +(UIColor *)xyz_indigoColor { return [UIColor colorWithRed:75/255.0f green:0/255.0f blue:130/255.0f al...
A simple switch statement: switch a + b { case c: // do something case d: // do something else default: // do something entirely different } The above example is equivalent to: if a + b == c { // do something } else if a + b == d { // do something else } else { ...
There are a variety of undocumented methods on UIColorwhich expose alternate colors or functionality. These can be found in the UIColor private header file. I will document the use of two private methods, styleString() and _systemDestructiveTintColor(). styleString Since iOS 2.0 there is a priva...
The order of keys in Python dictionaries is arbitrary: they are not governed by the order in which you add them. For example: >>> d = {'foo': 5, 'bar': 6} >>> print(d) {'foo': 5, 'bar': 6} >>> d['baz'] = 7 >>> print(a) {'baz': 7, 'foo': 5, 'bar': 6} >&g...
Table Setup CREATE TABLE dbo.Employees ( EmployeeID INT NOT NULL PRIMARY KEY, FirstName NVARCHAR(50) NOT NULL, LastName NVARCHAR(50) NOT NULL, ManagerID INT NULL ) GO INSERT INTO Employees VALUES (101, 'Ken', 'Sánchez', NULL) INSERT INTO Employees VALUES (102, 'Keith', ...
This example comes from the official document. Suppose you have a python application using redis as backend. After writing Dockerfile, create a docker-compose.yml file like this: version: '2' services: web: build: . ports: - "5000:5000" volumes: - .:/code ...
You can add wildcards in string resources and populate them at runtime: Edit strings.xml <string name="my_string">This is %1$s</string> Format string as needed String fun = "fun"; context.getString(R.string.my_string, fun);
string[] names= { "mark", "steve", "adam" }; Ascending: Query Syntax var sortedNames = from name in names orderby name select name; Method Syntax var sortedNames = names.OrderBy(name => name); sortedNames contains the names in following ord...
Floating point numbers of type real cannot have any real value. They can represent real numbers up to certain amount of decimal digits. FORTRAN 77 guaranteed two floating point types and more recent standards guarantee at least two real types. Real variables may be declared as real x double prec...
This example shows how to create a simple notification that starts an application when the user clicks it. Specify the notification's content: NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) // notification icon .se...
Switch statement make use of partial matching. let coordinates: (x: Int, y: Int, z: Int) = (3, 2, 5) switch (coordinates) { case (0, 0, 0): // 1 print("Origin") case (_, 0, 0): // 2 print("On the x-axis.") case (0, _, 0): // 3 print("On the y-axis.") ca...
iex(1)> a = 10 10 iex(2)> b = 20 20 iex(3)> a + b 30 You can get a specific row passing the index of the row: iex(4)> v(3) 30 You can also specify an index relative to the current row: iex(5)> v(-1) # Retrieves value of row (5-1) -> 4 30 iex(6)> v(-5) # Retrieves...
All these are shell commands. docker-machine env to get the current default docker-machine configuration eval $(docker-machine env) to get the current docker-machine configuration and set the current shell environment up to use this docker-machine with . If your shell is set up to use a proxy, yo...
All these are shell commands If you need to log onto a running docker-machine directly, you can do that: docker-machine ssh to ssh into the default docker-machine docker-machine ssh machinename to ssh into a non-default docker-machine If you just want to run a single command, you can do so...
You can set the opacity to a certain UIColor without creating a new one using the init(red:_,green:_,blue:_,alpha:_) initializer. Swift let colorWithAlpha = UIColor.redColor().colorWithAlphaComponent(0.1) Swift 3 //In Swift Latest Version _ colorWithAlpha = UIColor.red.withAlphaComponent(0.1)...
The following code is based on the examples provided by the documentation on std::net::TcpListener. This server application will listen to incoming requests and send back all incoming data, thus acting as an "echo" server. The client application will send a small message and expect a reply...
The following (trivial) example function simply returns the constant INT value 12. DELIMITER || CREATE FUNCTION functionname() RETURNS INT BEGIN RETURN 12; END; || DELIMITER ; The first line defines what the delimiter character(DELIMITER ||) is to be changed to, this is needed to be s...
This code example creates a TCP client, sends "Hello World" over the socket connection, and then writes the server response to the console before closing the connection. // Declare Variables string host = "stackoverflow.com"; int port = 9999; int timeout = 5000; // Create ...

Page 102 of 826