Skip to content

Instantly share code, notes, and snippets.

View bockoblur's full-sized avatar

Slobodan Babic bockoblur

  • Novi Sad, Serbia
View GitHub Profile
@bockoblur
bockoblur / abbreviatedNumber.ts
Last active May 16, 2023 19:12 — forked from eugenemtn/abbreviatedNumber.ts
Formatter for abbrevated numbers
export function abbreviatedNumber(value: number, precision=2): string {
if (isNaN(value)) {
return "";
}
let newValue = value;
const suffixes = ["", "K", "M", "B", "T"];
let suffixNum = 0;
while (Math.abs(newValue) >= 1000) {
newValue /= 1000;
suffixNum++;
const getRandomInt = (min = 0, max = 1) => {
min = Math.ceil(min);
max = Math.floor(max);
// The maximum is exclusive and the minimum is inclusive
return Math.floor(Math.random() * (max - min) + min);
}
@bockoblur
bockoblur / add-predefined-color.js
Last active February 28, 2019 14:02
Ionic 4 : Add new predefined colors (and enumerate them)
// make sure you include tinycolor library from npm
// npm install tinycolor2
const ionPrefix = ".ion-color-";
//
// example usage
//
// addIonColor("myColor", "#123456");
//
@bockoblur
bockoblur / shuffleLetters.js
Created June 3, 2018 21:51
Shuffle letters in input string
//range: (0..x-1)
function rnd(x){
return Math.floor(Math.random()*x);
}
function shuffleLetters(s){
var res="";
var a=s.split("");
while (a.length>0)
res+=a.splice(rnd(a.length),1)[0];
@bockoblur
bockoblur / rgbaToHex.js
Created January 10, 2018 15:07 — forked from phuonghd/rgbaToHex.js
Use JavaScript to Convert RGBA CSS Value to Hexadecimal
#!/usr/bin/env node
// Takes an rgba() CSS value and converts it to its 8 digit hexadecimal value.
//
// Usage: ./rgbaToHex.js "{YOUR_RGBA_STRING}"
//
// Example: ./rgbaToHex.js "rgba(197, 200, 198, .2)" => #C5C8C633
function trim (str) {
return str.replace(/^\s+|\s+$/gm,'');