Skip to content

Instantly share code, notes, and snippets.

View heiswayi's full-sized avatar
👽

Heiswayi Nrird heiswayi

👽
View GitHub Profile
@heiswayi
heiswayi / LinearSmoothMove.cs
Last active December 21, 2016 15:00
C# code snippet - Making mouse cursor linear movement looks more realistic. Source: http://stackoverflow.com/a/913703/2019740
[DllImport("user32.dll")]
private static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out Point p);
public static void LinearSmoothMove(Point newPosition, int steps)
{
Point start = new Point();
GetCursorPos(out start);
@heiswayi
heiswayi / function.js
Last active December 21, 2016 15:05
A JavaScript function to get which line number of caret current position belongs to in textarea element. Demo: http://jsfiddle.net/heiswayi/oxax5ouq/
function getLineOfCaret(a) {
var b = 0;
if (a.selectionEnd) b = a.selectionEnd; else if (document.selection) {
a.focus();
var c = document.selection.createRange();
if (null == c) b = 0; else {
var d = a.createTextRange(), e = d.duplicate();
d.moveToBookmark(c.getBookmark());
e.setEndPoint("EndToStart", d);
b = e.text.length;
@heiswayi
heiswayi / App.xaml.cs
Last active January 13, 2017 02:13
C# SmartDispatcher class by Jeff Wilcox for WPF MVVM
public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;
SmartDispatcher.Initialize(Deployment.Current.Dispatcher);
InitializeComponent();
}
@heiswayi
heiswayi / progress.ps1
Last active February 8, 2017 16:23
Update progress in PowerShell
$Num = 5
$Jobs = @()
ForEach ($Job in (1..$Num))
{ $Jobs += Start-Job -ScriptBlock {
$Count = 1
Do {
Write-Progress -Id 2 -Activity "Background Job" -Status $Count -PercentComplete 1
$Count ++
Start-Sleep -Seconds 4
using System;
// it's required for reading/writing into the registry:
using Microsoft.Win32;
// and for the MessageBox function:
using System.Windows.Forms;
namespace Utility.ModifyRegistry
{
public class ModifyRegistry
{

Simplicity is prerequisite for reliability. --Edger Djikstra

Effective Engineer - Notes

What's an Effective Engineer?

  • They are the people who get things done. Effective Engineers produce results.

Adopt the Right Mindsets

@heiswayi
heiswayi / SimplestLoggerUtility.cs
Created March 10, 2018 04:56
Simplest logger utility class using Windows built-in logging facility
using System;
using System.Diagnostics;
namespace SimplestLoggerUtility
{
public static class Logger
{
public static void Success(string message)
{
EventLog.WriteEntry(AppDomain.CurrentDomain.FriendlyName, message, EventLogEntryType.Information);
@heiswayi
heiswayi / gist:7775ec456f2e98b739a6c556a19e0cb1
Created April 26, 2018 04:58 — forked from digitaljhelms/gist:4287848
Git/GitHub branching standards & conventions

Branching

Quick Legend

Description, Instructions, Notes
Instance Branch
using System;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace CompressString
{
internal static class StringCompressor
{
/// <summary>