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 / QueryableExtensions.cs
Created January 20, 2024 20:09
C# .WhereIf(bool, predicate) LINQ Queryable Extension Method
using System.Linq.Expressions;
public static class QueryableExtensions
{
public static IQueryable<T> WhereIf<T>(this IQueryable<T> queryable, bool condition, Expression<Func<T, bool>> predicate)
{
return condition ? queryable.Where(predicate) : queryable;
}
}
@grandsilence
grandsilence / SwitchVirtualDesktopByTaskbarScroll.ahk
Created November 27, 2023 12:10
Windows AutoHotKey script switch virtual desktops by mouse scroll on taskbar or by Alt+Right / Alt+Left
#If MouseIsInvolumecontrolarea() and not WinActive("ahk_class TscShellContainerClass")
WheelUp::Send {LControl down}#{Right}{LControl up}
WheelDown::Send {LControl down}#{Left}{LControl up}
#If
MouseIsInvolumecontrolarea()
{
CoordMode, Mouse, Screen
MouseGetPos, xpos, ypos
if (ypos > A_ScreenHeight-60 and xpos <= A_ScreenWidth-500)
@grandsilence
grandsilence / vimrc
Created March 21, 2020 11:17
CVim / vb4c Chrome Extension Settings
let locale = "ru"
let langmap = "Ё|АFБ<ВDГUДLЕTЖ:ЗPИBЙQКRЛKМVНYОJПGРHСCТNУEФAХ{ЦWЧXШIЩOЪ}ЫSЬMЭ\"Ю>ЯZаfб\\,вdгuдlеtж\\;зpиbйqкrлkмvнyоjпgрhсcтnуeфaх[цwчxшiщoъ]ыsьmэ'ю.яzё\\№#"
let qmark m = ["https://mail.google.com"]
let qmark g = ["https://github.com/grandsilence?tab=repositories"]
let qmark n = ["https://github.com/new"]
let qmark h = ["https://www.cheatography.com/yograf/cheat-sheets/cvim/"]
let blacklists = ["https://console.hetzner.cloud/*","http://trans-energo36.ru/*","https://2doom.itch.io/*","https://music.yandex.ru/*"]
<Target Name="AfterBuild">
<!-- the ILMergePath property points to the location of ILMerge.exe console application -->
<Exec Command="$(ILMergeConsolePath) /target=winexe /ndebug=false /targetplatform=v4 /wildcards bin\Release\App.exe ^
/out:bin\Release\App_merged.exe ^
bin\Release\*.dll" />
</Target>
@grandsilence
grandsilence / DeepCopy.cs
Created March 6, 2020 03:45
C# Deep Copy
public static T? DeepCopy<T>(this T self) where T : class
{
if (!typeof(T).IsSerializable)
throw new ArgumentException("Type must be serializable");
if (ReferenceEquals(self, null))
return default;
var formatter = new BinaryFormatter();
using var stream = new MemoryStream();
@grandsilence
grandsilence / dont_track_me_google_safari_tamper_monkey.js
Last active January 9, 2020 22:04
Don't Track Me Google for Safari Extension: Tamper Monkey
// ==UserScript==
// @name Don't track me Google
// @namespace Rob W, Grand Silence
// @description Removes the annoying link-conversion at Google Search/maps/... The Referrer is also hidden to improve your privacy. Designed for Firefox and Google Chrome.
// @version 3.7
// @match *://*.google.com/*
// @match *://*.google.ad/*
// @match *://*.google.ae/*
// @match *://*.google.com.af/*
// @match *://*.google.com.ag/*
@grandsilence
grandsilence / AssemblyInfo.tt
Last active December 25, 2019 21:33
C# Project Auto Increment Assembly Version using T4 Templates
<#@ template language="C#" #>
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Project")]
[assembly: AssemblyDescription("")]
@grandsilence
grandsilence / Chunk.cs
Last active October 28, 2019 21:56
C# Correct chunk messages for telegram bot (limit 4096 per message) with emoji and unicode support.
// Telegram has 4096 limit per message. So use chunkSize = 4096.
public static IEnumerable<string> ChunkUnicode(this string self, int chunkSize)
{
if (string.IsNullOrEmpty(self))
return Enumerable.Empty<string>();
if (chunkSize < 4)
throw new ArgumentException("Minimum chunk size is 4.", nameof(chunkSize));
var results = new List<string>();
@grandsilence
grandsilence / get_currencies.php
Created October 15, 2019 12:22
Get currency rates from floatrates API
<?php
public static $currencies = false;
public static function getCurrenciesJson()
{
if (!self::$currencies) {
$json = json_decode(system::GET('http://www.floatrates.com/daily/rub.json'), true);
self::$currencies = !empty($json) ? $json : false;
}
return self::$currencies;
@grandsilence
grandsilence / TelegramReplyKeyboard.cs
Created October 9, 2019 10:28
C# Telegram Bot Reply Keyboard
var keyboard = new InlineKeyboardMarkup(new InlineKeyboardButton[][]
{
new [] {
new InlineKeyboardButton {
Text ="Текст для первой кнопки",
CallbackData = "cb1"
},
},
});