Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
aptitude update
aptitude install -f php5-cgi php5-cli nginx
cat << 'EOF' > /etc/default/php-fastcgi
#
# Settings for php-cgi in external FASTCGI Mode
#
# Should php-fastcgi run automatically on startup? (default: no)
@tbsmcd
tbsmcd / email_extended.php
Created June 11, 2012 16:34 — forked from msng/email_extended.php
Another CakePHP validation rule for email, accepting irregular addresses once allowed by docomo and au
<?php
//For PHP 5.3.x or later
public function emailExtended($data, $deep = false) {
$pattern = '/.+@(docomo|ezweb)\.ne\.jp$/i';
$check = preg_replace_callback($pattern, function($matches) {
$patterns = array('/\.{2,}/', '/\.@/');
$replacements = array('.', '@');
return preg_replace($patterns, $replacements, $matches[0]);
}, array_shift($data));
return Validation::email($check, $deep);
$ php -a
Interactive shell
php > echo preg_match('/.+@(docomo.ne.jp|ezweb.ne.jp)$/i', 'example@ docomo-ne.jp');
1
@tbsmcd
tbsmcd / countFri.php
Created July 13, 2012 09:03
13friday
#!/path/to/php
<?php
$week = array(
'Mon' => 0,
'Tue' => 0,
'Wed' => 0,
'Thu' => 0,
'Fri' => 0,
'Sat' => 0,
'Sun' => 0,
#!/path/to/php
<?php
$week = array(
'Mon' => 0,
'Tue' => 0,
'Wed' => 0,
'Thu' => 0,
'Fri' => 0,
'Sat' => 0,
'Sun' => 0,
$period = new DatePeriod(
new Datetime('2012-01-13'),
new DateInterval('P1M'),
new Datetime('2012-12-13')
);
foreach ($period as $day) {
echo $day->format('Y-m-d') . PHP_EOL;
}
// 2012-01-13
#!/bin/sh
export LC_ALL=en
date "+%Y.%m.%d %a"
#!/bin/sh
export LC_ALL=en
date "+%Y.%m.%d %a"
date "+%H:%M:%S"
#!/bin/sh
df -h | grep disk0s2 | awk '{print "SSD: " $3 " used " $4 " free"}'
top -l 2 | awk '/CPU usage/ && NR > 5 {print "CPU: " $3 " user " $5 " sys"}'
top -l 1 | awk '/PhysMem/ {print "RAM: " $10 " free " $8 " inactive " $6 " active " $2 " wired"}'
<?php
$mongo = new Mongo('127.0.0.1:27017'); // local の場合。ポート 27017
// example が存在しない場合、 CREATE DATABASE 相当の操作は自動でやってくれる
$db = $mongo->selectDB('example');
// RDB でいうところの table
// test が存在しない場合(以下略)
$collection = $db->selectCollection('test');