Skip to content

Instantly share code, notes, and snippets.

View fetus-hina's full-sized avatar
💭
I may be slow to respond.

AIZAWA Hina fetus-hina

💭
I may be slow to respond.
View GitHub Profile
@fetus-hina
fetus-hina / weeknumber2date.php
Created November 23, 2012 10:44
Calculate date by ISO-Week-Number (and wday)
<?php
function weekNumberToDate($year, $week, $wday = 1) {
// http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
$correction = (int)gmdate('w', gmmktime(0, 0, 0, 1, 4, (int)$year)) + 3;
$yday = (int)$week * 7 + (int)$wday - $correction;
$time = gmmktime(0, 0, 0, 1, $yday, (int)$year);
return array((int)gmdate('Y', $time), (int)gmdate('n', $time), (int)gmdate('j', $time));
}
var_dump(weekNumberToDate(2008, 39, 6));
@fetus-hina
fetus-hina / credit_card_brand.php
Created November 13, 2012 04:47
credit card brand
<?php
require_once('Zend/Validate/CreditCard.php');
var_dump(getCcBrand('4980000000000006')); // => "VISA"
function getCcBrand($ccnum) {
$brands = array(
Zend_Validate_CreditCard::VISA => 'VISA',
Zend_Validate_CreditCard::MASTERCARD => 'MASTER',
Zend_Validate_CreditCard::JCB => 'JCB',
@fetus-hina
fetus-hina / shuffle.php
Created September 18, 2012 11:28
mt_shuffle(), array_shuffle()
<?php
function fy_shuffle(array &$array, $rand = 'mt_rand') {
$array = array_values($array);
for($i = count($array) - 1; $i > 0; --$i) {
$j = $rand(0, $i);
if($i !== $j) {
list($array[$i], $array[$j]) = array($array[$j], $array[$i]);
}
}
return true;
@fetus-hina
fetus-hina / function.csrf_token.php
Created August 30, 2012 10:26
Yii Framework と Smarty を使う時の CSRF トークン埋め込み用プラグイン(環境が限定的すぎる)
<?php
function smarty_function_csrf_token(array $params, Smarty_Internal_TemplateBase $smarty) {
$req = Yii::app()->getRequest();
return
$req->enableCsrfValidation
? CHtml::hiddenField($req->csrfTokenName, $req->getCsrfToken())
: '';
}
@fetus-hina
fetus-hina / gist:3117296
Created July 15, 2012 14:58
kyubuns_bot のコマンド正規表現
/銀枠|遺影|くりんぺ|くれんぺ|climpet|半額|モノクロ|白黒|セピア|エッジ|エッヂ|エンボス|色反転|馬|濁流|♪|(?:枠|わく|waku)\s*(∞)?\s*(\d+)?|モザイク\s*(\d+)?|(?:jubeat|ユビート|ゆびーと|指)\s*([01234]{16})?/i
@fetus-hina
fetus-hina / shinkansen.oud
Created June 15, 2012 19:06
東海道・山陽・九州新幹線 ダイヤデータ
FileType=OuDia.1.01
Rosen.
Rosenmei=東海道・山陽・九州新幹線
Eki.
Ekimei=東京
Ekijikokukeisiki=Jikokukeisiki_NoboriChaku
Ekikibo=Ekikibo_Syuyou
.
Eki.
Ekimei=品川
@fetus-hina
fetus-hina / ArcFile.hpp
Created May 6, 2012 10:48
PULLTOP の新しい *.arc ファイルとりあえずこれで読めた
#pragma once
#include <stdint.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <exception>
#include <stdexcept>
#include <boost/noncopyable.hpp>
@fetus-hina
fetus-hina / normalizer.cpp
Created March 18, 2012 11:43
ICU 4.2.1 (RHEL 6) で Unicode Normalization
#include <string>
#include <stdexcept>
#define U_USING_ICU_NAMESPACE 0 // ヘッダで using namespace するな…
#include <unicode/normlzr.h>
namespace Normalizer {
namespace {
std::string normalize(const std::string &utf8, /* U_ICU_NAMESPACE:: */ UNormalizationMode mode);
}
@fetus-hina
fetus-hina / counter.php
Created March 13, 2012 15:25
http://nemoa.biz/php/data.html のアクセスカウンタープログラム
<?php
// http://nemoa.biz/php/data.html の「アクセスカウンター」プログラム
$pointer=fopen("log.cgi", "r");
$line = fgets($pointer);
fclose($pointer);
$nom = $line +1;
$fp = fopen("log.cgi","w");
@fetus-hina
fetus-hina / locale_date_format.php
Created February 24, 2012 09:09
Zend_Date (と Zend_Locale) を使ってそれなりに地域化されたフォーマットをするサンプル
<?php
require_once('Zend/Date.php');
$locales = array('ja_JP', 'en_US', 'en_GB');
$formats =
array(
'DATE_FULL' => Zend_Date::DATE_FULL,
'DATE_LONG' => Zend_Date::DATE_LONG,
'DATE_MEDIUM' => Zend_Date::DATE_MEDIUM,