Sign up
Login
New paste
Home
Archive
English
English
Sign up
Login
New Paste
Browse
<?php const DB_FILE = '2b2t_queue.db'; const ENDPOINT_MAGIC = '69042'; // nice $db = new SQLite3(DB_FILE); if (isset($_POST['update']) && $_POST['auth'] == ENDPOINT_MAGIC) { // update mode $ts = intval($_POST['ts']); $qp = intval($_POST['qp']); $ret = $db->query('SELECT seq, qp FROM `2b2q_log` ORDER BY id DESC LIMIT 1')->fetchArray(); $seq = $ret[0]; $last_qp = $ret[1]; if ($last_qp < $qp) { $seq++; } $stmt = $db->prepare('INSERT INTO `2b2q_log` (seq, ts, qp) VALUES (:seq, :ts, :qp)'); $stmt->bindValue(':seq', $seq); $stmt->bindValue(':ts', $ts); $stmt->bindValue(':qp', $qp); $stmt->execute(); header('HTTP/1.0 204 No Content'); } else { // stats mode $now = time(); $last_seq = $db->query('SELECT seq FROM `2b2q_log` ORDER BY id DESC LIMIT 1')->fetchArray()[0]; $ret = $db->query("SELECT MIN(id), MAX(id) FROM `2b2q_log` WHERE seq = $last_seq")->fetchArray(); $first_id = $ret[0]; $last_id = $ret[1]; if ($first_id == $last_id) { die('Insufficient data'); } $ret = $db->query("SELECT ts, qp FROM `2b2q_log` WHERE id = $first_id")->fetchArray(); $initial_ts = $ret[0]; $initial_qp = $ret[1]; $ret = $db->query("SELECT ts, qp FROM `2b2q_log` WHERE id = $last_id")->fetchArray(); $current_ts = $ret[0]; $current_qp = $ret[1]; // don't divide by zero dummy if ($initial_ts == $current_ts || $initial_qp == $current_qp) { die('Insufficient data'); } // linear regression using only two points isn't that great, the head of the queue moves slower $est_total_wait = $current_qp * ($current_ts - $initial_ts) / ($initial_qp - $current_qp); $est_remaining_wait = $initial_ts + $est_total_wait - $now; if ($est_remaining_wait < 0) { $est_remaining_wait = 0; } ?><head> <meta charset="utf-8"> <meta http-equiv="Refresh" content="60"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>2b2t Queue Info</title> </head> <body> <p>Last update: <?= date(DATE_RFC1123, $current_ts); ?></p> <p>Queue position: <?= $current_qp ?></p> <p>Estimated wait time: <?= round($est_remaining_wait / 60) ?> minutes</p> </body> <?php } // end else $db->close();
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Do you like cookies?
🍪 We use cookies to ensure you get the best experience on our website.
Learn more
I agree