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 / load.js
Created April 18, 2019 02:35
Critical Path
function loadStylesheet(src) {
if (document.createStylesheet) {
document.createStylesheet(src);
} else {
const linkTag = document.createElement('link');
linkTag.rel = "stylesheet";
linkTag.type = "text/css";
linkTag.href = src;
document.getElementsByTagName('head')[0].appendChild(linkTag);
}
@hwindo
hwindo / index.html
Created February 11, 2019 13:24
Responsive iFrame
<!doctype html>
<html>
<head>
<title>Responsive iFrame</title>
<style>
.resp-iframe {}
.resp-iframe__container {
position: relative;
overflow: hidden;
padding-top: 56.25%; // video ratio 9 / 16 = 0.5625 ~ 56.25% change this according video ratio
@hwindo
hwindo / telephoneCheck.js
Created September 22, 2018 06:07
Javascript Telephone Number Validator
function telephoneCheck(strPhoneNumber) {
let phonePattern = /^\d{10}$|^(1{1}[ ]?)?((\(\d{3}\) ?)|(\d{3}))[- ]?\d{3}[- ]\d{4}$/;
return phonePattern.test(strPhoneNumber);
}
// telephoneCheck("555-555-5555"); // --> true
@hwindo
hwindo / diagonal-stripe.css
Created August 11, 2018 03:31
a repeating gradient that make diagonal stripe
.diagonal-stripe {
background: repeating-linear-gradient(
45deg,
yellow 0px,
yellow 40px,
black 40px,
black 80px
);
}
@hwindo
hwindo / package.json
Created August 5, 2018 22:31
basic-webpack-scss
{
"name": "basic-webpack-scss",
"version": "1.0.0",
"description": "Minimum Webpack SCSS for development",
"main": "",
"scripts": {
"build": "webpack --watch",
"start": "webpack-dev-server --open"
},
"author": "Herwindo Artono",
@hwindo
hwindo / package.json
Created July 29, 2018 02:17
Basic webpack config with scss support
{
"name": "basic-webpack-config-windo",
"sideEffects": [
"*.css"
],
"version": "0.0.1",
"description": "",
"private": true,
"main": "index.js",
"scripts": {
# https://stackoverflow.com/questions/40505481/error-when-launching-rethinkdb-restore-no-such-file-or-director/51242048#51242048
python -mrethinkdb._restore #FILE
/**
* addItem
* adding item into existing array by matching id
*/
function addItem(item, currentArrayOfItem) {
let exist = currentArrayOfItem.find(_item => _item.id === item.id);
if (exist) {
let index = currentArrayOfItem.indexOf(exist);
currentArrayOfItem.splice(index, 1, item); // reason: reactivity
} else {
@hwindo
hwindo / checkStringIsXML.js
Last active June 6, 2018 07:07
simple js function to check if a string is XML using Regular Expression
function checkStringIsXML(data) {
var matcher = new RegExp('<?xml');
return data.match(matcher) ? true : false;
}
/**
* msNow
* UNIX timestamp in javascript
*/
function msNow(): number {
return (new Date()).getTime();
}