Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View hyeonseok's full-sized avatar
🧐

Hyeonseok Shin hyeonseok

🧐
View GitHub Profile
@hyeonseok
hyeonseok / ajax.js
Last active December 12, 2015 05:45
Minimal Ajax function
// Minimal Ajax function https://gist.github.com/hyeonseok/604812e389aa9e74d346
function ajax(u,c,d){var x=new(this.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP");x.onreadystatechange=function(){this.readyState^4||c(this)};if(d){x.open('POST',u);x.setRequestHeader('Content-type','application/x-www-form-urlencoded')}else{x.open('GET',u)}x.send(d)}
/*
GET request
ajax('whatever.php?foo=bar', function (xhr) {
console.log(xhr.responseText);
});
POST request
ajax('whatever.php', function (xhr) {
@hyeonseok
hyeonseok / SwapScroll.js
Last active August 2, 2018 09:15
Swap window scroll from main content to modal window, and vise versa.
// Needs to be clean up.
var mainContent = document.getElementById('main');
var open = function (target) {
var closeButton = target.querySelector('p.button button');
mainContent.style.top = -1 * document.body.scrollTop + 'px';
mainContent.style.position = 'fixed';
target.setAttribute('aria-hidden', 'false');
document.body.scrollTop = 0;
closeButton.addEventListener('click', close);
# blank
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
# 10% black
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAADUExURQkJCQC1BbgAAAABdFJOUxq9hCEcAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==
# 20% black
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAADUExURQoKBSBopAkAAAABdFJOUzP/NrlwAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==
# 30% black
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAADUExURQ0JBpcDsPUAAAABdFJOU01Ii+VLAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==
# 40% black
@hyeonseok
hyeonseok / random.html
Created April 18, 2014 01:52
Random number, at the end of event.
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>추첨기</title>
<style>
html,
body {
height: 100%;
}
@hyeonseok
hyeonseok / android_version.php
Created December 21, 2013 17:14
Check Android version from user agent string.
<?php
$str = '~~ Android 2.2.1; ~~';
function get_android_version($str) {
$start = strpos($str, ' Android ');
if ($start === false) {
return '';
}
$remains = substr($str, $start);
$end = strpos($remains, ';');
$remains = substr($remains, 0, $end);
@hyeonseok
hyeonseok / userContent.css
Last active April 13, 2017 07:10
UserCSS for Firefox.
/**
* UserCSS for Firefox.
* https://gist.github.com/hyeonseok/7243239
*
* ln -s ~/Dropbox/src/firefox-usercss/userContent.css /Users/hyeonseok/Library/Application\ Support/Firefox/Profiles/{USER_PROFILE}/chrome/userContent.css
*/
* {
-webkit-touch-callout: text !important;
-webkit-user-select: text !important;
function emphasisKeyword(keyword, string) {
var h = { e: "[eéê]", a: "[aáâ]" };
var matched = keyword.match(/[\S\s]/g);
var res = [];
for (var i = 0; i < matched.length; i++) {
if (h[matched[i]]) {
res.push(h[matched[i]]);
} else {
<?php
function tests($expect, $actual) {
if ($expect == $actual) {
echo('PASS');
} else {
echo('FAIL');
}
echo(': ' . $expect . '/' . $actual . PHP_EOL);
}
@hyeonseok
hyeonseok / Emmet.sublime-settings
Last active October 9, 2020 08:49
Private setting for Emmet for Sublime text 2
{
"snippets":
{
"css":
{
"snippets":
{
"tf": "-webkit-transform: ${1:func};\n-moz-transform: $1;\n-ms-transform: $1;\n-o-transform: $1;\ntransform: $1;",
"ts": "-webkit-transition: ${1:func};\n-moz-transition: $1;\n-ms-transition: $1;\n-o-transition: $1;\ntransition: $1;"
}
@hyeonseok
hyeonseok / right-click.js
Last active December 22, 2015 03:28
Small JavaScript function to allow user using context menu or selecting text on some damn web pages.
(function () {
var d = document;
d.oncontextmenu = null;
d.ondragstart = null;
d.onselectstart = null;
d.body.style.MozUserSelect = '';
})();