Skip to content

Instantly share code, notes, and snippets.

View bfatemi's full-sized avatar
🎯
In my zone

Bobby Fatemi bfatemi

🎯
In my zone
View GitHub Profile
library(shiny)
user_selected <- reactiveValues(a = 1, b = 1, c = 1)
observeEvent(input$slider, {
apt-get install -y unixodbc unixodbc-dev
apt-get install -y odbc-postgresql
odbcinst -i -s -l -f template/dsn_template_file
## as admin user
##
sudo adduser rsc-demo # passwd +Ds&.dm/YL!^RX6-
sudo useradd rsc-client # passwd: +Ds&.dm/YL!^RX6-
sudo usermod -aG rstudio-connect rsc-client
sudo usermod -aG rstudio-connect rsc-demo
##
## POSTGRES LITE DOCKERFILE- create db, user/pwd, and open listening
##
FROM postgres:11.1-alpine
ADD ./init.sh /docker-entrypoint-initdb.d/.
ENV PGDATA /var/lib/postgresql/data
EXPOSE 5432
#!/bin/bash
set -e
set -u
#
# GROUP: min user access...
# - can connect to database
# - can access schema
# - can read schema tables
#
# Change directory to the current Finder directory
cdf() {
target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
if [ "$target" != "" ]; then
cd "$target"; pwd
else
echo 'No Finder window found' >&2
fi
}
@bfatemi
bfatemi / implementDF.R
Created June 5, 2019 21:57
Better way to define a data.table (implement using structure)
# Usecases:
# when creating many R environments and each have independent data-set
ll <- list(
as.factor(c(2001, 2002, 2004, 2006)),
I(c(2001, 2002, 2004, 2006)),
ordered(c(2001, 2002, 2004, 2006)),
as.double(c(366.3240, 365.4124, 366.5323423, 364.9573234)),
@bfatemi
bfatemi / abcExample.r
Created June 5, 2019 03:12
activeBinding
ABC <- local({
x <- 1
function(v) {
if (missing(v)){
cat("get\n")
} else {
cat("set\n")
x <<- v
}
x
@bfatemi
bfatemi / example_quantile_reg.R
Created April 4, 2019 01:55
Example of plotting quantile regression in R.
install.packages("quantreg")
pdt <- dt[durProc < 400 &
ExpIndex < 500 &
ExpIndex > 4]
pdt2 <- pdt[, .(aveDur = mean(durProc)), ExpIndex][order(ExpIndex)]
m <- ggplot(pdt2, aes(ExpIndex, aveDur)) +
@bfatemi
bfatemi / example_loading_page.R
Created April 4, 2019 01:54
Loading page for shiny/R app implemented with the shinyjs R package.
library(shiny)
library(shinyjs)
load_data <- function() {
Sys.sleep(2)
hide("loading_page")
show("main_content")
}
ui <- fluidPage(