Skip to content

Instantly share code, notes, and snippets.

View marco-souza's full-sized avatar
🦕

Marco Antônio marco-souza

🦕
View GitHub Profile
@marco-souza
marco-souza / copyToClipboard.js
Created September 10, 2019 21:49
Function to copy text to clipboard in JS Vanilla
const copyToClipboard = (text, successCallback, errorCallback) => {
const textArea = document.createElement('textarea')
textArea.value = text
document.body.appendChild(textArea)
textArea.select()
try {
// Now that we've selected the anchor text, execute the copy command
document.execCommand('copy')
? successCallback()
@marco-souza
marco-souza / README.md
Created July 2, 2019 21:14
React project structure

React organization

I've created this file to register and share my definitions to organize react projects to avoid deep paths, dead code and to make sense to any new developer.

Base concepts

I'm using some concepts that may be known for many of you, but I'll pass through them to explain for júnior developers.

  • components - Here I defined components as simple components, just with visual definitions, actions calls, data but without states. Every action and data must be inserted by another components, or containers, as I call here. Components must never calls containers
  • containers: they are just components with state. It also may be a page, which integrates various containers to create a view and also has an route definition. Containers without route definition are just components, which some states and actions.
@marco-souza
marco-souza / downloadCSV.js
Created June 10, 2019 22:01
Download CSV form string
export function downloadCSV(CSVText, filename) {
const link = document.createElement('a');
link.setAttribute('href', window.URL.createObjectURL(
new Blob([CSVText]),
{ type: 'text/plain' }
));
link.setAttribute('download', `${filename}.csv`);
document.body.appendChild(link); // Required for FF
link.click();
document.body.removeChild(link);

xdotool - tool to fake system inputs.

Some commands using xdotool

play/pause

  • xdotool key XF86AudioPlay
@marco-souza
marco-souza / ext.md
Last active November 27, 2018 15:53
vscode extension list

General

  • Atom keymap
  • Code Runner
  • Comments Anchor
  • DotENV
  • EditorConfig for VS Code
  • gitignore
  • GitLens
// WARNING: it sould be runned in http://www.brazil-help.com/brazilian_states.htm
// to get the same results
const list_brazilien_states = () => {
const trs = document.querySelectorAll('.MsoNormalTable tr')
let data = []
trs.forEach((tr, index) => {
if (index > 3) {
const tds = tr.getElementsByTagName('td')
@marco-souza
marco-souza / tests.py
Last active August 10, 2018 15:00
Teste
# 1 - Bitmap
# Complete the decompress function below.
def decompress(linesAsStringArray):
result_line = ''
for line in linesAsStringArray:
while line:
sep, rep = line[:2]
line = line[2:]
result_line += (sep * int(rep))
result_line += '\n'
@marco-souza
marco-souza / steps.md
Last active August 6, 2018 18:56
Arch server

Settup Anarchist Server

  1. Fix etc/locale.gen to add pt_BR.UTF8 and run sudo locale-gen to generate it.

  2. Install yaourt

  3. Update system

  4. Install other programs

const getList = classname => [...document.getElementsByClassName(classname)]
.map(i => i.currentSrc)
.filter(i => String(i).includes(`frame`))
.map(i => i.replace(`_frame1.jpg`, ''))
.map(i => i.replace(`https://78.media.tumblr.com/`, ''))
.map(i => i.replace(`_frame1.jpg`, ''))
.map(i => `https://vtt.tumblr.com/${i}_480.mp4`)
const getVideos = () => getList('picture')
@marco-souza
marco-souza / wp-permission-updater.sh
Created July 6, 2018 14:41
Update WordPress permissions
chown www-data:www-data -R * # Let Apache be owner
find . -type d -exec chmod 755 {} \; # Change directory permissions rwxr-xr-x
find . -type f -exec chmod 644 {} \; # Change file permissions rw-r--r--