Skip to content

Instantly share code, notes, and snippets.

@hiromi2424
hiromi2424 / bulk_updatable.rb
Created June 13, 2023 10:32
Bulk Updatable
module BulkUpdatable
extend ActiveSupport::Concern
class_methods do
def bulk_update(attributes)
return true if attributes.empty?
attrs = attributes.map { |attribute| attribute.to_h.symbolize_keys }
fields = attrs.first.keys.map(&:to_sym) - [:id]
@hiromi2424
hiromi2424 / json_debug.php
Created April 21, 2011 10:39
simple json formatter(possible to use formatted)
// 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};
// ログインボタンを押した時のアクションは自分で設定する
@IBAction func twitterLoginButtonTapped(sender: AnyObject) {
MBProgressHUD.showHUDAddedTo(self.view, animated: true)
}
// Twitterログインボタン設定
func setupLoginWithTwitter() {
// Consumer Key, Consumer Secretの指定
NCMBTwitterUtils.initializeWithConsumerKey(kTwitterConsumerKey, consumerSecret: kTwitterConsumerSecret)
// Twitterログインボタン押下時の処理
<?php
App::uses('AppModel', 'Model');
class ArrayModel extends AppModel {
public $useDbConfig = 'array';
public $useTable = false;
public $records = [];
@hiromi2424
hiromi2424 / Post.php
Created March 12, 2012 03:56
CakePHP Mass Assignment Vulnerability - common process
<?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 December 18, 2011 21:06
migrations with initial records
<?php
class M4ec9e1ac040840e8b4383c94d8a96c37 extends CakeMigration {
/**
* Records keyed by model name.
*
* @var array $records
*/
public $records = array(
@hiromi2424
hiromi2424 / BaseActionComponent.php
Created December 10, 2011 05:43 — forked from slywalker/BaseActionComponent.php
CakePHP2.0 BaseActionComponent
<?php
App::uses('Component', 'Controller');
App::uses('Inflector', 'Utility');
class BaseActionComponent extends Component {
public $components = array('Session');
public $Controller;
<?php
public $components = array(
'RequestHandler' => array(
// 'enabled' => false,
),
'DebugKit.Toolbar' => array(
'history' => 5,
'panels' => array(
'Interactive.interactive',
),
<?php
class ChatController extends AppController {
public $components = array(
'WebSocket',
);
public function send() {
$this->autoRender = false;
@hiromi2424
hiromi2424 / 01_first.php
Created September 1, 2011 21:25
preferable example for getting data method for model
<?php
class Post extends AppModel {
/**
* Usage:
* $nextPost = $this->Post->getNext(1);
*/
public function getNext($id) {
$greater = $this->find('first', array(