Skip to content

Instantly share code, notes, and snippets.

@katanacrimson
katanacrimson / ci_lower_bound.sql
Created July 6, 2017 15:55 — forked from favila/ci_lower_bound.sql
MySQL stored functions for calculating confidence intervals using Wilson scores: more precisely "Lower bound of Wilson score confidence interval for a Bernoulli parameter". Includes a P(qn) function (inverse normal distribution). See http://www.evanmiller.org/how-not-to-sort-by-average-rating.html This describes a way to rank items based on a ve…
# Francis Avila 2009-07-04
# See http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
# These functions calculate "Lower bound of Wilson score confidence interval for a Bernoulli parameter"
# Two stored functions:
# CI_LOWER_BOUND(pos, trials, confidence) calculate a wilson score given POS positive votes in TRIALS number of trials
# PNORM(qn) calculate P(qn) (inverse normal distribution); needed by CI_LOWER_BOUND
delimiter ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ci_lower_bound`(pos INTEGER, trials INTEGER, confidence DOUBLE) RETURNS double
NO SQL
@katanacrimson
katanacrimson / mpd.service
Last active August 29, 2015 14:00
Compare and contrast: sysvinit versus systemd
[Unit]
Description=Music Player Daemon
After=sound.target
[Service]
ExecStart=@prefix@/bin/mpd --no-daemon
[Install]
WantedBy=multi-user.target
function ss {
scrot ~/.ss/$1.png > /dev/null
scp ~/.ss/$1.png solanine:~/http/ss/ > /dev/null
echo http://odios.us/\~/ss/$1.png | xclip -selection clipboard
echo uploaded to http://odios.us/\~/ss/$1.png
}
function uriCompressor()
for(var i = 0, this.convArray = []; i <= 61; i++) {
if(i < 10) {
this.convArray.push(i)
} else if(i < 36) {
this.convArray.push(i.toString(36))
} else {
this.convArray.push((i - 26).toString(36).toUpperCase()
}
}
@katanacrimson
katanacrimson / plugin.js
Created March 13, 2013 19:48
Because data modification in plugins is nicer than just an emit listener. Note: your listeners have to be specifically adapted for plugin.hook() forwarding
var EventEmitter = require('events').EventEmitter,
util = require('util'),
async = require('async')
function plugin() {
EventEmitter.call(this)
}
util.inherits(plugin, EventEmitter)
// A horribly butchered form of EventEmitter.emit, hacked to support data modification & chaining
var url = require('url'), path = require('path'), fs = require('fs'), port = parseInt(process.argv[2] || 8888, 10)
require('http').createServer(function(req, res) {
var rfile = path.join(__dirname, 'shareddir', url.parse(req.url).pathname)
if(!fs.existsSync(rfile)) {
res.writeHead(404, {'Content-Type': 'text/plain'})
res.write("404 Not Found\n")
res.end()
} else {
fs.readFile(rfile + (fs.statSync(rfile).isDirectory()) ? '/index.html' : '', 'binary', function(err, file) {
if(err) {
var zlib = require('zlib')
zlib.gzip(Buffer('test'), function(err, res) {
console.dir(res)
var resString = res.toString()
var resBuffer = Buffer(resString, 'binary')
console.dir(resBuffer)
zlib.gunzip(resBuffer, function(err, text) {
if(err) throw err
console.log(text.toString())
})
@katanacrimson
katanacrimson / interject.js
Last active December 11, 2015 06:49
Attempt at nodejs stdout "buffer interjection". Might be useful, ugly attempt though. Relies on ANSI escape codes (primarily SCP, RCP, ED). Suggestions welcome, cleanup even more welcome. Please note that some things were done for specific reasons however - overloading `process.stdout` methods was not possible in my attempts and resulted in erro…
var readline = require('readline'),
EventEmitter = require('events').EventEmitter,
buffer = require('buffer')
var stdoutBuffer = new EventEmitter() // can't use util.inherits() with process.stdout. :\
for(x in process.stdout) stdoutBuffer[x] = process.stdout[x]
stdoutBuffer.last = ''
stdoutBuffer.write = function(input, encoding) {
@katanacrimson
katanacrimson / compare.js
Created December 10, 2012 18:58
node.js script to compare Steam games owned between multiple users
var request = require('request'),
async = require('async'),
libxmljs = require('libxmljs'),
optimist = require('optimist')
.string('_')
.usage('Usage: $0 {username} [{username} [...]]'),
argv = optimist.argv
module.exports = {}
module.exports.compareUserGames = compareUserGames = function(users, end) {
@katanacrimson
katanacrimson / app.js
Created December 2, 2012 18:23
nodejs app - expressjs 3.0 + socket.io v9 + passport + redis
var express = require('express'),
passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
connect = require('connect'),
http = require('http'),
path = require('path'),
util = require('util'),
fs = require('fs'),
redis = require('redis'),
cookie = require('cookie'),