Skip to content

Instantly share code, notes, and snippets.

@jsonbecker
jsonbecker / index.html
Created August 8, 2023 00:08
One page at a time, chronological for Tufte
{{ partial "head.html" . }}
<body>
<div class="content list h-feed">
{{ partial "header.html" . }}
{{ $paginator := .Paginate (where .Site.Pages "Type" "post").ByDate.Reverse 1 }}
{{ range $paginator.Pages }}
{{ partial "li.html" . }}
{{ end }}
{{ partial "pagination.html" . }}
{{ partial "footer.html" . }}
@jsonbecker
jsonbecker / adn_download.exs
Created June 3, 2023 16:12
An inefficient way to download your App Dot Net posts using Elixir
Mix.install([{:httpoison, "~> 2.0"}])
defmodule ADNDownloader do
require HTTPoison
@base_url "https://adn.micro.blog/"
def get_posts(user_name) do
url = @base_url <> "users/" <> String.at(user_name, 0) <> "/" <> user_name <> ".txt"
@jsonbecker
jsonbecker / glightbox.html
Last active December 31, 2019 04:19
GLightbox shortcode
<a href="{{ .Get "src" }}"
class="glightbox"
{{ if .Get "gallery"}}
data-gallery="{{ .Get "gallery" }}"
{{ end }}
{{ if or (.Get "title") (.Get "description") }}
data-glightbox="title:{{ .Get "title" | default "" }};description:{{ .Get "description" | default "" }}"
{{end}}
>
<img src="{{ .Get "src" }}"
@jsonbecker
jsonbecker / geom_bar_fill.R
Created December 1, 2016 04:01
How do I get labels on this plot?
library(ggplot2)
df <- data.frame(type = c(rep('Elementary', 2), rep('Middle', 2), rep('High', 2)),
included = rep(c('included','excluded'),3),
dollars = c(1000, 2500, 4000, 1000, 3000, 2800))
ggplot(data = df, aes(type, dollars, fill = included)) +
geom_bar(position = 'fill', stat = 'identity') +
geom_text()

Keybase proof

I hereby claim:

  • I am jsonbecker on github.
  • I am jsonbecker (https://keybase.io/jsonbecker) on keybase.
  • I have a public key ASDIgFzpTFWImOtO0Dw5-XJVu-LiDxUfqB53ZkGSUzla7go

To claim this, I am signing this object:

@jsonbecker
jsonbecker / timing.R
Created September 19, 2016 20:00
A small bit of code to log how long something took
# Ever want to log how long someting takes? I know I do. timing()
# isn't about benchmarking, it's about getting feedback from long running
# tasks, especially if they are scheduled in production. Anyway, I love
# this function because it's a simple wrapper that can go around anything.
# I use it inside our tools at Allovue when extracting data to get things
# like this:
#> accounts <- extract_data(config_file$accounts)
# Starting queries/accounts.sql at: Mon Sep 19 15:27:34 2016
# Completed at: Mon Sep 19 15:28:14 2016
@jsonbecker
jsonbecker / photoDate.py
Last active January 2, 2016 00:38
A few versions of getting date data from photos.
import sys
import os, shutil, time
import subprocess
import os.path
import exifread
from datetime import datetime
def photoDateSIPS(f):
"Return the date/time on which the given photo was taken."
@jsonbecker
jsonbecker / link_list_templates.html
Last active December 28, 2015 17:59
How to modify your `articles.html` and `index.html` template for "Linked List" style posts.
@jsonbecker
jsonbecker / cutoff_matrix.R
Created October 17, 2013 19:17
Quick function to calculate common statistics when evaluating a predictor of binary outcomes.
cutoff_matrix <- function(df, classifier, outcome, breaks=seq(1,0,-.01)){
results <- data.frame(cutoff=vector(mode='numeric', length=length(breaks)),
true_pos=vector(mode='numeric', length=length(breaks)),
true_neg=vector(mode='numeric', length=length(breaks)),
false_pos=vector(mode='numeric', length=length(breaks)),
false_neg=vector(mode='numeric', length=length(breaks)))
for(i in seq(1, length(breaks))){
value <- breaks[i]
j <- data.frame(table(df[[classifier]]>value, df[[outcome]]))
results[i,1] <- value
@jsonbecker
jsonbecker / modalSDPdt.R
Created January 31, 2013 01:46
SDP business rules to resolve student attributes.
modal_person_attribute <- function(df, attribute){
# df: rbind of all person tables from all years
# attribute: vector name to calculate the modal value
# Calculate the number of instances an attributed is associated with an id
dt <- data.table(df)
mode <- dt[, rle(as.character(.SD[[attribute]])), by=sasid]
setnames(mode, c('sasid', 'counts', as.character(attribute)))
setkeyv(mode, c('sasid', 'counts'))
# Only include attributes with the maximum values. This is equivalent to the
# mode with two records when there is a tie.