Skip to content

Instantly share code, notes, and snippets.

View Dinir's full-sized avatar
🦽
Lost

Dinir Nertan Dinir

🦽
Lost
View GitHub Profile
@Dinir
Dinir / tree_text.php
Last active October 6, 2017 06:45
Turn an indented text list to a multi-dimensional array.
<?php
$tree_text = function(string $text): array {
$lines = explode(PHP_EOL, $text);
$levels = array_map(function($line){
$level = 0;
while(substr($line, $level, 1) == "\t") {
$level++;
}
return $level;
}, $lines);
@Dinir
Dinir / fullscreenSlideshow.js
Last active September 12, 2017 07:46
adds a fullscreen slideshow on a webpage
/**
* @typedef {object} stoppableTimer
* @desc 일시정지가 가능한 인터벌 타이머입니다.
* @method stop 타이머를 멈춥니다.
* @method start 타이머를 시작합니다. 새로운 타이머 값을 줄 수 있습니다.
* @method reset 타이머를 리셋합니다. 새로운 타이머 값을 줄 수 있습니다.
*/
/**
* 일시정지가 가능한 인터벌 타이머를 만듭니다.
@Dinir
Dinir / format_date.php
Last active September 5, 2017 07:47
format 'YYYY-MM-DD' for other languages
<?php
/**
* 날짜 문자열을 다른 언어의 표기 방식에 따라 바꾸어서 반환합니다.
*
* @param string $date_string 'YYYY-MM-DD' 형식으로 표기한 날짜입니다.
* @param string $language 날짜를 표시하려는 언어입니다. (ISO 639 언어 코드)[_(ISO 3166 국가 코드)] 형식을 따릅니다.
*
* @return string 바꾸어진 날짜 문자열입니다.
*/
function format_date(string $date_string, string $language): string {
@Dinir
Dinir / mapPins.js
Last active August 9, 2017 08:53
Prepare pins to put on a block display element, probably with an image in it.
/**
* Prepare pins to put on a block display element, probably with an image in it.
*
* As creating an instance, a CSS rule will be written in the document
* for the pins with `className` as the class name.
* And the element the pins will be on will have its position property
* set to 'relative'.
*
* @param {!HTMLElement} containerDOM the element to put pins on
* @param {number} [diameter=24] diameter of pins
@Dinir
Dinir / logic.js
Last active November 25, 2018 21:21
Simple 4-button Gamepad Input Display, made as a makeshift tool, so maybe only works with the first pad connected. 😟
/* eslint-disable no-undef */
window.onload = function () {
const axisDom = document.getElementsByClassName('analogLeft')[0]
const dpadDoms = document.getElementsByClassName('dpad')[0]
const buttonDoms = document.getElementsByClassName('buttons')[0]
const cos45 = Math.cos(1 / 4 * Math.PI)
let mapping = {
analogLeft: [0, 1], // hori, vert
dpad: [12, 13, 14, 15], // up, down, left, right
/**
* 오브젝트가 비어있는지 확인합니다.
*
* @param {object} obj
* @returns {boolean}
*/
var isEmptyObj = function (obj) {
if(obj)
return Object.keys(obj).length === 0 && obj.constructor === Object;
else
@Dinir
Dinir / grabGamepadInfo.js
Last active January 6, 2018 14:13
Grabs gamepad datas in Chrome environment.
const rAF = window.requestAnimationFrame;
const gamepads = {};
const handler = {
connect: function(e) {
gamepads[e.index] = e;
console.log(`${e.index} connected`);
},
disconnect: function(e) {
@Dinir
Dinir / Format_Hangul_Table.php
Last active September 20, 2017 09:46
Format a copy-pasted table data text from Hangul Word Processor as an array.
<?php
/**
* Format a copy-pasted table data text from Hangul Word Processor as an array.
*
* A pasted text is formatted like this:
* \nA1\nB1\nC1\nA2\nB2\nC2\nA3\nB3\nC3\n
*
* with an appropriate regex used as a delimiter, e.g. '/\R(?!A)/',
* this function can format the text to an array:
* [['A1', 'B1', 'C1'], ['A2', 'B2', 'C2'], ['A3', 'B3', 'C3']]
@Dinir
Dinir / pico-8 korean.txt
Created October 18, 2016 01:16
PICO-8 Manual (Korean)
============================================================================================
PICO-8 v0.1.8
http://www.pico-8.com
(c) Copyright 2014-2016 Lexaloffle Games LLP
만든 이: Joseph White // [email protected]
옮긴 이: Dinir Nertan // [email protected]
PICO-8은 아래의 기술로 만들어졌습니다:
SDL2 http://www.libsdl.org
@Dinir
Dinir / changeClass.js
Created September 5, 2016 10:50
Change DOM classes quickly.
const changeClass = (target, firstCl, secondCl) => {
// if first exist = add it
// if both exist = change first to second
// if both exist and first is * = overwrite with second
if(firstCl) {
if(!secondCl) {
target.className += ` ${firstCl}`;
} else {
target.className = firstCl==="*"?
secondCl: