Tutorial by Examples: ce

Using the Android API 23 or higher, very often such situation can be seen: This situation is caused by the structural change of the Android API regarding getting the resources. Now the function: public int getColor(@ColorRes int id, @Nullable Theme theme) throws NotFoundException should...
Define a menu in res/menu <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/first_...
git diff myfile.txt Shows the changes between the previous commit of the specified file (myfile.txt) and the locally-modified version that has not yet been staged. This also works for directories: git diff documentation The above shows the changes between the previous commit of all files in ...
There are two ways to achieve that, the first and most known is the following: docker attach --sig-proxy=false <container> This one literally attaches your bash to the container bash, meaning that if you have a running script, you will see the result. To detach, just type: Ctl-P Ctl-Q Bu...
Before the C compiler starts compiling a source code file, the file is processed in a preprocessing phase. This phase can be done by a separate program or be completely integrated in one executable. In any case, it is invoked automatically by the compiler before compilation proper begins. The prepro...
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,...
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...
public async Task<Product> GetProductAsync(string productId) { using (_db) { return await _db.QueryFirstOrDefaultAsync<Product>("usp_GetProduct", new { id = productId }, commandType: CommandType.StoredProcedure); } }
A try/catch block is used to catch exceptions. The code in the try section is the code that may throw an exception, and the code in the catch clause(s) handles the exception. #include <iostream> #include <string> #include <stdexcept> int main() { std::string str("foo&...
There are several R packages to read excel files, each of which using different languages or resources, as summarized in the following table: R packageUsesxlsxJavaXLconnectJavaopenxlsxC++readxlC++RODBCODBCgdataPerl For the packages that use Java or ODBC it is important to know details about your s...
(loop for i in '(one two three four five six) do (print i)) (loop for i in '(one two three four five six) by #'cddr do (print i)) ;prints ONE THREE FIVE (loop for i on '(a b c d e f g) do (print (length i))) ;prints 7 6 5 4 3 2 1 (loop for i on '(a b c d e f g) by #'cddr ...
Run the command below in a shell after installing Ruby. This shows how you can execute simple Ruby programs without creating a Ruby file: ruby -e 'puts "Hello World"' You can also feed a Ruby program to the interpreter's standard input. One way to do that is to use a here document in...
Slices are objects in themselves and can be stored in variables with the built-in slice() function. Slice variables can be used to make your code more readable and to promote reuse. >>> programmer_1 = [ 1956, 'Guido', 'van Rossum', 'Python', 'Netherlands'] >>> programmer_2 = [ 18...
docopt turns command-line argument parsing on its head. Instead of parsing the arguments, you just write the usage string for your program, and docopt parses the usage string and uses it to extract the command line arguments. """ Usage: script_name.py [-a] [-b] <path> ...
Sometimes it's necessary to be able to extract values from an object using only references (ie. without transferring ownership). struct Token { pub id: u32 } struct User { pub token: Option<Token> } fn main() { // Create a user with an arbitrary token let user = User...
A sequence is very much like a list: it is an immutable object that can give you its first element or the rest of its elements in constant time. You can also construct a new sequence from an existing sequence and an item to stick at the beginning. You can test whether something is a sequence using ...
Although it is possible to create a fragment constructor with parameters, Android internally calls the zero-argument constructor when recreating fragments (for example, if they are being restored after being killed for Android's own reasons). For this reason, it is not advisable to rely on a constru...
C++11 inline namespace includes the content of the inlined namespace in the enclosing namespace, so namespace Outer { inline namespace Inner { void foo(); } } is mostly equivalent to namespace Outer { namespace Inner { void foo(); } u...
public interface IShape { decimal Area(); } public struct Rectangle : IShape { public decimal Length { get; set; } public decimal Width { get; set; } public decimal Area() { return Length * Width; } }

Page 17 of 134