Skip to content

Instantly share code, notes, and snippets.

View daltonmenezes's full-sized avatar
:octocat:
"Hey ho, let's code" - R4m0n3s

Dalton Menezes daltonmenezes

:octocat:
"Hey ho, let's code" - R4m0n3s
View GitHub Profile
@daltonmenezes
daltonmenezes / symbol-iterator.example.js
Created October 9, 2019 23:07
A simple symbol iterator example
const obj = {
values: [1, 2, 3, 4, 5],
[Symbol.iterator]() {
let i = 0
return {
next: () => {
i++
return {
@daltonmenezes
daltonmenezes / minify.js
Created September 3, 2019 05:07
A function to minify strings in JavaScript.
const multilineString = `
This is...
a multiline string.
`
const minify = it => it.replace(/\s+/g, '')
minify(multilineString)
// Thisis...amultilinestring.
@daltonmenezes
daltonmenezes / to-camel-case.js
Created August 28, 2019 04:50
To camelCase function for javascript.
const toCamelCase = (str, separator) =>
separator
? str.toLowerCase().replace(
new RegExp(`(${separator})*(${separator}.{1})`, 'g'),
char => char.toUpperCase().substr(1)
)
: str
console.log(
toCamelCase('my-cool-function', '-') // myCoolFunction
@daltonmenezes
daltonmenezes / prepare-module-for-injection.js
Last active August 28, 2019 04:43
Convert your external module to String and catches the module body to inject using executeJavaScript on Electron
const prepareModuleForInjection = code => {
const moduleBody = /(?<=\{return\s).*(?=})|(?<=({(?![return]))).*(?=})|(?<=\=>\s)(?=[a-z]).*|(?<=\=>)\n.*/gsi
const [extractedBody] = String(code).match(moduleBody) || ''
return extractedBody
? `${extractedBody.trim()}\n\n`
: ''
}
webview.executeJavaScript(
@daltonmenezes
daltonmenezes / rebuildObject.js
Last active March 22, 2020 03:05
Rebuilds an object deleting an array key value from object property and keeps the rest of the old object
const tableProps = {
postId: ['varchar', 'NOT NULL', 'PRIMARY KEY'],
id: ['numeric', 'NOT NULL', 'PRIMARY KEY'],
data: ['json', 'NOT NULL']
}
const result =
Object
.keys(tableProps)
.reduce((acc, key) => {
@daltonmenezes
daltonmenezes / getTrace.js
Last active July 22, 2019 20:49
Get only path and line number of stack trace errors
const getTrace = error => error.stack.match(/(?<=\().*(?=\))/g)
@daltonmenezes
daltonmenezes / instagram-dark-theme.js
Last active March 16, 2019 03:52
Instagram Dark Theme for Web
var style = document.createElement('style')
style.textContent = `
html, body { display: contents; }
html, body, img, time, div[role=button] canvas, .coreSpriteDropdownArrowGrey9, button .glyphsSpriteHeart__outline__24__grey_9, .glyphsSpriteComment__outline__24__grey_9, .glyphsSpriteShare__outline__24__grey_9, .glyphsSpriteSave__outline__24__grey_9, video { filter: invert(1); }
.glyphsSpriteComment_like, .glyphsSpriteMore_horizontal__outline__24__grey_9 { filter: invert(1) !important; color: white !important; }
li div span span, main div button { filter: invert(1) !important; color: white !important; }
li div span span a { color: #77b3d8 !important; }
label { filter: invert(1) !important; }
header button img, button span img, button div canvas { filter: invert(0) !important; }
time { color: #77b3d8 !important; }
{
"settings": "{\n \"workbench.startupEditor\": \"newUntitledFile\",\n \"workbench.colorTheme\": \"One Monokai 80s\",\n \"editor.tabSize\": 2,\n \"terminal.external.linuxExec\": \"zsh\",\n \"terminal.integrated.shell.osx\": \"/bin/zsh\",\n \"editor.minimap.enabled\": false,\n \"window.zoomLevel\": 0,\n \"javascript.updateImportsOnFileMove.enabled\": \"always\",\n \"editor.wordWrap\": \"on\",\n \"breadcrumbs.enabled\": false,\n \"editor.overviewRulerBorder\": false\n}\n",
"keybindings": "// Place your key bindings in this file to overwrite the defaultsauto[]\n[\n {\n \"key\": \"f5\",\n \"command\": \"workbench.action.debug.continue\",\n \"when\": \"inDebugMode\"\n },\n {\n \"key\": \"f5\",\n \"command\": \"-workbench.action.debug.continue\",\n \"when\": \"inDebugMode\"\n }\n]",
"snippets": [
{
"dalton.code-snippets": "{\n\t\"Print to console\": {\n\t\t\"scope\": \"javascript,typescript\",\n\t\t\"prefix\": \"log\",\n\t\t\"body\": [\n\t\t\t\"
@daltonmenezes
daltonmenezes / remove-accent.js
Created November 25, 2018 06:10
Função de uma linha para remover acentos | Inline function to remove accents
const removeAccent = s => s.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
@daltonmenezes
daltonmenezes / netflix-my-list.js
Last active May 11, 2018 04:53
Lists My List from Netflix in text format and places it on the clipboard to share it.
list = ''
document.querySelectorAll('.video-preload-title-label').forEach(name => list += `${name.textContent} \n`)
copy(list)
console.log(list)