This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Sample usage in controller action | |
[HttpPost] | |
[Route("in/batch-update")] | |
[RateLimit] | |
public virtual async Task<IActionResult> BatchUpdate(SomeModel model) | |
{...} | |
*/ | |
/// <summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// credits to: https://dusted.codes/dotenv-in-dotnet | |
// To read add something like: | |
// public static class Program | |
// { | |
// public static async Task Main(string[] args) | |
// { | |
// var root = Directory.GetCurrentDirectory(); | |
// var dotenv = Path.Combine(root, ".env"); | |
// DotEnv.Load(dotenv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage example: | |
// static readonly SemaphoreLocker _semaphoreLocker = new SemaphoreLocker(); | |
// var values = await _semaphoreLocker.LockAsync(valuesKey, async () => { return await SomeActionAsync(); }); | |
public class SemaphoreLocker | |
{ | |
static readonly ConcurrentDictionary<string, SemaphoreSlim> lockDictionary = new ConcurrentDictionary<string, SemaphoreSlim>(); | |
public async Task LockAsync(string key, Func<Task> worker) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NamedLocker | |
{ | |
private readonly ConcurrentDictionary<string, object> _lockDict = new ConcurrentDictionary<string, object>(); | |
// Get a lock for use with a lock(){} block | |
public object GetLock(string name) | |
{ | |
return _lockDict.GetOrAdd(name, s => new object()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------------------------------------------- | |
-- Creates procedure that takes schema/user/modificationFromDate as parameters and calls it for some schema/user/today in the end. This works for MariaDB too. | |
-- Example of grant as concat select | |
-- SELECT CONCAT('GRANT EXECUTE ON PROCEDURE YOUR_SCHEMA.', routine_name, ' TO user@`10.1.%`;') FROM information_schema.routines where routine_schema = 'YOUR_SCHEMA' AND ROUTINE_TYPE = 'PROCEDURE'; | |
-- SELECT CONCAT('GRANT EXECUTE ON FUNCTION YOUR_SCHEMA.', routine_name, ' TO user@`10.1.%`;') FROM information_schema.routines where routine_schema = 'YOUR_SCHEMA' AND ROUTINE_TYPE = 'FUNCTION'; | |
---- Grant all procedures that were changed TODAY (or other date as parameter) in any database (as parameter) for any user (as parameter) | |
DROP PROCEDURE IF EXISTS SysExecuteGrantsForModifiedProcedures; | |
CREATE PROCEDURE SysExecuteGrantsForModifiedProcedures(IN p_schema VARCHAR(120), IN p_mysqlUser VARCHAR(120), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" | |
autoReload="true" | |
throwExceptions="false" | |
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log"> | |
<variable name="telegramBotToken" value="YOUR_TELEGRAM_BOT_TOKEN"/> | |
<variable name="telegramChatId" value="YOUR_BOT_CHAT_ID"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcd for n numbers | |
static int gcd(int[] numbers) | |
{ | |
return numbers.Aggregate(gcd); | |
} | |
// gcd for 2 | |
static int gcd(int a, int b) | |
{ | |
return b == 0 ? a : gcd(b, a % b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ng build --prod && sshpass -f ~/test_pass scp -r ./dist/project/* REMOTE_USER@REMOTE_SERVER:/var/www/html | |
# Where: | |
# test_pass is the file, containing the password for remote server access | |
# the project will be deployed to /var/www/html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
eval $(keychain --eval id_github_rsa) # in case you use keychain to store keys. https://linux.die.net/man/1/keychain | |
find . -maxdepth 1 -type d -exec sh -c '(cd {} && echo $PWD && git pull && git push)' ';' |
NewerOlder