Skip to content

Instantly share code, notes, and snippets.

View monsat's full-sized avatar

TANAKA Kohji monsat

View GitHub Profile
@monsat
monsat / gist:1175109
Created August 27, 2011 07:39
no cache by CakePHP2.x
<div>
<!--nocache-->
<?php echo $this->Session->read('Auth.User.username'); ?>
<!--/nocache-->
</div>
@monsat
monsat / SampleController.php
Created August 27, 2011 12:22
Set Data at CakePHP2.x Controller
$this->request->data('Post.title', 'New post')
->data('Comment.1.author', 'Mark');
@monsat
monsat / Post.php
Created September 16, 2011 06:42
extend find method by CakePHP2.0
<?php
class Post extends AppModel {
public $findMethods = array(
'latest' => true,
);
protected function _findLatest($state, $query, $results = array()) {
if ($state == 'before') {
// extend
// $query = Set::merge($query, array('conditions' => array()));
return $query;
@monsat
monsat / Post.php
Created September 19, 2011 02:50
new placeholder of validation messages on CakePHP2.0
<?php
class Post extends AppModel {
public $validate = array(
'title' => array(
'between' => array(
'rule' => array('between', 10, 100),
'message' => 'The title must have between %d to %d characters',
),
),
);
@monsat
monsat / .gitconfig
Created September 29, 2011 04:23
To push for multiple Repositories
# .git/config
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = /var/dev/repos/tipshare.git
url = git@github.com:MontBlanc-Sucks/tipshare.git
@monsat
monsat / CakePHP2.gitignore
Created October 3, 2011 03:37
CakePHP2's .gitignore
tmp/*
Config/database.php
app/tmp/*
app/Config/database.php
!empty
@monsat
monsat / delete_cache.sh
Created October 4, 2011 03:02
delete all cache files on CakePHP's app with .gitignore in tmp directory
#!/bin/sh
cd /path/to/your_app_root
# ls
# cake app ...
find ./*/tmp/cache -type f -name '*' -exec rm {} \;
@monsat
monsat / ApoController.php
Created October 5, 2011 21:53
CakePHP2.0 i18n sample
public function beforeFilter() {
parent::beforeFilter();
$this->_setLocale();
}
protected function _setLocale() {
if (isset($this->request->query['hl'])) {
CakeSession::write('App.lang', $this->request->query['hl']); // you can use any key instead of 'App.lang'
}
if (CakeSession::read('App.lang')) {
@monsat
monsat / AppController.php
Created October 9, 2011 15:15
disable DebugKit if Ajax request by using CakePHP2.0
public function beforeFilter() {
$this->disableDebugKitIfisAjax();
}
protected function disableDebugKitIfisAjax() {
if ($this->request->isAjax()) {
Configure::write('debug', 0);
$this->Components->disable('Toolbar');
}
}
@monsat
monsat / FizzBuzz.js
Created October 10, 2011 09:53
FizzBuzz by JavaScript
Number.prototype.fizzBuzz = function() {
return (this % 3 === 0 ? "Fizz" : "") + (this % 5 === 0 ? "Buzz" : "") || this.toString();
}
// main
for (var i=1; i<=100; i++) {
console.log( i.fizzBuzz() );
}