Skip to content

Instantly share code, notes, and snippets.

<html>
<head>
<script language="javascript" type="text/javascript">
window.onload = function(){
var elements = document.getElementsByTagName('label');
for (var i=0; i <elements.length; i++) {
elements[i].onclick = function(){
var radios = this.getElementsByTagName('input');
for (var j=0;j<radios.length;j++) {
if (radios[j].getAttribute('type').toLowerCase() == 'radio') {
@haruta
haruta / seq num sql
Created March 8, 2012 11:00
有る親IDに対する連番をどうにかしたいSQL
create table t
(
id int auto_increment not null primary key,
parent_id int,
in_seq_num int
);
// parent_id 内の連番を in_seq_num に入れたい
set @lastid := 0;
set @number := 0;
@haruta
haruta / gist:2699870
Created May 15, 2012 07:58
apache combined access log parse by php
preg_match('/^([^ ]*) ([^ ]*) ([^ ]*) \[([^]]*)\] "([^ ]*)(?: *([^ ]*) *([^ ]*))?" ([^ ]*) ([^ ]*) "(.*?)" "(.*?)"/', $buf, $log_stat);
list($all, $host, $ident, $user, $time, $method, $resource, $proto, $status, $bytes, $referer, $agent) = $log_stat;
@haruta
haruta / gist:3332452
Created August 12, 2012 15:59
private method access for php using Reflection
<?php
class Ex1 {
private function private_method($val1 , $val2) {
return func_get_args();
}
}
$obj = new Ex1();
$r = call_private_method($obj, 'private_method', 'test1', 'test2');
function copy_row($fromid, $overwride = array()) {
$fom = $this->db->getTable('table')->find($fromid);
$to = $this->db->getTable('table')->create();
$to->fromArray(array_merge($overwride, $from->toArray()));
$to->save();
}
$new_row = copy_row(1, array('id' => null));
$response = parent::render();
$response->setContent(str_replace('a','b',$response->getContent()));
return $reponse;
@haruta
haruta / gist:3630938
Created September 5, 2012 05:16
assert input field and value by symfony2 unit test
protected function assertInuptValue($crawler, $key, $val)
{
$input = $crawler->filter('input[name="'.$key.'"]');
$this->assertEquals(
$val, $input->attr('value'), $key.' failed'
);
}
protected function assertSelectValue($crawler, $key, $val)
{
@haruta
haruta / gist:3871202
Created October 11, 2012 09:18
git-current
#!/bin/sh
# usage:
# git current で現在のブランチ名を表示する
git branch | grep '*' | sed 's/* //'
@haruta
haruta / chatwork-to-all-helper.user.js
Created November 30, 2012 05:50
チャットワークで "@@" "@@" をチャンネル全員のTOに置き換えるchromeのユーザースクリプト
// ==UserScript==
// @name chatwork to all helper
// @match https://www.chatwork.com/*
// @version 1.1
// ==/UserScript==
(function(){
document.getElementById('cw_chattext').addEventListener('blur', function(e){
if (/[@@]{2}/.test(e.target.value)) {
var to_list = [];
var imgs = document.getElementById('cw_mention_gallery').getElementsByTagName('img');
@haruta
haruta / gist:4248291
Created December 10, 2012 03:50
storeEval で保存したデータをassertで使う
<tr>
<td>storeEval</td>
<td>this.page().getDocument().forms[0]['enc'].value</td>
<td>enc</td>
</tr>
<tr>
<td>assertValue</td>
<td>name=enc</td>
<td>${enc}</td>
</tr>