Skip to content

Instantly share code, notes, and snippets.

@mytory
mytory / make-url-clickable-without-a-tag.php
Last active October 19, 2021 13:13
URL을 링크로 바꿔 주는데, 이미 링크가 걸린 a 태그는 건드리지 않는다.
<?php
/**
* 아래는 참고한 자료.
* @link https://stackoverflow.com/questions/24651869/regex-matching-links-without-a-tag/24653720?stw=2#24653720
*/
function make_link_clickable($text)
{
return preg_replace(
'!<a(.|\n)*?</a>(*SKIP)(*F)|' //skip a tag
. '(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;/=]+)!i',
$fileName = 'Billing-Summary.csv';
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$fileName}");
header("Expires: 0");
header("Pragma: public");
$fh = @fopen( 'php://output', 'w' );
@mytory
mytory / duplicate_line_xcode.md
Created April 8, 2019 15:51 — forked from emotality/duplicate_line_xcode.md
Xcode - Duplicate Line key binding

Xcode line duplicate

Bind keys to duplicate lines in Xcode

  1. Open below directory in Finder with Cmnd + Shift + G
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/
@mytory
mytory / php_apache_homebrew.md
Created October 11, 2018 13:14 — forked from DragonBe/php_apache_homebrew.md
Installation of Apache 2.4 and PHP 7.1 with Homebrew

I posted several talks about compiling PHP from source, but everyone was trying to convince me that a package manager like Homebrew was a more convenient way to install.

The purpose of Homebrew is simple: a package manager for macOS that will allow you to set up and install common packages easily and allows you to update frequently using simple commands.

I used a clean installation of macOS Sierra to ensure all steps could be recorded and tested. In most cases you already have done work on your Mac, so chances are you can skip a few steps in this tutorial.

Apache and PHP with homebrew

I’ve made this according to the installation instructions given on GetGrav.

@mytory
mytory / short-open-tag-converter.php
Last active September 30, 2018 09:42
Change short open tag to long open tag.
<?php
// This script convert short open tag to long open tag.
// Inspired from https://stackoverflow.com/a/3621669
//
// Source: https://gist.github.com/mytory/5380b6a970ed4c14e16dd1be498e0919
// Usage: php short-open-tag-converter.php target_file_path.php
// Notice: This script change original file.
//
// If you want to change '<?=' to '<?php echo ' uncomment line 45~50.
@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
@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 / 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 / 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 / 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);