Skip to content

Instantly share code, notes, and snippets.

@impepc
impepc / fileview.js
Created April 26, 2018 11:10
fileviewer wsh
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ie = WScript.CreateObject("InternetExplorer.Application", "IE_");
var objshell = new ActiveXObject("shell.application");
var shell = WScript.CreateObject("WScript.Shell");
/* store current folder item's path */
var info = [];
/* position of showing image */
var position = 0;
@impepc
impepc / which.bat
Created April 6, 2018 23:02
which for windows
@ECHO OFF
CALL :CHECK %1
FOR /D %%e IN ('echo %PATHEXT%') DO (
FOR /F "delims=" %%n IN ('echo %1%%e') DO (
CALL :CHECK %%n
)
)
@ECHO ON
@GOTO :EOF
@impepc
impepc / echo-n.bat
Created April 6, 2018 22:00
echo without return
@SETLOCAL
@(<NUL (SET /P X=%*))
@ENDLOCAL
@impepc
impepc / walker_base.js
Created April 5, 2018 14:14
walker in WSH
function func(item) {
// some function
}
function getChildren(node) {
var children = [];
if (fso.FolderExists(node)) {
for (var e = new Enumerator(fso.GetFolder(node).SubFolders); !e.atEnd(); e.moveNext()) {
children.push(e.item().Path);
}
@impepc
impepc / screenshot.vbs
Last active April 7, 2018 00:15
when screen shot, paste it to active excel
If WScript.arguments.Count = 0 Then
' Call self to show window
Set shell = CreateObject("WScript.Shell")
shell.Run "cmd /C """ & WScript.ScriptFullName & """ 1", 1
WScript.Quit(0)
End If
span = 2
col = 2
@impepc
impepc / top_align
Created April 4, 2018 13:24
excel line align based with top
Set excel = GetObject(, "Excel.Application")
Set shape = excel.Selection.ShapeRange(1)
If shape.HorizontalFlip = 0 And shape.VerticalFlip = 0 Then
ElseIf shape.HorizontalFlip = -1 And shape.VerticalFlip = 0 Then
shape.Left = shape.Left + shape.Width
ElseIf shape.HorizontalFlip = 0 And shape.VerticalFlip = -1 Then
ElseIf shape.HorizontalFlip = -1 And shape.VerticalFlip = -1 Then
shape.Left = shape.Left + shape.Width
@impepc
impepc / left_align.vbs
Created April 4, 2018 13:23
excel line align based with left
Set excel = GetObject(, "Excel.Application")
Set shape = excel.Selection.ShapeRange(1)
If shape.HorizontalFlip = 0 And shape.VerticalFlip = 0 Then
ElseIf shape.HorizontalFlip = -1 And shape.VerticalFlip = 0 Then
shape.Top = shape.Top + shape.Height
ElseIf shape.HorizontalFlip = 0 And shape.VerticalFlip = -1 Then
ElseIf shape.HorizontalFlip = -1 And shape.VerticalFlip = -1 Then
shape.Top = shape.Top + shape.Height
@impepc
impepc / right_align.vbs
Created April 4, 2018 13:22
excel line align based with right
Set excel = GetObject(, "Excel.Application")
Set shape = excel.Selection.ShapeRange(1)
If shape.HorizontalFlip = 0 And shape.VerticalFlip = 0 Then
ElseIf shape.HorizontalFlip = -1 And shape.VerticalFlip = 0 Then
shape.Top = shape.Top + shape.Height
ElseIf shape.HorizontalFlip = 0 And shape.VerticalFlip = -1 Then
ElseIf shape.HorizontalFlip = -1 And shape.VerticalFlip = -1 Then
shape.Top = shape.Top + shape.Height
@impepc
impepc / bottom_align.vbs
Created April 4, 2018 13:20
excel line align based with bottom
Set excel = GetObject(, "Excel.Application")
Set shape = excel.Selection.ShapeRange(1)
If shape.HorizontalFlip = 0 And shape.VerticalFlip = 0 Then
shape.Left = shape.Left + shape.Width
ElseIf shape.HorizontalFlip = -1 And shape.VerticalFlip = 0 Then
ElseIf shape.HorizontalFlip = 0 And shape.VerticalFlip = -1 Then
shape.Left = shape.Left + shape.Width
ElseIf shape.HorizontalFlip = -1 And shape.VerticalFlip = -1 Then
@impepc
impepc / greplike.bat
Last active April 1, 2018 04:34
grep like find batch
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
IF "%2" == "" (SET PWD="%CD%") ELSE (SET PWD=%~2)
FOR /F "delims=" %%f in ('dir /A-D /S /B "%PWD%"') DO (
FINDSTR "%~1" "%%~f" > NUL
IF "!ERRORLEVEL!" == "0"
ECHO %%f
)
ENDLOCAL
@ECHO ON