Skip to content

Instantly share code, notes, and snippets.

View joshua-feldman's full-sized avatar

Joshua Feldman joshua-feldman

View GitHub Profile
@joshua-feldman
joshua-feldman / is_anagram.R
Created April 24, 2021 16:36
Function to check whether two words are anagrams
# FUNCTION TO CHECK WHETHER TWO WORDS ARE ANAGRAMS
# Based on the following logic by @fermatslibrary:
# 1. Map each of the 26 English characters to a prime number
# 2. Multiply the characters of each word
# 3. Two words are anagrams if their products are the same
# This works because every integer is a prime or a unique product of primes
library(magrittr)
@joshua-feldman
joshua-feldman / matrix-factorisation-demo.R
Created December 9, 2019 10:09
Matrix factorisation demo using sparklyr
##############################
# 1. SETUP #
##############################
library(tidyverse)
library(sparklyr)
library(formattable)
set.seed(1234)
@joshua-feldman
joshua-feldman / prepend_functions.R
Last active February 11, 2024 13:24
Prepend all functions in an R script with package name
# Load the relevant packages
library(NCmisc)
library(stringr)
# Load the script and parse lines
file_name <- "example_script.R"
file_lines <- readLines(file_name)
# Save the function and package names
functions_list <- list.functions.in.file(file_name)