maybe use that one in the voter later because it's going to be usefull
320217
public function getCurrentPermissionArray(ResourceNode $resourceNode)
    {
        $currentRoles = $this->tokenStorage->getToken()->getRoles();

        $roleNames = array_map(function (RoleInterface $roleName) {
            return $roleName->getRole();
        }, $currentRoles);

        $creatable = [];
        if ($this->isManager($resourceNode)) {
            /** @var ResourceType[] $resourceTypes */
            $resourceTypes = $this->om->getRepository('ClarolineCoreBundle:Resource\ResourceType')->findAll();

            foreach ($resourceTypes as $resourceType) {
                $creatable[] = $resourceType->getName();
            }

            $perms = array_fill_keys(array_values($this->maskManager->getPermissionMap($resourceNode->getResourceType())), true);
        } else {
            $creatable = $this->getCreatableTypes($roleNames, $resourceNode);

            $perms = $this->maskManager->decodeMask(
                $this->rightsRepo->findMaximumRights($roleNames, $resourceNode),
                $resourceNode->getResourceType()
            );
        }

        return array_merge($perms, ['create' => $creatable]);
    }
899318
function init(pluginInterface) {
    pi = pluginInterface;
    log = pi.log;
    localStorage = pi.localStorage;

    pollLog = localStorage.getItem('pollLog', []);

    resetPolling();
}
655837
public void setLastVotedFor(MemberId candidate) {
    // If we've already voted for another candidate in this term then the last voted for candidate cannot be overridden.
    checkState(!(lastVotedFor != null && candidate != null), "Already voted for another candidate");
    DefaultRaftMember member = cluster.getMember(candidate);
    checkState(member != null, "Unknown candidate: %d", candidate);
    this.lastVotedFor = candidate;
    meta.storeVote(this.lastVotedFor);

    if (candidate != null) {
      log.debug("Voted for {}", member.memberId());
    } else {
      log.trace("Reset last voted for");
    }
  }
151277
public static int poll(Selector selector, PollItem[] items, int count, long timeout)
    {
        Utils.checkArgument(items != null, "items have to be supplied for polling");
        if (count == 0) {
            if (timeout <= 0) {
                return 0;
            }
            LockSupport.parkNanos(TimeUnit.NANOSECONDS.convert(timeout, TimeUnit.MILLISECONDS));
            return 0;
        }
        long now = 0L;
        long end = 0L;

        HashMap<SelectableChannel, SelectionKey> saved = new HashMap<SelectableChannel, SelectionKey>();
        for (SelectionKey key : selector.keys()) {
            if (key.isValid()) {
                saved.put(key.channel(), key);
            }
        }

        for (int i = 0; i < count; i++) {
            PollItem item = items[i];
            if (item == null) {
                continue;
            }

            SelectableChannel ch = item.getChannel(); // mailbox channel if ZMQ socket
            SelectionKey key = saved.remove(ch);

            if (key != null) {
                if (key.interestOps() != item.interestOps()) {
                    key.interestOps(item.interestOps());
                }
                key.attach(item);
            }
            else {
                try {
                    ch.register(selector, item.interestOps(), item);
                }
                catch (ClosedSelectorException e) {
                    // context was closed asynchronously, exit gracefully
                    return -1;
                }
                catch (ClosedChannelException e) {
                    throw new ZError.IOException(e);
                }
            }
        }

        if (!saved.isEmpty()) {
            for (SelectionKey deprecated : saved.values()) {
                deprecated.cancel();
            }
        }

        boolean firstPass = true;
        int nevents = 0;
        int ready;

        while (true) {
            //  Compute the timeout for the subsequent poll.
            long waitMillis;
            if (firstPass) {
                waitMillis = 0L;
            }
            else if (timeout < 0L) {
                waitMillis = -1L;
            }
            else {
                waitMillis = TimeUnit.NANOSECONDS.toMillis(end - now);
                if (waitMillis == 0) {
                    waitMillis = 1L;
                }
            }

            //  Wait for events.
            try {
                int rc;
                if (waitMillis < 0) {
                    rc = selector.select(0);
                }
                else if (waitMillis == 0) {
                    rc = selector.selectNow();
                }
                else {
                    rc = selector.select(waitMillis);
                }

                for (SelectionKey key : selector.keys()) {
                    PollItem item = (PollItem) key.attachment();
                    ready = item.readyOps(key, rc);
                    if (ready < 0) {
                        return -1;
                    }

                    if (ready > 0) {
                        nevents++;
                    }
                }
                selector.selectedKeys().clear();

            }
            catch (ClosedSelectorException e) {
                // context was closed asynchronously, exit gracefully
                return -1;
            }
            catch (IOException e) {
                throw new ZError.IOException(e);
            }
            //  If timeout is zero, exit immediately whether there are events or not.
            if (timeout == 0) {
                break;
            }

            if (nevents > 0) {
                break;
            }

            //  At this point we are meant to wait for events but there are none.
            //  If timeout is infinite we can just loop until we get some events.
            if (timeout < 0) {
                if (firstPass) {
                    firstPass = false;
                }
                continue;
            }

            //  The timeout is finite and there are no events. In the first pass
            //  we get a timestamp of when the polling have begun. (We assume that
            //  first pass have taken negligible time). We also compute the time
            //  when the polling should time out.
            if (firstPass) {
                now = Clock.nowNS();
                end = now + TimeUnit.MILLISECONDS.toNanos(timeout);
                if (now == end) {
                    break;
                }
                firstPass = false;
                continue;
            }

            //  Find out whether timeout have expired.
            now = Clock.nowNS();
            if (now >= end) {
                break;
            }
        }
        return nevents;
    }
