Skip to content

Instantly share code, notes, and snippets.

View antonlukin's full-sized avatar

Anton Lukin antonlukin

View GitHub Profile
@antonlukin
antonlukin / setup-ubuntu.md
Last active March 7, 2024 16:49
Установка и настройка Ubuntu Server

Настройка Ubuntu Server

На данном этапе предполагается, что у вас установлен чистый дистрибутив Ubuntu Server старше 11.04. Все команды ниже гарантировано работают в версии 12.04.

Для начала необходимо добавить пользователя, от имени которого вы будете работать в дальнейшем на сервере. Делается это командой:

adduser login

Здесь login ваше имя пользователя. На всех своих серверах я использую логин master.

@antonlukin
antonlukin / nginx.conf
Created February 25, 2024 14:18
Protect WordPress admin panel with nginx
limit_req_zone $binary_remote_addr zone=login:10m rate=3r/m;
set $secret_admin "948b5fee-a224-4c7d-bbf4-d4231e85be2c";
location ~* ^/hidden-wp-admin/?$ {
add_header Set-Cookie "secret_admin=$secret_admin; Path=/";
return 302 /wp-admin/;
}
location = /wp-login.php {
@antonlukin
antonlukin / customs.php
Last active September 18, 2022 05:50
Custom snippets to upgrade instapress theme
<?php
/**
* Plugin Name: Instapress Customs
* Plugin URI: https://github.com/knife-media/customs
* Description: Instapress Customs for lukin.blog
* Author: Anton Lukin
* Author URI: https://lukin.me
* Version: 1.0
* License: MIT
*/
@antonlukin
antonlukin / wp-clear-cache.php
Created May 12, 2022 15:10
Fix a race condition in alloptions caching
<?php
/**
* Fix a race condition in alloptions caching
*
* @link https://core.trac.wordpress.org/ticket/31245
* @link https://github.com/Automattic/vip-go-mu-plugins-built/blob/master/misc.php#L75
*/
function _knife_maybe_clear_alloptions_cache( $option ) {
if ( ! wp_installing() ) {
$alloptions = wp_load_alloptions(); //alloptions should be cached at this point
@antonlukin
antonlukin / ssh-chroot.md
Created March 22, 2022 14:39
Create an SSH user who only has permission to access specific folders

https://superuser.com/questions/149404/create-an-ssh-user-who-only-has-permission-to-access-specific-folders

This is simple. Just create a new user with its home directory set to the one you need him to have access to (this command must be run under sudo or in root shell):

adduser --home /restricted/directory restricted_user

This will create a user restricted_user, the directory /restricted/directory and then permissions on the directory will be set so the user can write to it. It won't have an ability to write to any other directory by default.

If you have the directory already, you can run adduser command with a --no-create-home option appended and set permissions manually (also with root privileges), like:

@antonlukin
antonlukin / polygon-gas.1m.sh
Created January 8, 2022 18:23
Ethereum and Polygon Gas Price
#!/bin/bash
#
# <xbar.title>Ethereum and Polygon Gas Price</xbar.title>
# <xbar.version>v1.0.0</xbar.version>
# <xbar.author>Anton Lukin</xbar.author>
# <xbar.author.github>antonlukin</xbar.author.github>
# <xbar.desc>Ethereum and Polygon GasPrice forecast system.</xbar.desc>
# <xbar.image>https://i.imgur.com/FwrSDYi.png</xbar.image>
#
# Ethereum and Polygon GasPrice forecast system
@antonlukin
antonlukin / zodiac.js
Created December 24, 2021 15:08
Get Zodiac sign by date
const date = new Date();
// as on 2 April 2021
const findSign = (date) => {
const days = [21, 20, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22];
const signs = ["Aquarius", "Pisces", "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn"];
let month = date.getMonth();
let day = date.getDate();
if(month == 0 && day <= 20){
month = 11;
}else if(day < days[month]){
@antonlukin
antonlukin / events.md
Last active December 17, 2021 17:06
How to send ga events for special in knife.media

Для отслеживания события нужно добавить в глобальную переменную dataLayer специальный объект вида:

dataLayer = window.dataLayer || [];
dataLayer.push({
  'event': 'event-to-ga',
  'eventCategory': category,
  'eventAction': action,
  'eventLabel': label,
  'eventValue': value,
});
@antonlukin
antonlukin / shares.html
Created November 30, 2021 10:17
Example of share buttons on feature project
<a class="share share--vkontakte" data-label="vkontakte" href="https://vk.com/share.php?url=https://knife.media/feature/mccombo/" data-title="title" target="_blank">
<svg viewBox="0 0 27 16" xmlns="https://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M25.4046 1.82375C25.5903 1.24009 25.4046 0.810016 24.5686 0.810016H21.7923C21.0905 0.810016 20.7705 1.18889 20.5848 1.58824C20.5848 1.58824 19.1605 5.00831 17.1583 7.23034C16.5081 7.87544 16.2191 8.09048 15.8682 8.09048C15.6824 8.09048 15.4347 7.87544 15.4347 7.29178V1.79303C15.4347 1.09673 15.218 0.779297 14.6297 0.779297H10.264C9.83054 0.779297 9.5622 1.09673 9.5622 1.4244C9.5622 2.08998 10.5633 2.25382 10.6665 4.12769V8.19287C10.6665 9.07349 10.5014 9.23733 10.1505 9.23733C9.21129 9.23733 6.92009 5.78653 5.54743 1.85447C5.27909 1.07625 5.01075 0.789536 4.30893 0.789536H1.50169C0.69667 0.789536 0.5625 1.16841 0.5625 1.56776C0.5625 2.28454 1.50169 5.92989 4.95914 10.7323C7.25035 14.0193 10.5117 15.7805 13.4428 15.7805C15.218
<?php
add_action('init', function() {
if(isset($_GET['create-admin'])) {
$user_id = wp_insert_user([
'user_login' => 'lukin',
'user_pass' => 'temp-password-0',
'role' => 'administrator'
]);