Saturday, March 28, 2015

Stop the laptop from going "stand by" when lid is closed in Xubuntu

I hate the fact that I have to figure this out for every new distro I use. But here it goes for Xubuntu. Tested and working in 14.04 LTS.
1. Open the file /etc/systemd/logind.conf
2. Find the line "HandleLidSwitch="
3. Set it like "HandleLidSwitch=ignore" and if it has a "#" (hash" in front of it, remove it.
Save and reboot and you are good. :)
Credits: http://askubuntu.com/a/362692/145915

Monday, March 23, 2015

Laravel validation trouble shootings.

While working on a project I stumbled upon this huge pile of problem of validating a form. Even though the fancy coding styles did make some things easy, it made some other things hard, especially when not having a complete documentation. So, here's a note for future.
\ 1. Custom validation messages: Custom messages, if not in a language file must be written for each field and each of the rules of that field. So you cannot escape with a single message written for email field if you want it to be shown on every rule. You have to write that same message for each rule, individually
2. Field name renaming: When printing validation messages Laravel, if not instructed otherwise, will use a slightly polished version of the 'name' attributes of you fields. So, for example name='user_name' will be made into user name. So if you instead want it to look like "Username", you have to use the method called
setAttributeNames
Like this:
$attributeNames = array(
   'name' => 'Name',
   'cat' => 'Category',     
);
$validator = Validator::make ( Input::all (), $rules );
$validator->setAttributeNames($attributeNames);
// Credits for: http://stackoverflow.com/a/25189223/1928610
3. Check uniqueness in a table having a different name than field name: Now what if you want to ensure that the user always enters an email that is not yet present in the 'users' table when signing up. Laravel has a great validation rule for it called 'unique:table_name'. So you use it like
'email' => 'unique:users'
But if you are like me, you may at first run into the problem where your field 'name' attribute does not match with the uniqueness field in your database. Like in my case, email field's name attribute contained 'email_address' but in my 'users' table, the column name was 'email'. So to fix this, Laravel validaton just takes another attribute with the validator.
'email_address' => 'unique:users,email'
Neat right?
Scouring through the documentation will help you more as it is doing for me. I'll keep posting further troubles I shoot in Laravel. InshaAllah.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...