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 / WebStorageQueue.js
Last active February 8, 2019 12:10
WebStorageを使用したQueue
/**
* WebStorageでQueueを管理するクラス
* @class WebStorageQueue
*/
;WebStorageQueue = (function() {
'use strict';
function WebStorageQueue(storage, key) {
if(!storage) {
throw new Error('Storageオブジェクトが取得できませんでした。');
}
@tai-sho
tai-sho / main.js
Created July 3, 2017 17:42
jsでURLの一番最後のディレクトリ名を取得する
location.pathname.replace(/\/+$/, "").split('/').pop();
@tai-sho
tai-sho / removeExif.php
Last active May 19, 2021 03:27
EXIF情報を削除する関数
<?php
/**
* JPEGのEXIF情報を削除します。
* 元画像は削除した上で変換後のファイルを置き換えます。
* @param string $path 画像パス
* @return boolean
*/
function removeExif($path) {
$status = true;
list(, , $type) = getimagesize($path);
@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
{
@tai-sho
tai-sho / gist:23031046a6a37e17c708d49bee34f661
Last active June 9, 2017 02:37
cakephp2.xでjsonを返す
<?php
$this->Components->load('RequestHandler')->renderAs($this, 'json');
$response = array();
$this->set($response);
$this->set('_serialize', array_keys($response));
@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 / 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 / sanitize.php
Last active June 9, 2017 02:36
PHP再帰的にサニタイズをする。
<?php
$sanitize = function($data) use (&$sanitize) {
foreach($data as &$value) {
if(is_array($value)) {
$value = $sanitize($value);
} else {
$value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
}
return $data;
@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が対応していないブラウザです。');
@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 = {