Skip to content

Instantly share code, notes, and snippets.

Avatar

Hyeonseok Shin hyeonseok

View GitHub Profile
@hyeonseok
hyeonseok / random.html
Created Apr 18, 2014
Random number, at the end of event.
View random.html
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>추첨기</title>
<style>
html,
body {
height: 100%;
}
@hyeonseok
hyeonseok / ajax.js
Last active Dec 12, 2015
Minimal Ajax function
View ajax.js
// 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 / diff2html.php
Last active Dec 22, 2015
Word diff to HTML
View diff2html.php
<?php
/*
http://hyeonseok.com/soojung/dev/2013/09/02/743.html
git diff -U1 --word-diff > ../diff.txt
Execute this command from repository then run this script.
*/
$diff_file = file('diff.txt');
@hyeonseok
hyeonseok / right-click.js
Last active Dec 22, 2015
Small JavaScript function to allow user using context menu or selecting text on some damn web pages.
View right-click.js
(function () {
var d = document;
d.oncontextmenu = null;
d.ondragstart = null;
d.onselectstart = null;
d.body.style.MozUserSelect = '';
})();
View azaa.php
<?php
function tests($expect, $actual) {
if ($expect == $actual) {
echo('PASS');
} else {
echo('FAIL');
}
echo(': ' . $expect . '/' . $actual . PHP_EOL);
}
View emphasis.js
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 {
@hyeonseok
hyeonseok / android_version.php
Created Dec 21, 2013
Check Android version from user agent string.
View android_version.php
<?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 / layerOpen.js
Created Jan 15, 2016
Open layer, then close layer by clicking document.
View layerOpen.js
// TODO: Add complete HTML document.
$layer: $('.layer'),
$button: $('.button'),
_initialize: function() {
$(document).on('click', this._onClick.bind(this));
},
_onClick: function(event) {
@hyeonseok
hyeonseok / setPhotoSize.js
Created Jan 20, 2016
Fit image to the container while cropping given ratio.
View setPhotoSize.js
_setPhotoSize: function($image) {
var cropPortion = 1.2,
imageWidth = $image.width(),
imageHeight = $image.height(),
imageRatio = imageWidth / imageHeight,
windowWidth = LayoutManager().getScreenWidth(),
windowHeight = LayoutManager().getScreenHeight(),
windowRatio = windowWidth / windowHeight,
width, height, top = 0, left = 0;