Tutorial by Examples: converti

Let's say you have a library that returns callbacks, for example the fs module in NodeJS: const fs = require("fs"); fs.readFile("/foo.txt", (err, data) => { if(err) throw err; console.log(data); }); We want to convert it to a promise returning API, with bluebird - ...
You can convert a single function with a callback argument to a Promise-returning version with Promise.promisify, so this: const fs = require("fs"); fs.readFile("foo.txt", (err, data) => { if(err) throw err; console.log(data); }); becomes: const promisify = requ...
In order to convert any callback API to promises assuming the promisify and promisifyAll version doesn't fit - you can use the promise constructor. Creating promises generally means specifying when they settle - that means when they move to the fulfilled (completed) or rejected (errored) phase to i...
To easily convert all tables in one database, use the following: SET @DB_NAME = DATABASE(); SELECT CONCAT('ALTER TABLE `', table_name, '` ENGINE=InnoDB;') AS sql_statements FROM information_schema.tables WHERE table_schema = @DB_NAME AND `ENGINE` = 'MyISAM' AND `TABLE_TYPE` = '...
import cv2 import numpy as np img = cv2.imread('<your_image>') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cv2.imshow('image', img) cv2.imshow('gray', gray) cv2.waitKey(0) cv2.destroyAllWindows()
Being able to understand Error/Exit codes is a fundamental skill for developers on Window's machine. Yet for many, the cryptic hexadecimal code that can be produced on an application exiting with on error can prove to be time consuming and painstaking process for the developer to track down and isol...
Usually the case when one wants to change a field type to another, for instance the original collection may have "numerical" or "date" fields saved as strings: { "name": "Alice", "salary": "57871", "dob": "198...
This example by Daniel Baggio was taken directly from this StackExchange answer, but has been reposted for visibility. This class takes an Mat object and returns the BufferedImage object used by the javax.swing libraries. This can be used by a Graphics object to draw the image. private BufferedIma...
const Promise = require('bluebird'), fs = require('fs') Promise.promisifyAll(fs) // now you can use promise based methods on 'fs' with the Async suffix fs.readFileAsync('file.txt').then(contents => { console.log(contents) }).catch(err => { console.error('error reading', er...
This example is how to turn an image into a Base64 string (i.e. a string you can use directly in a src attribute of an img tag). This example specifically uses the Imagick library (there are others available, such as GD as well). <?php /** * This loads in the file, image.jpg for manipulation....
Converting a java.util.Calendar object: Calendar rightNow = Calendar.getInstance(); LocalDate today = LocalDate.fromCalendarFields(rightNow); Converting a java.util.Date object: Date rightNow = new Date(); LocalDate today = LocalDate.fromDateFields(rightNow); Converting a string: String d...
As mentioned before strings are normally case insensitive but that only regards comparison of strings. There's built in functions for changing case. CAPS (string) Makes string upper case LC(string) Makes string lower case DEFINE VARIABLE c AS CHARACTER NO-UNDO. DEFINE VARIABLE d AS C...
Use Enum.chunk/2 to group elements into sub-lists, and Map.new/2 to convert it into a Map: [1, 2, 3, 4, 5, 6] |> Enum.chunk(2) |> Map.new(fn [k, v] -> {k, v} end) Would give: %{1 => 2, 3 => 4, 5 => 6}
Kotlin Plugin for Android Studio support converting existing Java files to Kotlin files. Choose a Java file and invoke action Convert Java File to Kotlin File:
Dim lo as ListObject Set lo = Sheet1.ListObjects("Table1") lo.Unlist
Many C++ libraries use enums and return/receive data using vectors that contain enums. As C enums are not Objective-C objects, Objective-C collections cannot be used directly with C enums. The example below deals with this by using a combination of an NSArray and generics and a wrapper object for th...
In the new Angular framework, Components are the main building blocks that compose the user interface. So one of the first steps that helps an AngularJS app to be migrated to the new Angular is to refactor it into a more component-oriented structure. Components were also introduced in the old Angu...
~~ Could be used on non-numeric values. A numeric expression will be first converted to a number and then performed bitwise NOT operation on it. If expression cannot be converted to numeric value, it will convert to 0. true and false bool values are exceptions, where true is presented as numeric v...

Page 4 of 4