Skip to content

Instantly share code, notes, and snippets.

View tsmsogn's full-sized avatar
:octocat:
Set your status

tsmsogn tsmsogn

:octocat:
Set your status
View GitHub Profile
@tsmsogn
tsmsogn / 0012_A_Point_in_a_Triangle.rb
Last active August 28, 2015 04:08
[ruby]A Point in a Triangle
# Heron
module Heron
def self.calc(a, b, c)
s = (a + b + c) * 0.5
Math.sqrt(s * (s - a) * (s - b) * (s - c))
end
end
def dist(x1, y1, x2, y2)
Math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
@tsmsogn
tsmsogn / gist:9224167
Last active August 29, 2015 13:56
CakePHP: Dynamic virtualFields
public function __construct($id = false, $table = null, $ds = null) {
    parent::__construct($id, $table, $ds);
    $this->virtualFields['displayName'] = sprintf('CONCAT(%s.name_prefix, %s.name, %s.name_suffix)', $this->alias, $this->alias, $this->alias);
    $this->virtualFields['employ_kbn_view'] = "SELECT kbn_name1 FROM mst_hanyo_kbn WHERE kbn_id LIKE '03' AND kbn_value LIKE LPAD(`TrnKyujinInfo`.`employ_kbn`, '3', '0')";
    $this->virtualFields['licence_cd1_view'] = "SELECT licence_nm FROM mst_licence WHERE licence_cd LIKE LPAD(`TrnKyujinInfo`.`licence_cd1`, '3', '0')";
}
@tsmsogn
tsmsogn / gist:9244863
Last active August 29, 2015 13:56
CakePHP: How to implement checkbox groups

Case 1

<?php
$data = array('a', 'b', 'c');
foreach ($data as $key => $value) {
  echo $this->Form->input('zero.', array(
    'type' => 'checkbox',
    'value' => $key,
 'label' =&gt; $value'
@tsmsogn
tsmsogn / gist:9826149
Last active August 29, 2015 13:57
MDB2: Snippets
<?php
$stmt = $db->prepare('SELECT * FROM `foo` WHERE `key` LIKE ?');
$res = $stmt->execute(array($Req->get('key')));
$slot = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
$query = 'SELECT * FROM `foo` WHERE `key` LIKE ' . $db->quote($Req->get('key'));
$data = $db->queryRow($query, null, MDB2_FETCHMODE_ASSOC);
@tsmsogn
tsmsogn / gist:11277725
Last active August 29, 2015 14:00
[cakephp]CSV Import Helper
<?php
/**
* CsvImport Helper
*
* @author Toshimasa Oguni <tsmsogn@gmail.com>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class CsvImportHelper {
private $__default = array('delimiter' => ',', 'enclosure' => '"', 'hasHeader' => true, 'headerMap' => '');

git初心者への道

まずやってみよう - コミットする、ログを見る、差分を見る

初登場するコマンド: init, add, commit, log, config, status, diff

@tsmsogn
tsmsogn / gist:bdc5e25f7c2b355b47c3
Last active August 29, 2015 14:01
CakePHP: CartComponent
<?php
App::uses('Component', 'Controller');
class CartComponent extends Component {
/**
* @var array
*/
public $components = array('Session');
@tsmsogn
tsmsogn / expand-max-input
Last active August 29, 2015 14:01
PHP: ini_set
max_input_vars 100000
@tsmsogn
tsmsogn / gist:fffbf0817a2c88e4cfa4
Last active August 29, 2015 14:02
[cakephp]How to use $Model->invalidate()

It's working

$this->User->set($this->request->data);
$this->User->invalidate('name', 'invalid name');

It's not working

$this->User->invalidate('name', 'invalid name');
$this-&gt;User-&gt;set($this-&gt;request-&gt;data);
export PATH=/usr/local/bin:$PATH:$HOME/.phpenv/bin
# Swapping from PHP53 to PHP54
export PATH="$(brew --prefix josegonzalez/php/php53)/bin:$PATH"
# export PATH="$(brew --prefix josegonzalez/php/php54)/bin:$PATH"
if which rbenv > /dev/null; then eval "$(rbenv init - zsh)"; fi
setopt nonomatch
# users generic .zshrc file for zsh(1)