Trap expressions don't have to be individual functions or programs, they can be more complex expressions as well.
By combining jobs -p and kill, we can kill all spawned child processes of the shell on exit:
trap 'jobs -p | xargs kill' EXIT
Enum constants are instantiated when an enum is referenced for the first time. Therefore, that allows to implement Singleton software design pattern with a single-element enum.
public enum Attendant {
INSTANCE;
private Attendant() {
// perform some initialization routine
...
To get basic information about a DataFrame including the column names and datatypes:
import pandas as pd
df = pd.DataFrame({'integers': [1, 2, 3],
'floats': [1.5, 2.5, 3],
'text': ['a', 'b', 'c'],
'ints with None': [1, None, 3]})
...
NuGet version
Before you start: make sure your NuGet version is up to date.
In Visual Studio, go to Tools > Extensions and Updates, then Updates > Visual Studio Gallery. Check if there is a NuGet Update available and install it. Or, you can uninstall the existing nuget and reinstall it. It w...
End a line with two or more spaces to create a line break.
Ending a line with no spaces
or with just one space
doesn't create a line beak.
Use two or more spaces
to create a line break.
Use an empty line to make a new paragraph.
Ending a line with no spaces
or with just one space...
SilverStripe can be installed via composer or through the extraction of downloaded zip file.
To install through composer we run the following command
composer create-project silverstripe/installer /path/to/project 3.4.0
A download zip file can be found on the download page of the SilverStripe w...
You can validate any object, even plain ruby.
class User
include ActiveModel::Validations
attr_reader :name, :age
def initialize(name, age)
@name = name
@age = age
end
validates :name, presence: true
validates :age, numericality: { only_integer: true, greater_than...
You can use an initializer to set default property values:
struct Example {
var upvotes: Int
init() {
upvotes = 42
}
}
let myExample = Example() // call the initializer
print(myExample.upvotes) // prints: 42
Or, specify default property values as a part of the property...
Using the idiom from The Manual Way several times in a script soon gets tedious so you might want to try a module.
use Path::Tiny;
my $contents = path($filename)->slurp;
You can pass a binmode option if you need control over file encodings, line endings etc. - see man perlio:
my $contents =...
With the use of the extends keyword among classes, all the properties of the superclass (also known as the Parent Class or Base Class) are present in the subclass (also known as the Child Class or Derived Class)
public class BaseClass {
public void baseMethod(){
System.out.println(&...
To install the latest version of a package named SomePackage:
$ pip install SomePackage
To install a specific version of a package:
$ pip install SomePackage==1.0.4
To specify a minimum version to install for a package:
$ pip install SomePackage>=1.0.4
If commands shows permission den...
To list installed packages:
$ pip list
# example output
docutils (0.9.1)
Jinja2 (2.6)
Pygments (1.5)
Sphinx (1.1.2)
To list outdated packages, and show the latest version available:
$ pip list --outdated
# example output
docutils (Current: 0.9.1 Latest: 0.10)
Sphinx (Current: 1.1.2 Late...
Euler angles are "degree angles" like 90, 180, 45, 30 degrees. Quaternions differ from Euler angles in that they represent a point on a Unit Sphere (the radius is 1 unit). You can think of this sphere as a 3D version of the Unit circle you learn in trigonometry.
Quaternions differ from Eu...
When adding indented code blocks inside a list you first need a blank line, then to indent the code further. Different flavours of Markdown have different rules for this.
StackExchange requires code to be indented by 8 characters instead of the usual 4. (Spaces replaced with * for clarity):
1...
Examine the following strings:
foobarfoo
bar
foobar
barfoo
the regular expression bar will match all four strings,
\bbar\b will only match the 2nd,
bar\b will be able to match the 2nd and 3rd strings, and
\bbar will match the 2nd and 4th strings.
uvloop is an implementation for the asyncio.AbstractEventLoop based on libuv (Used by nodejs). It is compliant with 99% of asyncio features and is much faster than the traditional asyncio.EventLoop.
uvloop is currently not available on Windows, install it with pip install uvloop.
import asyncio
i...