Skip to content

Instantly share code, notes, and snippets.

@anisotropy
anisotropy / react-read-text-file.js
Created August 16, 2017 06:09
자바스크립트(리액트)에서 텍스트 파일 읽기
import React, {Component} from 'react';
class Example extends Component {
handleChange(e){
let file = e.target.files[0];
let fileReader = new FileReader();
fileReader.onload = () => {
console.log(fileReader.result);
};
fileReader.readAsText(file);
@anisotropy
anisotropy / react-medium-inserting-clauses.js
Created May 15, 2017 07:26
react-medium-editor을 이용해, 지정된 블럭에 정해진 조항이름을 입력할 수 있는 코드
import React, {Component} from 'react';
import {_pushpull} from '../accessoris/functions';
import Editor from 'react-medium-editor';
import MediumEditorTable from 'medium-editor-tables';
import MediumButton from 'medium-button';
import 'medium-editor/dist/css/medium-editor.css';
import 'medium-editor/dist/css/themes/default.css';
import 'medium-editor-tables/dist/css/medium-editor-tables.css';
@anisotropy
anisotropy / get-current-selection.js
Created May 14, 2017 03:24
get current selection in javascript
getCurrentSelection() {
var html = ''
var sel
if (typeof window.getSelection != 'undefined') {
sel = window.getSelection()
if (sel.rangeCount) {
var container = document.createElement('div')
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents())
@anisotropy
anisotropy / remove-blank-of-button-on-firefox.css
Created December 17, 2016 08:23
파이어폭스에서 버튼 내부의 여백 제거
button.element::-moz-focus-inner {
padding:0;
border:0;
}
@anisotropy
anisotropy / react-filter-child-by-type.js
Last active December 17, 2016 08:24
리액트: child의 type에 따라 필터링
class DdItem extends Component {
...
}
class DdHead extends Component {
...
}
class Dropdown extends Component {
render(){
let head, items = [];
@anisotropy
anisotropy / react-file-upload.js
Created November 4, 2016 07:26
React: 파일 업로드
import React, {Component} from 'react';
import axios from 'axios';
class UploadFiles extends Component {
componentWillMount(){
this.setState({
file: undefined
});
}
handleSubmit(event){
@anisotropy
anisotropy / wp-change-the-title-when-media-upload.php
Created October 29, 2016 08:40
워드프레스: 미디어를 업로드할 때 그 미디어의 이름을 변경
<?php
add_action('add_attachment', 'my_add_attachment');
function my_add_attachment($attchment_id){
wp_update_post(array('ID' => $attchment_id, 'post_title' => 'something'));
}
?>
@anisotropy
anisotropy / wp-set-slug-of-cat-and-tag.php
Created October 27, 2016 23:51
워드프레스: 카테고리와 태그를 생성할 때 슬러그를 강제로 변경한다.
<?php
add_action('create_category', 'actplugin_set_catslug', 10, 1);
function actplugin_set_catslug($cat_id){
wp_update_term($cat_id, 'category', array(
'slug' => 'c'.$cat_id
));
}
add_action('create_term', 'actplugin_set_tagslug', 10, 3);
function actplugin_set_tagslug($term_id, $tt_id, $taxonomy){
if($taxonomy == 'post_tag'){
@anisotropy
anisotropy / wp-search-by-title-and-update-post.php
Last active October 27, 2016 23:58
워드프레스: 특정한 문자열이 포함된 제목을 가진 포스트들을 구하고 그 포스트들의 내용을 변경
<?php
$keyword = 'something';
global $wpdb;
$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_title LIKE '%keyword%'");
foreach($posts as $p){
$id = $p->ID;
$title = $p->post_title;
$content = $p->post_content;
wp_update_post(array(
'ID' => $id,
@anisotropy
anisotropy / extract-text-from-html-tags.php
Last active October 12, 2016 03:07
태그 사이에 있는 텍스트를 추출
<?php
$str = '<div class="a-class-name">some text</div>';
// PHP의 정규표현식은 구분자(delimiters)로 시작해서 구분자로 끝을 내야한다.
// 구분자는 보통 슬래쉬(/)를 사용하지만 꼭 그래야 하는 것은 아니고 해쉬(#)와 같이 알파벳과 백슬래쉬 그리고 공백이 아닌 문자를 사용하면 된다.
$pattern = '#<div class="a-class-name">(.*?)</div>#';
preg_match($pattern, $str, $matches);
echo $matches[1];
?>