Skip to content

Instantly share code, notes, and snippets.

View tai-sho's full-sized avatar
🏠
Working from home

ShoheiTai tai-sho

🏠
Working from home
View GitHub Profile
@tai-sho
tai-sho / views.py
Created March 31, 2014 05:47
django view test
from django.http import HttpResponse
from django.shortcuts import render_to_response
def helloworld(request):
return render_to_response('test.html', {'title': 'djangoTest!'})
@tai-sho
tai-sho / debugLog.php
Last active August 29, 2015 13:58
素のPHPでログを出したいとき
<?php
function debugLog($label, $val) {
static $filename = 'logs/debug.log';
$mtime = microtime();
$timeStmp = explode(' ', $mtime);
$time = date('Y-m-d H:i:s', (int)$timeStmp[1]);
$mtime = number_format($mtime,5);
$val = var_export($val, true);
@tai-sho
tai-sho / afterLayout.php
Last active August 29, 2015 13:58
CakePHPが出力するHTMLからスペースやタブを削除する。
<?php
App::uses('Helper', 'View');
class AppHelper extends Helper {
/**
* CakeがHTMLを出力する際に生成される無駄なタブを削除する。
* @see Helper::afterLayout()
*/
public function afterLayout($layoutFile) {
parent::afterLayout($layoutFile);
@tai-sho
tai-sho / jquery.readmore.js
Last active June 16, 2017 08:00
要改善。
;(function($) {
//最大文字数
var OVER_LENGTH = 100;
//「続きを読む」リンクのクラス
var READ_MORE_CLASS = 'read-more';
$.fn.readmore = function(option) {
if(option.length) {
OVER_LENGTH = option.length;
}
$.each(this, function() {
@tai-sho
tai-sho / MyHtmlHelper.php
Last active December 10, 2017 15:46
SEO対策。microdataを付与したパンくずリストを生成する。HtmlHelper::addCrumbListを継承。
<?php
App::uses('HtmlHelper', 'View/Helper');
class MyHtmlHelper extends HtmlHelper {
/**
* microdata属性対応版
* @link https://support.google.com/webmasters/answer/185417?hl=en
* @see HtmlHelper::getCrumbList()
*/
@tai-sho
tai-sho / AppModel.php
Last active August 29, 2015 14:07
CakePHP2.xでモデルの空配列を作る関数
<?php
App::uses('Model', 'Model');
class AppModel extends Model {
/**
* モデルの空配列を返します。
* @return array モデルの空配列
*/
public function getModelArray() {
//カラムタイプの配列からキーのみを取得
$keys = array_keys($this->getColumnTypes());
@tai-sho
tai-sho / benchmark.php
Last active August 29, 2015 14:08
速度計測用関数
<?php
function bench() {
//計測回数
$count = 10;
//試行回数
$testCount = 100000;
//小数点桁数
$decimalDigits = 10;
//平均値
$average = 0.0;
@tai-sho
tai-sho / MyFrame.py
Created December 14, 2014 14:27
wxPythonでGUIアプリケーションを作成するサンプル
# -*- coding: cp932 -*-
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(500,500),pos=(10,10))
#ステータスバー
self.CreateStatusBar()
#ファイルメニュー
filemenu = wx.Menu()
@tai-sho
tai-sho / fontAwesomeSpinner.js
Last active August 29, 2015 14:11
font-awesomeとjqueryを使用したspinnerの実装。
/**
* スピナーオブジェクト
*/
var Spinner = function() {
/**
* ランダムでIDを生成する
*/
this.id = 'spinner' + Math.floor(Math.random () * 10000) + 1;
};
Spinner.prototype = {
@tai-sho
tai-sho / Speech.js
Last active November 29, 2017 13:03
Speech Synthesis APIで文字列を喋らせるクラス
/**
* HTML5 WebSpeechAPI SpeechSynthesis
* @class Speech
*/
var Speech = (function() {
// 存在チェック
if (!'SpeechSynthesisUtterance' in window) {
throw new Error('SpeechSynthesisAPI unsupported.');
alert('SpeechSynthesisAPIが対応していないブラウザです。');