Tutorial by Examples

Consider the following naive method for adding two positive numbers using recursion: public static int add(int a, int b) { if (a == 0) { return b; } else { return add(a - 1, b + 1); // TAIL CALL } } This is algorithmically correct, but it has a major problem. ...
Manually open and close a file. # Using new method f = File.new("test.txt", "r") # reading f = File.new("test.txt", "w") # writing f = File.new("test.txt", "a") # appending # Using open method f = open("test.txt", "r&...
If you're just getting started with Chef, we recommend starting off with our Learn Chef tutorial at http://learn.chef.io/. If you have questions during or after that, check out or discussion forum/mailing list at https://discourse.chef.io/ or our public Slack team at https://community-slack.chef.io...
We request that the Chef community not use this StackOverflow documentation feature. Docs managed via wiki (or community editing in general) tend to rot very quickly and are of poor quality. We've all experienced the sense of dread when searching for an answer on Google and getting back a half-unrea...
For immutable elements (e.g. None, string literals etc.): my_list = [None] * 10 my_list = ['test'] * 10 For mutable elements, the same construct will result in all elements of the list referring to the same object, for example, for a set: >>> my_list=[{1}] * 10 >>> print(my_...
General syntax: DATEADD (datepart , number , datetime_expr) To add a time measure, the number must be positive. To subtract a time measure, the number must be negative. Examples DECLARE @now DATETIME2 = GETDATE(); SELECT @now; --2016-07-21 14:39:46.4170000 SELECT DAT...
These are the datepart values available to date & time functions: datepartAbbreviationsyearyy, yyyyquarterqq, qmonthmm, mdayofyeardy, ydaydd, dweekwk, wwweekdaydw, whourhhminutemi, nsecondss, smillisecondmsmicrosecondmcsnanosecondns NOTE: Use of abbreviations is generally discouraged as they c...
General syntax: DATEDIFF (datepart, datetime_expr1, datetime_expr2) It will return a positive number if datetime_expr is in the past relative to datetime_expr2, and a negative number otherwise. Examples DECLARE @now DATETIME2 = GETDATE(); DECLARE @oneYearAgo DATETIME2 = DATEADD(YEAR, -1, @now...
DATEPART returns the specified datepart of the specified datetime expression as a numeric value. DATENAME returns a character string that represents the specified datepart of the specified date. In practice DATENAME is mostly useful for getting the name of the month or the day of the week. There a...
Using the DATEADD and DATEDIFF functions, it's possible to return the last date of a month. SELECT DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, '2016-09-23') + 1, 0)) -- 2016-09-30 00:00:00.000 SQL Server 2012 The EOMONTH function provides a more concise way to return the last date of a month, and...
Sometimes when destructuring maps, you would like to bind the destructured values to their respective key name. Depending on the granularity of the data structure, using the standard destructuring scheme may be a little bit verbose. Let's say, we have a map based record like so : (def john {:lastn...
One approach that is employed often is to use bootstrap's gridded framework in order to define the area that the chart will exist in. Using this in conjunction with clientWidth variable and the window.onresize event, it is very easy to create responsive d3 SVGs. Let's first create a row and a colum...
A CSS rule consists of a selector (e.g. h1) and declaration block ({}). h1 {}
Some properties can take multiple values, collectively known as a property list. /* Two values in this property list */ span { text-shadow: yellow 0 0 3px, green 4px 4px 10px; } /* Alternate Formatting */ span { text-shadow: yellow 0 0 3px, green 4px 4px 10px; } ...
This example shows how to create a table, insert data, and select from the database using the SQLAlchemy ORM. For information re: SQLAlchemy Core, see here. First things first, we need to connect to our database, which is identical to how we would connect using SQLAlchemy Core (Core). from sqlalch...
add_action( 'wp_enqueue_scripts', 'enqueue_my_styles_and_scripts' ); /** * Enqueue styles (or scripts) conditionally. * * Load stylesheets (or scripts) specifically for IE. IE10 and above does * not support conditional comments in standards mode. * * @link https://gist.github.com/wpsc...
@media print { p { page-break-inside: avoid; } h1 { page-break-before: always; } h2 { page-break-after: avoid; } } This code does 3 things: it prevents a page break inside any p tags, meaning a paragraph will never be broken in two pages, if possible. it for...
The most basic instance of an if construct evaluates a condition and executes some code according to the condition outcome. If the condition returns true, the code within the conditional is executed. counter = 10 if counter is 10 console.log 'This will be executed!' The if construct can be e...
To start using Spring data JPA, you must include the dependency in your project with the one of Spring core, all together. If you're using Maven as dependency management system (replace version-number for the version you want to use): <dependencies> <dependency> <groupI...

Page 582 of 1336