Skip to content

Instantly share code, notes, and snippets.

View oh-sky's full-sized avatar

Yoshihiro Ohsuka oh-sky

View GitHub Profile
@oh-sky
oh-sky / atagitaiwohsc.php
Created April 26, 2013 03:28
PHPで <a> タグ以外をhtmlspecialcharsする関数 何の役に立つか?つまんねー事聞くなよ!
<?php
// <a> </a> タグ以外をhtmlspecialcharsする関数
function atagigaiwohsc($src,$flags = ENT_QUOTES){
// encode including <a></a>
$sanitized = htmlspecialchars($src,$flags);
// decode all <a>
if(preg_match_all('@&lt;a.*?&gt;@', $sanitized, $matches, PREG_SET_ORDER)){
foreach($matches as $match){
@oh-sky
oh-sky / pre-commit
Created September 9, 2015 15:04
masterブランチへのコミットを禁止するgit-hook
#!/bin/sh
BRANCH=`git rev-parse --abbrev-ref HEAD`
if test $BRANCH = 'master'; then
echo 'Commiting to master is forbidden.'
exit 1
fi
@oh-sky
oh-sky / jobcan-shutsutaikin-henshu.js
Last active May 16, 2019 06:47
ジョブカンの出退勤編集画面の入力をサポートするジャバスクリプト(bookmarklet)
void((function() {
var editJikoku = function (jikoku) {
return function () {
var inputForm = jQuery(this);
if (inputForm.parents('tr').css('background-color') != 'transparent') {
return;
}
if (inputForm.val() != jikoku) {
inputForm.val(jikoku);
inputForm.css('background-color', '#fcc');
@oh-sky
oh-sky / CakePHP2_Replication.php
Created December 14, 2013 01:57
CakePHP2で、特定のモデルでのSELECTでレプリケーションスレーブを参照する方法 AppModel::$useReplicaをtrueにすると、参照先がslaveになる belongsToのモデルもslaveからの参照となる
// app/Config/database.php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'master.mysql.host',
'login' => 'mysql_username',
'password' => 'mysql_password',
'database' => 'schema_name',
@oh-sky
oh-sky / hatebu.php
Created January 8, 2014 14:40
はてな認証APIを使って、はてなIDを取得するテスト
<?php
$apiKey = '';
$apiSecret = '';
if (isset($_GET['cert'])) {
$apiSig = md5($apiSecret . 'api_key' . $apiKey . 'cert' . $_GET['cert']);
$jsonString = file_get_contents("http://auth.hatena.ne.jp/api/auth.json?api_key={$apiKey}&cert={$_GET['cert']}&api_sig={$apiSig}");
$obj = json_decode($jsonString);
if (!$obj->has_error) {
echo file_get_contents("http://b.hatena.ne.jp/{$obj->user->name}/rss");
@oh-sky
oh-sky / knkr.rb
Last active December 22, 2015 02:39
艦隊をコマンドで操作したかった・・・ ※ちょっと待て、使う前に利用規約をちゃんと読め → http://www.dmm.com/rule/=/category=onlinegame_service/
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
# configure
API_VERNO = 1
API_TOKEN = ''
KNKR_HOST = ''
$header = {
'Referer' => "http://#{KNKR_HOST}/kcs/port.swf?version=1.3.7",
@oh-sky
oh-sky / gitwatcher.bash
Created December 15, 2015 13:36
git_kanshi_tool
#!/bin/bash
APP_DIRS=('/path/to/dir' '/path/2/dir')
for app_dir in ${APP_DIRS[@]}
do
cd $app_dir
number_of_changed=`git ls-files --modified | wc -l`
if test $number_of_changed -gt 0 ; then
curl -F text="$app_dir} 以下の${number_of_changed}個のファイルに変更がありました。確認してください。" -F channel= -F token='' https://slack.com/api/chat.postMessage
fi

$ mysql -u root -p < /usr/local/mysql/share/innodb_memcached_config.sql

mysql> install plugin daemon_memcached soname "libmemcached.so";

$ telnet localhost 11211

@oh-sky
oh-sky / mkchmodall.rb
Last active December 12, 2015 00:08
カレントディレクトリ以下のファイル、ディレクトリ(.gitを除く)のパーミッションをchmodall.shというファイルに記録しておく。git clone 後にsh chmodall.sh すれば、各ファイルのパーミッションをコピーできる。
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
class FileList
def initialize(filelist)
@filelist = filelist
@disposedlist = nil
end
def disposeList()
@oh-sky
oh-sky / README.md
Last active December 11, 2015 22:49
http.conf を、同階層の{domain.example.com}.conf へのソフトリンクにするスクリプト
$ ls -l /opt/local/apache2/conf
bar.example.com.conf
foo.example.com.conf 
httpd.conf@ -> bar.example.com.conf

$ sudo a2ensite foo.example.com
$ls -l /opt/local/apache2/conf
bar.example.com.conf
foo.example.com.conf