Tutorial by Examples: c

CoSOS (cousin of SOS) is an open source extension for WinDbg focusing on .NET memory fragmentation (!gcview) and threading issues (!wfo, !tn). Typically, the extension is not available side by side to any other DLL, so it is usually loaded with .load x:\full\path\to\cosos.dll. It requires that SOS ...
Ref returns and ref locals are useful for manipulating and returning references to blocks of memory instead of copying memory without resorting to unsafe pointers. Ref Return public static ref TValue Choose<TValue>( Func<bool> condition, ref TValue left, ref TValue right) { ...
Determine your key ID gpg --list-secret-keys --keyid-format LONG /Users/davidcondrey/.gnupg/secring.gpg -------------------------------------- sec 2048R/YOUR-16-DIGIT-KEY-ID YYYY-MM-DD [expires: YYYY-MM-DD] Your ID is a alphanumeric 16-digit code following the first forward-slash. ...
Sometimes we want to look at what is sent and received in the SOAP request. The following methods will return the XML in the request and response: SoapClient::__getLastRequest() SoapClient::__getLastRequestHeaders() SoapClient::__getLastResponse() SoapClient::__getLastResponseHeaders() For ex...
array_flip function will exchange all keys with its elements. $colors = array( 'one' => 'red', 'two' => 'blue', 'three' => 'yellow', ); array_flip($colors); //will output array( 'red' => 'one', 'blue' => 'two', 'yellow' => 'three' )
When pasting text through a terminal emulator, the auto-indent feature may destroy the indentation of the pasted text. For example: function () { echo 'foo' echo 'bar' echo 'baz' } will be pasted as: function () { echo 'foo' echo 'bar' echo 'baz' ...
When static_cast is used to convert T D::* to T B::*, the member pointed to must belong to a class that is a base class or derived class of B. Otherwise the behavior is undefined. See Derived to base conversion for pointers to members
The following uses of pointer arithmetic cause undefined behavior: Addition or subtraction of an integer, if the result does not belong to the same array object as the pointer operand. (Here, the element one past the end is considered to still belong to the array.) int a[10]; int* p1 = &a...
C++11 Example from the Standard, [dcl.attr.noreturn]: [[ noreturn ]] void f() { throw "error"; // OK } [[ noreturn ]] void q(int i) { // behavior is undefined if called with an argument <= 0 if (i > 0) throw "positive"; }
In this example, a destructor is explicitly invoked for an object that will later be automatically destroyed. struct S { ~S() { std::cout << "destroying S\n"; } }; int main() { S s; s.~S(); } // UB: s destroyed a second time here A similar issue occurs when a st...
Example from the Standard, [temp.inst]/17: template<class T> class X { X<T>* p; // OK X<T*> a; // implicit generation of X<T> requires // the implicit instantiation of X<T*> which requires // the implicit instantiation of X<T**&...
Single characters can be extracted using array (square brace) syntax as well as curly brace syntax. These two syntaxes will only return a single character from the string. If more than one character is needed, a function will be required, i.e.- substr Strings, like everything in PHP, are 0-indexed....
Creating a list of KeyValuePair: Dictionary<int, int> dictionary = new Dictionary<int, int>(); List<KeyValuePair<int, int>> list = new List<KeyValuePair<int, int>>(); list.AddRange(dictionary); Creating a list of keys: Dictionary<int, int> dictionary ...
Text is saved encoded (see also Strings topic) then sometimes you may need to change its encoding, this example assumes (for simplicity) that file is not too big and it can be entirely read in memory: public static void ConvertEncoding(string path, Encoding from, Encoding to) { File.WriteAllT...
This example updates last write time of a huge number of files (using System.IO.Directory.EnumerateFiles instead of System.IO.Directory.GetFiles()). Optionally you can specify a search pattern (default is "*.*" and eventually search through a directory tree (not only the specified director...
This snippet is an helper function to enumerate all files older than a specified age, it's useful - for example - when you have to delete old log files or old cached data. static IEnumerable<string> EnumerateAllFilesOlderThan( TimeSpan maximumAge, ...
Having example type like this: public TestClass { public static string StaticPublicField = "StaticPublicFieldValue"; } We can retrieve value of StaticPublicField: var fieldExpr = Expression.Field(null, typeof(TestClass), "StaticPublicField"); var labmda = Expression....
Autostash is a very useful configuration option when using rebase for local changes. Oftentimes, you may need to bring in commits from the upstream branch, but are not ready to commit just yet. However, Git does not allow a rebase to start if the working directory is not clean. Autostash to the res...
echo off cls sqlcmd.exe -S "your server name" -U "sql user name" -P "sql password" -d "name of databse" -Q "here you may write your query/stored procedure" Batch files like these can be used to automate tasks, for example to make backups of ...
It's a good practice to run NodeJS apps controlled by process managers. Process manager helps to keep application alive forever, restart on failure, reload without downtime and simplifies administrating. Most powerful of them (like PM2) have a built-in load balancer. PM2 also enables you to manage ...

Page 465 of 826