Skip to content

Instantly share code, notes, and snippets.

View nathancday's full-sized avatar

Nathan (Nate) Day nathancday

View GitHub Profile
@nathancday
nathancday / trec_tok_vec
Created February 28, 2023 13:51
Hybrid vigor: a winning way to use hybrid search
PUT trec
{
"mappings": {
"properties": {
"title" : {"type": "text"},
"episode": {"type": "text"},
"text": {"type": "text"},
"embed": {"type": "dense_vector", "dims": 3}
}
}
@nathancday
nathancday / hyperparameter_optimization.py
Last active February 1, 2023 21:42
Companion code for the OSC blogpost "Maximizing Search Relevance with Hyperparameter Optimization"
#### SETUP ####
# 1. Download this GIST as a zip (download icon upper-right in web UI)
# 2. Unzip locally and navigate into new folder
# 3. Setup virtual Python environment with: `python3 -m venv venv`
# 4. Activate new virtual environment with: `source venv/bin/activate`
# 5. Install Python dependencies with: `pip install -r requirements.txt`
# 5. Run this file with: `python hyperparameter_optimization.py`
#### HELPERS ####
@nathancday
nathancday / weighted_sampling_scratch.R
Created October 24, 2022 11:47
Code snippet for demo and graphic in Probability-Proportional-To-Size-Sampling blogpost
#' ---
#' title: Code snippet for demo and graphic in Probability-Proportional-To-Size-Sampling blogpost
#' author: nathancday--at-Github--
#' date: 2022-10-24
#' ---
# Libs --------------------------------------------------------------------
library(cowplot)
library(tidyverse)
con <- file("test.log", "at")
sink(con, append=T, type = "message")
con <- file("test_sleep100.log", "at")
sink(con, append=T, type = "message")
library(purrr)
map(1:100,
possibly(function(x) {
library(scales)
library(magrittr)
library(tidyverse)
theme_set(
ggthemes::theme_fivethirtyeight(base_size = 10) +
theme(legend.position = "right",
legend.direction = "vertical",
axis.title = element_text())
)
@nathancday
nathancday / outline_demo.R
Created December 25, 2019 16:46
Open in Rstudio to see a outline demo for organizing your Rscripts
#' ---
#' title: The best title
#' author: You
#' date: 2019-12-25
#' ---
library(magrittr)
library(tidyverse)
# Import ------------------------------------------------------------------
@nathancday
nathancday / inputMap.R
Last active May 6, 2019 15:00
Using a leaflet map as Shiny input widget
library(shiny)
library(sf)
library(leaflet)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
ui <- fluidPage(
titlePanel("inputMap in Shiny"),
sidebarLayout(
sidebarPanel(
# https://en.wikipedia.org/wiki/Fizz_buzz
values <- 1:15
rules <- c("fizz" = 3, "buzz" = 5)
container <- rep("", length.out = length(values))
for (name in names(rules)) {
rule_idx <- values %% rules[name] == 0
function export_gcal_to_gsheet(){
// fill with your details
var mycal = "you@email.com";
var cal = CalendarApp.getCalendarById("email.com@hakjshfkhflsafkshfklaj@group.calendar.google.com");
// interval of interest
var events = cal.getEvents(new Date("August 1, 2018 00:00:00 CST"), new Date("August 31, 2018 23:59:59 CST"));
var sheet = SpreadsheetApp.getActiveSheet();
@nathancday
nathancday / gtfs_sf.R
Last active March 31, 2019 18:06
library(gtfs) %>% library(sf)
library(sf)
library(magrittr)
library(tidyverse)
gtfs_routes_sf <- function(gtfs) {
## gather key-values first ----
# trips_df has route_id:shape_id
shape_key <- gtfs$trips_df %>%