Keep pebble time watchface backlight on for longer than 3 seconds

The pebble time watchface dims pretty fast and it only lasts 3 seconds, unfortunately there is no option right to increase that. in watchface it is possible to change this behavior programatically here is how i did it.


static int seconds; static void set_backlight(){ light_enable_interaction(); if (seconds<=4)return; app_timer_register(3000,set_backlight, NULL); } static void accel_tap_handler(AccelAxisType axis,int32_t direction) { light_enable_interaction(); seconds = 10; app_timer_register(3000,set_backlight, NULL); } static void main_window_load(Window *window) { ... accel_tap_service_subscribe(&accel_tap_handler); ... } static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { if (seconds>0)seconds--; ... } static void init() { ... tick_timer_service_subscribe(SECOND_UNIT, tick_handler); ... }

How to validate form fields in magento without submitting the form

If you want to validate a form in Magento using prototype validations, if you use


myForm = new VarienForm('myform-id'); myform.submit = function () { results=myForm.prototype.submit.bind(myForm)();

then the form will be submitted automatically if there is no error. That’s perfectly fine unless you want to do other work before submitting, for example submitting the form in an ajax request.

Instead you can do this to test


myForm = new VarienForm('myform-id'); myform.submit = function () { results=myForm.validator.validate();

If results return true then there is no error.

How to check if user is an admin in wordpress

The best way so far to check whether the current user is a super admin user with full permissions in wordpress is to use current_user_can function and check for manage_options . If user has manage_options they clearly have full permissions. I use this for example to hide ads from me and to hide google analytics so that it doesn’t count me while I’m logged in as admin.

google analytics code goes here

How to login a customer/user programmatically in Magento

How to login a user programmatically in Magento? To find out how to do that, we can try to look at Magento code itself. so if we search for ->login in magento files, we will find among others. the following method inside Mage_Customer_AccountController (App/Code/Mage/Customer/controllers/AccountController.php)

public function loginPostAction() { if ($this->_getSession()->isLoggedIn()) { $this->_redirect('*/*/'); return; } $session = $this->_getSession(); if ($this->getRequest()->isPost()) { $login = $this->getRequest()->getPost('login'); if (!empty($login['username']) && !empty($login['password'])) { try { $session->login($login['username'], $login['password']); if ($session->getCustomer()->getIsJustConfirmed()) { $this->_welcomeCustomer($session->getCustomer(), true); } } catch (Mage_Core_Exception $e) { switch ($e->getCode()) { case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED: $value = Mage::helper('customer')->getEmailConfirmationUrl($login['username']); $message = Mage::helper('customer')->__('This account is not confirmed. Click here to resend confirmation email.', $value); break; case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD: $message = $e->getMessage(); break; default: $message = $e->getMessage(); } $session->addError($message); $session->setUsername($login['username']); } catch (Exception $e) { // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password } } else { $session->addError($this->__('Login and password are required.')); } } $this->_loginPostRedirect(); }

Based on that, we can take the useful part for us:


$email="customer email address"; $password="customer password"; $session = Mage::getSingleton('customer/session'); $message=""; //error message to add to session try { $session->login( $email, $password ); if ($session->getCustomer()->getIsJustConfirmed()) { //Customer is confirmed and successfully logged in } } catch (Mage_Core_Exception $e) { //error occured switch ($e->getCode()) { case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED: //email not confirmed actions here break; case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD: //Email or password invalid actions here $message = $e->getMessage();//echo the error message break; default: $message = $e->getMessage(); //Display other error messages } $session->addError($message); } catch (Exception $e) { //login failed because of some other error. }

How to display Magento CMS blocks in template files programmatically

There are a lot of reasons you might want to call cms blocks programmatically in magento inside your template or inside your own plugin. Particularly cms blocks are very useful to allow admin access to html from control panel avoiding the need to change theme files.  So, how do you display a cms block inside a theme phtml file?

Here is how to get the CMS helper:


$cmsHelper = Mage::helper('cms');

Now to get the CMS block by id, you ll need to do this


$block = Mage::getModel('cms/block')->load("your CMS block id here");

It is better to check if the CMS block is active by:


if ($block->getIsActive()){

To get CMS block title:


$block->getTitle()

To get CMS block content/description:


$block->getContent()

However when you echo description directly you might notice it contains unprocessed magento path variables, therefore you’ll need to convert those to what they mean using Magento’s own method getPageTemplateProcessor


$processor = $cmsHelper->getPageTemplateProcessor(); $block_content=$processor->filter($block->getContent());

Here is a complete example that get the content and title of a CMS block, checking if it is active and process its variables


$cmsHelper = Mage::helper('cms'); $processor = $cmsHelper->getPageTemplateProcessor(); $block = Mage::getModel('cms/block')->load("my_cms_block_id"); if ($block->getIsActive()){ echo "Title:".$block->getTitle()."
"; echo "Content:".$processor->filter($block->getContent())."
"; }