Skip to content

Instantly share code, notes, and snippets.

View MattSandy's full-sized avatar
💭
Hungry

Matt Sandy MattSandy

💭
Hungry
View GitHub Profile
@MattSandy
MattSandy / .dockerfile
Created June 30, 2023 21:12
Another way to get sftp access to docker volume
FROM ubuntu:latest
# Install SSH server and SFTP
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
# Create a new user 'sftpuser' with password 'password' (replace with your own credentials)
RUN useradd -rm -d /home/sftpuser -s /bin/bash -g root -G sudo -u 1001 sftpuser
RUN echo 'sftpuser:password' | chpasswd
@MattSandy
MattSandy / app.js
Last active January 20, 2024 15:57
Tweet Scraper in Node.JS
var Twitter = require('node-tweet-stream')
, t = new Twitter({
consumer_key: '',
consumer_secret: '',
token: '',
token_secret: ''
});
var watch = [
"SB52",
"SBLII",
@MattSandy
MattSandy / companies_2022.R
Created August 19, 2022 13:54
Inc. 5000 2022
library(tidyverse)
library(jsonlite)
df <- "https://api.inc.com/rest/i5list/2022" %>%
fromJSON() %>%
.$companies %>%
bind_rows() %>%
group_by(inc5000companyId) %>%
mutate(
article = ifelse(is.null(article %>% unlist %>% .[1]),NA,article %>% unlist %>% .[1]),
editorsPick = editorsPick %>% unlist %>% paste(collapse = ",")
@MattSandy
MattSandy / benchmark.R
Last active June 14, 2023 18:42
Two ways of formatting time periods from numeric
library(microbenchmark)
long_way <- function(time_vector) {
return(
time_vector |>
lapply(function(x){
(x |>
str_match_all("[0-9]{1}") |>
unlist() |>
rev())[1:4] |>
(\(time){
@MattSandy
MattSandy / client.R
Created March 21, 2023 18:50
R Socket Sending Bin
con <- socketConnection(
host="localhost",
port = 6011,
blocking=TRUE,
server=FALSE,
open="r+"
)
the_data <- "testing this dang thing"
write_resp <- writeLines(as.character(nchar(the_data)), con)
@MattSandy
MattSandy / run.R
Created December 16, 2022 19:45
SWRLT
library(sf)
library(ggmap)
library(ggplot2)
library(ggthemes)
library(dplyr)
library(magrittr)
library(data.table)
# Fetching
library(rvest)
# Cleaning column names
@MattSandy
MattSandy / ReadMe.md
Last active November 8, 2022 17:54
SocketIO Client and Server Performance

SocketIO Performance Tests for Server and Client

Logs milliseconds for each leg of a websocket event.

@MattSandy
MattSandy / run.R
Created November 2, 2022 14:07
GT Table Grouping
library(tidyverse)
library(gt)
mtcars %>%
group_by(gear,cyl) %>%
summarise(
n = n(),
mpg = mean(mpg)
) %>% (function(df){
df$gear[which(duplicated(df$gear))] <- ' '
return(df)
@MattSandy
MattSandy / tree.R
Created December 19, 2021 20:05
Christmas Tree in R
library(tidyverse)
df <- data.frame(
x1 = rep(0,200),
y1 = 21:220 + sample(1:10,200,replace = TRUE),
g = 1:200
) %>%
cbind(
data.frame(
x2 = (200:1 + (sample(1:200,200,replace = TRUE)/100)) / 1.5,
y2 = 1:200 - log(1:20) - (sample(1:200,200,replace = TRUE)/100)
@MattSandy
MattSandy / compare_user_activity.R
Created October 23, 2021 16:51
Looks at number of Reddit comments in the last 60 days
library(tidyverse)
library(glue)
library(jsonlite)
library(lubridate)
df <- c("user_a","user_b") %>%
lapply(function(user){
after <- ""
df <- list()
for(i in 1:40) {