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 / 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 / teratail-slack-notification.gs
Created September 15, 2016 15:44
GoogleAppsScriptとSlackWebhookを利用してteratailの新規質問をSlackに通知する
/**
* main
*/
function main() {
var tagName = 'php';
var questionUrl = 'https://teratail.com/questions/';
var response = getQuestionByTagName(tagName, {limit: 3});
if(!'questions' in response) {
return false;
}
@tai-sho
tai-sho / functions.php
Created November 20, 2016 06:32
defer_stylesheets
<?php
function defer_stylesheet() {
$styles = array(
'//fonts.googleapis.com/css?family=Lato:300,400,400italic,600,700|Raleway:300,400,500,600,700|Crete+Round:400italic',
'//fonts.googleapis.com/earlyaccess/notosansjapanese.css',
get_template_directory_uri(). '/css/bootstrap.css',
);
$styles = json_encode($styles);
echo <<<SCRIPT
<script>
@tai-sho
tai-sho / MailComponent.php
Created June 9, 2017 02:33
AppEngineでのメール送信処理
<?php
namespace App\Controller\Component;
use \google\appengine\api\mail\Message;
use Cake\Controller\Component;
/**
* メール送信を行うコンポーネント
*/
class MailComponent extends Component
{