Skip to content

Instantly share code, notes, and snippets.

View seunggabi's full-sized avatar
🎯
Focusing

Seunggabi Kim seunggabi

🎯
Focusing
View GitHub Profile
@seunggabi
seunggabi / decimalToHex.java
Last active September 17, 2019 10:23
decimalToHex.java
public static String decimalToHex(int decimal, Integer length) {
return String.format("%0"+length+"x", decimal);
}
@seunggabi
seunggabi / autoPlay.js
Last active June 28, 2019 06:00
Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.
window.__autoPlay = setInterval(() => {
this.playTracks();
}, 500);
const promise = new Audio('/temp.mp3').play();
if (promise !== undefined) {
promise.then(() => {
window.__autoPlay && clearInterval(window.__autoPlay);
}).catch(() => {});
@seunggabi
seunggabi / requestUtils.js
Last active January 2, 2020 11:53
requestUtils.js
function requestUtils(method, url, body) {
var xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.withCredentials = true;
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
console.log(this);
console.log(url, body);
@seunggabi
seunggabi / post.js
Last active May 5, 2019 05:10
post.js
function post(url, body) {
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
console.log(this);
console.log(url, body);
}
@seunggabi
seunggabi / shuffle.js
Created May 4, 2019 08:47
shuffle.js
function shuffle(arr) {
var i = arr.length;
var random;
var temp;
while (i > 0) {
random = Math.floor(Math.random() * i--);
temp = arr[i];
arr[i] = arr[random];
const isMobile = (userAgent) => {
userAgent = userAgent || window.navigator.userAgent;
const device = ['iPhone', 'iPod', 'Android', 'Windows CE', 'BlackBerry', 'Symbian', 'Windows Phone', 'webOS', 'Opera Mini', 'Opera Mobi', 'POLARIS', 'IEMobile', 'lgtelecom', 'nokia', 'SonyEricsson', 'LG', 'SAMSUNG'].join('|');
const regexp = new RegExp(device, 'i');
return regexp.test(userAgent);
};