1299921
function later (info) {
	process.stdin.resume();
	const action = start.bind(null, info);
	process.on('SIGINT', action);
	process.on('SIGTERM', action);

	(function wait () {
		if (beenthere) {
			return;
		}

		setTimeout(wait, EVENT_LOOP);
	}());
}
166980
def up_vote!(votable)
      begin
        up_vote(votable)
        success = true
      rescue Exceptions::AlreadyVotedError
        success = false
      end
      success
    end
1289770
public function onBeforeWrite()
    {
        parent::onBeforeWrite();
        $parent = $this->Parent();
        if ($parent->exists() && !$parent instanceof Blog) {
            $first_blog = Blog::get()->first();
            if ($first_blog) {
                $this->ParentID = $first_blog->ID;
            }
        }
        $this->extend('onBeforeWrite');
    }
266652
private void acceptNewState( double fx_candidate ) {
		DMatrixRMaj tmp = x;
		x = x_next;
		x_next = tmp;

		fx = fx_candidate;

		mode = Mode.COMPUTE_DERIVATIVES;
	}
531953
def refresh(self):
        
        strawpoll_response = requests.get('{api_url}/{poll_id}'.format(api_url=api_url, poll_id=self.id))
        raise_status(strawpoll_response)
        self.status_code = strawpoll_response.status_code
        self.response_json = strawpoll_response.json()
        self.id = self.response_json['id']
        self.title = self.response_json['title']
        self.options = self.response_json['options']
        self.votes = self.response_json['votes']
        self.captcha = self.response_json['captcha']
        self.dupcheck = self.response_json['dupcheck']
        self.url = 'https://www.strawpoll.me/{id}'.format(id=self.id)
        self.results_url = 'https://www.strawpoll.me/{id}/r'.format(id=self.id)
1277941
def askForPreviousFutures(self):
        """"""
        # Don't request it too often (otherwise it ping-pongs because)
        # the broker answer triggers the _poll of pop()
        if time.time() < self.lastStatus + POLLING_TIME / 1000:
            return
        self.lastStatus = time.time()

        for future in scoop._control.futureDict.values():
            # Skip the root future
            if scoop.IS_ORIGIN and future.id == (scoop.worker, 0):
                continue

            if future not in self.inprogress:
                self.socket.sendStatusRequest(future)
