Skip to content

Instantly share code, notes, and snippets.

@wesleybliss
wesleybliss / split_view.dart
Created July 7, 2022 04:47
Resizable split view widget
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// 2022-07-06 Updated to null safety
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
/// A widget that takes two children, lays them out along [axis], and allows
/// the user to resize them.
(async function() {
const cls1 = [
'article[role="presentation"]',
'div[style]',
'div[style]',
'div[role="button"]',
'div',
'div[role="button"]',
'div[style]',
'img[crossorigin="anonymous"][class]',
// Slashy things are single-line comments, very useful
/*
* Slashy + star are multi-line comments
*
* This is a basic inheritence example,
* which is a core principle of OOP, or Object Oriented Programming
*/
// Imports let you use things from other libraries (code)
// that you or others have written
@wesleybliss
wesleybliss / tables-to-csvs.js
Last active November 18, 2021 20:00
Download all tables as CSVs
(function() {
const table2csv = table => {
const rows = [...table.querySelectorAll('tr')]
const csv = []
if (rows.length < 20) return null
for (let i in rows) {
@wesleybliss
wesleybliss / is_valid_email.js
Created December 17, 2020 15:12
Is valid email #js
export const isValidateEmail = email => {
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return re.test(String(email).toLowerCase())
}
@wesleybliss
wesleybliss / format_currency.js
Created December 17, 2020 15:12
Format currency #js
export const formatCurrency = (number, currency) => {
const options = {
minimumFractionDigits: 2,
currencyDisplay: 'narrowSymbol',
currencySign: 'accounting',
}
if (currency) {
options.style = 'currency'
options.currency = currency
}
@wesleybliss
wesleybliss / get_locale.js
Created December 17, 2020 15:11
Get locale #js
export const getLocale = () => {
const locale = (navigator.languages && navigator.languages.length)
? navigator.languages[0]
: navigator.language
return locale || 'en-US'
}
@wesleybliss
wesleybliss / snippet.js
Created December 17, 2020 15:11
Snippet ellipsis #js
export const snippet = (val, len = 5) =>
(val && val.length > (len * 2))
? val.substring(0, len) + '...' + val.substring(val.length - len)
: val
@wesleybliss
wesleybliss / is_primitive.js
Created December 17, 2020 15:11
Check if isPrimitive #js
export const isPrimitive = val => {
const type = typeof val
if (Array.isArray(val)) return false
if (type === 'object') return val === null
return type !== 'function'
}
@wesleybliss
wesleybliss / debounce.js
Created December 17, 2020 15:10
Debounce #js
export function debounce(func, wait, immediate) {
let timeout
return function (...args) {
clearTimeout(timeout)
timeout = setTimeout(() => {
timeout = null
if (!immediate) func.apply(this, args)
}, wait)
if (immediate && !timeout) func.apply(this, [...args])
}