Skip to content

Instantly share code, notes, and snippets.

View jongbinjung's full-sized avatar

Jongbin Jung jongbinjung

View GitHub Profile
@jongbinjung
jongbinjung / parse_gsheet.py
Last active October 11, 2023 17:38
Load and parse data from Gsheet
#!/usr/bin/env python
"""Collect and parse data from Gsheet
Read spreadsheet from https://docs.google.com/spreadsheets/d/{SHEET_ID}
and parse as a polars DataFrame.
This example is using a benign sheet of junk from
https://docs.google.com/spreadsheets/d/1cFVczEL7oznX_G-_VyJv5tgkEPmoVHRsGanzMj1O4nM
but should give you the idea.
@jongbinjung
jongbinjung / pendulum_examples.py
Created June 23, 2023 00:35
Example of some common pendulum use cases
#!/usr/bin/env python3
"""
Example of common pendulum use cases
Author: jongbin.jung
"""
import pandas as pd
import pendulum
results <- foreach(i=1:1000, .combine = bind_rows) %:%
foreach(method=c("binomial", "quasibinomial"), .combine = bind_rows) %dopar% {
beta <- 0.1
df <- data.frame(id = rep(1:1000, 2)) %>%
mutate(m = rnorm(2000, 0, 1),
x = rnorm(2000, m, 2),
e = rnorm(2000, 0, beta / 2),
y = inv_logit(1 + beta*x+e)) %>%
@jongbinjung
jongbinjung / srr-example.R
Created May 16, 2017 18:20
Select-regress-and-round
# Assuming a (logistic) model with k features fit in R with the variable name "model",
# generate a simple rule that uses integers in the range [-M, M]:
# (note that M is set to 3 in this example)
M <- 3
model_coefs <- coef(model)
scaled_coefs <- (model_coefs / max(model_coefs)) * M
rounded_coefs <- round(scaled_coefs)
# The k features to be included in the initial model is best determined by domain expertise,
# i.e., what are the minimal features that expert(s) in the field believes to be predictive
@jongbinjung
jongbinjung / gist:8eaef8cb335392aba63d
Created September 30, 2015 18:10 — forked from jrnold/gist:6799152
Create a plot of the normal distribution with an area shaded in. Useful for teaching z-scores and stuff like that.
library("ggplot2")
#' Draw Normal Distribution Density with an area shaded in.
#'
#' @param lb Lower bound of the shaded area. Use \code{-Inf} for a left tail.
#' @param ub Upper bound of the shaded area. Use \code{Inf} for a right tail.
#' @param mean Mean of the normal distribution
#' @param sd Standard deviation of the normal distribution
#' @param limits Lower and upper bounds on the x-axis of the area displayed.
#' @return ggplot object.
@jongbinjung
jongbinjung / ViNavigation.ahk
Created December 14, 2012 17:48
Vi-like navigation for AutoHotKey
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; HotKey to Initiate VI-mode with Double-tap of Alt
Shift::
If (A_PriorHotKey = "Shift" AND A_TimeSincePriorHotKey < 200)
{
; Set the flags for OSD
Gui, 99:+AlwaysOnTop -Caption +ToolWindow +Disabled -SysMenu +Owner