Skip to content

Instantly share code, notes, and snippets.

Avatar

Davi Alexandre davialexandre

View GitHub Profile
@davialexandre
davialexandre / provisioning_webgrind.yml
Last active Aug 29, 2015
tasks to install webgrind using Ansible
View provisioning_webgrind.yml
- name: PHP | Create the webgrind dirs
file: name=/var/www/webgrind/storage state=directory owner=www-data mode=0700
- name: PHP | Download webgrind package
get_url: url=https://github.com/bionoren/webgrind/archive/xdebug23.zip dest=/tmp/webgrind.tar.gz
- name: PHP | Extract the webgrind package
unarchive: src=/tmp/webgrind.tar.gz dest=/var/www/webgrind copy=no creates=/var/www/webgrind/index.php
- name: PHP | Move the webgrind package contents to the webgrind dir
@davialexandre
davialexandre / gist:e6bebdab22546aad1692
Created May 15, 2014
Bash prompt with divider line
View gist:e6bebdab22546aad1692
export PS1='$(printf '%.0s-' $(seq 1 $COLUMNS))\n\[\e[0;32m\]\u@\h:\[\e[m\]\[\e[36;40m\]\w\[\e[m\]\[\e[1;32m\]\$\[\e[m\] '
View 16855.json
{
_index:"index",
_type:"filme",
_id:"16855",
_version:1,
exists:true,
_source:{
titulo_portugues:"RIO",
titulo_original:"Rio",
ano:"2011",
View EnumExample.java
public class EnumExample {
public static void main(String []args){
testGender(Gender.FEMALE);
testGender(Gender.MALE);
}
public static void testGender(Gender gender) {
switch(gender) {
case FEMALE:
System.out.println("Female");
View login.php
<div id="login-box">
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username'); ?>
<?php echo $form->error($model,'username'); ?>
View AdminLoginForm.php
<?php
class AdminLoginForm extends CFormModel
{
public $username;
public $password;
public $rememberMe;
private $_identity;
@davialexandre
davialexandre / AdminModule.php
Created Nov 5, 2012
AdminModule::beforeControllerAction
View AdminModule.php
public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action))
{
if($this->user->isGuest && !($controller->id == 'default' && $action->id == 'login')) {
$this->user->loginRequired();
}
return true;
}
else
@davialexandre
davialexandre / DefaultController.php
Created Nov 5, 2012
Exemplo de um controller dentro de um módulo com Login
View DefaultController.php
<?php
class DefaultController extends CController
{
public $defaultAction = 'login';
public function actionLogin() {
$this->layout = 'login';
$model = new AdminLoginForm;
if(isset($_POST['AdminLoginForm'])) {
@davialexandre
davialexandre / gist:3921652
Created Oct 20, 2012
Exemplo de customização de filtros no CGridView
View gist:3921652
<?php $this->widget('zii.widgets.grid.CGridView', array(
'columns'=>array(
array(
'name' => 'pesquisa',
'value' => '$data->pesquisa',
'header' => 'Termo',
),
array(
'name' => 'data_cadastro',
'value' => 'Yii::app()->dateFormatter->formatDatetime(strtotime($data->data_cadastro), "short", "short")',
@davialexandre
davialexandre / relations.php
Created Oct 19, 2012
Relations - exemplos
View relations.php
<?php
class Os extends CActiveRecord {
public function relations() {
return array(
'cliente' => array(self::BELONGS_TO, 'Cliente', 'id_cliente'),
);
}
}