Skip to content

Instantly share code, notes, and snippets.

@heiswayi
heiswayi / Program.cs
Created Apr 14, 2016
C# multithreading
View Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Example1
{
class Program
@heiswayi
heiswayi / BindingProxy.cs
Last active Jun 5, 2016
To bind to data when the DataContext is not inherited
View BindingProxy.cs
public class BindingProxy : Freezable
{
#region Overrides of Freezable
protected override Freezable CreateInstanceCore()
{
return new BindingProxy();
}
#endregion
@heiswayi
heiswayi / character.csv
Created Nov 4, 2016
Target bruteforcing
View character.csv
character frequency
a 6.37933850459
1 6.21151241463
2 4.45739893876
e 4.35398645675
i 3.85404970133
o 3.74752759686
0 3.65563266802
3 3.34822752429
n 3.27218010954
@heiswayi
heiswayi / LinearSmoothMove.cs
Last active Dec 21, 2016
C# code snippet - Making mouse cursor linear movement looks more realistic. Source: http://stackoverflow.com/a/913703/2019740
View LinearSmoothMove.cs
[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 Dec 21, 2016
A JavaScript function to get which line number of caret current position belongs to in textarea element. Demo: http://jsfiddle.net/heiswayi/oxax5ouq/
View function.js
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 Jan 13, 2017
C# SmartDispatcher class by Jeff Wilcox for WPF MVVM
View App.xaml.cs
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 / Program.cs
Last active Feb 6, 2017
C# Multithreadings (Thread, Threadpool, Task & BackgroundWorker) vs single threading experiment. https://heiswayi.github.io/2016/understanding-multithreading-vs-single-threading-programming
View Program.cs
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace MultithreadingVsSingleThreading
{
internal class Program
{
@heiswayi
heiswayi / hnexplorer.php
Created Feb 7, 2017
Backup of HNExplorer source code -- a PHP file manager.
View hnexplorer.php
<?php
//
// Initialising variables. Don't change these.
//
$_CONFIG = array();
$_ERROR = "";
$_START_TIME = microtime(TRUE);
@heiswayi
heiswayi / progress.ps1
Last active Feb 8, 2017
Update progress in PowerShell
View progress.ps1
$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
View ModifyRegistry.cs
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
{