Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@erose
erose / decrypt_cookie.rb
Created April 24, 2017 02:50
Decrypt a Rails 5 session cookie
@erose
erose / adapters.application.js
Created May 10, 2017 04:41
ObjectProxy DS.HasMany
import Adapter from "ember-data/adapters/json-api";
export default Adapter.extend();
@erose
erose / controllers.application.js
Last active July 7, 2017 16:06
Moment.js Sort
import Ember from 'ember';
export default Ember.Controller.extend({
items: [
{time: moment()},
{time: moment().subtract(1, 'day')},
],
sortProperties: ['time'],
sortedItems: Ember.computed.sort('items', 'sortProperties'),
@erose
erose / differentiate.py
Last active October 29, 2019 16:33
Recurse Center application code -- symbolic differentiation
from typing import *
import sys
import re
def differentiate(expression: List[str], with_respect_to: str) -> List[str]:
# We do the differentiation in one pass, then simplify the result.
first_pass = [_differentiate_single_term(t, with_respect_to) for t in expression]
simplified = _simplify_expression(first_pass)
return simplified
@erose
erose / crash-the-haskell-typechecker.hs
Created December 9, 2019 18:20
The simplest way I know of to crash/hang the Haskell typechecker using UndecidableInstances.
-- Inspired by https://aphyr.com/posts/342-typing-the-technical-interview and
-- https://wiki.haskell.org/wikiupload/d/dd/TMR-Issue8.pdf. See the latter for a well-paced
-- introduction to what's going on in general.
-- Allows one type parameter to a class to be fully determined by the type of another.
{-# LANGUAGE FunctionalDependencies #-}
-- The head of an instance declaration may mention arbitrary nested types.
{-# LANGUAGE FlexibleInstances #-}

Bold is me. Everything else is the AI. This is from AI Dungeon with the Dragon model in Story mode.


You are talking to GPT-2, an AI designed to write Javascript. You ask the AI to output a function to calculate the factorial of a number. It outputs:

function factorial(n) { return n * (1 + x^n); }

You say: "No, that's not right. You should use a loop."

# A solution to "how do I sort by average rating, while taking into account the fact that some things have more ratings than others and this provides more Bayesian evidence about their quality? See https://www.evanmiller.org/how-not-to-sort-by-average-rating.html
def ci_lower_bound(pos, n)
if n == 0
return 0
end
z = 1.96 # hardcoded confidence level of 0.95
phat = 1.0*pos/n
midpoint = phat + z*z/(2*n)