Skip to content

Instantly share code, notes, and snippets.

Avatar
🎧
‌‌

Wagner Souza waghcwb

🎧
‌‌
View GitHub Profile
@waghcwb
waghcwb / ConvertMS.js
Created Apr 29, 2021 — forked from flangofas/ConvertMS.js
JS: Convert Milliseconds to days? minutes? seconds? or all!
View ConvertMS.js
function convertMiliseconds(miliseconds, format) {
var days, hours, minutes, seconds, total_hours, total_minutes, total_seconds;
total_seconds = parseInt(Math.floor(miliseconds / 1000));
total_minutes = parseInt(Math.floor(total_seconds / 60));
total_hours = parseInt(Math.floor(total_minutes / 60));
days = parseInt(Math.floor(total_hours / 24));
seconds = parseInt(total_seconds % 60);
minutes = parseInt(total_minutes % 60);
View hash.js
const sha256 = async message => {
const msgBuffer = new TextEncoder('utf-8').encode(message);
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('');
}
@waghcwb
waghcwb / maxWordsPerLine.js
Created Jun 15, 2020
Script that breaks a string into lines based on a maximum attribute
View maxWordsPerLine.js
function maxWordsPerLine(str, max = 30) {
const result = [];
let counter = 1;
let tempArr = [];
for (const [index, letter] of str.split('').entries()) {
if (counter === max + 1) {
counter = 1;
result.push(tempArr);
View javascript.closest.js
if (!Element.prototype.findParentTagName) {
Element.prototype.findParentTagName = function (stringData) {
try {
if (this.tagName.equal(stringData)) return this;
let parent = this.parentElement;
while (parent) {
if (parent.tagName.equal(stringData)) return parent;
parent = parent.parentElement;
}
} catch (e) {
View diff.js
function diff(arr1, arr2) {
return arr1.filter(x => arr2.includes(x));
}
const arr1 = [
34242,
33030,
34241,
27118,
34152,
@waghcwb
waghcwb / code.md
Created Jan 11, 2020 — forked from gopalindians/code.md
Jetbrains IntelliJ IDEA 2019.2.4 Activation code
View code.md

Please make fork of this, as this can be removed by Github.com sooner or later.

CATF44LT7C-eyJsaWNlbnNlSWQiOiJDQVRGNDRMVDdDIiwibGljZW5zZWVOYW1lIjoiVmxhZGlzbGF2IEtvdmFsZW5rbyIsImFzc2lnbmVlTmFtZSI6IiIsImFzc2lnbmVlRW1haWwiOiIiLCJsaWNlbnNlUmVzdHJpY3Rpb24iOiJGb3IgZWR1Y2F0aW9uYWwgdXNlIG9ubHkiLCJjaGVja0NvbmN1cnJlbnRVc2UiOmZhbHNlLCJwcm9kdWN0cyI6W3siY29kZSI6IklJIiwicGFpZFVwVG8iOiIyMDIwLTAxLTA4In0seyJjb2RlIjoiQUMiLCJwYWlkVXBUbyI6IjIwMjAtMDEtMDgifSx7ImNvZGUiOiJEUE4iLCJwYWlkVXBUbyI6IjIwMjAtMDEtMDgifSx7ImNvZGUiOiJQUyIsInBhaWRVcFRvIjoiMjAyMC0wMS0wOCJ9LHsiY29kZSI6IkdPIiwicGFpZFVwVG8iOiIyMDIwLTAxLTA4In0seyJjb2RlIjoiRE0iLCJwYWlkVXBUbyI6IjIwMjAtMDEtMDgifSx7ImNvZGUiOiJDTCIsInBhaWRVcFRvIjoiMjAyMC0wMS0wOCJ9LHsiY29kZSI6IlJTMCIsInBhaWRVcFRvIjoiMjAyMC0wMS0wOCJ9LHsiY29kZSI6IlJDIiwicGFpZFVwVG8iOiIyMDIwLTAxLTA4In0seyJjb2RlIjoiUkQiLCJwYWlkVXBUbyI6IjIwMjAtMDEtMDgifSx7ImNvZGUiOiJQQyIsInBhaWRVcFRvIjoiMjAyMC0wMS0wOCJ9LHsiY29kZSI6IlJNIiwicGFpZFVwVG8iOiIyMDIwLTAxLTA4In0seyJjb2RlIjoiV1MiLCJwYWlkVXBUbyI6IjIwMjAtMDEtMDgifSx7ImNvZGUiOiJEQiIsI

View get-hardcoded-strings-jsp.js
const { readFile: originalReadFile, writeFile: originalWriteFile } = require('fs')
const { promisify } = require('util')
const { resolve, join } = require('path')
const originalGlob = require('glob')
const glob = promisify(originalGlob)
const readFile = promisify(originalReadFile)
const writeFile = promisify(originalWriteFile)
class Storefront {
View browser-detect.js
/**
* This method is used to detect the user browser and environment
*/
establishBrowser() {
const userAgent = (navigator && navigator.userAgent || '').toLowerCase()
const vendor = (navigator && navigator.vendor || '').toLowerCase()
const comparator = {
'<': function(a, b) { return a < b; },
'<=': function(a, b) { return a <= b; },
View call-nodejs-from-ant.xml
<!-- i needed to run webpack from ant build, so this was the solution -->
<macrodef name="nodejs">
<attribute name="module" description="The name of the NodeJS module to execute" />
<attribute name="failonerror" default="true" description="Fail if the exit code is not 0" />
<attribute name="dir" description="Directory to execute task" />
<element name="args" implicit="yes" description="Argument to pass to the exec task" />
<sequential>
<exec executable="cmd.exe" dir="@{dir}" failonerror="@{failonerror}" osfamily="winnt">
@waghcwb
waghcwb / encoding-video.md
Created Aug 8, 2019 — forked from Vestride/encoding-video.md
Encoding video for the web
View encoding-video.md

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus