Find position of the first and last base
424490
def get_left_right(seq):
    
    cseq = seq.strip(GAPS)
    leftjust = seq.index(cseq[0])
    rightjust = seq.rindex(cseq[-1])

    return leftjust, rightjust
1146032
def __get_depth(root):
    
    if root is None:
        return 0
    left  = __get_depth(root.left)
    right = __get_depth(root.right)
    if abs(left-right) > 1 or -1 in [left, right]:
        return -1
    return 1 + max(left, right)
354629
def find_base(path):
	""""""
	result = _pattern.match(path)

	if result:
		base = result.group(0)
	else:
		base = "./"

	if base.endswith('/') or base.endswith('\\'):
		return os.path.abspath(base)
	else:
		return os.path.dirname(os.path.abspath(base))
458400
function (coords) {
        var base = {
                ref: this.ref,
                length: this.length,
                cycles: this.cycles
            },
            position,
            iteration;

        if (!_.isObject(coords)) {
            return _.assign(base, {eof: true, bof: true, empty: this.empty()});
        }
        if (!this.length) {
            return _.assign(base, {eof: true, bof: true, empty: true});
        }

        position = coords.position;
        iteration = coords.iteration;

        // increment position
        position += 1;

        // check if we need to increment cycle
        if (position >= this.length) {
            // set position to 0 and increment iteration
            position = 0;
            iteration += 1;

            if (iteration >= this.cycles) {
                return _.assign(base, {
                    position: this.length - 1,
                    iteration: iteration - 1,
                    eof: true
                });
            }

            return _.assign(base, {
                position: position,
                iteration: iteration,
                cr: true
            });
        }

        return _.assign(base, {position: position, iteration: iteration});
    }
1041804
function findClosest(c) {

    if (colorTab === null) return -1;
    var r = (c & 0xFF0000) >> 16;
    var g = (c & 0x00FF00) >> 8;
    var b = (c & 0x0000FF);
    var minpos = 0;
    var dmin = 256 * 256 * 256;
    var len = colorTab.length;

    for (var i = 0; i < len;) {
      var dr = r - (colorTab[i++] & 0xff);
      var dg = g - (colorTab[i++] & 0xff);
      var db = b - (colorTab[i] & 0xff);
      var d = dr * dr + dg * dg + db * db;
      var index = i / 3;
      if (usedEntry[index] && (d < dmin)) {
        dmin = d;
        minpos = index;
      }
      i++;
    }
    return minpos;
  }
1328470
function(colorStops) {
			var from = 0;
			
			colorStops.forEach(function(cs, i) {
				// make sure that first and last positions are defined
				if (!i) {
					return cs.position = cs.position || 0;
				}
				
				if (i == colorStops.length - 1 && !('position' in cs)) {
					cs.position = 1;
				}
				
				if ('position' in cs) {
					var start = colorStops[from].position || 0;
					var step = (cs.position - start) / (i - from);
					colorStops.slice(from, i).forEach(function(cs2, j) {
						cs2.position = start + step * j;
					});
					
					from = i;
				}
			});
		}
1269914
function(first, second) {
			var start = 0;
			var max = 0;

			for (var i = 0; i < first.length; i++) {
				for (var j = 0; j < second.length; j++) {
					var x = 0;
					while (first[i + x] === second[j + x]) {
						x++;
						if ((i + x >= first.length) || (j + x >= second.length)) {
							break;
						}
					}
					if (x > max) {
						max = x;
						start = i;
					}
				}
			}

			return first.slice(start, start + max);
		}
149378
function findPositions(getInner, getOuter, thingsToMeasure) {
        var tablePositions = [];

        // Skip the first item in the array = no left (LTR), right (RTL) or top bars
        for (var i = 1; i < thingsToMeasure.length; i++) {
          // Get the element from the details
          var item = thingsToMeasure[i].element;

          // We need to zero index this again
          tablePositions.push(getInner(i - 1, item));
        }

        var lastTableLineToMake = thingsToMeasure[thingsToMeasure.length - 1];
        tablePositions.push(getOuter(thingsToMeasure.length - 1, lastTableLineToMake.element));

        return tablePositions;
      }
55773
function getDirectionPositionForRange (value, min, max, orientation) {
  return isVertical(orientation) ? (
    // as upper value is used to calculate `top`;
    Math.round(((max - value[1]) / max - min) * 100)
  ) : (
    Math.round((value[0] / max - min) * 100)
  );
}
418132
def bottom(self, z=0, radius=0, degrees=0, reference=None):
        
        coordinates = self.from_center(
            r=radius,
            theta=(degrees / 180) * math.pi,
            h=-1,
            reference=reference)
        return (self, coordinates + (0, 0, z))
984431
void calcFirstPos(RBBINode n) {
           if (n == null) {
               return;
           }
           if (n.fType == RBBINode.leafChar  ||
               n.fType == RBBINode.endMark   ||
               n.fType == RBBINode.lookAhead ||
               n.fType == RBBINode.tag) {
               // These are non-empty leaf node types.
               n.fFirstPosSet.add(n);
               return;
           }

           // The node is not a leaf.
           //  Calculate firstPos on its children.
           calcFirstPos(n.fLeftChild);
           calcFirstPos(n.fRightChild);

           // Apply functions from table 3.40 in Aho
           if (n.fType == RBBINode.opOr) {
               n.fFirstPosSet.addAll(n.fLeftChild.fFirstPosSet);
               n.fFirstPosSet.addAll(n.fRightChild.fFirstPosSet);
           }
           else if (n.fType == RBBINode.opCat) {
               n.fFirstPosSet.addAll(n.fLeftChild.fFirstPosSet);
               if (n.fLeftChild.fNullable) {
                   n.fFirstPosSet.addAll(n.fRightChild.fFirstPosSet);
               }
           }
           else if (n.fType == RBBINode.opStar ||
                    n.fType == RBBINode.opQuestion ||
                    n.fType == RBBINode.opPlus) {
               n.fFirstPosSet.addAll(n.fLeftChild.fFirstPosSet);
           }
       }
