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_01_fetch_tweets.r
Created July 24, 2017 10:59
Fetching tweets with R (sample for TC17)
library(twitteR)
library(ROAuth)
## Twitter authentication
## Replace strings with your credentials
setup_twitter_oauth("consumer_key", "consumer_secret",
"access_token", "access_secret")
# Fetch tweets from user timeline
tweets <- userTimeline("xlth", n = 3200)
@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@?^=%&/~+#-]))'
)