Skip to content

Instantly share code, notes, and snippets.

View taishikato's full-sized avatar
🏠
Working from home

Taishi taishikato

🏠
Working from home
View GitHub Profile
@taishikato
taishikato / get_root_page.php
Last active December 24, 2015 05:58
WordPressの固定ページにおける親ページ判定関数
<?php
function get_root_page ( $cur_post, $cnt = 0 ) {
if ( $cnt > 100 ) { return false; }
$cnt++;
if ( $cur_post->post_parent == 0 ) {
$root_page = $cur_post;
} else {
$root_page = get_root_page( get_post( $cur_post->post_parent ), $cnt );
}
return $root_page;
@taishikato
taishikato / upload_image.php
Last active December 24, 2015 05:59
画像アップロード処理
<?php
$fileName = date('YmdHis').$_FILES['userPicture'][('name')];
move_uploaded_file($_FILES['userPicture']['tmp_name'], APP.'webroot/img/profile'.DS.$fileName);
@taishikato
taishikato / avoid_direct_load.php
Created October 11, 2013 17:23
そのファイルへの直接アクセスを回避するスクリプト
<?php
if (basename($_SERVER['SCRIPT_NAME']) == basename(__FILE__)) exit('Please do not load this page directly');
@taishikato
taishikato / scrollsmooth.js
Created November 9, 2013 10:04
ページ内リンクjQuery
$(function(){
$('a[href^=#]').click(function(){
var speed = 500;
var href= $(this).attr("href");
var target = $(href == "#" || href == "" ? 'html' : href);
var position = target.offset().top;
$("html, body").animate({scrollTop:position}, speed, "swing");
return false;
});
});
@taishikato
taishikato / create_csv_line_array.php
Last active December 29, 2015 01:39
CSV 行毎に配列を生成する
<?php
function createCsvLineArray ($csv_file) {
$file = $csv_file;
$data = file_get_contents($file);
$data = mb_convert_encoding($data, 'UTF-8', 'sjis');
$temp = tmpfile();
$csv = array();
fwrite($temp, $data);
@taishikato
taishikato / reset.css
Created December 19, 2013 05:05
Reset CSS
@charset "UTF-8";
/* style reset */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
@taishikato
taishikato / wp_tips.php
Created December 27, 2013 10:03
WordPress 良く使うコード
<?php
/**
* タイトル
*/
?>
<title><?php bloginfo('name'); ?><?php wp_title( '|', true, 'left' ); ?></title>
@taishikato
taishikato / fade_in_out.js
Created December 27, 2013 15:13
スタンダードだけど、きれいにフェードインアウトするjQuery
$(function() {
$('#report-map a').hover(
function() {
var keyid = $(this).attr('id');
$('.'+keyid).animate({opacity: "show"}, "slow");
},
function() {
var keyid = $(this).attr('id');
$('.'+keyid).animate({opacity: "hide"}, "fast");
}
$(function() {
var nav = $('#glo-navi'),
offset = nav.offset();
$(window).scroll(function () {
if($(window).scrollTop() > offset.top) {
nav.addClass('fixed');
} else {
nav.removeClass('fixed');
}
@taishikato
taishikato / create_file.rb
Created March 3, 2014 08:05
Ruby ハッシュをもとにファイルを生成
File.open("./test.tsv", "w") do |file|
@element.each do |key, val|
file.write("#{key} #{val}\n")
end
end