Tutorial by Examples: converti

Boolean(...) will convert any data type into either true or false. Boolean("true") === true Boolean("false") === true Boolean(-1) === true Boolean(1) === true Boolean(0) === false Boolean("") === false Boolean("1") === true Boolean("0") === t...
If you're ever dealing with C Binary API's from Perl Code, via the syscall, ioctl, or fcntl functions, you need to know how to construct memory in a C Compatible way. For instance, if you were ever dealing with some function that expected a timespec, you'd look into /usr/include/time.h and find: s...
First the setup for the example: import datetime as dt from sqlalchemy import Column, Date, Integer, Text, create_engine, inspect from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() Session = sessionmaker() class User(B...
In SQLAlchemy core, the result is RowProxy. In cases where you want an explicit dictionary, you can call dict(row). First the setup for the example: import datetime as dt from sqlalchemy import ( Column, Date, Integer, MetaData, Table, Text, create_engine, select) metadata = MetaData() u...
Use TO_CHAR( date [, format_model [, nls_params]] ): (Note: if a format model is not provided then the NLS_DATE_FORMAT session parameter will be used as the default format model; this can be different for every session so should not be relied on. It is good practice to always specify the format mod...
Int("123") // Returns 123 of Int type Int("abcd") // Returns nil Int("10") // Returns 10 of Int type Int("10", radix: 2) // Returns 2 of Int type Double("1.5") // Returns 1.5 of Double type Double("abcd") // Returns nil Note that do...
Destructuring also gives you the ability to interpret a sequence as a map: (def my-vec [:a 1 :b 2]) (def my-lst '("smthg else" :c 3 :d 4)) (let [[& {:keys [a b]}] my-vec [s & {:keys [c d]} my-lst] (+ a b c d)) ;= 10 It is useful for defining functions with named p...
The function toupper will convert a string to upper case (capital letters). For example: BEGIN { greeting = "hello" loud_greeting = toupper(greeting) print loud_greeting } This code will output "HELLO" when run.
The datetime module can convert a POSIX timestamp to a ITC datetime object. The Epoch is January 1st, 1970 midnight. import time from datetime import datetime seconds_since_epoch=time.time() #1469182681.709 utc_date=datetime.utcfromtimestamp(seconds_since_epoch) #datetime.datetime(2016, 7, 2...
1. URLByDeletingPathExtension: If the receiver represents the root path, this property contains a copy of the original URL. If the URL has multiple path extensions, only the last one is removed. 2. URLByAppendingPathExtension: Returns a new URL made by appending a path extension to the original U...
When you need to pass a collection into a Java method: import scala.collection.JavaConverters._ val scalaList = List(1, 2, 3) JavaLibrary.process(scalaList.asJava) If the Java code returns a Java collection, you can turn it into a Scala collection in a similar manner: import scala.collectio...
GetLastError returns a numerical error code. To obtain a descriptive error message (e.g., to display to a user), you can call FormatMessage: // This functions fills a caller-defined character buffer (pBuffer) // of max length (cchBufferLength) with the human-readable error message // for a Win32 ...
There are various methods available for explicitly converting a string to an integer, such as: Convert.ToInt16(); Convert.ToInt32(); Convert.ToInt64(); int.Parse(); But all these methods will throw a FormatException, if the input string contains non-numeric characters. For t...
Dart has a robust async library, with Future, Stream, and more. However, sometimes you might run into an asynchronous API that uses callbacks instead of Futures. To bridge the gap between callbacks and Futures, Dart offers the Completer class. You can use a Completer to convert a callback into a Fut...
A method can be converted to a closure using the & operator. def add(def a, def b) { a + b } Closure addClosure = this.&add assert this.add(4, 5) == addClosure(4, 5)
var degrees:Number = radians * 180 / Math.PI;
var radians:Number = degrees / 180 * Math.PI;
When you need to set a pixel value for something like Paint.setTextSize but still want it be scaled based on the device, you can convert dp and sp values. DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); float pixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12f, m...
You can convert a numeric string to various Java numeric types as follows: String to int: String number = "12"; int num = Integer.parseInt(number); String to float: String number = "12.0"; float num = Float.parseFloat(number); String to double: String double = "1...
In Java, we can convert between integer values and floating-point values. Also, since every character corresponds to a number in the Unicode encoding, char types can be converted to and from the integer and floating-point types. boolean is the only primitive datatype that cannot be converted to or f...

Page 2 of 4