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 / 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 / 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 / IE10quickWorkaround.js
Last active July 26, 2017 02:04
IE10 ๐Ÿ˜ก
/**
* ์˜ค๋ธŒ์ ํŠธ๊ฐ€ ๋น„์–ด์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
*
* @param {object} obj
* @returns {boolean}
*/
var isEmptyObj = function (obj) {
if(obj)
return Object.keys(obj).length === 0 && obj.constructor === Object;
else
@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
@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 / 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 / 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 / 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 / mb_ereg_bulk_replace.php
Created September 20, 2017 07:04
Replace multiple parts of a string at once using `mb_ereg_replace`.
<?php
/**
* It let you do what you can do with `preg_replace` with `mb_ereg_replace`.
*
* replacing multiple strings at once.
*
* @param array $pattern
* @param array $replacement
* @param $string
*
@Dinir
Dinir / modifyStreamlabsHostingAlertViewerCount.js
Last active January 2, 2018 05:21
add random number of digits to Streamlabs' host alert message in the viewer count
var randomNumber = function(length, isLengthRandom = false) {
var number = 0;
actualLength = isLengthRandom?
parseInt(Math.random()*length)+1:
length;
number = parseInt(Math.random()*Math.pow(10, actualLength));
return number;
}
var formatEachLetter = function(str, format, indicator) {
var formatted = "";