Skip to content

Instantly share code, notes, and snippets.

View BattlefieldDuck's full-sized avatar
🍚
Eating...

BattlefieldDuck BattlefieldDuck

🍚
Eating...
View GitHub Profile
@BattlefieldDuck
BattlefieldDuck / UdpClient.php
Created January 27, 2024 00:11
(Async) This class provides a method to communicate with a server using UDP protocol.
<?php
use Amp\Future;
use Amp\Socket\ConnectContext;
use Amp\TimeoutCancellation;
use function Amp\async;
use function Amp\Socket\connect;
/**
* Class UdpClient
@BattlefieldDuck
BattlefieldDuck / TaskEx.cs
Created February 23, 2022 22:24
Exception Handling in Task.Run using TaskEx.cs
namespace WindowsGSM.Utilities
{
public static class TaskEx
{
public static async Task Run(Action action)
{
Exception? exception = await Task.Run(() =>
{
try
{
@BattlefieldDuck
BattlefieldDuck / MudPasswordField.razor
Created February 11, 2022 20:25
MudBlazor - MudPasswordField
@inherits MudTextField<string>
@{
base.BuildRenderTree(__builder);
}
@code {
protected override void OnInitialized()
{
base.AdornmentIcon = Icons.Material.Filled.VisibilityOff;
@BattlefieldDuck
BattlefieldDuck / markSix.js
Created November 23, 2021 14:22
[One-Liner] Mark Six Random Number Generator
// Create an array of ascending numbers (1-49) -> suffle -> take first 6 number in suffled array -> sort ascendingly
console.log(Array(49).fill().map((_, i) => 1 + i).sort(() => .5 - Math.random()).slice(0, 6).sort((a, b) => a - b));
// Example output
// [ 1, 8, 15, 22, 44, 46 ]
// [ 3, 8, 34, 35, 41, 45 ]
// [ 11, 14, 26, 40, 48, 49 ]
@BattlefieldDuck
BattlefieldDuck / GateWebsocket.js
Last active November 12, 2021 03:21
Gate.io WebSocket v4
/**
* Gate.io Websocket v4 (lightweight)
*
* @author BattlefieldDuck
* @since 11/11/2021
*/
const { createHmac } = require('crypto');
const EventEmitter = require('events');
const WebSocket = require('ws');
import asyncio
async def test(i):
print(str(i) + ' - start')
await asyncio.sleep(1)
print(str(i) + ' - end')
# Faster!
async def start_start_end_end():
tasks = [test(i) for i in range(10)]
@BattlefieldDuck
BattlefieldDuck / SetStartOnBoot.cs
Last active December 24, 2019 08:06
C# Set Form / WPF run on startup
private void SetStartOnBoot(bool enable)
{
try
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
var productName = System.Windows.Forms.Application.ProductName;
if (enable)
{
key.SetValue(productName, System.Windows.Forms.Application.ExecutablePath);
}
@BattlefieldDuck
BattlefieldDuck / steambot.sh
Created November 13, 2019 14:49
A Simple Shell Script To Restart SteamBot.exe With Mono and Screen
# A Simple Shell Script To Restart SteamBot.exe With Mono and Screen
# BattlefieldDuck - 11/13/2019
#
# Set crontab:
# 1. crontab -e
# 2. 0 */3 * * * ./steambot.sh
#
echo "Sending quit to SteamBot.exe..."
@BattlefieldDuck
BattlefieldDuck / 14D.cpp
Last active November 4, 2018 17:09
HKOI 2018/19 -Senior Group Q14
#include <iostream>
#include <cmath>
using namespace std;
void checkPalindromes(int, int, bool);
int main()
{
//Able to edit the value
int test_range = 50000;
@BattlefieldDuck
BattlefieldDuck / env_sniperdot.sp
Last active November 4, 2018 16:56
CreateEntityByName("env_sniperdot")
#define FSOLID_NOT_SOLID 0x0004
#define EF_NOSHADOW (1 << 4)
#define EFL_FORCE_CHECK_TRANSMIT (1<<7)
int CreateSniperDot(int client)
{
int sniperdot = CreateEntityByName("env_sniperdot");
if (IsValidEntity(sniperdot))
{
SetEntityMoveType(sniperdot, MOVETYPE_NONE);
SetEntProp(sniperdot, Prop_Send, "m_usSolidFlags", GetEntProp(sniperdot, Prop_Send, "m_usSolidFlags")|FSOLID_NOT_SOLID);