Skip to content

Instantly share code, notes, and snippets.

@chx
chx / gist:22fe4f2fee869a7ecde9e4db12d73a19
Last active April 14, 2024 16:13
Expected profit of an Einhar Harvest memory
#!/bin/bash
LEAGUE=$(curl -s https://poe.ninja/api/data/getindexstate|jq -r '.economyLeagues[0].name')
URL="https://poe.ninja/api/data/itemoverview?league=$LEAGUE&type"
# 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
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) {
rail.remove();
let old_strip = document.querySelector('div.p-workspace_switcher_prototype div.p-control_strip')
if (old_strip) {
old_strip.remove()
}
let strip = document.querySelector('div.p-control_strip');
document.querySelector('div.p-workspace_switcher_prototype').appendChild(strip);
@chx
chx / README.md
Last active December 16, 2023 08:08
Use this script to push a patch into a drupal.org 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

Now:

  1. File issue as normal
  2. Press Create issue fork button
  3. Copy the checkout command https://i.imgur.com/Ek1uQvi.png
@chx
chx / Table.php
Last active September 13, 2023 09:52
Media migration
<?php
namespace Drupal\sd8_import\Plugin\migrate\source;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
/**
* Table source from database.
*
* @MigrateSource(
<?php
// Note this is not a transliterator. See https://unicode-org.github.io/icu/userguide/transforms/general/#overview
// 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);
<?php
# 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
chx / PauseRedirectRequestSubscriber.php
Created September 17, 2022 20:14
Pause redirect module
<?php
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
chx / MapItemTest.php
Created October 31, 2020 08:30
map item test
<?php
namespace Drupal\Tests\field\Kernel;
use Drupal\entity_test\Entity\EntityTestMapField;
class MapItemTest extends FieldKernelTestBase {
protected function setUp(): void {
parent::setUp();
@chx
chx / resolve.php
Last active May 2, 2020 21:17
Drupal config export YAML diff resolver
<?php
use Drupal\Core\Serialization\Yaml;
include 'autoload.php';
chdir('..');
$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": "https://example.atlassian.net/secure/RapidBoard.jspa?rapidView=102&modal=detail&selectedIssue=WEB-8424&quickFilter=107",
"exampleResult": "https://example.atlassian.net/browse/WEB-8424",
"error": null,
"includePattern": "^(.*atlassian.net)/secure/RapidBoard.jspa.*modal=detail&selectedIssue=([^&]+)",