Skip to content

Instantly share code, notes, and snippets.

// execute with nodejs on bash terminal.
var string = "test text";
for(var i = 0; i < 110; i++){
// 스타일링 : \033[스타일번호m문자열\033[m
// 강조 스타일링 : \033[01;스타일번호m문자열\033[m
console.log(i + " => " + "\033[" + i + "m" + string + "\033[m" + " " + "\033[01;" + i + "m" + string + "\033[m");
}
@mytory
mytory / batch_detect_encoding.php
Last active January 7, 2016 10:43
PHP command line script. It detect encoding from files on directory and subdirectories and print it.
<?php
function print_file_encoding_from($dir){
if($handle = opendir($dir)){
echo "\n\n## Directory is $dir\n\n";
while(false !== ($file = readdir($handle))){
if(in_array($file, array('.', '..', '.git'))){
continue;
}
$file_path = realpath($dir . DIRECTORY_SEPARATOR . $file);
$extension = pathinfo($file_path, PATHINFO_EXTENSION);
/**
* Create Select2 library field that also can direct input.
* @param selector
*/
function direct_write_select2(selector){
$(selector).select2({
minimunInputLength: 1,
query: function(options){
var data = {results: []};
var dataSource;
@mytory
mytory / anything2html.php
Last active March 1, 2016 10:51
Created by [gnoownow10](https://github.com/gnoownow10). docx, doc, hwp to html.
<?php
/**
* @see dependencies: libreoffice, pyhwp https://pythonhosted.org/pyhwp/ko/
* Class Anything2html
*/
class Anything2html {
static $hwp5html;
static $libreoffice;
static $error;
@mytory
mytory / download-functions.php
Created April 21, 2016 08:17
Download file with specific name in all browser.
/**
* Download file from path and mimetype.
*
* @param $path
* @param $mimetype
* @param null $filename
*/
function download_file ($path, $mimetype, $filename = NULL) {
if (empty($filename)) {
$filename = pathinfo($path, PATHINFO_BASENAME);
@mytory
mytory / get_smashing_magazine_calendar.php
Last active May 9, 2016 09:45
script get smashing magazine monthly wallpaer
<?php
/**
* Author: An, Hyeong-woo
* Email: mytory@gmail.com
* Blog: http://mytory.net
* Description: See detail on help message. You can see by running this script without args.
* Dependencies: Tidy extension.
*/
function cmd_echo($str){
echo $str . PHP_EOL;
@mytory
mytory / webfont.js
Created June 15, 2016 13:05
Updated version of 'The deferred font loading logic for Smashing Magazine' by An, Hyeong-woo.
(function () {
"use strict";
// 스매싱 매거진의 '지연된 웹폰트 불러오기' javascript를 안형우가 수정한 것.
// https://gist.github.com/hdragomir/8f00ce2581795fd7b1b7
// 한 번 캐시하면 css 파일은 클라이언트 측에 저장한다.
// 아래 css_href 가 바뀌면 그 때 다시 받는다.
// woff base64를 내장한 css
var css_href = 'css/webfont.woff.css';
// localStorage 를 지원하지 않는 브라우저를 위한 css
@mytory
mytory / fetch-attachment.js
Created August 18, 2016 15:53 — forked from hasinhayder/fetch-attachment.js
Fetch WordPress Media Files (Attachments) Via Backbone Model
var attachment_id = 1234;
var attachment = new wp.media.model.Attachment.get(attachment_id);
attachment.fetch({success:function(att){
if (_.contains(['png','jpg','gif','jpeg'],att.get('subtype'))) {
console.log(att.attributes);
$("<img/>").attr("src",att.attributes.sizes.thumbnail.url).appendTo($("body"));
}
}});
@mytory
mytory / Dockerfile
Created August 7, 2018 13:00
Dockerfile basic template for Korean ubuntu user.
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
# repository
RUN sed -i 's|archive.ubuntu.com|mirror.kakao.com|g' /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y
# timezone