Skip to content

Instantly share code, notes, and snippets.

@espio999
espio999 / make_daily_folder.ps1
Created Jan 12, 2022
make daily working folder under target drive as" Drive:\%y\%m%d\"
View make_daily_folder.ps1
$parent_folder = drive = "d:\" + Get-Date -UFormat %y
$daily_folder = Get-Date -UFormat %m%d
$path = $parent_Frive + $parent_folder + $daily_folder
New-Item -Path $path -ItemType Directory
@espio999
espio999 / KeyHook.cs
Created Dec 17, 2021
Hook keyboard event on Windows
View KeyHook.cs
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace OnePushSnap
{
internal class KeyHook
{
delegate int delegateHookCallback(int nCode, IntPtr wParam, IntPtr lParam);
@espio999
espio999 / Capture.cs
Last active Dec 16, 2021
Windows screen capture - screen, active window and designated rectangle area
View Capture.cs
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApp1
{
internal class Capture
{
[StructLayout(LayoutKind.Sequential)]
@espio999
espio999 / screenshot.cs
Last active Dec 4, 2021
screenshot of whole screen and active window with .NET Framework
View screenshot.cs
String filename(String val)
{
String my_dir = "d:\\user temp\\20211204\\";
String my_file = DateTime.Now.ToString("hhmmss") + ".jpg";
return (my_dir + val + my_file);
}
Size screen_size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Size window_size = this.Size;
@espio999
espio999 / dev-random.ps1
Last active Nov 10, 2021
/dev/random with PowerShell
View dev-random.ps1
$size = 128 - 1
[byte[]] $data = 0..$size | %{Get-Random -Maximum $size}
Set-Content -Value $data -Encoding byte my_binary.dat
@espio999
espio999 / dev-zero.ps1
Created Nov 7, 2021
/dev/zero with PowerShell
View dev-zero.ps1
$size = 1024 * 128
$data = New-Object byte[] $size
Set-Content -Value $data -Encoding byte my_binary.dat
@espio999
espio999 / PCA.r
Created Sep 12, 2021
PCA (Principal Component Analysis) - plot, analysis, and prediction
View PCA.r
library(FactoMineR)
library(factoextra)
library(corrplot)
mydata = LifeCycleSavings
mypca = PCA(mydata, scale.unit = TRUE, graph = FALSE)
mypca$eig
fviz_pca_var(mypca, col.var = "cos2", gradient.cols = c("blue", "red"), repel = TRUE)
@espio999
espio999 / clustering.r
Last active Sep 12, 2021
Clustering - identify number of clusters, analysis, and plot
View clustering.r
library(NbClust)
library(factoextra)
library(Rmisc)
mydata = scale(LifeCycleSavings)
myAHCnum = NbClust(mydata, method = "ward.D", index = "all")
myNHCnum = NbClust(mydata, method = "kmeans", index = "alllong")
fig1 = fviz_nbclust(myAHCnum, method = "silhouette")
fig2 = fviz_nbclust(myNHCnum, method = "gap_stat", nboot = 100)
@espio999
espio999 / ConvertToAAC-LC.ps1
Created Sep 12, 2021
Convert to AAC-LC with qaac
View ConvertToAAC-LC.ps1
$s_folder = "D:\temp\2020\20201204\source"
$d_folder = "D:\temp\2020\20201204\destination"
$bps = 48
$csv = import-csv -path .\test.csv
foreach ($myline in $csv){
$s_path = $s_folder + '\' + $myline.source
$d_path = $d_folder + '\' + $myline.destination
.\qaac64.exe $s_path -o $d_path -v $bps -r $myline.sampling --artist $myline.artist --album $myline.album --genre $myline.genre
@espio999
espio999 / MountISO_ChangeDrv-Good.ps1
Last active Sep 12, 2021
Mount ISO and change its drive letter with PowerShell - good pattern
View MountISO_ChangeDrv-Good.ps1
$myISO = 'E:\ISO\Microsoft Bookshelf Basic\BSBASIC2.ISO'
Mount-DiskImage $myISO
$vol = Get-DiskImage $myISO | Get-Volume
$old_drv = $vol.DriveLetter + ':'
$new_drv = 'X:'
Get-WmiObject -Class Win32_Volume | Where-Object {$_.DriveLetter -eq $old_drv} | Set-WmiInstance -Arguments @{DriveLetter=$new_drv}