Skip to content

Instantly share code, notes, and snippets.

View davialexandre's full-sized avatar

Davi Alexandre davialexandre

View GitHub Profile
@davialexandre
davialexandre / AdminModule.php
Created November 5, 2012 17:59
AdminModule::beforeControllerAction
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
<?php
class AdminLoginForm extends CFormModel
{
public $username;
public $password;
public $rememberMe;
private $_identity;
<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'); ?>
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");
{
_index:"index",
_type:"filme",
_id:"16855",
_version:1,
exists:true,
_source:{
titulo_portugues:"RIO",
titulo_original:"Rio",
ano:"2011",
@davialexandre
davialexandre / gist:e6bebdab22546aad1692
Created May 15, 2014 13:57
Bash prompt with divider line
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\] '
@davialexandre
davialexandre / provisioning_webgrind.yml
Last active August 29, 2015 14:20
tasks to install webgrind using Ansible
- 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 / NomeDoSeuTypeType.php
Created June 2, 2016 20:23
Using getRepository on a FormType
<?php
namespace AppBundle\Form\Type;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class NomeDoSeuTypeType extends AbstractType
{
/**
<?php
public function getNumberOfPublicHolidaysForPeriod() {
if(!$this->numberOfPublicHolidaysInPeriod) {
$this->numberOfPublicHolidaysInPeriod = PublicHoliday::getNumberOfPublicHolidaysForPeriod(
$this->period->start_date,
$this->period->end_date
);
}
return $this->numberOfPublicHolidaysInPeriod;
<?php
class CSVAbsenceTypeCleaner extends CSVCleanerVisitor {
public function visit(array $row) {
$this->deleteRecord('HRAbsenceType', ['name' => $row['name']]);
}
}