Skip to content

Instantly share code, notes, and snippets.

@ping -n %1 localhost > NUL
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET COUNT=0
FOR /F %%f IN (%1) DO (
SET /A COUNT=!COUNT! + 1
)
echo !COUNT!
ENDLOCAL
@ECHO ON
@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
@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 / 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 / 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 / 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 / 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 / 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 / echo-n.bat
Created April 6, 2018 22:00
echo without return
@SETLOCAL
@(<NUL (SET /P X=%*))
@ENDLOCAL