Skip to content

Instantly share code, notes, and snippets.

View MurzNN's full-sized avatar
🎯
Focusing

Alexey Murz Korepov MurzNN

🎯
Focusing
View GitHub Profile
@DiesIrae
DiesIrae / cascadeDelete.ts
Last active March 22, 2022 20:10
Abstract Cascade Delete Hook for Keystone 6
// "@keystone-next/types": "^22.0.0",
// "@keystone-next/keystone": "^22.0.0"
// The actual lib
// utils/keystone/cascadeDelete.ts
import { ListHooks } from "@keystone-next/types"
import { BaseGeneratedListTypes } from "@keystone-next/types/src/utils"
type BeforeDeleteType = Exclude<
ListHooks<BaseGeneratedListTypes>["beforeDelete"],
@fomigo
fomigo / gist:2382775
Created April 14, 2012 07:59
Russian Plural Form in PHP
<?php
/*
echo plural_form(42, array('арбуз', 'арбуза', 'арбузов'));
*/
function plural_form($n, $forms) {
return $n%10==1&&$n%100!=11?$forms[0]:($n%10>=2&&$n%10<=4&&($n%100<10||$n%100>=20)?$forms[1]:$forms[2]);
}
@RWhar
RWhar / PHPUnitMockMagicGet
Last active July 26, 2022 06:16
PHPUnit - Mock _get() on an Abstract Class
class TestMyObjectLoader extends PHPUnit_Framework_TestCase
{
protected $mockObject;
public function setUp()
{
$this->mockObject = $this->getMockForAbstractClass('Project\MyObject', [], '', true, true, true, ['initialize', '__get']);
}
@hagemann
hagemann / blocksToHtml.js
Last active October 27, 2022 08:11
Render EditorJS blocks to HTML.
const renderHtml = (blocks) => {
var html = blocks.map(block => {
switch (block.type) {
case 'code':
return `<pre><code>${ block.data.code }</pre></code>`
/**
* Original type is 'header' but I renamed the block to follow correct terminology:
* https://github.com/editor-js/header/issues/21
*/
@andriyun
andriyun / drupal8-change-active-theme-programmatically.php
Last active November 22, 2022 19:56
Drupal 8 switch active theme programmatically
<?php
/**
* See original implementation http://cgit.drupalcode.org/mailsystem/tree/src/MailsystemManager.php#n60
*/
// Switch the theme to the configured mail theme.
$theme_manager = \Drupal::service('theme.manager');
$mail_theme = '[your theme name]';
$current_active_theme = $theme_manager->getActiveTheme();
if ($mail_theme && $mail_theme != $current_active_theme->getName()) {
$theme_initialization = \Drupal::service('theme.initialization');
@meysam-mahmoodi
meysam-mahmoodi / kubernetes-uninstall.md
Last active April 12, 2024 18:50
Kubernetes completely uninstall

Kubernetes completely uninstall

This a gist for quick uninstall kubernetes

If the cluster is node, First delete it from master

kubectl drain <node name> — delete-local-data — force — ignore-daemonsets
kubectl delete node <node name>
@gunjanpatel
gunjanpatel / revert-a-commit.md
Last active April 29, 2024 12:53
Git HowTo: revert a commit already pushed to a remote repository

Revert the full commit

Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.

git revert {commit_id}

About History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32: