Skip to content

Instantly share code, notes, and snippets.

View phelipetls's full-sized avatar

Phelipe Teles phelipetls

View GitHub Profile
@phelipetls
phelipetls / convert-to-template-string.lua
Created October 15, 2022 15:40
Convert JavaScript string into template string, if it contains `${`, with treesitter in neovim
-- in ~/.config/nvim/lua/convert-to-template-string.lua
local M = {}
local replace_surroundings_with = function(node, char)
local start_row, start_col, end_row, end_col = node:range()
vim.api.nvim_buf_set_text(0, start_row, start_col, start_row, start_col + 1, { char })
vim.api.nvim_buf_set_text(0, end_row, end_col - 1, end_row, end_col, { char })
end
@phelipetls
phelipetls / bouncing-balls.py
Last active December 2, 2020 14:56
An exercise in Vpython
import random
import math
from vpython import sphere, vector, scene
RANGE = 30
X_START = -RANGE - RANGE / 2
X_END = RANGE + RANGE / 2
Y_START = -RANGE
Y_END = RANGE
RADIUS = 0.05 * RANGE
" ~/.vim/after/syntax/python.vim or ~/.config/nvim/after/syntax/python.vim
syn match pythonEscape +{{+ contained containedin=pythonfString,pythonfDocstring
syn match pythonEscape +}}+ contained containedin=pythonfString,pythonfDocstring
syn region pythonfString matchgroup=pythonQuotes
\ start=+[fF]\@1<=\z(['"]\)+ end="\z1"
\ contains=@Spell,pythonEscape,pythonInterpolation
syn region pythonfDocstring matchgroup=pythonQuotes
\ start=+[fF]\@1<=\z('''\|"""\)+ end="\z1" keepend
\ contains=@Spell,pythonEscape,pythonSpaceError,pythonInterpolation,pythonDoctest
@phelipetls
phelipetls / async_make.lua
Last active February 8, 2024 23:18
Run :make asynchronously in Neovim
local M = {}
function M.make()
local lines = {""}
local winnr = vim.fn.win_getid()
local bufnr = vim.api.nvim_win_get_buf(winnr)
local makeprg = vim.api.nvim_buf_get_option(bufnr, "makeprg")
if not makeprg then return end
@phelipetls
phelipetls / Salesforce.bas
Created August 14, 2020 14:09
Download a Salesforce report via Analytics API
Sub DownloadReports
Dim Username As String, Password As String, SecurityToken As String
Username = "username"
Password = "password"
SecurityToken = "secret"
Dim SessionId As String
SessionId = SalesforceLogin(Username, Password, SecurityToken)
@phelipetls
phelipetls / highlight_cells.vim
Last active May 25, 2020 21:32
Highlight a line with signs in Vim
hi cellDelimiterHi ctermbg=8 ctermfg=0
sign define cellLine linehl=cellDelimiterHi
function! HighlightCellDelimiter()
execute "sign unplace * group=cellsDelimiter file=".expand("%")
for l:lnum in range(line("w0"), line("w$"))
if getline(l:lnum) =~ "^#%%$"
execute "sign place ".l:lnum." line=".l:lnum." name=cellLine group=cellsDelimiter file=".expand("%")
endif
@phelipetls
phelipetls / lsp.lua
Last active December 9, 2022 18:21
Neovim built-in LSP diagnostics into location list
local severity_map = { "E", "W", "I", "H" }
local parse_diagnostics = function(diagnostics)
if not diagnostics then return end
local items = {}
for _, diagnostic in ipairs(diagnostics) do
local fname = vim.fn.bufname()
local position = diagnostic.range.start
local severity = diagnostic.severity
table.insert(items, {
@phelipetls
phelipetls / download_kimetsu.sh
Last active November 9, 2019 20:41
Download arbitrary chapter of Demon Slayer manga. Just use with ./download_kimetsu 89 to download chapter 89. It will then download all pages into a folder called 089 etc.
#!/bin/bash
n=1
curl "https://ww1.demonslayermanga.com/chapter/demon-slayer-kimetsu-no-yaiba-chapter-$1/" |
sed -n '/<img class/p' |
sed -nr 's/.*src="(.*)".*/\1/p' |
tr -d '\015' | # some carriage return got in the way, gotta delete them
while read url;
do curl "$url" --create-dirs --output "$(printf %03d $1)/$(printf %02d $n).png";
# gerar uma sequência de -2pi até 2pi, com discretização de 2000
t <- seq(from = -2*pi, to = 2*pi, length.out = 2000)
# função para gerar os valores de x
X <- function(t, a, A = 1, d = pi/2) {
A*sin(a*t+d)
}
# para gerar os valores de y
Y <- function(t, b, B = 1) {