Skip to content

Instantly share code, notes, and snippets.

View Konard's full-sized avatar
🖥️
Watch how I code at https://www.youtube.com/c/КонстантинДьяченко

Konstantin Diachenko Konard

🖥️
Watch how I code at https://www.youtube.com/c/КонстантинДьяченко
View GitHub Profile
@Konard
Konard / is_prime.py
Last active February 20, 2022 17:23
Prime numbers pattern in unary numbers represented as doublets.
is_prime_array = [False, True, True, True, False]
primes = [1, 2, 3, 5]
def is_prime(n):
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
@Konard
Konard / StructMethodCannotBeUsedAsDelegate.cs
Last active January 3, 2022 13:50
Methods of structs cannot be used as delegates. The struct is copied in the process of delegate creation, and therefore there is no way to get mutuable struct updated in this case. https://replit.com/@Konard/StructMethodCannotBeUsedAsDelegate
using System;
struct StructSetter
{
public int Result;
public void Set(int value) => Result = value;
}
class ClassSetter
@Konard
Konard / create_indexes.sql
Created December 5, 2021 12:54
PostgreSQL functions to create indexes for all columns of any table.
DROP FUNCTION create_btree_index;
CREATE OR REPLACE FUNCTION create_btree_index(schema_name text, table_name text, column_name text) RETURNS void
AS $$
BEGIN
EXECUTE 'CREATE INDEX IF NOT EXISTS ' || table_name || '__' || column_name || '_btree ON ' || schema_name || '.' || table_name || ' USING btree (' || column_name || ');';
END;
$$ LANGUAGE plpgsql;
DROP FUNCTION create_btree_indexes_for_all_columns;
@Konard
Konard / accept-all-friend-requests.sh
Last active October 11, 2021 18:14
VK automation scripts (written in VK script). These scripts should be set up via https://vk.com/apps?act=manage to be usable. To execute via curl you will need to get token: https://oauth.vk.com/authorize?client_id=0&scope=friends&redirect_uri=https://oauth.vk.com/blank.html&display=page&response_type=token&revoke=1 (replace 0 near client_id wit…
#!/bin/bash
ACCESS_TOKEN=`cat access-token`
while :
do
curl "https://api.vk.com/method/execute.acceptAllFriendRequests?access_token=${ACCESS_TOKEN}&v=5.131"
printf "\n"
#include <iostream>
#include <tuple>
#include <functional>
#define THIS_REFERENCE_WRAPPER_METHODS(MethodName, TWrapped) \
constexpr auto&& MethodName() & { return static_cast<TWrapped&>(*this); } \
constexpr auto&& MethodName() && { return static_cast<TWrapped&&>(*this); } \
constexpr auto&& MethodName() const & { return static_cast<const TWrapped&>(*this); } \
constexpr auto&& MethodName() const && { return static_cast<const TWrapped&&>(*this); }
@Konard
Konard / columns-with-missing-indexes.sql
Created July 26, 2021 14:38
The PostgreSQL query that shows columns with missing indexes for a specific table.
SELECT c.table_schema, c.table_name, c.column_name
FROM (SELECT * FROM
information_schema.tables) As t INNER JOIN
(SELECT * FROM information_schema.columns) c
ON (t.table_name = c.table_name AND t.table_schema = c.table_schema)
LEFT JOIN pg_catalog.pg_indexes i ON
(i.tablename = c.table_name AND i.schemaname = c.table_schema
AND indexdef LIKE '%' || c.column_name || '%')
WHERE i.tablename IS NULL AND c.table_schema = 'public' AND c.table_name = 'nodes'
ORDER BY c.table_schema, c.table_name;
@Konard
Konard / acceptAllFriendsRequests.js
Created July 13, 2021 09:45
The code is written in VK Script. To try it out create an app and a stored procedure at: https://vk.com/apps?act=manage
var requests = API.friends.getRequests().items;
var i = 0;
while(i < requests.length)
{
API.friends.add({ user_id: requests[i] });
i = i + 1;
}
return requests;
@Konard
Konard / StorJ1.sh
Last active May 21, 2021 15:55
StorJ node startup commands with my settings.
sudo docker run -d --restart unless-stopped --stop-timeout 300 -p 28967:28967 -p 192.168.1.74:14002:14002 -e WALLET="0x102c4f1957484E3cf5507B115cFa9fB47da7862A" -e EMAIL="[email protected]" -e ADDRESS="konard.ddns.net:28967" -e STORAGE="500GB" --mount type=bind,source="/mnt/usb-Seagate_BUP_Slim_BL_NA7LAG1K-0:0-part2/identity/storagenode",destination=/app/identity --mount type=bind,source="/mnt/usb-Seagate_BUP_Slim_BL_NA7LAG1K-0:0-part2/storj",destination=/app/config --name storagenode storjlabs/storagenode:latest
@Konard
Konard / equal.js
Last active December 26, 2020 11:29
A way to make JavaScript great again. This method works as excepted with all objects that have valueOf function defined. Note: this method allows to compare Arrays without loops, you can also create your own comparable objects using valueOf function definition.
function equal(a, b) { return (a >= b) && (a <= b); }
{"contents":{"editor":{"tabSize":2},"launch":{"version":"0.2.0","configurations":[{"type":"chrome","request":"launch","name":"Meteor: Chrome","url":"http://localhost:3000","webRoot":"${workspaceFolder}"},{"type":"node","request":"launch","name":"Meteor: Node","runtimeExecutable":"npm","runtimeArgs":["run","debug"],"port":9229,"timeout":999999,"console":"integratedTerminal"}]}},"overrides":[],"keys":["editor.tabSize","launch.version","launch.configurations"]}