Skip to content

Instantly share code, notes, and snippets.

View mkearney's full-sized avatar
📈
Data Sciencing

Michael W. Kearney mkearney

📈
Data Sciencing
View GitHub Profile
library(V8)
library(rvest)
library(hrbrthemes)
library(tidyverse)
ctx <- v8()
pg <- read_html("https://www.tiobe.com/tiobe-index/")
html_nodes(pg, xpath=".//script[contains(., 'series:')]") %>%

Keybase proof

I hereby claim:

  • I am mkearney on github.
  • I am kearneymw (https://keybase.io/kearneymw) on keybase.
  • I have a public key ASAprxnmWoBc1OCGFVW6Lid1F4IXNx6uabYjq-hOiDx_hQo

To claim this, I am signing this object:

@mkearney
mkearney / get-gh-stars.R
Last active February 22, 2019 09:16
Get a tidy data frame of information about all of your Github stars (repos you've starred)
## install {remotes} pkg
if (!requireNamespace("remotes", quietly = TRUE)) {
install.packages("remotes")
}
## install {tfse} from github
remotes::install_github("mkearney/tfse")
## load {tfse}
library(tfse)
@mkearney
mkearney / tax-tweets-to-trump.R
Last active February 7, 2019 21:21
Sentiment of tax-related tweets sent to:realDonaldTrump
## install packages (from CRAN) if not already
pkgs <- c("dplyr", "rtweet", "ggplot2", "syuzhet", "ggbeeswarm", "remotes")
if (any(!pkgs %in% installed.packages())) {
install.packages(pkgs[!pkgs %in% installed.packages()])
}
## install {dataviz} theme from github
remotes::install_github("mkearney/dataviz")
## define paste function I really like rn
#' Conditionally apply expressions on a data object
#'
#' @param .data Input data
#' @param condition A logical value to determine whether to use .if or .else
#' @param .if Formula or function to apply to intput data when condition is TRUE
#' @param .else Formula or function to apply to intput data when condition is FALSE
#' @return Output of appropriate .if/.else call
#' @export
#' @importFrom rlang as_closure
do_if_else <- function(.data, condition, .if, .else = identity) {
@mkearney
mkearney / keynote.R
Last active November 16, 2019 17:40 — forked from dkiesow/keynote.R
R script used with rtweet and Keynote rTweet AppleScript to automate tweets from Mac Keynote
#!/usr/bin/env Rscript
##keynote.R v1.0 Damon Kiesow @dkiesow
##Use with the Keynote rTweet AppleScript app to automate threaded tweeting during Keynote presentations
##
## load rtweet package
library(rtweet)
me <- rtweet:::home_user()
## Pull parameters from command line (first_status will be "yes" or "no" and provided from the AppleScript)
args <- commandArgs(trailingOnly = TRUE)
@mkearney
mkearney / lav-clpm-3var.R
Created August 27, 2019 14:33
Example of a three-variable cross lagged panel model in R using {lavaan}
## generate data set
x2 <- rnorm(200)
x1 <- x2 + rnorm(200)
y2 <- rnorm(200) + x2
y1 <- y2 + rnorm(200)
z2 <- rnorm(200) + y2
z1 <- z2 + rnorm(200)
d <- data.frame(x1, x2, y1, y2, z1, z2)
## specify null and full models
@mkearney
mkearney / bytes2char.R
Created August 27, 2019 20:34
Convert bytes in string to appropriate char(s)
bytes2char <- function(x) {
m <- gregexpr("<[[:alnum:]]{2}>", x)
y <- regmatches(x, m)[[1]]
y <- gsub("^<|>$", "", y)
y <- strsplit(y, "[><]+")
regmatches(x, m) <- list(sapply(y, function(.x) rawToChar(as.raw(paste0("0x", .x)))))
x
}
## read in string with bytes
@mkearney
mkearney / anyconnect.scpt
Created September 12, 2019 21:57 — forked from andrewh/anyconnect.scpt
Applescript to automate the Cisco AnyConnect SSL VPN client on OS X Mavericks
-- 1. Place in ~/Library/Scripts and enable the Applescript menu via the Applescript Editor
-- 2. Substitute "vpn.example.com" and "redacted" for your VPN server and password
-- 3. Open Security & Privacy System Preferences, go to Privacy, Accessibility
-- 4. Enable Applescript Editor and System UI Server
-- 5. Trigger script from the menu
-- 6. Enjoy being connected
tell application "Cisco AnyConnect Secure Mobility Client"
activate
end tell
@mkearney
mkearney / get-congress-follows.R
Created October 31, 2019 21:53
Get all accounts followed by members of the U.S. Congress
## load rtweet and congress116
library(rtweet)
library(congress116)
## create long-version of congress116 data (and drop rows w/o screen names)
sns <- with(congress116, data.frame(
bioguide = c(bioguide, bioguide[!is.na(screen_name_personal)]),
handle = c(screen_name_official, screen_name_personal[!is.na(screen_name_personal)]),
stringsAsFactors = FALSE
))