View required_keys.php
<?php
function f($in, $required) {
$keys = array_keys(array_intersect_key(($in), array_flip($required)));
sort($keys);
sort($required);
return $keys === $required;
}
$required = array('key1', 'key2');
View partition_by_range.sql
CREATE TABLE `samples` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`comment` varchar(255) NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`,`created`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
PARTITION BY RANGE COLUMNS(`created`) (
PARTITION samples_p20170427 VALUES LESS THAN('2017-04-28 00:00:00'),
PARTITION samples_p20170428 VALUES LESS THAN('2017-04-29 00:00:00')
);
View sample_array_reduce.php
<?php
$a = array('name' => array( 'error1', 'error2'));
$b = array('email' => array('error3', 'error4'));
$errors = array_merge($a, $b);
$result = array_reduce($errors, function($c, $v) { return array_merge($c, $v); }, array());
print_r($errors);
print_r($result);
print_r(implode('\n', $result));
View gist:70be287215ca6be9dab07aad5ee154a1
mkdir ~/build
cd ~/build
wget https://www.kernel.org/pub/software/scm/git/git-2.9.0.tar.gz
tar xzf git-2.9.0.tar.gz
cd git-2.9.0
make prefix=/usr/local all
make prefix=/usr/local install
git --version
View decode_python_exception.php
<?php
$data = '';
$list = array();
if (!empty($_POST['data'])) {
$data = $_POST['data'];
$matches = array();
$result = preg_match_all("/u'(.*)',|'(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})',/", $data, $matches);
if ($result) {
$subjects = $matches[1];
$subjects[0] = array_filter($matches[2])[0];
View main.yml
---
#################### gather fact about subnet
- name: gather a fact about subnet
ec2_vpc_subnet_facts:
region: '{{ vpc_region }}'
filters:
'tag:Name': '{{ site_name }}-{{ stage }}-bastion'
'tag:env': '{{ stage }}'
'tag:Tier': bastion
View isinstance.py
print isinstance(1, (int, unicode))
# True
print isinstance(u'text', (int, unicode))
# True
print isinstance('8-bit string', (int, unicode))
# False
View gist:bc4e7869bf6b4f8c152b

方針

  • rootがない状況なので $HOME/local へ入れる
  • configureで使うライブラリがないので apt-cache search hoge でさがして apt-get source hoge で入れて configure, make, make installする

ホームディレクトリ

cd ~
mkdir -p {bin,tmp,etc/profile.d,swap,undo,backup,tags,src,.trash,.tmux,build}
View setting.md

vimrcへの設定

if neobundle#is_sourced('vim-ref') " {{{
  if has('win32') || has('win64')
    let g:ref_phpmanual_path = $VIM . '/vimfiles/manual/php_manual_ja/'
  else
    let g:ref_phpmanual_path = $HOME . '/.vim/manual/php_manual_ja/'
  endif
View export-url-from-about.rb
# "12345", "long text...."
# "12346", "long text...."
require 'csv'
require 'uri'
CSV.open('url.csv', 'wb', force_quotes: true) do |output|
CSV.read('about.csv', encoding: 'UTF-8:UTF-8', header_converters: nil).map do |input|
tmp = []
tmp << input[0]
tmp << URI.extract(input[1])