text:
package mb.nabl2.terms.matching;

import static mb.nabl2.terms.build.TermBuild.B;

import java.util.Objects;
import java.util.Optional;

import org.metaborg.util.collection.CapsuleUtil;
import org.metaborg.util.functions.Action2;
import org.metaborg.util.functions.Function0;
import org.metaborg.util.functions.Function1;

import io.usethesource.capsule.Set;
import mb.nabl2.terms.IAttachments;
import mb.nabl2.terms.ITerm;
import mb.nabl2.terms.ITermVar;
import mb.nabl2.terms.Terms;
import mb.nabl2.terms.substitution.IRenaming;
import mb.nabl2.terms.substitution.ISubstitution;
import mb.nabl2.terms.unification.u.IUnifier;

public final class IntPattern extends Pattern {
    private static final long serialVersionUID = 1L;

    private final int value;

    IntPattern(int value, IAttachments attachments) {
        super(attachments);
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    @Override public Set<ITermVar> getVars() {
        return CapsuleUtil.immutableSet();
    }

    @Override public boolean isConstructed() {
        return true;
    }

    @Override protected boolean matchTerm(ITerm term, ISubstitution.Transient subst, IUnifier.Immutable unifier,
            Eqs eqs) {
        // @formatter:off
        return unifier.findTerm(term).match(Terms.<Boolean>cases()
            .integer(intTerm -> {
                return intTerm.getValue() == value;
            }).var(v -> {
                eqs.add(v, this);
                return true;
            }).otherwise(t -> {
                return false;
            })
        );
        // @formatter:on
    }

    @Override public IntPattern apply(IRenaming subst) {
        return this;
    }

    @Override public Pattern eliminateWld(Function0<ITermVar> fresh) {
        return this;
    }

    @Override protected ITerm asTerm(Action2<ITermVar, ITerm> equalities,
            Function1<Optional<ITermVar>, ITermVar> fresh) {
        return B.newInt(value, getAttachments());
    }

    @Override public String toString() {
        return Integer.toString(value);
    }

    @Override public boolean equals(Object o) {
        if(this == o)
            return true;
        if(o == null || getClass() != o.getClass())
            return false;
        IntPattern that = (IntPattern) o;
        return value == that.value;
    }

    @Override public int hashCode() {
        return Objects.hash(value);
    }
}

redpajama_set_name: RedPajamaGithub


text:
package org.apache.hadoop.chukwa.datacollection.adaptor.filetailer;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
import org.apache.hadoop.chukwa.datacollection.ChunkReceiver;

/**
 * Checkpoint state:
 *   date modified of most-recently tailed file, offset of first byte of that file,
 *   then regular FTA arts
 *
 */
public class RCheckFTAdaptor extends LWFTAdaptor implements FileFilter {

  private static class FPair implements Comparable<FPair> {
    File f;
    long mod;
    FPair(File f) {
      this.f = f;
      mod = f.lastModified();
    }
    /**
     * -1   implies this is LESS THAN o
     */
    @Override
    public int compareTo(FPair o) {
      if(mod < o.mod)
        return -1;
      else if (mod > o.mod)
        return 1;
      //want toWatch to be last after a rotation; otherwise, this is basically
      //just a heuristic that hasn't been tuned yet
      else return (o.f.getName().compareTo(f.getName()));
    }
  }

  long prevFileLastModDate = 0;
  LinkedList<FPair> fileQ = new LinkedList<FPair>();
  String fBaseName;
  File cur; //this is the actual physical file being watched.
            // in contrast, toWatch is the path specified by the user
  boolean caughtUp = false;
  /**
   * Check for date-modified and offset; if absent assume we just got a name.
   */
  @Override
  public String parseArgs(String params) {
    Pattern cmd = Pattern.compile("d:(\\d+)\\s+(\\d+)\\s+(.+)\\s?");
    Matcher m = cmd.matcher(params);
    if (m.matches()) {
      prevFileLastModDate = Long.parseLong(m.group(1));
      offsetOfFirstByte = Long.parseLong(m.group(2));
      toWatch = new File(m.group(3)).getAbsoluteFile();
    } else {
      toWatch = new File(params.trim()).getAbsoluteFile();
    }
    fBaseName = toWatch.getName();
    return toWatch.getAbsolutePath();
  }

  public String getCurrentStatus() {
    return type.trim() + " d:" + prevFileLastModDate + " "  + offsetOfFirstByte + " " + toWatch.getPath();
  }

  @Override
  public boolean accept(File pathname) {
    return pathname.getName().startsWith(fBaseName) &&
     ( pathname.getName().equals(fBaseName) ||
       pathname.lastModified() > prevFileLastModDate);
  }

  protected void mkFileQ() {

    File toWatchDir = toWatch.getParentFile();
    File[] candidates = toWatchDir.listFiles(this);
    if(candidates == null) {
      log.error(toWatchDir + " is not a directory in "+adaptorID);
    } else {
      log.debug("saw " + candidates.length + " files matching pattern");
      fileQ = new LinkedList<FPair>();
      for(File f:candidates)
        fileQ.add(new FPair(f));
      Collections.sort(fileQ);
    }
  }

