Snippets
#
Systems
#
Windows
#
Java
#
Tomcat
#
Git
#
Javascript
#
CSS
Add shortcuts in this folder to be able to add them to the start menu
Systems Windows
%AppData%\Microsoft\Windows\Start Menu\Programs
Send logs from tomcat console to a file, also known as "catalina.out"
Java Tomcat
Replace this at startup.bat:
call "%EXECUTABLE%" start %CMD_LINE_ARGS%
With:
SET isodt=%date:~6,4%-%date:~3,2%-%date:~0,2%
SET isodt=%isodt: =0%
SET logFile=..\logs\console.%isodt%.log
powershell "%EXECUTABLE% %CMD_LINE_ARGS% run 2>&1 | ForEach-Object ToString | Tee-Object %logFile% -Append"
Shortcut to open cmd at a defined route
Systems Windows
C:\WINDOWS\system32\cmd.exe /k "D: & cd D:\Bryan\Git"
Cherry pick a folder from an specific commit
Git
$ git checkout 1a64b23a8994cf9945eb4c1e9490e536e6a9117a -- path/to/the/folder/
Format a number of bytes to human readable text
Javascript
function bytesToHuman(bytes: number) {
let i = Math.floor(Math.log(bytes) / Math.log(1024));
let sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
return `${(bytes / Math.pow(1024, i)).toFixed(2) * 1} ${sizes[i]}`;
}
Copy to clipboard from variable natively
Javascript
if (!navigator.clipboard) {
console.error('Clipboard feature not supported in this browser')
return
}
await navigator.clipboard.writeText(textVar)
Color RGBA with variables
CSS
--colorB: 25, 58, 154;
--color1: rgba(var(--colorB), 0.2);
--color2: rgba(var(--colorB), 0.14);
--color3: rgba(var(--colorB), 0.12);
box-shadow:
0px 8px 10px -5px var(--color1),
0px 16px 24px 2px var(--color2),
0px 6px 30px 5px var(--color3)
!important;
Add git commit hash using webpack
Javascript Git
// Get hash using command-line
let commitHash = require('child_process')
.execSync('git rev-parse --short HEAD')
.toString();
// Add to webpack plugins a new Plugin
...
plugins: [
new webpack.DefinePlugin({
__COMMIT_HASH__: JSON.stringify(commitHash),
})
]
...
// Add to .eslintrc
globals: { __COMMIT_HASH__: true }
Create a .patch file from the last commit
Git
$ git format-patch HEAD~1 --stdout > patchfile.patch
Await X milliseconds in one line using async/await
Javascript
await new Promise(resolve => setTimeout(resolve, 1000));
Iterate over a number in Js like Ruby X.times()
Javascript
for (let i of Array(100).keys()) {
console.log(i)
}
Path to windows hosts file
Systems Windows
C:\Windows\System32\drivers\etc
Traverse directory recursively with depth option
Javascript
function getFiles(dirPath, currentLevel, maxLevel) {
if (currentLevel > maxLevel) {
return
} else {
fs.readdirSync(dirPath).forEach(function (file) {
let filepath = path.join(dirPath, file)
let stat = fs.statSync(filepath)
if (stat.isDirectory()) {
getFiles(filepath, currentLevel + 1, maxLevel)
} else {
console.info(filepath + '\n')
}
})
}
}