Skip to content

Instantly share code, notes, and snippets.

View s-hiroshi's full-sized avatar

Hiroshi Sawai s-hiroshi

View GitHub Profile
@s-hiroshi
s-hiroshi / index.php
Created October 9, 2012 11:29
WordPress > snippet > 子ページのタイトル取得
/**
* スラッグからIDを取得して子ページを取得する。
*/
<?php
$parentPage = get_page_by_path('example');
$parentId = $parentPage->ID;
?>
<ul>
<?php $lastposts = get_posts('post_type=page&posts_per_page=5&post_parent=' . $parentId); ?>
<?php foreach($lastposts as $post) : setup_postdata($post); ?>
@s-hiroshi
s-hiroshi / base.js
Created October 25, 2012 06:31
JavaScript > snippets
if(!(navigator.userAgent.indexOf("Safari") > 0 || navigator.userAgent.indexOf("Chrome") > 0)) {
// Safari and Chrome
}
if(!(navigator.userAgent.indexOf("Safari") > 0 || navigator.userAgent.indexOf("Chrome") > <0)) {
// Safari and not Chrome
}
@s-hiroshi
s-hiroshi / escapeutility.php
Created November 5, 2012 04:43
PHP > エスケープ処理
<?php
/**
* HTMLエンティティへエンコード(エスケープ)及びデコード
*/
class EscapeUtility {
/**
* 文字列をHTMLエスケープする
*
* @param string $string エスケープする文字列
@s-hiroshi
s-hiroshi / remove.php
Created November 6, 2012 06:04
PHP > snippets > ディレクトリ削除
d/*
* ディレクトリ削除
*
* 中身のファイルを削除してからディレクトリを削除する。
*
* @param $dir 削除するディレクトリ。末尾/はなし
* @return bool ディレクトリ削除に成功したらtrue, 失敗はfalse
*/
function removeDirectory($dir)
{
@s-hiroshi
s-hiroshi / LICENSE.txt
Last active April 10, 2016 23:44
JavaScript > ドラッグアンドドロップで画像を表示
The MIT License (MIT)
Copyright (c) 2016 Hiroshi Sawai
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@s-hiroshi
s-hiroshi / validation.html
Created November 14, 2012 04:41
JavaScript > snippets > バリデーション
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>Validation Test</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.10.0.css" media="all">
</head>
<body>
<div id="qunit"></div>
<script src="http://code.jquery.com/qunit/qunit-1.10.0.js"></script>
@s-hiroshi
s-hiroshi / index.html
Created November 17, 2012 12:46
JavaScript > Canvas要素に描画した画像の回転
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>キャンバス画像の回転サンプル</title>
<link rel="stylesheet" href="bootstrap.min.css" media="all">
<link rel="stylesheet" href="bootstrap-responsive.min.css" media="all">
<link rel="stylesheet" href="rotate.css" media="all">
<script src="jquery-1.8.2.min.js"></script>
@s-hiroshi
s-hiroshi / example.js
Created November 25, 2012 09:20
JavaScript > snippets > Canvasデーターの保存
jQuery(function($) {
// body部パラメーター
var data = {};
// Canvasのデータをbase64でエンコードした文字列を取得
var canvasData = $('canvas').get(0).toDataURL();
// 不要な情報を取り除く
canvasData = canvasData.replace(/^data:image\/png;base64,/, '');
$catObj = new Category($post->ID);
$parentList = $catObj->getParentList();
$childList = $catObj->getChildList();
$childTree = $catObj->getChildTree();
@s-hiroshi
s-hiroshi / descendant-category-widget.php
Last active December 11, 2015 03:19
WordPress > snippets 基準カテゴリーの子孫カテゴリーリストを出力
<?php
/**
* 子孫カテゴリー表示ウィジェット
* @author Sawai Hiroshi
*/
class DescendantCategoryWidget extends WP_Widget {
/** constructor */
function DescendantCategoryWidget() {
parent::WP_Widget(false, $name = 'DescendantCategoryWidget');
}