Skip to content

Instantly share code, notes, and snippets.

View Download Instagram Image
(async function() {
const cls1 = [
'article[role="presentation"]',
'div[style]',
'div[style]',
'div[role="button"]',
'div',
'div[role="button"]',
'div[style]',
'img[crossorigin="anonymous"][class]',
View main.dart
// 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 Nov 18, 2021
Download all tables as CSVs
View tables-to-csvs.js
(function() {
const table2csv = table => {
const rows = [...table.querySelectorAll('tr')]
const csv = []
if (rows.length < 20) return null
for (let i in rows) {
View 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())
}
View format_currency.js
export const formatCurrency = (number, currency) => {
const options = {
minimumFractionDigits: 2,
currencyDisplay: 'narrowSymbol',
currencySign: 'accounting',
}
if (currency) {
options.style = 'currency'
options.currency = currency
}
View 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 Dec 17, 2020
Snippet ellipsis #js
View snippet.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 Dec 17, 2020
Check if isPrimitive #js
View is_primitive.js
export const isPrimitive = val => {
const type = typeof val
if (Array.isArray(val)) return false
if (type === 'object') return val === null
return type !== 'function'
}
View 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])
}
View copy_to_clipboard.js
export const copyToClipboard = async (text) => {
if (!navigator.clipboard)
// Clipboard API not available
throw new Error('Your browser doesn\'t allow clipboard access')
try {
await navigator.clipboard.writeText(text)
} catch (e) {
log.error('Failed to copy', e)