Skip to content

Instantly share code, notes, and snippets.

@jsks
jsks / gmm_em.jl
Created February 18, 2024 21:19
Gaussian mixture model
using Distributions, LinearAlgebra, LogExpFunctions
function gaussians(μ, Σ)
@views [MvNormal(μ[:, i], Σ[:, :, i]) for i in 1:size(μ, 2)]
end
function E_step!(Y, γ, π, μ, Σ)
dists = gaussians(μ, Σ)
lpi = log.(π)
@jsks
jsks / gmm_em.R
Last active June 20, 2023 13:54
Expectation maximization in R
#!/usr/bin/env Rscript
#
# Gaussian mixture model fit with the expectation-maximization algorithm
###
library(mclust)
library(mvtnorm)
set.seed(4323)
@jsks
jsks / fit.R
Created July 26, 2022 21:36
SRM in Stan
#!/usr/bin/env Rscript
library(cmdstanr)
library(dplyr)
options(mc.cores = parallel::detectCores() - 1)
load("./day5.rda")
# Actor list
@jsks
jsks / .gitignore
Last active November 29, 2021 16:27
Default gitignore for new Rmarkdown projects
data/
stan/*
!stan/*.stan
.DS_Store
.Rhistory
.Rprof.user
\#*\#
.\#*
@jsks
jsks / Makefile
Last active May 6, 2021 14:50
Makefile template for Rmarkdown projects
# Makefile template for Rmarkdown projects
#
# Includes implicit rules to generate pdf and html versions of Rmd
# files as well as several commands for development workflows.
#
# Invoke `make help` to get started.
#
# By default, Make will compile the pdf versions of all Rmd files
# found in the current working directory.
#
@jsks
jsks / bf.c
Created August 15, 2020 20:17
Brainfuck interpreter in C
/*
* Copyright (c) 2020, Joshua Krusell
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@jsks
jsks / 0001-Python-3.8-support-10777.patch
Created November 21, 2019 19:05
azure-cli python3.8 archlinux
From b7b0801c8b9a97a67b1e329d25fe090fe61a818d Mon Sep 17 00:00:00 2001
From: Jamie Magee <JamieMagee@users.noreply.github.com>
Date: Thu, 31 Oct 2019 09:57:34 +0100
Subject: [PATCH] Python 3.8 support (#10777)
* Python 3.8 support
time.clock() was deprecated in Python 3.3, and removed in Python 3.8. Python 3.8 will be released on 14th October. See [PEP 596](https://www.python.org/dev/peps/pep-0569/) for more info.
Tested locally against Python 3.8.0rc1.
@jsks
jsks / retina.patch
Created January 3, 2019 15:45
YAMAMOTO Mitsuharu's patch for pdf-tools on MacOS https://lists.gnu.org/archive/html/emacs-devel/2016-04/msg00648.html
diff --git a/lisp/pdf-annot.el b/lisp/pdf-annot.el
index b0ff3c2..82cf122 100644
--- a/lisp/pdf-annot.el
+++ b/lisp/pdf-annot.el
@@ -981,6 +981,7 @@ other annotations."
(pdf-cache-renderpage-highlight
page (car size)
`("white" "steel blue" 0.35 ,@edges))
+ :width (car size)
:map (pdf-view-apply-hotspot-functions
@jsks
jsks / pkgBuild.R
Last active June 5, 2017 12:11
R Build Script
#!/usr/bin/env Rscript
#
# Simple R pkg build script with logging posted to Slack. Output gets copied to
# a pkg repository under `/usr/share/nginx/R`.
#
# Wrap with *sh to background script and save as git hook.
#
# Requires:
# 1. Slack API Test Token
# 2. Slack Webhook URL
'use strict'
/*
* blocket.js
* Webscrapes blocket apt ads and emails results
*
* Files
* email_template.html: html template for results email
* filter.txt: newline deliminated list of regex keywords to filter out ads by
*
* Config Vars (set through env)