scala
import org.scalatest.mock.MockitoSugar
import org.mockito.Mockito._
with MockitoSugar
class Solution { | |
public int lengthOfLongestSubstring(String s) { | |
int l = 0; | |
int result = 0; | |
Set<Character> set = new HashSet<>(); | |
// We start with right pointer from 0, both left and right are at 0!. | |
for (int r = 0; r < s.length(); r++) { | |
// As long as we have duplicates move left first. Trick! at first 0,0 no duplicates! | |
while (set.contains(s.charAt(r))) { | |
set.remove(s.charAt(l)); // Note we remove what left points to! until we remove all duplicates with left. |
_ |
// ==UserScript== | |
// @name Interview Run Code | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @include https://repl.it/* | |
// @include http://tomer-test-public.s3-website-us-west-2.amazonaws.com/* | |
// @grant none | |
// @require http://code.jquery.com/jquery-3.3.1.min.js |
brew install libpq | |
```R | |
install.packages('RPostgres') | |
library(RPostgres) | |
pconn_r <- dbConnect(RPostgres::Postgres(), | |
host = host, | |
port = port, | |
user = user, | |
password = password, | |
dbname = dbname, |
BigDecimal(1.002).setScale(2, BigDecimal.RoundingMode.HALF_UP).doubleValue() // Round double to #.## | |
| **Spark Term** | **Description** | | |
| ------------------------------------------------------------ | ------------------------------------------------------------ | | |
| Spreadsheet | Think of data as spreadsheet | | |
| Statistical learning | Output = f(input) # => f(inputVariable) or f(inputVector), or f(independent variables) or Y = F(X) // X1,X2,.. | | |
| Programming learning | OutputAttributes = Program(InputAttributes) or Program(InputFeatures) or Model = Algorithm(Data) | | |
| Error | Y = f(X) + e # => You learn a function! | | |
| Parametric learning | No |
> df <- data.frame(x=c("spam", "spam", "ham"), y=c("some mail", "some other mail", "some third mail")) | |
> add.string.func <- function(somestr) { paste("prefix-", somestr, "-postfix", sep = "") } | |
> df[1,] | |
x y | |
1 spam some mail | |
> df[,1] | |
[1] spam spam ham | |
Levels: ham spam | |
> apply(X = df[1,], add.string.func, MARGIN = 1) | |
1 |
df <- data.frame(x=c("spam", "spam", "ham"), y=c("some mail", "some other mail", "some third mail")) | |
names(df) <- c("Label", "Text") | |
df$Label <- as.factor(df$Label) // Fill by label would not work if not factor. | |
df$TextLength <- nchar(as.character(df$Text)) | |
View(df) | |
ggplot(df, aes(x = TextLength, fill = Label)) + theme_bw() + | |
geom_histogram(binwidth = 5) + | |
labs(y = "Text Count", x = "Length of Text", title = "Distribution of text on labels") |
library(RCurl) | |
library(bitops) | |
URL = "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv" | |
x = getURL(URL) | |
out = read.csv(textConnection(x)) | |
head(out[1:6]) |
mylog <- readLines("./reputation") # => R read load text file |