惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
Martin Fowler
Martin Fowler
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
C
Cisco Blogs
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
T
Tenable Blog
A
Arctic Wolf
小众软件
小众软件
Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
PCI Perspectives
PCI Perspectives
博客园 - 司徒正美
The Last Watchdog
The Last Watchdog
H
Hacker News: Front Page
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Stack Overflow Blog
Stack Overflow Blog
N
News and Events Feed by Topic
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 【当耐特】
S
Security @ Cisco Blogs
P
Proofpoint News Feed
Cloudbric
Cloudbric
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Jina AI
Jina AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
月光博客
月光博客
Schneier on Security
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
V
Visual Studio Blog
D
DataBreaches.Net
H
Help Net Security
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Project Zero
Project Zero
阮一峰的网络日志
阮一峰的网络日志
Cyberwarzone
Cyberwarzone
博客园 - Franky
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
N
News and Events Feed by Topic
The Cloudflare Blog
Simon Willison's Weblog
Simon Willison's Weblog
S
SegmentFault 最新的问题
W
WeLiveSecurity
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
I
Intezer
Hugging Face - Blog
Hugging Face - Blog
Attack and Defense Labs
Attack and Defense Labs

Feed of "schmarty/gem-diamond"

issue when using indieauth[dot]com? gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond proxy for profile images gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond gem-diamond
gem-diamond
schmarty · 2024-06-24 · via Feed of "schmarty/gem-diamond"

共有 6 个文件被更改,包括 91 次插入10 次删除

@ -92,13 +92,41 @@ class Controller {
return $this->render('directory', ['profiles' => $profiles])->withStatus(200);
}
public function random(ServerRequestInterface $request, array $args): ResponseInterface {
// if $args['slug'] is present this is an old-style URL.
// but we don't do anything with that knowledge so it's just a lonely comment.
public function next(ServerRequestInterface $request, array $args): ResponseInterface {
$fromUrl = $request->getHeader('referer')[0] ?? false;
if (! $fromUrl) { return $this->random($request, $args); }
$fromSite = $this->site->getSite($fromUrl); // exact matches only sorry
if($fromSite) {
// get the next active site by our current ordering
$toUrl = $this->site->getNextSite($fromSite['url'])['url'] ?? '/';
} else {
// get a random active site and redirect to it!
$toUrl = $this->site->randomActive()['url'];
}
return $this->response->withHeader('Location', $toUrl)->withStatus(302);
}
public function previous(ServerRequestInterface $request, array $args): ResponseInterface {
$fromUrl = $request->getHeader('referer')[0] ?? false;
if (! $fromUrl) { return $this->random($request, $args); }
// if $request->getHeader('referer')[0] is present, that's where the visitor came from.
// but we don't do anything with that knowledge so it's just a lonely comment.
$fromSite = $this->site->getSite($fromUrl); // exact matches only sorry
if($fromSite) {
// get the next active site by our current ordering
$site = $this->site->getPreviousSite($fromSite['url']);
} else {
// get a random active site and redirect to it!
$site = $this->site->randomActive();
}
return $this->response->withHeader('Location', $site['url'])->withStatus(302);
}
public function random(ServerRequestInterface $request, array $args): ResponseInterface {
// get a random active site and redirect to it!
$site = $this->site->randomActive();
return $this->response->withHeader('Location', $site['url'])->withStatus(302);

@ -31,6 +31,34 @@ class Site {
return $query->execute() ? $query->fetch() : '/';
}
public function getNextSite ($url) {
$query = $this->db->prepare('
SELECT * FROM Sites
WHERE sorting > (
SELECT sorting FROM Sites
WHERE url = :url
)
ORDER BY sorting
LIMIT 1
');
return $query->execute([$url]) ? $query->fetch() : $this->randomActive();
}
public function getPreviousSite ($url) {
$query = $this->db->prepare('
SELECT * FROM Sites
WHERE sorting < (
SELECT sorting FROM Sites
WHERE url = :url
)
ORDER BY sorting DESC
LIMIT 1
');
return $query->execute([$url]) ? $query->fetch() : $this->randomActive();
}
public function all() {
$query = $this->db->prepare('SELECT * FROM Sites');
return $query->execute() ? $query->fetchAll() : [];
@ -64,6 +92,22 @@ class Site {
return $query->execute() ? $query->fetchAll() : [];
}
/**
* Updates all active sites to a deterministic sort ordering
* Uses `sin` for pseudo-randomness, the timestamp that each site was added
* to the ring as a deterministic input, and an offset of the current month
* to make it different every month.
*/
public function updateSorting() {
$offset = date('n'); // numeric month, no leading zero
$query = $this->db->prepare("
UPDATE Sites
SET sorting = SIN(STRFTIME('%s', timestamp) + :offset)
WHERE active=1
");
return $query->execute([$offset]);
}
protected function addSite (String $url) {
$query = $this->db->prepare('INSERT INTO Sites (url, active) VALUES (:url, 1)');
return $query->execute([$url]) ? [ 'url' => $url, 'active' => 1 ] : false;

@ -33,3 +33,6 @@ if (count($argv) > 1) {
} else {
$gardener->garden();
}
// re-order active sites
$sites->updateSorting();

@ -38,6 +38,10 @@
"scripts": {
"test": "php -dpcov.enabled=1 -dpcov.directory=./app ./vendor/bin/phpunit --config tests/phpunit.xml",
"test:clean": "rm -rf tests/clover.xml tests/html-coverage tests/junit.xml tests/testdox.html vendor/bin/.phpunit.result.cache tests/.phpunit.result.cache",
"garden": "LOGFILE=data/gardener.log php bin/gardener.php"
"garden": "LOGFILE=data/gardener.log php bin/gardener.php",
"serve": [
"Composer\\Config::disableProcessTimeout",
"cd public && php -S 127.0.0.1:1234"
]
}
}

@ -36,8 +36,8 @@ $app->route->get('/terms', 'App\\Controller::terms');
$app->route->get('/directory', 'App\\Controller::directory');
// ring navigation
$app->route->get('/next', 'App\\Controller::random');
$app->route->get('/previous', 'App\\Controller::random');
$app->route->get('/next', 'App\\Controller::next');
$app->route->get('/previous', 'App\\Controller::previous');
$app->route->get('/{slug}/next', 'App\\Controller::random');
$app->route->get('/{slug}/previous', 'App\\Controller::random');

@ -1,7 +1,9 @@
CREATE TABLE Sites (
url TEXT PRIMARY KEY,
active INTEGER, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
profile text
active INTEGER,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
profile text,
sorting real not null default 0
);
CREATE TABLE SiteChecks (
url TEXT KEY,