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...
You can open a connection (i.e. request one from the pool) using a context manager:
with engine.connect() as conn:
result = conn.execute('SELECT price FROM products')
for row in result:
print('Price:', row['price'])
Or without, but it must be closed manually:
conn = engine.co...
There are multiple ways to populate an array.
Directly
'one-dimensional
Dim arrayDirect1D(2) As String
arrayDirect(0) = "A"
arrayDirect(1) = "B"
arrayDirect(2) = "C"
'multi-dimensional (in this case 3D)
Dim arrayDirectMulti(1, 1, 2)
arrayDirectMulti(0, 0, 0...
Smoothing, also known as blurring, is one of the most commonly used operation in Image Processing.
The most common use of the smoothing operation is to reduce noise in the image for further processing.
There are many algorithms to perform smoothing operation.
We'll look at one of the most commonl...
Python has only limited support for parsing ISO 8601 timestamps. For strptime you need to know exactly what format it is in. As a complication the stringification of a datetime is an ISO 8601 timestamp, with space as a separator and 6 digit fraction:
str(datetime.datetime(2016, 7, 22, 9, 25, 59, 55...
import flash.net.URLRequest;
import flash.media.Sound;
import flash.events.Event;
var req:URLRequest = new URLRequest("filename.mp3");
var snd:Sound = new Sound(req);
snd.addEventListener(Event.COMPLETE, function(e: Event)
{
snd.play(0, int.MAX_VALUE); // There is no way to...
The Iterator.remove() method is an optional method that removes the element returned by the previous call to Iterator.next(). For example, the following code populates a list of strings and then removes all of the empty strings.
List<String> names = new ArrayList<>();
names.add("...
File streams are buffered by default, as are many other types of streams. This means that writes to the stream may not cause the underlying file to change immediately. In oder to force all buffered writes to take place immediately, you can flush the stream. You can do this either directly by invokin...
The numpy.reshape (same as numpy.ndarray.reshape) method returns an array of the same total size, but in a new shape:
print(np.arange(10).reshape((2, 5)))
# [[0 1 2 3 4]
# [5 6 7 8 9]]
It returns a new array, and doesn't operate in place:
a = np.arange(12)
a.reshape((3, 4))
print(a)
# ...
Install the necessary Python Library via:
$ pip install elasticsearch
Connect to Elasticsearch, Create a Document (e.g. data entry) and "Index" the document using Elasticsearch.
from datetime import datetime
from elasticsearch import Elasticsearch
# Connect to Elasticsearch using ...
To filter a slice without allocating a new underlying array:
// Our base slice
slice := []int{ 1, 2, 3, 4 }
// Create a zero-length slice with the same underlying array
tmp := slice[:0]
for _, v := range slice {
if v % 2 == 0 {
// Append desired values to slice
tmp = append(tmp, ...
A Service is a component which runs in the background (on the UI thread) without direct interaction with the user. An unbound Service is just started, and is not bound to the lifecycle of any Activity.
To start a Service you can do as shown in the example below:
// This Intent will be used to star...
The unary negation (-) precedes its operand and negates it, after trying to convert it to number.
Syntax:
-expression
Returns:
a Number.
Description
The unary negation (-) can convert the same types / values as the unary plus (+) operator can.
Values that can't be converted will evaluat...
rgdal
ESRI shape files can easily be imported into R by using the function readOGR() from the rgdal package.
library(rgdal)
shp <- readORG(dsn = "/path/to/your/file", layer = "filename")
It is important to know, that the dsn must not end with / and the layer does not all...
The difference between size and count is:
size counts NaN values, count does not.
df = pd.DataFrame(
{"Name":["Alice", "Bob", "Mallory", "Mallory", "Bob" , "Mallory"],
"City":["Seattle", &q...