Skip to content

Instantly share code, notes, and snippets.

View bobdobbalina's full-sized avatar

Mike Grunwald bobdobbalina

View GitHub Profile
@bobdobbalina
bobdobbalina / slugify.js
Last active November 7, 2022 19:27
Javascript: slugify string
function slugify(string) {
return string.replace(/\W+/g, "-")
.replace(/[-]+$/, "")
.toLowerCase();
}
@bobdobbalina
bobdobbalina / codeswing.json
Last active January 14, 2022 20:14
objectHasKeys
{
"scripts": [],
"showConsole": true
}
@bobdobbalina
bobdobbalina / codeswing.json
Last active May 10, 2021 11:09
Ian's Ten Minutes
{
"scripts": [],
"styles": []
}
@bobdobbalina
bobdobbalina / randomArrayItem.js
Last active March 23, 2021 18:28
Javascript: Get random item from array
function random_item(items) {
return items[Math.floor(Math.random() * items.length)];
}
const items = [254, 45, 212, 365, 2543];
console.log(random_item(items));
@bobdobbalina
bobdobbalina / randomHex.js
Created March 22, 2021 21:33
Javascript: Random Hex Value
var randomColor = Math.floor(Math.random() * 16777215).toString(16);
@bobdobbalina
bobdobbalina / _base.scss
Last active March 11, 2021 15:23
BitttersKitchenSink
// Bitters 2.0.4
// https://github.com/thoughtbot/bitters
// Copyright 2013-2019 thoughtbot, inc.
// MIT License
@import "variables";
@import "buttons";
@import "forms";
@import "layout";
@bobdobbalina
bobdobbalina / update_gitignore.sh
Last active February 12, 2021 19:02
Remove files from updated .gitignore
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached
### Alias in .zshrc or .bashrc because too hard to remember
# alias ungit="git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached"
@bobdobbalina
bobdobbalina / formatCurrancy.js
Created January 20, 2021 19:27
Javascript: Format currency
const toCurrency = (n, curr, LanguageFormat = undefined) =>
Intl.NumberFormat(LanguageFormat, { style: 'currency', currency: curr }).format(n);
toCurrency(123456.789, 'EUR'); // €123,456.79 | currency: Euro | currencyLangFormat: Local
toCurrency(123456.789, 'USD', 'en-us'); // $123,456.79 | currency: US Dollar | currencyLangFormat: English (United States)
toCurrency(322342436423.2435, 'JPY'); // ¥322,342,436,423 | currency: Japanese Yen | currencyLangFormat: Local
toCurrency(322342436423.2435, 'JPY', 'fi'); // 322 342 436 423 ¥ | currency: Japanese Yen | currencyLangFormat: Finnish
@bobdobbalina
bobdobbalina / nativeType.js
Created January 20, 2021 19:26
Javascript: Get the native type of any value
const nativeType = v =>
v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
nativeType(new Set([1, 2, 3])); // set
@bobdobbalina
bobdobbalina / nonASCII.js
Created January 20, 2021 19:25
Javascript: Remove non ASCII characters from strings
const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, '');
removeNonASCII('äÄçÇéÉêlorem-ipsumöÖÐþúÚ'); // lorem-ipsum