Skip to content

Instantly share code, notes, and snippets.

View seunggabi's full-sized avatar
🎯
Focusing

Seunggabi Kim seunggabi

🎯
Focusing
View GitHub Profile
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);
};
@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];
@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 / 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 / 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 / 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 / getDateTime.java
Created September 3, 2019 07:27
getDateTime.java
public static String getDateTime() {
Date from = new Date();
SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return transFormat.format(from);
}
@seunggabi
seunggabi / reverseString.js
Created September 17, 2019 10:25
reverseString.js
function reverse(str) {
return str.split('').reserve().join('')
}
@seunggabi
seunggabi / [Github] close change files by jQuery
Last active March 9, 2020 07:49
[Github] close change files by jQuery
$$('.btn-octicon.js-details-target').forEach(a => a.click())
$$('.js-reviewed-checkbox:checked').forEach(a => a.click())
@seunggabi
seunggabi / checkHttpStatus.py
Created September 28, 2019 08:19
checkHttpStatus.py
from urllib.request import urlopen
from urllib.error import HTTPError
def checkHttpStatus(URL):
try:
res = urlopen(URL)
return res.status
except HTTPError as e:
code = e.getcode()