Skip to content

Instantly share code, notes, and snippets.

View agusputra's full-sized avatar
🏠
Working from home

Agus Syahputra agusputra

🏠
Working from home
View GitHub Profile
(() => {
const execute = () => {
jQuery(($) => {
///
// Do something
///
});
};
const executeIf = (globalProp, execute) => () => {
@agusputra
agusputra / sticky.js
Last active November 3, 2019 15:47
Make element sticky to the viewport when scroll
function setSticky(elementId) {
const stickyElement = document.getElementById(elementId)
const stickyTop = stickyElement.offsetTop
const setStickyClass = () => {
if (window.pageYOffset > stickyTop) {
stickyElement.classList.add('sticky')
}
else {
stickyElement.classList.remove('sticky')
@agusputra
agusputra / do-if-jquery.js
Last active November 3, 2019 10:07
do-if-jquery.js
const detectJQuery = () => typeof jQuery !== 'undefined'
doIf(detectJQuery, main, 1000)
function main() {
jQuery(($) => {
// jQuery detected
})
}
@agusputra
agusputra / do-if.js
Created November 3, 2019 09:32
do-if.js
function doIf(predicate, callback, timeOut) {
setTimeout(() => {
if (predicate()) {
callback()
}
else {
doIf(predicate, callback);
}
}, timeOut)
}
@agusputra
agusputra / Bootstrap-Grid-System.css
Last active November 3, 2019 09:34
Bootstrap Grid System
/**/
/* Min Width */
/**/
@media (min-width: 0) {
}
@media (min-width: 576px) {
@agusputra
agusputra / bs-utils.scss
Created January 5, 2019 07:21
Utils for bootstrap
@mixin when-xs {
@media all and (max-width: 575px) {
@content
}
}
@mixin when-sm {
@media all and (min-width: 576px) and (max-width: 767px) {
@content
}
@agusputra
agusputra / allMatches.js
Created January 5, 2019 07:10
Get all matches when using regex
function allMatches (regex, text) {
if (!regex.global) throw new Error('option global not set')
let matches = []
while(true) {
const match = regex.exec(text)
if (!match) break;
matches.push(match)
}
@agusputra
agusputra / getUtf8Bytes.js
Created October 14, 2017 10:06
Get UTF-8 bit/byte representation of unicode character in JS
new TextEncoder('utf-8').encode('\u0001')
new TextEncoder('utf-8').encode('\uffff')
0x03De52113EA16E78b807905EF76D2323598E61c5
/* Modified from: https://css-tricks.com/dont-overthink-it-grids/ */
.row {
margin: 0 -20px;
}
.row:after {
content: "";
display: table;
clear: both;