Skip to content

Instantly share code, notes, and snippets.

chx / gist:22fe4f2fee869a7ecde9e4db12d73a19
Last active April 14, 2024 16:13
Expected profit of an Einhar Harvest memory
LEAGUE=$(curl -s|jq -r '.economyLeagues[0].name')
# There are nine beasts in a memory and there are nine kinds of harvest beasts with equal chance. Thus, the expected value is one beast per memory and the income is the sum of their value.
# However, only five is worth selling, the two Primal C beasts are worthless, Primal Rhex Matriach (synth map) and Vivid Abberach (guardian map) we run ourselves.
BEASTS=$(curl -s "$URL=Beast" |jq -r '[.lines[]| select(.name==("Wild Hellion Alpha","Wild Brambleback","Wild Bristle Matron","Vivid Vulture","Vivid Watcher"))|.chaosValue]|add')
# There are four non-replica synth maps equally weighted, so calculate the expected value:
SYNTH=$(curl -s "$URL=UniqueMap"|jq -r '[.lines[]| select(.baseType=="Synthesised Map" and .name!="Cortex" and .name!="Replica Cortex")|.chaosValue]|add' | awk '{print $1/4}')
# It's near impossible to calculate the expected value fo
chx / gist:22372925d1db05e19e76d7438262a575
Last active March 15, 2024 12:46
Remove the new Slack "rail" containing activity and other useless things
const domObserver = new MutationObserver(() => {
let rail = document.querySelector('div.p-tab_rail');
if (rail) {
let old_strip = document.querySelector('div.p-workspace_switcher_prototype div.p-control_strip')
if (old_strip) {
let strip = document.querySelector('div.p-control_strip');
chx /
Last active December 16, 2023 08:08
Use this script to push a patch into a issue fork

Only once:

  1. Have a Drupal core checkout somewhere
  2. set up a DRUPALREPO variable pointing it, for example add to ~/.profile: export DRUPALREPO=~/drupal


  1. File issue as normal
  2. Press Create issue fork button
  3. Copy the checkout command
chx / Table.php
Last active September 13, 2023 09:52
Media migration
namespace Drupal\sd8_import\Plugin\migrate\source;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
* Table source from database.
* @MigrateSource(
// Note this is not a transliterator. See
// on why it was originally named Transliterator but now does a lot more.
$transformation = \Transliterator::createFromRules(':: NFD; :: [:Mn:] Remove; :: NFC;');
$letters = preg_grep('/\pL/u', array_map('utf8', range(0x80, 0x2000)));
$letters = array_combine($letters, $letters);
$transformed = array_map([$transformation, 'transliterate'], $letters);
$map = array_diff_assoc($transformed, $letters);
print count($map);
# put this file in ~/.config/psysh/
if (class_exists('Drupal')) {
foreach (\Drupal::entityTypeManager()->getDefinitions() as $definition) {
$class = $definition->getClass();
$parts = explode('\\', $class);
class_alias($class, end($parts));
chx / PauseRedirectRequestSubscriber.php
Created September 17, 2022 20:14
Pause redirect module
namespace Drupal\pause_redirect\EventSubscriber;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\pause_redirect\Form\PauseRedirectSettingsForm;
use Drupal\redirect\EventSubscriber\RedirectRequestSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\RequestEvent;
chx / MapItemTest.php
Created October 31, 2020 08:30
map item test
namespace Drupal\Tests\field\Kernel;
use Drupal\entity_test\Entity\EntityTestMapField;
class MapItemTest extends FieldKernelTestBase {
protected function setUp(): void {
chx / resolve.php
Last active May 2, 2020 21:17
Drupal config export YAML diff resolver
use Drupal\Core\Serialization\Yaml;
include 'autoload.php';
$old = Yaml::decode(shell_exec('git show origin/master^:' . $argv[1]));
$new = Yaml::decode(shell_exec('git show origin/master:' . $argv[1]));
$diff = make_diff($new, $old);
"createdBy": "Redirector v3.5.3",
"createdAt": "2020-04-16T03:37:40.345Z",
"redirects": [
"description": "No more JIRA popups",
"exampleUrl": "",
"exampleResult": "",
"error": null,
"includePattern": "^(.**modal=detail&selectedIssue=([^&]+)",