712353
function handleVote(link) {
    if (!opts.voting) {
      showError("You'll need to login to vote.");
      return;
    }

    var id = link.attr('id');
    if (!id) {
      // Didn't click on one of the voting arrows.
      return;
    }
    // If it is an unvote, the new vote value is 0,
    // Otherwise it's 1 for an upvote, or -1 for a downvote.
    var value = 0;
    if (id.charAt(1) != 'u') {
      value = id.charAt(0) == 'u' ? 1 : -1;
    }
    // The data to be sent to the server.
    var d = {
      comment_id: id.substring(2),
      value: value
    };

    // Swap the vote and unvote links.
    link.hide();
    $('#' + id.charAt(0) + (id.charAt(1) == 'u' ? 'v' : 'u') + d.comment_id)
      .show();

    // The div the comment is displayed in.
    var div = $('div#cd' + d.comment_id);
    var data = div.data('comment');

    // If this is not an unvote, and the other vote arrow has
    // already been pressed, unpress it.
    if ((d.value !== 0) && (data.vote === d.value * -1)) {
      $('#' + (d.value == 1 ? 'd' : 'u') + 'u' + d.comment_id).hide();
      $('#' + (d.value == 1 ? 'd' : 'u') + 'v' + d.comment_id).show();
    }

    // Update the comments rating in the local data.
    data.rating += (data.vote === 0) ? d.value : (d.value - data.vote);
    data.vote = d.value;
    div.data('comment', data);

    // Change the rating text.
    div.find('.rating:first')
      .text(data.rating + ' point' + (data.rating == 1 ? '' : 's'));

    // Send the vote information to the server.
    $.ajax({
      type: "POST",
      url: opts.processVoteURL,
      data: d,
      error: function(request, textStatus, error) {
        showError('Oops, there was a problem casting that vote.');
      }
    });
  }
375822
protected void onPrevious()
	{
		stateMachine.previous();
		updateButtonState();
		final String name = getStateMachine().getCurrentState().getName();
		final CardLayout cardLayout = getWizardContentPanel().getCardLayout();
		cardLayout.show(getWizardContentPanel(), name);
	}
701569
async def wait_for_election_success(cls):
        """"""
        if cls.leader is None:
            cls.leader_future = asyncio.Future(loop=cls.loop)
            await cls.leader_future
1123787
def update_or_create_candidate(
        self, candidate, aggregable=True, uncontested=False
    ):
        """"""
        candidate_election, c = CandidateElection.objects.update_or_create(
            candidate=candidate,
            election=self,
            defaults={"aggregable": aggregable, "uncontested": uncontested},
        )

        return candidate_election
998824
public function onBeforeWrite()
    {
        parent::onBeforeWrite();

        // Generate a unique item key based on the current ID and customisations
        $key = base64_encode(json_encode($this->Customisations()->map("Title", "Value")->toArray()));
        $this->Key = $this->StockID . ':' . $key;
    }
1048025
function it_provides_useful_information_about_iterations()
    {
        $this->next('one');
        $this->getIndex()->shouldBe(0);
        $this->getKey()->shouldBe('one');
        $this->isFirst()->shouldBe(true);
        $this->isLast()->shouldBe(false);

        $this->next('two');
        $this->getIndex()->shouldBe(1);
        $this->getKey()->shouldBe('two');
        $this->isFirst()->shouldBe(false);
        $this->isLast()->shouldBe(false);

        $this->next('three');
        $this->getIndex()->shouldBe(2);
        $this->getKey()->shouldBe('three');
        $this->isFirst()->shouldBe(false);
        $this->isLast()->shouldBe(true);
    }
1047980
function maybeToFirst(maybe) {
  if(isFunction(maybe)) {
    return function(x) {
      const m = maybe(x)

      if(!isSameType(Maybe, m)) {
        throw new TypeError('maybeToFirst: Maybe returning function required')
      }

      return applyTransform(m)
    }
  }

  if(isSameType(Maybe, maybe)) {
    return applyTransform(maybe)
  }

  throw new TypeError('maybeToFirst: Maybe or Maybe returning function required')
}