Skip to content

Instantly share code, notes, and snippets.

@do-aki
do-aki / groonga-http.php
Last active August 29, 2015 14:05
use groonga with nise-nabe/groonga-http-php
<?php
require __DIR__ . '/vendor/autoload.php';
use Groonga\Http\Client;
$grn = new Client('http://localhost:10041');
$grn->tableCreate('Site', ['flags' => 'TABLE_HASH_KEY','key_type' => 'ShortText']);
$grn->columnCreate('Site', 'title', 'COLUMN_SCALAR', 'ShortText');
$grn->load('Site', json_encode([
["_key" => "http://example.org/","title" => "This is test record 1!"],
@do-aki
do-aki / eachlize.php
Created August 15, 2014 05:49
同じメソッドで foreach も each(function) もできるようにする例
<?php
class R {
private $begin;
private $end;
public function __construct($begin, $end) {
$this->begin = $begin;
$this->end = $end;
}
$ php -v
PHP 5.5.14 (cli) (built: Jul 23 2014 16:08:06) (DEBUG)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
$ php -d zend.multibyte=1 -d zend.script_encoding='EUC-JP' aa.php
PHP Warning: Unexpected character in input: ' in /tmp/aa.php on line 11
PHP Warning: Unexpected character in input: ' in /tmp/aa.php on line 11
PHP Warning: Unexpected character in input: ' in /tmp/aa.php on line 11
@do-aki
do-aki / gist:7771047
Created December 3, 2013 15:23
AngularJS の練習。 タグ的なものを入力する感じのモノ。
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular.min.js"></script>
<script src="http://code.angularjs.org/1.2.3/angular-animate.min.js"></script>
<script>
function ctrl($scope) {
$scope.words = [];
$scope.input = function() {
@do-aki
do-aki / generator.php
Created September 3, 2013 11:38
trait と generator の練習。
<?php
trait GeneratorAction {
private $_g;
public function initializeGenerator($g) {
$this->_g = $g;
}
public function getGenerator() {
@do-aki
do-aki / mylogin_dumper.pl
Created April 17, 2013 08:54
MySQL Casual Talks Vol.4 LT 「セキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editor」 http://www.slideshare.net/do_aki/mysql-config-editor を参照。 Crypt::ECB と Crypt::OpenSSL::AES が必要です。
######################################
# usage
# mylogin_dumper.pl ~/.mylogin.conf
######################################
use strict;
use warnings;
use Crypt::ECB;
#use Crypt::OpenSSL::AES;
my $my_login_file = shift;
@do-aki
do-aki / html_purifier.php
Last active December 16, 2015 02:09
HTML Purifier を使って html を消毒する ref: http://qiita.com/items/b7767b63d6c3d65cd3da
<?php
require_once('$PATH_TO_LIBRARY/HTMLPurifier.includes.php');
use HTMLPurifier;
use HTMLPurifier_Config;
function sanitize($tainted_html) {
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.SerializerPath', $PATH_TO_TEMPORARY_DIR);
$purifier = new HTMLPurifier($config);
return $purifier->purify($tainted_html);
@do-aki
do-aki / download.html
Created February 25, 2013 08:07
Excel 向け日本語 CSV ファイル
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>日本語csv sample</title>
</head>
<body>
<a id="js-download" href="dummy">download</a>
<script>
// (1) BOM の用意
@do-aki
do-aki / phantomjs.spec.patch
Created December 24, 2012 07:49
phantomjs 1.8 付属の spec ファイルを 1.8 に対応させるパッチ
--- phantomjs.spec.original 2012-12-21 08:51:10.000000000 +0900
+++ phantomjs.spec 2012-12-24 07:34:04.000000000 +0900
@@ -1,5 +1,5 @@
%define name phantomjs
-%define version 1.7
+%define version 1.8.0
%define release 1
%define prefix /usr
@@ -122,6 +122,18 @@
@do-aki
do-aki / redmine.sh
Created July 3, 2012 07:49
redmine 起動スクリプト
#!/bin/sh
export HOME=/home/redmine
SHELL="$HOME/.rvm/bin/rvm-shell 1.9.3"
PID_FILE=$HOME/redmine.pid
LISTEN='127.0.0.1:3001'
APP_DIR=$HOME/redmine-2.0
start() {
cd $APP_DIR && $SHELL -c "unicorn --listen $LISTEN --pid=$PID_FILE --env=production --daemonize"