1178076
private function position($pos, $oldWidth, $oldHeight, $waterWidth, $waterHeight, $isText = false, $fontSize = 14)
    {
        if ( is_array($pos) )
        {
            return [
                'x' => $pos[0],
                'y' => $pos[1]
            ];
        }

        if ($pos === self::POS_TOP_LEFT)
        {
            $posX = 0;
            $posY = ($isText) ? $waterHeight : 0;
        }
        elseif ($pos === self::POS_TOP_CENTER)
        {
            $posX = ($oldWidth - $waterWidth) / 2;
            $posY = ($isText) ? $waterHeight : 0;
        }
        elseif ($pos === self::POS_TOP_RIGHT)
        {
            $posX = $oldWidth - $waterWidth;
            $posY = ($isText) ? $waterHeight : 0;
        }
        elseif ($pos === self::POS_CENTER_LEFT)
        {
            $posX = 0;
            $posY = ($isText) ? (($oldHeight - $waterHeight) / 2) + $fontSize : ($oldHeight - $waterHeight) / 2;
        }
        elseif ($pos === self::POS_CENTER_CENTER)
        {
            $posX = ($oldWidth - $waterWidth) / 2;
            $posY = ($isText) ? (($oldHeight - $waterHeight) / 2) + $fontSize : ($oldHeight - $waterHeight) / 2;
        }
        elseif ($pos === self::POS_CENTER_RIGHT)
        {
            $posX = $oldWidth - $waterWidth;
            $posY = ($isText) ? (($oldHeight - $waterHeight) / 2) + $fontSize : ($oldHeight - $waterHeight) / 2;
        }
        elseif ($pos === self::POS_BOTTOM_LEFT)
        {
            $posX = 0;
            $posY = ($isText) ? ($oldHeight - $waterHeight) + $fontSize : $oldHeight - $waterHeight;
        }
        elseif ($pos === self::POS_BOTTOM_CENTER)
        {
            $posX = ($oldWidth - $waterWidth) / 2;
            $posY = ($isText) ? ($oldHeight - $waterHeight) + $fontSize : $oldHeight - $waterHeight;
        }
        elseif ($pos === self::POS_BOTTOM_RIGHT)
        {
            $posX = $oldWidth - $waterWidth;
            $posY = ($isText) ? ($oldHeight - $waterHeight) + $fontSize : $oldHeight - $waterHeight;
        }
        else
        {
            $posX = rand(0, ($oldWidth  - $waterWidth));
            $posY = rand(0, ($oldHeight - $waterHeight));
        }

        return [
            "x" => $posX,
            "y" => $posY
        ];
    }
832084
def bottom(self):
        """"""
        if self._has_real():
            return self._data.real_bottom
        return self._data.bottom
443918
def get_position(self):
        """"""
        rect = _Rect()
        GetWindowRect(self._hwnd, ctypes.pointer(rect))
        return rect.left, rect.top, rect.right, rect.bottom
519087
function findNodeBeforePos(pos) {
    const lut = this.ends;
    assert(is.finitenumber(pos) && pos >= 0);

    let left = 0;
    let right = lut.length - 1;
    while (left < right) {
        const mid = Math.ceil((left + right) / 2);
        assert(mid >= 0 && mid < lut.length);
        if (pos < lut[mid].range[1]) {
            right = mid - 1;
        }
        else {
            left = mid;
        }
    }
    if (left > right) {
        assert(lut[0].range[1] > pos);
        return null;
    }

    const found = left;
    const foundPos = lut[found].range[1];
    if(foundPos > pos) {
        return null;
    }
    if (found <= lut.length - 2) {
        const nextPos = lut[found + 1].range[1];
        assert(nextPos > pos);
    }

    return lut[found];
}
627257
def positions(self, reverse=False):
        """"""
        def Posgen(reverse):
            if reverse:
                lastrootsib = self.last_sibling_position(self.root)
                current = self.last_decendant(lastrootsib)
                while current is not None:
                    yield current
                    current = self.prev_position(current)
            else:
                current = self.root
                while current is not None:
                    yield current
                    current = self.next_position(current)
        return Posgen(reverse)
723021
private int findLast(CharSequence input, int beginIndex) {
        boolean firstInSubDomain = true;
        boolean canEndSubDomain = false;
        int firstDot = -1;
        int last = -1;
        for (int i = beginIndex; i < input.length(); i++) {
            char c = input.charAt(i);
            if (firstInSubDomain) {
                if (subDomainAllowed(c)) {
                    last = i;
                    firstInSubDomain = false;
                    canEndSubDomain = true;
                } else {
                    break;
                }
            } else {
                if (c == '.') {
                    if (!canEndSubDomain) {
                        break;
                    }
                    firstInSubDomain = true;
                    if (firstDot == -1) {
                        firstDot = i;
                    }
                } else if (c == '-') {
                    canEndSubDomain = false;
                } else if (subDomainAllowed(c)) {
                    last = i;
                    canEndSubDomain = true;
                } else {
                    break;
                }
            }
        }
        if (domainMustHaveDot && (firstDot == -1 || firstDot > last)) {
            return -1;
        } else {
            return last;
        }
    }