This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaScript Version of: https://raw.githubusercontent.com/developit/mitt/main/src/index.ts | |
// Define the event bus outside of the exported function to ensure a singleton | |
const all = new Map(); | |
const on = (type, handler) => { | |
const handlers = all.get(type) || []; | |
all.set(type, [...handlers, handler]); | |
}; | |
const off = (type, handler) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Sometimes you need to move your existing git repository | |
# to a new remote repository (/new remote origin). | |
# Here are a simple and quick steps that does exactly this. | |
# | |
### OPTION 1 ########################################################################################### | |
# Let's assume we call "old repo" the repository you wish | |
# to move, and "new repo" the one you wish to move to. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Make a function that recursively invokes itself at the end on a timer | |
//This immediately invokes my_func, and then recursively invokes it at the end of the function after a 5 second delay. | |
(function my_func() { | |
// your code | |
setTimeout( my_func, 5000 ); | |
})(); | |
(function my_func() { | |
// your code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.shuffle = function () { | |
var a = this.split(""), | |
n = a.length; | |
for (var i = n - 1; i > 0; i--) { | |
var j = Math.floor(Math.random() * (i + 1)); | |
var tmp = a[i]; | |
a[i] = a[j]; | |
a[j] = tmp; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getNumberId(prefix) { | |
var p = prefix || "i"; | |
function shuffle(str) { | |
var a = str.split(""); | |
var n = a.length; | |
for (var i = n - 1; i > 0; i--) { | |
var j = Math.floor(Math.random() * (i + 1)); | |
var tmp = a[i]; | |
a[i] = a[j]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="dhtml-gantt-chart"> | |
{{word}} | |
<div id="gantt_here" ref="dhtml" style="width:100%; height:400px;"></div> | |
</div> | |
</template> | |
<script> | |
//Component's location: src/components/charts/DHTMLganttChart.vue | |
//Library's location: src/assets/dhtmlgantt-v4-pro/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@returns String | |
function getFormatedDate(formating, date) { | |
const format = formating || 'DD MMM YYYY'; | |
const days = ["Sun", "Mon", "Tue", "We", "Thu", "Fri", "Sat"]; | |
const monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; | |
function parse(str) { | |
var time = new Date(date); | |
return isNaN(time.getTime()) ? null : time; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [ | |
{key:"11", value:"1100"}, | |
{key:"22", value:"2200"} | |
]; | |
var obj = arr.reduce(function(obj,item) { | |
obj[item.key] = item.value; | |
return obj; | |
},{}); | |
console.log(JSON.stringify(obj)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myArray = [{ 'id': '73', 'foo': 'one' }, { 'id': '45', 'foo': 'two' }]; | |
function searchByPropValue(prop, value) { | |
return function (element) { | |
if (element.hasOwnProperty(prop)) { | |
if (value) { | |
if (element[prop] == value) return element; | |
} else { | |
return element; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateUUID() { | |
let d = new Date().getTime() | |
let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { | |
let r = (d + Math.random() * 16) % 16 | 0; | |
d = Math.floor(d / 16); | |
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16) | |
}) | |
return uuid | |
} |
NewerOlder