Tutorial by Examples: c

Sometimes you would like to change main WordPress query. Filter pre_get_posts is the way to go. For example using pre_get_posts you can tell main loop to show only 5 posts. Or to show posts only from one category, or excluding any category etc. add_action( 'pre_get_posts', 'my_callback_function' ...
add_action( 'pre_get_posts', 'single_category_exclude' ); function single_category_exclude( $query ) { if( !$query->is_main_query() || is_admin() ) return; $query->set( 'cat', '-1' ); return; }
All we need to do is to use set() method of $query object. It takes two arguments, first what we want to set and second what value to set. add_action( 'pre_get_posts', 'change_posts_per_page' ); function change_posts_per_page( $query ) { if( !$query->is_main_query() || is_admin() ) retu...
Let's say you need to check if an email address appears in a long list of email addresses. Use the MATCH function to return the row number on which the email address can be found. If there is no match, the function returns an #N/A error. =MATCH(F2,$D$2:$D$200,0) The value you're retrieving ...
This will rollback both inserts due to an invalid datetime: BEGIN TRANSACTION BEGIN TRY INSERT INTO dbo.Sale(Price, SaleDate, Quantity) VALUES (5.2, GETDATE(), 1) INSERT INTO dbo.Sale(Price, SaleDate, Quantity) VALUES (5.2, 'not a date', 1) COMMIT TRANSACTION END TRY BEG...
The as operator will cast to a supertype. As it cannot fail, it does not return an optional. let name = "Ringo" let value = string as Any // `value` is of type `Any` now

GCT

The GCT file format is a tab-delimited text file format used for describing processed gene expression or RNAi data, typically derived from microarray chip analysis. This data is arranged with a single annotated gene or probe per line, and a single chip sample per column (beyond the annotation colum...
To use the constant simply use its name: if (EARTH_IS_FLAT) { print "Earth is flat"; } print APP_ENV_UPPERCASE; or if you don't know the name of the constant in advance, use the constant function: // this code is equivalent to the above code $const1 = "EARTH_IS_FLAT&quo...
Java SE 7 switch itself can not be parameterised to be case insensitive, but if absolutely required, can behave insensitive to the input string by using toLowerCase() or toUpperCase: switch (myString.toLowerCase()) { case "case1" : ... break; case &...
Encoding //convert the image to NSData first let imageData:NSData = UIImagePNGRepresentation(image)! // convert the NSData to base64 encoding let strBase64:String = imageData.base64EncodedStringWithOptions(.Encoding64CharacterLineLength) Decoding let dataDecoded:NSData = NSData(base64Encoded...
Let's say we have type ENUM('fish','mammal','bird') An alternative is type VARCHAR(20) COMENT "fish, bird, etc" This is quite open-ended in that new types are trivially added. Comparison, and whether better or worse than ENUM: (same) INSERT: simply provide the string (worse?)...
Changing an auto-increment value is useful when you don't want a gap in an AUTO_INCREMENT column after a massive deletion. For example, you got a lot of unwanted (advertisement) rows posted in your table, you deleted them, and you want to fix the gap in auto-increment values. Assume the MAX value o...
To insert data retrieved from SQL query (single or multiple rows) INSERT INTO Table_name (FirstName, LastName, Position) SELECT FirstName, LastName, 'student' FROM Another_table_name Note, 'student' in SELECT is a string constant that will be inserted in each row. If required, you can select a...
using System; using System.Linq; using System.Security.Cryptography; namespace YourCryptoNamespace { /// <summary> /// Salted password hashing with PBKDF2-SHA1. /// Compatibility: .NET 3.0 and later. /// </summary> /// <remarks>See http://crackstation.net/h...
attr() gets/sets the HTML attribute using the DOM functions getAttribute() and setAttribute(). prop() works by setting the DOM property without changing the attribute. In many cases the two are interchangeable, but occasionally one is needed over the other. To set a checkbox as checked: $('#tosAcc...
$q is a built-in service which helps in executing asynchronous functions and using their return values(or exception) when they are finished with processing. $q is integrated with the $rootScope.Scope model observation mechanism, which means faster propagation of resolution or rejection into your m...
(.) lets us compose two functions, feeding output of one as an input to the other: (f . g) x = f (g x) For example, if we want to square the successor of an input number, we can write ((^2) . succ) 1 -- 4 There is also (<<<) which is an alias to (.). So, (+ 1) <<&lt...
Control.Category defines (>>>), which, when specialized to functions, is -- (>>>) :: Category cat => cat a b -> cat b c -> cat a c -- (>>>) :: (->) a b -> (->) b c -> (->) a c -- (>>>) :: (a -> b) -> (b -> c) -> (a -> c...
The angular.forEach accepts an object and an iterator function. It then runs the iterator function over each enumerable property/value of the object. This function also works on arrays. Like the JS version of Array.prototype.forEach The function does not iterate over inherited properties (prototype...
Google App scripts are of three types. Standalone Bound to Google Apps Web Apps Standalone script Standalone scripts are not bound to any Google apps i.e Docs, Sheets or Forms etc. Standalone script can either be created by visiting script.google.com or by connecting Google app script with ...

Page 370 of 826