Skip to content

Instantly share code, notes, and snippets.

View StevenMMortimer's full-sized avatar

Steven M. Mortimer StevenMMortimer

View GitHub Profile
@StevenMMortimer
StevenMMortimer / most-starred-r-packages.R
Last active March 8, 2024 22:06
Most Starred R Packages
# load packages & custom functions ---------------------------------------------
today_date <- Sys.Date()
from_date <- as.Date("2015-06-01")
to_date <- as.Date("2020-05-31")
library(tidyverse)
library(httr)
library(cranlogs)
library(ggrepel)
options(stringsAsFactors = FALSE)
library(rjson)
library(RDSTK)
street2coordinates <- function (address, session = getCurlHandle())
{
api <- paste(getOption("RDSTK_api_base"), "/street2coordinates/",
sep = "")
get.addy <- getURL(paste(api, URLencode(address), sep = ""),
**Convert .ipynb to Slides**
cd "test"
ipython nbconvert "test.ipynb" --to slides --reveal-prefix "http://cdn.jsdelivr.net/reveal.js/2.6.2" --post serve --config slides_config.py
* To print slides add ?print-pdf at the end of the URL and print
**Convert .ipynb to LaTex/PDF**
ipython nbconvert MyFirstNotebook.ipynb --to latex --post PDF
**Convert .ipynb to HTML**
library(RSelenium)
appURL <- "XXXXXX.com"
username <- "myusername"
password <- "mypassword"
RSelenium::startServer()
library(RSelenium)
RSelenium::startServer()
pJS <- phantom(pjs_cmd='path/to/phantomjs',
curl -u userName:password -H "Accept: application/json" http://locahost:8080/pentaho/api/userroledao/users
curl -u userName:password -H "Accept: application/json" http://locahost:8080/pentaho/api/userroledao/roles
curl -X PUT -u userName:password http://locahost:8080/pentaho/api/userroledao/createUser \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{ "userName" : "Test1", "password" : "test" }'
curl -X PUT -u userName:password http://locahost:8080/pentaho/api/userroledao/createUser \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
res <- sendmail(from="{my_gmail_account}",
to='[email protected]',
subject='Test',
msg=doc,
headers=list(`Content-Type` = "text/html; charset=\"utf-8\""),
smtp = list(host.name = "smtp.gmail.com", port = 465,
ssl=TRUE, user.name = "{my_gmail_account}",
passwd = "{my_gmail_password}"))
# BELOW IS THE FORMAT OF A CRONTAB THAT WILL:
# EXECUTE AN R SCRIPT COMMAND, SEND STDERR AND STDOUT TO A TEMP FILE
# WHILE ONLY SENDING THE CONTENTS OF THE TEMP FILE TO SCREEN, WHICH TRIGGERS AN EMAIL,
# IF THE EXIT CODE OF THE RSCRIPT WAS NON-ZERO
# ESSENTIALLY CONFIGURATION LOGS EVERYTHING WHILE EMAILING ONLY ON ERROR
#
# To install a cron from this file use:
# dos2unix < mycrontab.txt | crontab -
# NOTE: mycrontab.txt must have everything needed since it completely wipes the existing crontab
#
-- create a rule that will ignore dupe inserts
-- this is done on a table-by-table basis
CREATE OR REPLACE RULE db_table_ignore_duplicate_inserts AS
ON INSERT TO schema.table
WHERE EXISTS (
SELECT 1
FROM schema.table
WHERE id = NEW.id
)
DO INSTEAD NOTHING;
# request the report
# this returns a reportID that's used for retrieving the results
curl https://api5.omniture.com/admin/1.4/rest/?method=Report.Queue \
-H "Accept: application/json" \
-H 'Authorization: WSSE profile="UsernameToken"' \
-H 'X-WSSE: UsernameToken Username="my.username:My Company", PasswordDigest="{sha1 encrypted password goes here}", Nonce="1450112360.27583", Created="2015-12-14T16:59:20Z"' \
-X POST \
-d '{
"reportDescription":{
# in existing base R the dataframe method of duplicated won't do multiple incomparables at a time
# this function implements that
myduplicatedfunc <- function(x, incomparables = FALSE, fromLast = FALSE, ...) {
n <- ncol(x)
nmx <- names(x)
nmincomparables <- names(incomparables)
lincomparables <- length(incomparables)
if(is.null(nmincomparables)) {