Skip to content

Instantly share code, notes, and snippets.

@rinatio
rinatio / gist:3757866
Created September 20, 2012 19:30
ActiveRecord
<?php
class ActiveRecord extends CActiveRecord
{
public static function model($className = null)
{
return parent::model($className ? : get_called_class());
}
@rinatio
rinatio / gist:3873386
Created October 11, 2012 15:59 — forked from mattheworiordan/gist:1037984
Backbone patch to defer update method requests when new create requests are not complete on a model
(function() {
Backbone.Model.prototype._save = Backbone.Model.prototype.save;
Backbone.Model.prototype.save = function (attrs, options) {
var that = this;
if (!options) {
options = {};
}
if (this.savingNewRecord) {
// store or replace last PUT request with the latest version, we can safely replace old PUT requests with new ones
// but if there are callbacks from a previous PUT request, we need to make sure they are all called as well
<?php
class SetRoleCommand extends CConsoleCommand
{
public function actionIndex($role, $userId)
{
$auth = Yii::app()->authManager;
$roles = $auth->getRoles();
if (!array_key_exists($role, $roles)) {
$auth->createRole($role);
@rinatio
rinatio / _hover_info
Created May 24, 2013 06:52
Simple hover info with css
.hover-info {
$pd: 20px; // Padding
$bd: 1px; // Border width
$bdr: 8px; // Border radius
$bdc: rgba(0, 0, 0, 0.1); // Border color
$bsh: 2px 2px 2px rgba(0, 0, 0, 0.2); // Box shadow
.hover-details {
display: none;
}
$db = $this->getContext()->getDB();
$dbConf = $this->getContext()->getConf()->database;
$dbh = new PDO("mysql:host=$dbConf->host;dbname=$dbConf->database", $dbConf->username, $dbConf->password);
$sql = "update runresults set report_html = :report where id = :id";
$q = $dbh->prepare($sql);
$q->execute(array(
':report'=>gzencode('hello'),
':id'=> 1052
));
@rinatio
rinatio / simple.js
Created June 15, 2013 00:03
Simple Jasmine Tests Reuse Example
define([
'jasmine'
], function() {
describe('Simple Test', function() {
var view, context = {};
beforeEach(function() {
view = 1;
context.view = view;
});
@rinatio
rinatio / composer.json
Created July 11, 2013 21:20
Yii2 composer.json example
{
"repositories" : [
{
"type": "package",
"package": {
"name": "yiisoft/yii2",
"version": "master",
"source": {
"type": "git",
"url": "https://github.com/yiisoft/yii2.git",
@rinatio
rinatio / config.rb
Last active June 15, 2016 19:43
Simple capistrano config.rb for yii/php app
# for more information look at help.github.com/capistrano/
set :application, "yii2-app-basic"
server "example.com", :web # your server address or IP
set :user, "username" # your username for ssh
set :use_sudo, false
# set the remote directory you're going to deploy to
set :deploy_to, "/home/#{user}/www/#{application}"
# disable rails specific normalize_assets property
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="//code.highcharts.com/highcharts.js"></script>
<script>
var chart, el;
window.onload = function() {
el = document.getElementById('chart');
};
@rinatio
rinatio / gist:cf2fb1fdd501c6ee206f
Last active August 29, 2015 14:03
AngularJS $q resolved
angular.module('testQDecorator', [])
.config(function($provide) {
$provide.decorator('$q', function($delegate) {
function decoratePromise(promise) {
promise.resolved = false;
promise.finally(function() {
promise.resolved = true;
});
return promise;
}