how disable edit for a certain content type, and a certain role, in a drupal 7 site i have been given to maintain, it seems that permissions are not working as expected. I check and uncheck the buttons for a certain user role, but that user role always has the right to edit any node that belongs to this particular type. 
1. What could be the cause for this? 
2. If this is not working from the gui, how i could achieve something similar with code?
I would appreciate an example
In /admin/people/permissions Under "Node" category you can uncheck the permission "Edit content X" for your desired role. 

I would recommend using this module if your site has a lot of modules/permissions since due max upload vars limitation by PHP could led to not storing your chages when submitting the form.

Also by code you can implement hook_node_access and put there some logic. Take a look on how core does it.

/**
 * Implements hook_node_access().
 */
function node_node_access($node, $op, $account) {
  $type = is_string($node) ? $node : $node-&gt;type;

  if (in_array($type, node_permissions_get_configured_types())) {
    if ($op == 'create' &amp;&amp; user_access('create ' . $type . ' content', $account)) {
      return NODE_ACCESS_ALLOW;
    }

    if ($op == 'update') {
      if (user_access('edit any ' . $type . ' content', $account) || (user_access('edit own ' . $type . ' content', $account) &amp;&amp; ($account-&gt;uid == $node-&gt;uid))) {
        return NODE_ACCESS_ALLOW;
      }
    }

    if ($op == 'delete') {
      if (user_access('delete any ' . $type . ' content', $account) || (user_access('delete own ' . $type . ' content', $account) &amp;&amp; ($account-&gt;uid == $node-&gt;uid))) {
        return NODE_ACCESS_ALLOW;
      }
    }
  }

  return NODE_ACCESS_IGNORE;
}