Skip to content

Instantly share code, notes, and snippets.

View grandsilence's full-sized avatar
💻
Freelancer

Grand Silence grandsilence

💻
Freelancer
View GitHub Profile
@grandsilence
grandsilence / JS - Image Aspect Ratio Fit.js
Last active February 5, 2019 23:44
Conserve aspect ratio image
/**
* Conserve aspect ratio of the orignal region. Useful when shrinking/enlarging
* images to fit into a certain area.
*
* @param {Number} srcWidth Source area width
* @param {Number} srcHeight Source area height
* @param {Number} maxWidth Fittable area maximum available width
* @param {Number} maxHeight Fittable area maximum available height
* @return {Object} { width, heigth }
*
@grandsilence
grandsilence / MonitorsInfo.cs
Last active November 14, 2018 18:02
C# Получение модели монитора
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
namespace ConsoleApp1
{
public static class MonitorsInfo
{
@grandsilence
grandsilence / MailSmtpClient.cs
Last active January 24, 2019 01:00
C# Mail SMTP Client: Send Message async. Singleton.
using Leaf.Core.Extensions.Net;
//using Leaf.Core.Patterns;
public class MailClient // : Singleton<MailClient>
{
public static async Task SendAsync(string body, string subject = "Test Email")
{
SmtpClient client = null;
MailMessage mail = null;
@grandsilence
grandsilence / SHA256.cs
Last active July 24, 2024 11:50
C# SHA 256 to String
public static string Sha256(string text)
{
var sb = new StringBuilder();
using (var hash = SHA256.Create())
{
var result = hash.ComputeHash(Encoding.UTF8.GetBytes(text));
// ReSharper disable once ForCanBeConvertedToForeach
for (int i = 0; i < result.Length; i++)
sb.Append(result[i].ToString("x2"));
}
@grandsilence
grandsilence / pretty_phone.php
Created March 13, 2019 11:07
Convert international phone +79004001234 to +7 900 400 12-34. Or local Russian 88004001234 to 8 800 400 12 34. Raw
<?php
function pretty_phone($phone) {
if (!preg_match('/^(\+?)(\d)(\d{3})(\d{3})(\d{2})(\d{2})$/', $phone, $matches)) {
return 'invalid phone';
}
$is_international = !empty($matches[0]) && $matches[0] === '+';
$last_delimiter = $is_international ? '-' : ' ';
$delimeters = [' ', ' ', $last_delimiter, $last_delimiter];
@grandsilence
grandsilence / vscode_styles.css
Last active March 26, 2019 23:21
Visual Studio Code Custom CSS when DirectWrite is disabled
/* Global font */
.monaco-shell, .windows {
font-family: Tahoma, Arial, sans-serif !important;
--monaco-monospace-font: 'Terminus (TTF) for Windows', Consolas, 'Courier New', monospace !important;
}
/* Remove italic for selected file */
.monaco-icon-label.italic>.monaco-icon-label-description-container>.label-description, .monaco-icon-label.italic>.monaco-icon-label-description-container>.label-name {
font-style: normal !important;
color: #c5b482;
}
@grandsilence
grandsilence / composer.json
Created April 10, 2019 12:28
PHP Composer use fork of package
"repositories": [
{
"type": "vcs",
"url": "https://github.com/grandsilence/laravel-steam-auth"
}
],
"require": {
"invisnik/laravel-steam-auth": "dev-master",
}
@grandsilence
grandsilence / generate.bat
Last active March 21, 2021 21:25
RUN AS ADMIN! Copy near generate.bat (OSPanel\modules\http\<YOUR SETUP>\conf)
@echo off
set OPENSSL_CONF=%~dp0..\conf\openssl.cnf
..\bin\openssl req -x509 -sha256 -newkey rsa:2048 -nodes -days 5475 -keyout rootCA.key -out rootCA.crt -subj "/CN=OSPanel/"
..\bin\openssl req -newkey rsa:2048 -nodes -days 5475 -keyout server.key -out server.csr -subj "/CN=PhpStorm/"
..\bin\openssl x509 -req -sha256 -days 5475 -in server.csr -extfile v3.txt -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out server.crt
..\bin\openssl dhparam -out dhparam.pem 2048
@grandsilence
grandsilence / steam_api_get_inventory.txt
Created August 14, 2019 21:56
steam_api_get_inventory
https://steamcommunity.com/inventory/76561198180976409/440/2?l=english&count=5000