Skip to content

Instantly share code, notes, and snippets.

View alexcmgit's full-sized avatar

Alex Castro alexcmgit

View GitHub Profile
@alexcmgit
alexcmgit / distance_between.dart
Created July 19, 2021 16:24
Function to calculate distance between two lat and lon points.
import 'dart:math' as math;
void main() {
/// Online Tool https://www.meridianoutpost.com/resources/etools/calculators/calculator-latitude-longitude-distance.php?
final distance = DistanceUtils.distanceBetween(40.689202777778, -74.044219444444, 38.889069444444, -77.034502777778);
print(distance);
}
abstract class DistanceUtils {
import 'dart:async';
void main() {
/// Debounce example
final debounce = debounceIt(Duration(seconds: 2)); // Or DebounceIt(...)
debounce(() => print('First call'));
debounce(() => print('Second call'));
debounce(() => print('Third call'));
debounce(() => print('Fourth call'));
/// Checks if [source] contains all the characters of [text] in the correct order
///
/// Example:
/// ```
/// hasMatch('abcdef', 'adf') // true
/// hasMatch('dbcaef', 'adf') // false
/// ```
bool hasWildcardMatch(String source, String text) {
final regexp = text.split('').join('.*');
window.onbeforeunload = (e) => {
return "Dude, are you sure you want to leave? Think of the kittens!";
}
const bts = document.querySelectorAll("[aria-label='Delete']")
const b = [...bts];
for(let bt of b) {
try {
const selectorsToDelete = [
".wrapper-3NnKdC.guilds-1SWlCJ",
".sidebar-2K8pFh",
".title-3qD0b-.container-1r6BKw.themed-ANHk51",
];
for(const select of selectorsToDelete) {
document.querySelector(select).remove();
}
@alexcmgit
alexcmgit / letter-and-number-regex.js
Created April 15, 2021 18:45
At leat one uppercase char, one lowercase, and one number with min length = 8
const regex = new RegExp('^(?=.*?[A-Z])(?=.*?[])(?=.*?[0-9]).{8,}$');
void main() {
final dynamicInstance = createInstanceOf<Foo>();
print(dynamicInstance);
}
T? createInstanceOf<T>() {
final factories = <Type, T Function()>{
Foo: () => Foo() as T,
Bar: () => Bar() as T,
@alexcmgit
alexcmgit / smooth_scroll_physics.dart
Last active April 11, 2021 21:40
Smooth scroll physics. Instagram like
import 'package:flutter/material.dart';
class SmoothScrollPhysics extends ScrollPhysics {
const SmoothScrollPhysics({ScrollPhysics parent}) : super(parent: parent);
@override
SmoothScrollPhysics applyTo(ScrollPhysics ancestor) {
return SmoothScrollPhysics(parent: buildParent(ancestor));
}
@alexcmgit
alexcmgit / zap-message.js
Last active April 8, 2021 16:54
Só copiar e colar no devtools e chamar a função sendMessage com uma string separada por quebra de linha
async function sendText(scriptText) {
const lines = scriptText.split("\n");
for (const line of lines) {
if (line.trim() != "") {
console.log(lines);
window.InputEvent = window.Event || window.InputEvent;
const event = new InputEvent("input", { bubbles: true });
escolher uma cor primária
gerar uma paleta de:
- background => é o scaffoldbackground
- surface => tal do paper
- elevation overlay =>
- surface overlay => chips & text fields, é um surface um pouco mais clarinho
- Error => Gera uma nova paleta, por recursividade, usando vermelho + a claridade escolhida + baseado no vermelho tudo
- Outline => É uma borda bem fininha e transparente,é basicamente a cor branca com pouca opacidade
- on surface => High|Medium|Low|Disabled emphasys