Skip to content

Instantly share code, notes, and snippets.

View chwnam's full-sized avatar

Changwoo Nam chwnam

View GitHub Profile
@chwnam
chwnam / iptime_block_from_log.py
Created June 2, 2022 09:06
IP 타임 로그로부터 차단 IP 설정 생성
import sys
def create_iptime_block_rules(ip_range, title_prefix):
output = "Type=firewall # Do not modify\n" + \
"Version=1.0.0 # Do not modify\n" + \
"lang=utf-8 # Do not modify\n\n"
for index, ip in enumerate(ip_range):
output += "[{0} {1}]\n".format(title_prefix, 1 + index)
@chwnam
chwnam / whitespacehell.py
Created March 29, 2022 08:48
화이트스페이스의 함정
#!/usr/bin/env python3
k1 = 'ABCDEag=='
k2 = 'ABCDEag==​​​'
print('Length of k1:', len(k1))
print('Length of k2:', len(k2))
print('--- k1:')
for c in k1:
@chwnam
chwnam / dynamic-user-scalable.html
Created March 28, 2022 07:12
동적으로 user-scalable 조정하는 예제.
<!DOCTYPE html>
<html lang="ko">
<head>
<title>또 하나의 웹사이트</title>
<meta charset="UTF-8">
<meta name="robots" content="noindex,nofollow">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, user-scalable=yes">
<style>
body {
<?php
/**
* Plugin Name: 메타 값 체크 예제
* Plugin URI: https://gist.github.com/chwnam/2fb5cf06237a43671875c3baf12dca35
* Description: 메타 값 저장 후 체크 예시
* Author: changwoo
* Author URI; https://blog.changwoo.pe.kr
*/
if ( ! defined( 'ABSPATH' ) ) {
@chwnam
chwnam / or-search.php
Last active March 19, 2022 16:57
OR 키워드 검색
<?php
/**
* Plugin Name: OR 키워드 검색
* Description: 입력된 키워드를 OR 조건으로 검색합니다.
* Author: changwoo
* Author URI: https://blog.changwoo.pe.kr
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
@chwnam
chwnam / customize-permastruct.php
Created July 30, 2021 10:23
Modify CPT URL permastructure
<?php
/**
* Plugin Name: My CPT with custom permalink.
* Description: Change permalink from /cpt/%postname% to /cpt/%post_id%.
*/
add_action( 'init', 'my_cpt_init' );
function my_cpt_init() {
register_post_type(
'my-cpt',
@chwnam
chwnam / wp_install
Created May 3, 2021 05:01
워드프레스 자동 설치 스크립트 샘플
#!/bin/bash
#
# Changwoo Blog 1일1워프 포스팅
# https://blog.changwoo.pe.kr/wp-install/
if [[ $# -ne 1 ]]; then
echo "Input name, please."
exit
fi
@chwnam
chwnam / wp-util-sample.php
Last active April 23, 2021 20:39
WP Util Sample: wp-util 활용법 샘플 코드
<?php
/*
* Plugin Name: wp-util-sample
* Description: wp.util sample code.
*/
add_action('admin_menu', 'wp_util_sample_menu');
function wp_util_sample_menu()
{
@chwnam
chwnam / get_mid_term.php
Created March 3, 2021 04:37
한 포스트의 중간 텀을 구한다.
/**
* 말단 텀 이외에 찍힌 것 제거
*
* @param int $post_id
* @param string $taxonomy
*
* @return WP_Term[]
*/
function get_mid_terms( int $post_id, string $taxonomy = 'category' ): array {
$terms = wp_get_object_terms( $post_id, $taxonomy );
@chwnam
chwnam / race-cond.php
Last active February 11, 2021 10:01
Race Cond - 옵션 업데이트가 매우 빈번히 일어날 때 주의할 사항
<?php
/**
* Plugin Name: Race Cond
* Plugin URI: https://gist.github.com/chwnam/c441ca20952856ca0e1a9cd0d657fac9
*
* @link https://blog.changwoo.pe.kr/option-race-condition/
*/
add_action( 'admin_menu', 'rcond_admin_menu' );
function rcond_admin_menu() {