# example data
test_sentences <- c("The quick brown fox", "jumps over the lazy dog")
Is there a match?
grepl() is used to check whether a word or regular expression exists in a string or character vector. The function returns a TRUE/FALSE (or "Boolean") vecto...
We can repeat an action some number of times using repeat.
CL-USER> (loop repeat 10 do (format t "Hello!~%"))
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
Hello!
NIL
CL-USER> (loop repeat 10 collect (random 50))
(28 46 44 31 5 33 43 35 37 4)
Combining typedef with struct can make code clearer. For example:
typedef struct
{
int x, y;
} Point;
as opposed to:
struct Point
{
int x, y;
};
could be declared as:
Point point;
instead of:
struct Point point;
Even better is to use the following
typedef struct Poin...
Assuming that bar is an alias for someCommand -flag1.
Type bar on the command line and then press Ctrl+alt+e
you'll get someCommand -flag1 where bar was standing.
This example assumes you have already installed Java and Gradle.
Use the following project structure:
src/
main/
java/
com/
example/
Application.java
build.gradle
build.gradle is your build script for Gradle build system with the following content:
buildscri...
You should implement SFSafariViewControllerDelegate so that your class is notified when the user hits the Done button on the SafariViewController and you can dismiss it as well.
First declare your class to implement the protocol.
class MyClass: SFSafariViewControllerDelegate {
}
Implement th...
You can add items to a user's Reading List in Safari by calling the addItem method on the SSReadingList singleton.
let readingList = SSReadingList.default()
readingList?.addItem(with: yourURL, title: "optional title", previewText: "optional preview text")
The default Reading...
Considering the following dictionary:
d = {"a": 1, "b": 2, "c": 3}
To iterate through its keys, you can use:
for key in d:
print(key)
Output:
"a"
"b"
"c"
This is equivalent to:
for key in d.keys():
print(key)
...
Run the command below in a shell after installing Ruby. This shows how you can execute simple Ruby programs without creating a Ruby file:
ruby -e 'puts "Hello World"'
You can also feed a Ruby program to the interpreter's standard input. One way to do that is to use a here document in...
This is the code for a simple console project, that prints "Hello, World!" to STDOUT, and exits with an exit code of 0
[<EntryPoint>]
let main argv =
printfn "Hello, World!"
0
Example breakdown Line-by-line:
[<EntryPoint>] - A .net Attribute that m...
There are 16 fundamental data types, or classes, in MATLAB. Each of these classes is in the form of a matrix or array. With the exception of function handles, this matrix or array is a minimum of 0-by-0 in size and can grow to an n-dimensional array of any size. A function handle is always scalar (1...
The following program says hello to the user. It takes one positional argument, the name of the user, and can also be told the greeting.
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('name',
help='name of user'
)
parser.add_argument('-g', '--greeting',
...
Every package requires a setup.py file which describes the package.
Consider the following directory structure for a simple package:
+-- package_name
| |
| +-- __init__.py
|
+-- setup.py
The __init__.py contains only the line def foo(): return 100.
The following setup.py...
docopt turns command-line argument parsing on its head. Instead of parsing the arguments, you just write the usage string for your program, and docopt parses the usage string and uses it to extract the command line arguments.
"""
Usage:
script_name.py [-a] [-b] <path>
...
To find every vector of the form (x, y) where x is drawn from vector X and y from Y, we use expand.grid:
X = c(1, 1, 2)
Y = c(4, 5)
expand.grid(X, Y)
# Var1 Var2
# 1 1 4
# 2 1 4
# 3 2 4
# 4 1 5
# 5 1 5
# 6 2 5
The result is a data.frame with one...
unique drops duplicates so that each element in the result is unique (only appears once):
x = c(2, 1, 1, 2, 1)
unique(x)
# 2 1
Values are returned in the order they first appeared.
duplicated tags each duplicated element:
duplicated(x)
# FALSE FALSE TRUE TRUE TRUE
anyDuplicated(x) >...
To count how many elements of two sets overlap, one could write a custom function:
xtab_set <- function(A, B){
both <- union(A, B)
inA <- both %in% A
inB <- both %in% B
return(table(inA, inB))
}
A = 1:20
B = 10:30
xtab_set(A, B)
# inB
...
You can restrict the valid types used in a generic class by bounding that type in the class definition. Given the following simple type hierarchy:
public abstract class Animal {
public abstract String getSound();
}
public class Cat extends Animal {
public String getSound() {
...
Have a table
NameAgeCityBob10ParisMat20BerlinMary24Prague
select Name from table where Age>10 AND City='Prague'
Gives
NameMary
select Name from table where Age=10 OR City='Prague'
Gives
NameBobMary
For if you have to fine-tune what is published.
import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
if (Meteor.isClient) {
// established this collection on the client only.
// a name is required (first parameter) and this...