Skip to content

Instantly share code, notes, and snippets.

View hyeonseok's full-sized avatar
🧐

Hyeonseok Shin hyeonseok

🧐
View GitHub Profile
@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 / 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 / diff2html.php
Last active December 22, 2015 03:28
Word diff to HTML
<?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 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 = '';
})();
<?php
function tests($expect, $actual) {
if ($expect == $actual) {
echo('PASS');
} else {
echo('FAIL');
}
echo(': ' . $expect . '/' . $actual . PHP_EOL);
}
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 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 / layerOpen.js
Created January 15, 2016 10:12
Open layer, then close layer by clicking document.
// 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 January 20, 2016 11:51
Fit image to the container while cropping given ratio.
_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;