Skip to content

Instantly share code, notes, and snippets.

View yussan's full-sized avatar
🏠
Working from home everyday

yussan yussan

🏠
Working from home everyday
View GitHub Profile
@yussan
yussan / iso2FlagEmoji.js
Created June 21, 2022 03:35 — forked from sandgraham/iso2FlagEmoji.js
Convert a country's ISO-2 string to a flag emoji in a single line
const iso2FlagEmoji = iso => String.fromCodePoint(...[...iso.toUpperCase()].map(char => char.charCodeAt(0) + 127397));
iso2FlagEmoji("US"); // "🇺🇸"
@yussan
yussan / msToTime.js
Created October 6, 2021 13:23
Convert Miliseconds to hh:ii:ss:ms
/**
* @desc function to convert ms to time format hh:ii:ss.ms
* @param {Number} duration, time ini miliseconds
* @return {String} sample 00:01:01:99
*/
export function msToTime(duration = 0) {
let milliseconds = parseInt((duration % 1000) / 100),
seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
@yussan
yussan / multilineElipsis.css
Last active October 6, 2021 13:20 — forked from vorvulev/multiline_elipsis.css
Multiline elipsis with overflow
.block-ellipsis {
display: block;
display: -webkit-box;
max-width: 100%;
height: 43px;
margin: 0 auto;
font-size: 14px;
line-height: 1;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
@yussan
yussan / getTimeBasedOnUTC.js
Last active October 6, 2021 13:19
Get Current Time Based On Active UTC
const now = new Date(now.getTime() - now.getTimezoneOffset() * 60000)
@yussan
yussan / getTotalExecutionTime.php
Last active October 6, 2021 13:20
Generate Total Execution Time on PHP in miliseconds
<?php
//place this before any script you want to calculate time
$time_start = microtime(true);
// your script code goes here
// do something
Put this at the end of your php file:
@yussan
yussan / With Async Await.js
Created May 30, 2020 04:26
sample script with and without Async Await
async function start() {
let x1 = await exe(1);
console.log("x1", x1);
let x2 = await exe(2);
console.log("x2", x2);
}
function exe(n) {
return new Promise((resolve, reject) => {
let response;
@yussan
yussan / loadExternalCSS.js
Last active October 6, 2021 13:21
Async load external CSS using JS
export default function loadCSS(href: string, cb: Function | null) {
if(!isStyleLoaded(href)) {
const l: HTMLElement | null = document.createElement('link')
l.setAttribute('rel', 'stylesheet')
l.setAttribute('href', href)
if(cb)
l.onload = cb()
document.body.appendChild(l)
}
}
@yussan
yussan / loadExternalJS.js
Last active October 6, 2021 13:21
Async load external JS using JS
export default function loadJS(src: string, args: any) {
if(!isScriptLoaded(src)) {
const s: HTMLElement | null = document.createElement('script')
s.setAttribute('src', src)
if(args.id) s.setAttribute('id', args.id)
if(args.cb)
s.onload = args.cb()
document.body.appendChild(s)
}
}
@yussan
yussan / Codelity-BinaryGap.js
Last active November 11, 2018 11:48
Find longest sequence of zeros in binary representation of an integer. Ref: https://app.codility.com/programmers/lessons/1-iterations/ . Codepen: https://codepen.io/yussan/pen/wQzqbw?editors=1011
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
const bin = Math.abs(N).toString(2)
let maxGap = 0, currentGap = 0
for(let n=0;n<bin.length;n++) {
if(bin[n]=="0"){
@yussan
yussan / addthis_reload.js
Created January 26, 2018 07:06 — forked from jonathanconway/addthis_reload.js
Reload (or initialize) addThis social share buttons. Useful when implementing addThis in a SPA (Single Page Application).
// Reload (or initialize) addThis social share buttons.
// IMPORTANT: make sure you put in a correct pubid on line 7.
window.addthis_reload = function () {
if (!window.addthis) {
// Load addThis, if it hasn't already been loaded.
window['addthis_config'] = { 'data_track_addressbar' : false };
$('body').append('<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid={YOUR PUBID HERE}"></script>');
} else {
// Already loaded? Then re-attach it to the newly rendered set of social icons.
// And reset share url/title, so they don't carry-over from the previous page.