Skip to content

Instantly share code, notes, and snippets.

@kaioduarte
kaioduarte / 01-template-literals.md
Created February 9, 2022 11:55
JS Reintroduction Presentation

Template literals are enclosed by the backtick (`) (grave accent) character instead of double or single quotes.

There are two types of template literals: Untagged and Tagged.

Untagged

Untagged template literals result in strings, which makes them useful in string interpolation and multiline strings.

Multi-line strings

@kaioduarte
kaioduarte / 01-counting_valleys.py
Last active April 13, 2020 16:34
Hacker Rank - Interview Preparation
def counting_valleys(n: int, s: str) -> int:
valleys = 0
state = 0
is_sea_level = True
for step in s:
if step == 'D':
state -= 1
else:
state += 1
@kaioduarte
kaioduarte / 01-palindrome.py
Last active April 9, 2020 09:15
Hydra - Exercicios
'''
Dada uma palavra S, implemente uma função que devolve True se a palavra é um
palíndromo e False se não for. Um palíndromo é uma palavra ou sequência de
palavras que se escreve da mesma forma da direita para a esquerda e da
esquerda para a direita. Os espaços contam como caracteres nesta versão.
'''
def solution(S):
for i in range(len(S) // 2):
if S[i] != S[-1 - i]:
@kaioduarte
kaioduarte / FrogRiverOne.py
Last active March 26, 2020 18:53
Codility Extra
def solution(X, A):
if X not in A:
return -1
steps = set()
target_len = len(set(range(1, max(A) + 1)))
for idx, el in enumerate(A):
steps.add(el)
if target_len == len(steps):
def solution(arr):
return sum(arr)
def solution(N):
N = bin(N)[2:]
maximum = count = 0
one_flag = False
for num in N:
if num == '1':
if count > maximum:
maximum = count
count = 0
@kaioduarte
kaioduarte / .vimrc
Last active December 11, 2020 10:29
My terminal configs
" ----------------------------------------------------------------------
" | General Settings |
" ----------------------------------------------------------------------
syntax on " Enable syntax highlighting
set autoindent " Copy indent to the new line
set backspace=indent "
set backspace+=eol " │ Allow `backspace`

Notes about controllers naming convention for reference

The content was based in some of the most popular and solid MVC frameworks such as Ruby on Rails, CakePHP and Laravel.

Controller naming

  • PascalCased: MyController
  • Resources names in plural: UsersControllers (accordingly RoR docs there are some execptions for this convention)

Actions Handled By Resource Controller

  • Based on Laravel documentation, maybe some actions can be different/or not exists in others frameworks, like create and edit.
@kaioduarte
kaioduarte / bot.py
Created January 30, 2018 14:25
Bot for game Math by @gamebot - Telegram
from time import sleep
from selenium import webdriver
from argparse import ArgumentParser
__author__ = "Kaio Duarte"
__email__ = "duartedossantos@gmail.com"
class Game(object):
@kaioduarte
kaioduarte / materialize-colors.py
Created January 3, 2018 00:05
Simple scrape with Selenium + BeautifulSoup to get colors from Materialize CSS.
import re
from bs4 import BeautifulSoup
from selenium import webdriver
URL = "http://materializecss.com/color.html"
HEX_RE = r"^#([A-Fa-f0-9]){3,6}$"
class Crawler(object):
def __init__(self, headless=True):