Skip to content

Instantly share code, notes, and snippets.

View gh640's full-sized avatar

Goto Hayato gh640

View GitHub Profile
@gh640
gh640 / set_whoops.php
Created February 6, 2016 12:47
PHP: エラーハンドラを whoops に差し替える auto_prepend_file ファイル
<?php
/**
* すべての PHP プロセスの前に whoops を呼び出す
*
* php.ini 内で次のようにセットされています
* auto_prepend_file = "/path/to/set_whoops.php"
*
* セットアップ手順:
* 1. whoops をインストール `$ composer global require 'filp/whoops'`
@gh640
gh640 / array_sum_numbers.php
Created February 6, 2016 12:47
PHP: 配列の要素同士を足し合わせた配列を生成する関数
<?php
/**
* ふたつの数値からなる配列の各要素を足しあわせた配列を返す
*
* array_map() を使いたいが長さが違う場合の挙動などが不明なので for ループで計算しています。
*
* @param float[] $a1
* 数値の配列。長さは $a2 と共通。
* @param float[] $a2
@gh640
gh640 / register_new_user.py
Created February 6, 2016 12:55
Drupal 7 でサイトに新しいユーザを登録する Selenium - Python スクリプト
coding: utf-8
"""
Drupal サイトでユーザを登録するためのスクリプト
必要なもの
- selenium: `pip install selenium`
"""
import sys
@gh640
gh640 / japan-prefectures-option.txt
Last active February 6, 2016 15:39
都道府県フィールド用オプションデータ
1|北海道
2|青森県
3|岩手県
4|宮城県
5|秋田県
6|山形県
7|福島県
8|茨城県
9|栃木県
10|群馬県
@gh640
gh640 / settings.php
Last active February 7, 2016 01:10
Drupal 7 でホワイトスクリーンではなく画面にエラーを表示するための設定
<?php
// なるべくホワイトスクリーンを避けてエラーを画面に表示するようにする
// - 開発環境のみで使用すること
// - 上 3 行は Drupal にかぎらず PHP 一般に有効
// @see https://www.drupal.org/node/1056468
error_reporting(-1);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
$conf['error_level'] = 2;
@gh640
gh640 / pressThisBookmarkletForDrupal.js
Created February 7, 2016 01:04
Drupal 7 でワンクリックで投稿画面を開くブックマークレット
/**
* Drupal 7 でワンクリックで投稿画面を開くブックマークレット
*
* Prepopulate モジュールが有効になっている必要があります
*/
javascript: (function(){
'use strict';
var BASE_URL,
NODE_TYPE,
@gh640
gh640 / delete_vocabularies.php
Created February 7, 2016 01:12
Drupal 7 で特定範囲のボキャブラリーを一括で削除する
<?php
/**
* 指定された範囲のボキャブラリーをまとめて削除する
*
* 例: my_func_delete_vocabularies(23, 35);
* vid が 23 から 35 まで( 35 を含む)のボキャブラリーを全件削除する。
*
* @param int $index_start
@gh640
gh640 / node_count.php
Created February 7, 2016 02:05
Drupal 7 でノードの body で使われているフォーマットをカウントする
<?php
/**
* node の body のフォーマットをカウントする
*
* 対象はあくまでも body だけなので他のフィールドでの使用有無はわからないため要注意
*
* 出力サンプル:
* array(
* 'full_html' => 21,
@gh640
gh640 / disable-table-sticky-header.php
Created February 7, 2016 02:07
Drupal 7 でテーブルフィールドの sticky header 効果をなくす
<?php
/**
* Implements template_preprocess_table().
*/
function mytheme_preprocess_table(&$variables) {
// すべてのテーブルでテーブルの sticky header を止める
$variables['sticky'] = FALSE;
}
@gh640
gh640 / fetch_wp_popular_plugins.py
Created March 9, 2016 11:35
WordPress の人気プラグインの情報を複数件まとめて取得するスクリプト