Skip to content

Instantly share code, notes, and snippets.

@shanna
shanna / ad_version_1.rb
Created May 21, 2012 07:23
Simple example of why mocks are stupid.
# First iteration of Ad
class Ad
attr_accessor :message
def view
"For sale #{message} call #{owner.name}"
end
end # Ad
@shanna
shanna / App.svelte
Last active April 19, 2022 18:14
Wails OIDC OAuth2 minimal inline hack.
<script>
const login = async () => {
window.location.href = await window.go.main.App.AuthURL();
};
let email;
window.go.main.App.AuthEmail()
.then(e => {
if (!e) login();
email = e;
require 'benchmark'
require 'sexpistol'
require 'sxp'
require 'strscan'
class Lexer < StringScanner
def next_token
# Housekeeping.
skip /\s*/
@shanna
shanna / keybase.md
Created October 5, 2017 23:00
keybase.md

Keybase proof

I hereby claim:

  • I am shanna on github.
  • I am shanna (https://keybase.io/shanna) on keybase.
  • I have a public key ASB7WctqxheSQaiFSOvDLCvRe47lFZMirPn1NQiv4ePUcQo

To claim this, I am signing this object:

@shanna
shanna / pg-install
Created September 6, 2016 14:14
Postgres install from source on OSX when homebrew won't give you a specific version.
#!/usr/bin/env bash
set -e
# Homebrew homebrew/versions was broken when I went to install postgres.
# This shell script just documents my install from source.
release=9.4.6
prefix=$HOME/local
mkdir -p $prefix
@shanna
shanna / main.c
Created March 6, 2017 23:31
Minimal webkit2gtk segfault on macOS runs on Linux.
#include <webkit2/webkit2.h>
#include <JavaScriptCore/JavaScript.h>
int main(int argc, char **argv) {
gtk_init(&argc, &argv);
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GtkWidget *webkit_view = webkit_web_view_new();
gtk_container_add(GTK_CONTAINER(main_window), webkit_view);
@shanna
shanna / example.rb
Last active February 8, 2017 14:33
Jaccard coeff against shingles.
require 'shingles'
compare = %w{
foo foo
foo bar
baz boz
foofoo foobar
}.each_slice(2)
compare.each do |a, b|
@shanna
shanna / brokenimage.js
Created October 19, 2016 10:11
Broken image JS.
// MIT https://github.com/alexrabarts/jquery-brokenimage minus the jquery.
function BrokenImage(selector, options) {
'use strict';
options = options || {};
var defaults = {
timeout: 2500
};
for (var key in defaults) {
@shanna
shanna / psql-migrate
Last active May 23, 2016 06:07
Postgres migration script.
#!/usr/bin/env sh
set -eu
if [ $# -ne 0 ]; then
cat <<-USAGE
psql-migrate
Takes a sorted list of filenames from stdin and writes psql migrations sql
to stdout.
@shanna
shanna / short-prompt.sh
Last active May 4, 2016 07:25
A short, smart, prompt.
# [ -e ~/.config/short-prompt.sh ] && source ~/.config/short-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=true
__git_ps1() { PS1="$1$2"; }
[ -e ~/.config/git-prompt.sh ] && source ~/.config/git-prompt.sh
__short_ps1() {
local exit=$?
local __short_ps1_host=""
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then