Tutorial by Examples

Asynchronously var fs = require('fs'); fs.stat('path/to/file', function(err) { if (!err) { console.log('file or directory exists'); } else if (err.code === 'ENOENT') { console.log('file or directory does not exist'); } }); Synchronously here, we must wr...
There may be situations where you have setup a pool of MySQL connections, but you have a number of queries you would like to run in sequence: SELECT 1; SELECT 2; You could just run then using pool.query as seen elsewhere, however if you only have one free connection in the pool you must wait un...
You can attach the query executed to your err object when an error occurs: var q = mysql.query('SELECT `name` FROM `pokedex` WHERE `id` = ?', [ 25 ], function (err, result) { if (err) { // Table 'test.pokedex' doesn't exist err.query = q.sql; // SELECT `name` FROM `pokedex` WHERE `id` ...
This is a collection of unique items, with O(1) lookup. HashSet<int> validStoryPointValues = new HashSet<int>() { 1, 2, 3, 5, 8, 13, 21 }; bool containsEight = validStoryPointValues.Contains(8); // O(1) By way of comparison, doing a Contains on a List yields poorer performance: Lis...
0-1 Knapsack The Knapsack Problem is a problem when given a set of items, each with a weight, a value and exactly 1 copy, determine the which item(s) to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. C++ Exampl...
Callback-based: db.notification.email.find({subject: 'promisify callback'}, (error, result) => { if (error) { console.log(error); } // normal code here }); This uses bluebird's promisifyAll method to promisify what is conventionally callback-based code like above. blueb...
Dependencies can also be injected by setters. interface Logger { public function log($message); } class Component { private $logger; private $databaseConnection; public function __construct(DatabaseConnection $databaseConnection) { $this->databaseConnection = $...
A view is most useful when it can be used to pull in data from more than one table. CREATE VIEW myview AS SELECT a.*, b.extra_data FROM main_table a LEFT OUTER JOIN other_table b ON a.id = b.id In mysql views are not materialized. If you now perform the simple query SELECT * FROM myview, my...
Content has been moved back to good 'ol JSP wiki page
The most important application events are: Application_Start - It is raised when the application/website is started. Application_End - It is raised when the application/website is stopped. Similarly, the most used Session events are: Session_Start - It is raised when a user first requests a page...
Common page and control events are: DataBinding - It is raised when a control binds to a data source. Disposed - It is raised when the page or the control is released. Error - It is a page event, occurs when an unhandled exception is thrown. Init - It is raised when the page or the control is in...
The default event for the Page object is Load event. Similarly, every control has a default event. For example, default event for the button control is the Click event. The default event handler could be created in Visual Studio, just by double clicking the control in design view. The following tab...
spray-json provides an easy way to work with JSON. Using implicit formats, everything happens "behind the scenes": Make the Library Available with SBT To manage spray-json with SBT managed library dependencies: libraryDependencies += "io.spray" %% "spray-json" % &quo...
ASP.NET is a unified Web development model that includes the services necessary for you to build enterprise-class Web applications with a minimum of coding. ASP.NET is part of the .NET Framework, and when coding ASP.NET applications you have access to classes in the .NET Framework. You can code you...
You can use this method to replace all of the HTML within the selector. Assuming you have an html element like this <div class="row"> <div class="col-md-12"> <div id="information"> <p>Old message</p> &l...
Loading the library (ql:quickload "fiveam") Define a test case (fiveam:test sum-1 (fiveam:is (= 3 (+ 1 2)))) ;; We'll also add a failing test case (fiveam:test sum2 (fiveam:is (= 4 (+ 1 2)))) Run tests (fiveam:run!) which reports Running test suite NIL Running test...
PHP 5.x5.4 When you build REST API's, you may need to reduce the information of an object to be passed to the client application. For this purpose, this example illustrates how to use the JsonSerialiazble interface. In this example, the class User actually extends a DB model object of a hypotetica...
Laravel allows user work on multiple database connections. If you need to connect to multiple databases and make them work together, you are beware of the connection setup. You also allow using different types of database in the same application if you required. Default connection In config/dat...
[JsonObject("person")] public class Person { [JsonProperty("name")] public string PersonName { get; set; } [JsonProperty("age")] public int PersonAge { get; set; } [JsonIgnore] public string Address { get; set; } } Person person = new...
There are two common conventions for private fields: camelCase and _camelCaseWithLeadingUnderscore. Camel case public class Rational { private readonly int numerator; private readonly int denominator; public Rational(int numerator, int denominator) { // "this&q...

Page 290 of 1336