Skip to content

Instantly share code, notes, and snippets.

# http://www.evanmiller.org/bayesian-ab-testing.html implemented in ruby
# requires the distribution gem from https://github.com/clbustos/distribution (gem 'distribution', require: false)
def probability_b_beats_a(completed_a, total_a, completed_b, total_b)
require 'distribution/math_extension'
total = 0.0
alpha_a = completed_a + 1
beta_a = total_a - completed_a + 1
alpha_b = completed_b + 1
@cfj
cfj / console.reverselog.js
Last active August 21, 2017 10:00
More console.log sillyness
var _log = console.log;
window.console.log = function(log){
_log.call(console, log.reverse ? log.reverse() : typeof log === 'string' ? log.split('').reverse().join('') : typeof log === 'number' ? log.toString().split('').reverse().join('') : typeof log === 'boolean' ? !log : log);
};
@lelandbatey
lelandbatey / whiteboardCleaner.md
Last active April 25, 2024 02:01
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

javascript:(function(){function%20grabdepth(tbl){var%20ims=tbl.getElementsByTagName("img"),re=/s\.gif/g;for(var%20i=0;i<ims.length;i++){if(re.exec(ims[i].src)){return%20ims[i].width;}}return%20null;}function%20getComments(tr){var%20c=[];d=grabdepth(tr);cd=d+1;while(cd>d){cs=tr.getElementsByTagName("font");for(var%20i=0;i<cs.length;i++){c[c.length]=cs[i];}cs=tr.getElementsByTagName("img");re=/s\.gif/g;for(var%20i=0;i<cs.length;i++){if(!re.exec(cs[i].src)){c[c.length]=cs[i];}}tr=tr.nextSibling;if(tr){cd=grabdepth(tr);}else{cd=d;}}return%20c;}function%20clicker(evt){var%20t=evt.target;evt.preventDefault();while(t.tagName!="TABLE"){t=t.parentElement;}while(t.tagName!="TR"){t=t.parentElement;}c=getComments(t);newstate="none";if(c[0].style.display=="none"){newstate="";}for(var%20i=0;i<c.length;i++){c[i].style.display=newstate;}}d=document.getElementsByClassName("comhead");for(var%20i=0;i<d.length;i++){t=d[i].firstChild.nextSibling;if(t){a=document.createElement("a");a.href="#";a.onclick=clicker;a.innerHTML=t.data;d
"""
This file contains code that, when run on Python 2.7.5 or earlier, creates
a string that should not exist: u'\Udeadbeef'. That's a single "character"
that's illegal in Python because it's outside the valid Unicode range.
It then uses it to crash various things in the Python standard library and
corrupt a database.
On Python 3... well, this file is full of syntax errors on Python 3. But
if you were to change the print statements and byte literals and stuff:
@chengyin
chengyin / linkedout.js
Last active July 11, 2021 15:23
Unsubscribe all LinkedIn email in "one click". For an easier to use version, you can check out the bookmarklet: http://chengyin.github.io/linkedin-unsubscribed/
// 1. Go to page https://www.linkedin.com/settings/email-frequency
// 2. You may need to login
// 3. Open JS console
// ([How to?](http://webmasters.stackexchange.com/questions/8525/how-to-open-the-javascript-console-in-different-browsers))
// 4. Copy the following code in and execute
// 5. No more emails
//
// Bookmarklet version:
// http://chengyin.github.io/linkedin-unsubscribed/
library(maptools)
library(geosphere)
# load USA state-level spatial data
# download from http://gadm.org
# click the 'download' tab
# select county = 'united states', file format = 'R', click ok
# download 'level 1' for state-level data
load("USA_adm1.RData")
require 'bundler'
Bundler.require
class Stream < Goliath::API
use Goliath::Rack::Params
use Goliath::Rack::Render, 'json'
use Goliath::Rack::Heartbeat
def response(env)
@larrybolt
larrybolt / cf-ddns.sh
Last active April 29, 2024 13:34
Automatically update your CloudFlare DNS record to the IP, Dynamic DNS for Cloudflare
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# Automatically update your CloudFlare DNS record to the IP, Dynamic DNS
# Can retrieve cloudflare Domain id and list zone's, because, lazy
# Place at:
# /usr/local/bin/cf-ddns.sh
@willurd
willurd / web-servers.md
Last active May 23, 2024 20:20
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000