Skip to content

Instantly share code, notes, and snippets.

@msng
msng / gist:4729246
Last active December 12, 2015 06:28
HTML の submit ボタンが押されたら disabled にする (要 jQuery)
<script type="text/javascript">
$('form').submit(function() {
$(this).submit(function () {
return false;
});
});
</script>
@msng
msng / gist:4023716
Created November 6, 2012 09:40
日本の「国民の祝日」の英語名と日本語名を対応させる配列。キーに英語名、値に日本語名を取る。
array(
"New Year's Day" => '元日',
"Coming-of-Age Day" => '成人の日',
"National Foundation Day" => '建国記念の日',
"Vernal Equinox Day" => '春分の日',
"Showa Day" => '昭和の日',
"Constitution Memorial Day" => '憲法記念日',
"Greenery Day" => 'みどりの日',
"Children's Day" => 'こどもの日',
"Marine Day" => '海の日',
@msng
msng / phpmatsuri2012_sunrise.php
Created November 3, 2012 07:32
「PHP祭り2日目の会場地点での、日の出の時刻は何時何分何秒でしょう?」への解答を示す PHP スクリプト
<?php
$timestamp = strtotime('2012-11-04');
$format = SUNFUNCS_RET_TIMESTAMP;
$latitude = 33.590383;
$longitude = 130.423992;
$sunriseTimestamp = date_sunrise($timestamp , $format, $latitude, $longitude);
$sunriseDateTime = date('H:i:s', $sunriseTimestamp);
echo $sunriseDateTime; //06:40:03
@msng
msng / fblogin.php
Created October 3, 2012 04:31
Sample of Faceook Login using Facebook SDK for PHP
<?php
//Facebook SDK for PHP の src/ にあるファイルを
//サーバ内の適当な場所にコピーしておく
require_once('php-sdk/facebook.php');
$config = array(
'appId' => '[取得した App ID]',
'secret' => '[取得した App Secret]'
);
@msng
msng / gist:2468439
Last active October 3, 2015 14:18
Google ドキュメントのフォームから投稿があったら確認メールを自動返信する(日本語版)
/**
* Google ドキュメントのフォームから投稿があったら確認メールを自動返信する(日本語版)
* English version will be available later.
*
* @author Masunaga Ray ( http://www.msng.info/ )
* @instruction http://www.msng.info/archives/2012/04/google-docs-auto-reply.php
*/
function sendConfirmation() {
try {
var ss = SpreadsheetApp.getActiveSpreadsheet();
@msng
msng / sendConfirmation.js
Created April 20, 2012 09:37
Google ドキュメントのフォームから投稿があったら確認メールを自動返信する(日本語版)
/**
* Google ドキュメントのフォームから投稿があったら確認メールを自動返信する(日本語版)
* English version will be available later.
*
* @author Masunaga Ray ( http://www.msng.info/ )
* @instruction http://www.msng.info/archives/2012/04/google-docs-auto-reply.php
*/
function sendConfirmation() {
//フォームでメールアドレスが入力される列の名前
var emailColName = "メールアドレス";
@msng
msng / is_zenkaku.php
Created March 23, 2012 11:25
全角のみのチェックもうこれでいいんじゃないの
<?php
//Requires function is_hankaku() https://gist.github.com/2167287
function is_zenkaku($str, $encoding = null) {
if (is_null($encoding)) {
$encoding = mb_internal_encoding();
}
$len = mb_strlen($str, $encoding);
for ($i = 0; $i < $len; $i++) {
$char = mb_substr($str, $i, 1, $encoding);
if (is_hankaku($char, true, true, $encoding)) {
@msng
msng / is_hankaku.php
Created March 23, 2012 05:34
文字列が半角のみでできているかどうかチェックするのもうこれでいいんじゃないの
<?php
function is_hankaku($str, $include_kana = false, $include_controls = false, $encoding = null) {
if (!$include_controls && !ctype_print($str)) {
return false;
}
if (is_null($encoding)) {
$encoding = mb_internal_encoding();
}
if ($include_kana) {
@msng
msng / gist:1736439
Created February 4, 2012 08:45
WordPress の個別記事にはてブと Google+ と Twitter と Facebook「いいね!」のボタンを出すサンプル
<!--
・できれば <body> タグの直後に置く
・日本語ボタンを出すなら en_US を ja_JP にする
・アプリケーションIDをつける場合は、xfbml=1 の後に
&appId=[Facebookで取得するアプリケーションID: https://developers.facebook.com/apps ]
をつける
-->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
@msng
msng / number_unformat.php
Created December 21, 2011 02:07
Unformats a number formatted with number_format().
<?php
function number_unformat($number, $force_number = true, $dec_point = '.', $thousands_sep = ',') {
if ($force_number) {
$number = preg_replace('/^[^\d]+/', '', $number);
} else if (preg_match('/^[^\d]+/', $number)) {
return false;
}
$type = (strpos($number, $dec_point) === false) ? 'int' : 'float';
$number = str_replace(array($dec_point, $thousands_sep), array('.', ''), $number);
settype($number, $type);