Skip to content

Instantly share code, notes, and snippets.

@tomer-ben-david
tomer-ben-david / longestSubsequenceNonRepeating.java
Created May 7, 2022 06:17
LeetCode 2 Find longest subsequence in string non repeating
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
@tomer-ben-david
tomer-ben-david / redshift.rstudio.R
Last active September 10, 2018 12:01
redshift rstudio
brew install libpq
```R
install.packages('RPostgres')
library(RPostgres)
pconn_r <- dbConnect(RPostgres::Postgres(),
host = host,
port = port,
user = user,
password = password,
dbname = dbname,
@tomer-ben-david
tomer-ben-david / scala.md
Last active April 10, 2018 12:14
#scala

scala

mockito

import org.scalatest.mock.MockitoSugar
import org.mockito.Mockito._

with MockitoSugar
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
@tomer-ben-david
tomer-ben-david / apply.function.to.matrix.R
Created January 20, 2018 10:11
apply function to matrix
> 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
@tomer-ben-david
tomer-ben-david / build.matrix.table.plot.R
Last active January 27, 2018 15:06
create matrix table r and plot load dataframe #R
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")
@tomer-ben-david
tomer-ben-david / read.csv.from.url.R
Created January 19, 2018 06:53
R read csv from URL #R
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])
@tomer-ben-david
tomer-ben-david / r.read.text.file.R
Created January 13, 2018 09:19
R read text file
mylog <- readLines("./reputation") # => R read load text file