Skip to content

Instantly share code, notes, and snippets.

View diogotito's full-sized avatar

Diogo Tito Victor Marques diogotito

View GitHub Profile
local function abcdefu(a, b, c, d, e, ...)
print(a)
print(b)
print(c)
print(d)
print(e)
print(...)
return "yay"
end
@diogotito
diogotito / paste_in_console.js
Created June 12, 2024 11:34
Testing requestAnimationFrame timings with `progress` as a live expression, ES6 Map and console.table
{
const SAMPLES = 1000
progressObj = {
p: 0,
target: SAMPLES,
bars: 10,
toString() {
if (this.p < this.target) {
let progressBar = [...Array(this.bars)].map((_, bar) => ((this.p) / this.target) > ((bar + 1) / this.bars) ? '#' : '.').join('')
let percent = ((this.p) / SAMPLES * 100).toFixed(2) + "%"
@diogotito
diogotito / keybindings.json
Last active April 17, 2024 16:45
VSCode keybindings and settings
// Place your key bindings in this file to override the defaultsauto[]
[
// ===== Vim ===== MARK:vim
// ---- <Alt-[eafbhjkl]> to move the cursor in Insert mode like MARK:vim-rsi
{
"key": "Alt+e",
"command": "vim.remap",
"when": "inputFocus && vim.mode == 'Insert'",
"args": {
"after": [
@diogotito
diogotito / Microsoft.PowerShell_profile.ps1
Created January 17, 2024 19:37
Powershell utility functions in $profile to easily colorize things in Calculated Properties (for Select-Object, Format-Table, etc.)
# aux
# ---------------------
enum CC { RESET = 0; RED = 31; GREEN; YELLOW; BLUE; MAGENTA; CYAN; GRAY }
function CCs() { [enum]::GetValues([CC]) | select -skip 1 | % { [pscustomobject]@{ Code = +$_; Name = (f $_ "$_") } } }
function Get-ColoredString($color, [string] $text) {
if ($Host.UI.SupportsVirtualTerminal) {
[char] $ESC = 27
[int] $code = $color -as [CC]
"$ESC[${code}m" + $text + "$ESC[0m"
@diogotito
diogotito / jq.md
Last active October 23, 2023 22:31
[pt] Apontamentos jq

jq

Created segunda-feira 28 junho 2021 @cheatsheet

Flags úteis

  • -s (slurp) "sorve" um fluxo de vários documentos JSON (AKA "JSON Lines") para uma array. O filtro só recebe esta array.
  • -r (raw) Se o meu filtro produzir uma stream de strings, isto tira as aspas no output. Útil para passar para outros comandos.
@diogotito
diogotito / sp_help.ps1
Last active October 23, 2023 22:22
Run, parse and present the output of SQL Server's "exec sp_help" on a table
param([string] $table_name)
# -------------------
# Auxiliary functions
# -------------------
function f([string] $code, [string] $text) {
if ($Host.UI.SupportsVirtualTerminal) {
[char] $ESC = 27
"$ESC[${code}m" + $text + "$ESC[0m"
@diogotito
diogotito / _aoc22day1_stream_iterators.cpp
Last active March 15, 2023 19:26
My attempt to solve Advent of Code 2022 day 1 with idiomatic modern C++20 (https://adventofcode.com/2022/day/1)
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <iterator>
#include <ranges>
#include <format>
#include <vector>
#include <string>
{
"always_run_in_app" : false,
"icon" : {
"color" : "pink",
"glyph" : "wifi"
},
"name" : "MF910 Dashboard: iPhone layout",
"script" : "\/\/ -- Networking utils ------------------------------------------------------\n\nconst query = opts => Object.entries(opts)\n .map(([k, v]) => `${k}=${v}`)\n .join('&')\n\nconst routerDo = (goformId, options={}) => Object.assign(new Request(''), {\n url: 'http:\/\/192.168.0.1\/goform\/goform_set_cmd_process',\n headers: {Referer: 'http:\/\/192.168.0.1\/index.html'},\n method: 'POST',\n allowInsecureRequest: true,\n body: query({isTest: false, ...options, goformId})\n}).loadJSON()\n\nconst routerGet = (...cmd) => Object.assign(new Request(''), {\n url: 'http:\/\/192.168.0.1\/goform\/goform_get_cmd_process?' +\n query({...(cmd.length > 1 ? {multi_data: 1} : {}), cmd}),\n headers: {Referer: 'http:\/\/192.168.0.1\/index.html'},\n}).loadJSON()\n .then(res => cmd.length === 1\n
@diogotito
diogotito / knowledge.rb
Created March 5, 2023 18:44
My first solution for the Metakoans (https://rubyquiz.com/quiz67.html)
require 'set'
class Module
def attribute(a, &block)
(attr_name, attr_default) = if a.is_a? Hash
name, value = a.first
[name, -> { value }]
elsif block_given?
[a.to_s, block]
@diogotito
diogotito / GrayAlpha.cs
Created November 7, 2022 17:54
Paint.NET CodeLab filter to calculate alpha for Windows tooltip shadow pixels in screenshots
// Name:
// Submenu:
// Author:
// Title:
// Version:
// Desc:
// Keywords:
// URL:
// Help:
#region UICode