Skip to content

Instantly share code, notes, and snippets.

View hwindo's full-sized avatar
🍉
Watermelon

Herwindo Artono hwindo

🍉
Watermelon
View GitHub Profile
@hwindo
hwindo / toArr.js
Created October 19, 2017 04:13
change object to arr using underscore
const toArr = function (objData) {
var arr = [];
_.map(objData, function (val, key) {
val.id = key;
arr.push(val);
});
return arr;
}
@hwindo
hwindo / createRef.js
Last active November 25, 2020 16:37
dynamically create firebase firestore ref
function createRef(collectionName) {
let result = firestore;
function addResult(_result, collDocObj) {
let collDocKey = Object.keys(collDocObj)[0];
let collDocVal = Object.values(collDocObj)[0];
return _result.collection(collDocKey).doc(collDocVal);
}
if (arguments[1]) {
@hwindo
hwindo / msToTime.js
Last active October 4, 2017 09:36
convert milliseconds into Minutes and Seconds
function msToTime(duration) {
var milliseconds = parseInt((duration%1000)/100)
, seconds = parseInt((duration/1000)%60)
, minutes = parseInt((duration/(1000*60))%60)
, hours = parseInt((duration/(1000*60*60))%24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
@hwindo
hwindo / firebase.js
Last active May 1, 2024 12:56
Checking firebase initialization
// basic checking
// if (firebase.apps.length === 0) {
// firebase.initializeApp({
// // ... firebase config
// })
// }
// node module
// example named file: firebase.js
/**
@hwindo
hwindo / printer.js
Last active October 2, 2017 04:33
Singleton Pattern Example Printer
var printer = (function () {
var printerInstance;
function create() {
var turnedOn = false;
var paper = 5;
function print() {
// underlying printer mechanics
@hwindo
hwindo / unclickable
Created February 16, 2017 06:25
Make element unclickable, event z-index on top
div.unclickable {
pointer-events: none;
}
@hwindo
hwindo / loggingStuff.js
Created August 18, 2016 07:48
Logging any item
function logStuff(stuff) {
if (typeof stuff === "string") {
console.log("type: String");
console.log(stuff);
} else if (typeof stuff === "object") {
console.log("type: Object");
for (var index in stuff) {
console.log(index + ": " + stuff[index]);
}
} else if (typeof stuff === "array") {
@hwindo
hwindo / gist:3951453
Created October 25, 2012 08:37
CSS: Image Replacement
.ir {
border:0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background-color: transparent;
}