Skip to content

Instantly share code, notes, and snippets.

@hiromi2424
hiromi2424 / json_debug.php
Created Apr 21, 2011
simple json formatter(possible to use formatted)
View json_debug.php
// almost same output can be seen at:
// http://jsonformatter.curiousconcept.com/
class JsonDebug {
function format($json, $output = false) {
$depth = 0;
$length = strlen($json);
$result = '';
for ($n = 0; $n < $length; $n++) {
$c = $json{$n};
View twitter_login.swift
// ログインボタンを押した時のアクションは自分で設定する
@IBAction func twitterLoginButtonTapped(sender: AnyObject) {
MBProgressHUD.showHUDAddedTo(self.view, animated: true)
}
// Twitterログインボタン設定
func setupLoginWithTwitter() {
// Consumer Key, Consumer Secretの指定
NCMBTwitterUtils.initializeWithConsumerKey(kTwitterConsumerKey, consumerSecret: kTwitterConsumerSecret)
// Twitterログインボタン押下時の処理
View ArrayModel.php
<?php
App::uses('AppModel', 'Model');
class ArrayModel extends AppModel {
public $useDbConfig = 'array';
public $useTable = false;
public $records = [];
@hiromi2424
hiromi2424 / Post.php
Created Mar 12, 2012
CakePHP Mass Assignment Vulnerability - common process
View Post.php
<?php
// モデルの場合。
// 以下と相似なヘルパーメソッドを作れば、いちいち同じようなメソッドを大量生産しなくて済むよ!
class Post extends AppModel {
public function edit($id, $data) {
$this->create(false);
$this->set($data);
$this->set('id', $id);
@hiromi2424
hiromi2424 / migration1.php
Created Dec 18, 2011
migrations with initial records
View migration1.php
<?php
class M4ec9e1ac040840e8b4383c94d8a96c37 extends CakeMigration {
/**
* Records keyed by model name.
*
* @var array $records
*/
public $records = array(
@hiromi2424
hiromi2424 / BaseActionComponent.php
Created Dec 10, 2011 — forked from slywalker/BaseActionComponent.php
CakePHP2.0 BaseActionComponent
View BaseActionComponent.php
<?php
App::uses('Component', 'Controller');
App::uses('Inflector', 'Utility');
class BaseActionComponent extends Component {
public $components = array('Session');
public $Controller;
View app_controller.partof.php
<?php
public $components = array(
'RequestHandler' => array(
// 'enabled' => false,
),
'DebugKit.Toolbar' => array(
'history' => 5,
'panels' => array(
'Interactive.interactive',
),
View ChatController.php
<?php
class ChatController extends AppController {
public $components = array(
'WebSocket',
);
public function send() {
$this->autoRender = false;
@hiromi2424
hiromi2424 / 01_first.php
Created Sep 1, 2011
preferable example for getting data method for model
View 01_first.php
<?php
class Post extends AppModel {
/**
* Usage:
* $nextPost = $this->Post->getNext(1);
*/
public function getNext($id) {
$greater = $this->find('first', array(
@hiromi2424
hiromi2424 / categorize.php
Created Sep 2, 2011
preferable example for getting data method for model(behaviorized)
View categorize.php
<?php
/**
* Available find keys:
* 'category': adding creteria with name of category.
*/
class CategorizeBehavior extends ModelBehavior {
public $defaultSettings = array(
'key' => 'category',