  protected void advanceQ() {
    FPair next = fileQ.poll();
    if(next != null) {
      cur = next.f;
      caughtUp = toWatch.equals(cur);
      if(caughtUp && !fileQ.isEmpty())
        log.warn("expected rotation queue to be empty when caught up...");
    }
    else {
      cur = null;
      caughtUp = true;
    }
  }

  @Override
  public void start(long offset) {
    mkFileQ(); //figure out what to watch
    advanceQ();
    super.start(offset);
  }

  @Override
  public synchronized boolean tailFile()
  throws InterruptedException {
    boolean hasMoreData = false;
    try {

      if(caughtUp) {
        //we're caught up and watching an unrotated file
        mkFileQ(); //figure out what to watch
        advanceQ();
      }
      if(cur == null) //file we're watching doesn't exist
        return false;

      long len = cur.length();
      long tsPreTail = cur.exists() ? cur.lastModified() : prevFileLastModDate;

      if(log.isDebugEnabled())
        log.debug(adaptorID + " treating " + cur + " as " + toWatch + " len = " + len);

      if(len < fileReadOffset) {
        log.info("file "+ cur +" shrank from " + fileReadOffset + " to " + len);
        //no unseen changes to prev version, since mod date is older than last scan.
        offsetOfFirstByte += fileReadOffset;
        fileReadOffset = 0;
      } else if(len > fileReadOffset) {
        log.debug("slurping from " + cur+ " at offset " + fileReadOffset);
        RandomAccessFile reader = new RandomAccessFile(cur, "r");
        slurp(len, reader);
        reader.close();
      } else {
        //we're either caught up or at EOF
        if (!caughtUp) {
          prevFileLastModDate = cur.lastModified();
          //Hit EOF on an already-rotated file. Move on!
          offsetOfFirstByte += fileReadOffset;
          fileReadOffset = 0;
          advanceQ();
          log.debug("not caught up, and hit EOF.  Moving forward in queue to " + cur);
        } else
          prevFileLastModDate = tsPreTail;

      }

    } catch(IOException e) {
      log.warn("IOException in "+adaptorID, e);
      deregisterAndStop();
    }

    return hasMoreData;
  }

  public String toString() {
    return "Rotation-aware Tailer on " + toWatch;
  }
}


text:
from model_mommy import mommy
from apps.boards.forms import BoardPositionForm
from apps.core.tests.utils import LoggedTestCase
from apps.issues.models import Issue
from apps.issues.views import IssueDetailView

class IssueDetailDefaultTest(LoggedTestCase):
    def get_view(self):
        return IssueDetailView.as_view()

    def setUp(self):
        super(IssueDetailDefaultTest, self).setUp()
        self.issue = mommy.make(Issue)

    def test_should_have_board_form_on_context(self):
        self.response = self.view(self.request, pk=self.issue.pk)
        self.assertTrue(self.response.context_data.has_key('board_form'))
        self.assertIsInstance(self.response.context_data['board_form'], BoardPositionForm)

    def test_redirect_if_not_logged(self):
        self.assertRedirectIfNotLogged()

class IssueDetailViewTest(IssueDetailDefaultTest):

    def setUp(self):
        super(IssueDetailViewTest, self).setUp()
        self.response = self.view(self.request, pk=self.issue.pk)

    def test_should_use_the_correctly_template(self):
        self.response = self.view(self.request, pk=self.issue.pk)
        self.assertIn('issues/issue_detail.html', self.response.template_name)

class IssueDetailAjaxViewTest(IssueDetailDefaultTest):
    ajax = True

    def test_should_use_the_correctly_template(self):
        self.response = self.view(self.request, pk=self.issue.pk)
        self.assertIn('issues/issue_detail_ajax.html', self.response.template_name)


text:
from copy import deepcopy
import numpy as np

class TimeStep:
    def __init__(
        self,
        time,
        rectangles,
        internal_death_rate_fields,
        external_death_rate_fields,
        external_input_numbers,
    ):
        self.time = time
        self.rectangles = rectangles
        self.internal_death_rate_fields = internal_death_rate_fields
        self.external_death_rate_fields = external_death_rate_fields
        self.external_input_numbers = external_input_numbers

    @property
    def updated_content(self):
        res = deepcopy(self.rectangles)
        external_losses = res.external_losses(self.external_death_rate_fields)
        internal_losses = res.internal_losses(self.internal_death_rate_fields)
        res.remove(external_losses)
        res.remove(internal_losses)
        res.shift()  # move forward in time which increases size of the fields
        # res.incorporate_gains(internal_losses,external_input_numbers)
        gains = internal_losses.gains
        res.receive(gains)
        res.receive_external(self.external_input_numbers)
        return res