Skip to content

Instantly share code, notes, and snippets.

View aloth's full-sized avatar

Alexander Loth aloth

View GitHub Profile
select
guid
, regexp_split_to_table(lower(post_content), '\s+') as word
, count(1) as word_count
from
alexblog_posts
group by
guid, word
CASE LEFT([Word], 1)
WHEN "#" THEN "Hash Tag"
WHEN "@" THEN "User Reference"
ELSE "Regular Content"
END
SCRIPT_STR('
library(sentiment)
get_emotion(.arg1, algorithm = "bayes")
'
, ATTR([Tweet Text]))
SCRIPT_STR('
library(sentiment)
get_polarity(.arg1, algorithm = "bayes")
'
, ATTR([Tweet Text]))
install.packages("devtools")
library(devtools)
install_github("aloth/sentiment/sentiment")
install.packages("Rcpp")
install.packages("http://alexloth.com/utils/sentiment/current/sentiment.zip",repos=NULL)
SCRIPT_REAL('
import numpy as np
return np.corrcoef(_arg1,_arg2)[0,1]
',
SUM([Sales]), SUM([Profit]))
SCRIPT_INT('
kmeans(data.frame(.arg1,.arg2,.arg3),' + STR([Cluster Amount]) + ')$cluster;
',
SUM([Sales]), SUM([Profit]), SUM([Quantity]))
@aloth
aloth / tc17_03_url_unshorten.txt
Created July 24, 2017 12:49
Unshorten URLs in Tableau with R
SCRIPT_STR('
newurl <- .arg1
url <- ""
while(url != newurl){
data <- system(toString(paste0("curl -I ", newurl)), intern=T)
if(sum(grepl("location: ", tolower(data))) == 0){
url <- newurl
}else{
data <- subset(data, tolower(substring(data, 1, 9))=="location:")
stringurl <- substring(data[1], 11, nchar(data[1])-1)
@aloth
aloth / tc17_02_url_extract.txt
Last active July 24, 2017 12:50
Extract URLs in Tableau with Regex
REGEXP_EXTRACT(
[Post Message],
'((?:http|https)://(?:[\w_-]+(?:(?:\.[\w_-]+)+))(?:[\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-]))'
)