Path manipulation black magic
355167
def path(path_name=None, override=None, *, root=None, name=None, ext=None,
         inject=None, relpath=None, reduce=False):
    
    path_name, identity, root = _initialize(path_name, override, root, inject)
    new_name = _process_name(path_name, identity, name, ext)
    new_directory = _process_directory(path_name, identity, root, inject)
    full_path = os.path.normpath(os.path.join(new_directory, new_name))
    if APPEND_SEP_TO_DIRS and not new_name and full_path[-1] != os.sep:
        full_path += os.sep
    final_path = _format_path(full_path, root, relpath, reduce)
    return final_path
192718
function temporaryWindowsPathFix (path, parentPath) {
  if (process.platform === 'win32') {
    let secondSlashIndex = path.indexOf('/', 1)
    let firstSegment = path.slice(1, secondSlashIndex)
    if (parentPath.endsWith(firstSegment)) {
      return path.slice(secondSlashIndex)
    }
  }
  return path
}
962959
function rotatePaths(paths, angle) {
            if (!angle) {
                return paths;
            }

            var bound = computeBoundingBox.computePath.apply(null, paths);

            var cx = bound.x + (bound.width) / 2;
            var cy = bound.y + (bound.height) / 2;

            paths.forEach(function (p) {
                pathRotate(p, angle, cx, cy);
            });

            return paths;
        }
357621
function makeAcyclic(g) {
    var onStack = {};
    var visited = {};

    function dfs(u) {
      if (u in visited) {
        return;
      }
      visited[u] = true;
      onStack[u] = true;
      g.successors(u).forEach(function(v) {
        if (v in onStack) {
          g.addEdge(v, u);
          g.removeEdge(u, v);
        } else {
          dfs(v);
        }
      });
      delete onStack[u];
    }

    g.nodes().forEach(function(u) {
      dfs(u);
    });
  }
1133455
function updatePathGuides(parent) {
	var handles = parent._handles,
		guides = parent._guides,
		handle, h,
		guide, g;
	if (parent._method === $.fn.drawQuadratic) {
		if (handles) {
			guide = parent._guide;
			if (guide) {
				for (h = 0; h < handles.length; h += 1) {
					handle = parent._handles[h];
					guide['x' + (h + 1)] = handle.x;
					guide['y' + (h + 1)] = handle.y;
				}
			}
		}
	} else if (parent._method === $.fn.drawBezier) {
		if (guides) {
			for (g = 0; g < guides.length; g += 1) {
				guide = guides[g];
				handles = guide._handles;
				if (guide && handles) {
					for (h = 0; h < handles.length; h += 1) {
						handle = handles[h];
						guide['x' + (h + 1)] = handle.x;
						guide['y' + (h + 1)] = handle.y;
					}
				}
			}
		}
	}
}
523593
function transformPath (bgp, group, options) {
  let i = 0
  var queryChange = false
  var ret = [bgp, null, []]
  while (i < bgp.length && !queryChange) {
    var curr = bgp[i]
    if (typeof curr.predicate !== 'string' && curr.predicate.type === 'path') {
      switch (curr.predicate.pathType) {
        case '/':
          ret = pathSeq(bgp, curr, i, group, ret[2], options)
          if (ret[1] != null) {
            queryChange = true
          }
          break
        case '^':
          ret = pathInv(bgp, curr, i, group, ret[2], options)
          if (ret[1] != null) {
            queryChange = true
          }
          break
        case '|':
          ret = pathAlt(bgp, curr, i, group, ret[2], options)
          queryChange = true
          break
        case '!':
          ret = pathNeg(bgp, curr, i, group, ret[2], options)
          queryChange = true
          break
        default:
          break
      }
    }
    i++
  }
  return ret
}
618651
private function path_tracer() {
		
		//TODO: consider working out how to trace paths one at a time, so the list of valid paths comes back in a more predictable manner.
		
		$tracerData = array();
		$this->validPaths = array();
		//build the initial tracerData for exploring the depths of this beastly array...
		foreach($this->data as $path=>$data) {
			if(is_array($data)) {
				$tracerData[] = array(
					'path'	=> "/". $path,
					'data'	=> $data
				);
			}
			else {
				//initial key ($path) doesn't have an array beneath it, so it's a blank root path.
				$this->validPaths[] = '/'. $path;
			}
		}
		
		//If we have anything left, we'll need to do some crazy while() looping madness.
		if(is_array($tracerData) && count($tracerData)) {
			while($myData = array_shift($tracerData)) {
				if(is_array($myData['data']) && count($myData['data'])) {
					$basePath = $myData['path'];
					foreach($myData['data'] as $key=>$val) {
						$tracerData[] = array(
							'path'	=> $basePath .'/'. $key,
							'data'	=> $val
						);
					}
				}
				else {
					$this->validPaths[] = $myData['path'];
				}
			}
		}
		
		
	}
901319
def expand_magic_path(aPath,aBasePath=nil)
			aBasePath ||= Dir.pwd
			path = aPath
			if path.begins_with?('...')
				rel_part = path.split3(/\.\.\.[\/\\]/)[2]
				return find_upwards(aBasePath,rel_part)
			end
			path_combine(aBasePath,aPath)
		end
983248
function (target, path, traverseArrays) {
      
      // if traversing arrays is enabled and this is an array, loop
      // may be a "array-like" node list (or similar), in which case it needs to be converted
      if (traverseArrays && Sysmo.isArrayLike(target)) {
        
        target = Sysmo.makeArray(target);
        
        var children = [];
        
        for (var i = 0; i < target.length; i++) {
          // recursively loop through children
          var child = Sysmo.getDeepValue(target[i], path, traverseArrays);
          
          // ignore if undefined
          if (typeof child != "undefined") {
            //flatten array because the original path points to one flat result set
            if (Sysmo.isArray(child)) {
              
              for (var j = 0; j < child.length; j++) {
                children.push(child[j]);
              }
              
            } else {
              
              children.push(child);
              
            }
          }
        }
        
        return (children.length) ? children : void(0);
      }
      
      var invoke_regex = /\(\)$/,
          properties = path.split('.'),
          property;

      if (target != null && properties.length) {
        
        var propertyName = properties.shift(),
            invoke = invoke_regex.test(propertyName)
        
        if (invoke) {
          propertyName = propertyName.replace(invoke_regex, "");
        }
        
        if (invoke && propertyName in target) {
          target = target[propertyName]();
        } else {
          target = target[propertyName];
        }
        
        path = properties.join('.');
        
        if (path) {
          target = Sysmo.getDeepValue(target, path, traverseArrays);
        }
      }
      
      return target;
    }
317801
function updatePathHandles(parent) {
	var handles = parent._handles,
		handle, h;
	if (handles) {
		// Move handles when dragging
		for (h = 0; h < handles.length; h += 1) {
			handle = handles[h];
			handle.x = parent[handle._xProp] + parent.x;
			handle.y = parent[handle._yProp] + parent.y;
		}
	}
	updatePathGuides(parent);
}
1177059
def find_path(start, goal, neighbors_fnct, reversePath=False, heuristic_cost_estimate_fnct=lambda a, b: Infinite, distance_between_fnct=lambda a, b: 1.0, is_goal_reached_fnct=lambda a, b: a == b):
    """"""
    class FindPath(AStar):

        def heuristic_cost_estimate(self, current, goal):
            return heuristic_cost_estimate_fnct(current, goal)

        def distance_between(self, n1, n2):
            return distance_between_fnct(n1, n2)

        def neighbors(self, node):
            return neighbors_fnct(node)

        def is_goal_reached(self, current, goal):
            return is_goal_reached_fnct(current, goal)
    return FindPath().astar(start, goal, reversePath)
412514
function inShadow(key) {
  var path = this;
  do {
    if (path.isFunction()) {
      var shadow = path.node.shadow;
      if (shadow) {
        // this is because sometimes we may have a `shadow` value of:
        //
        //   { this: false }
        //
        // we need to catch this case if `inShadow` has been passed a `key`
        if (!key || shadow[key] !== false) {
          return path;
        }
      } else if (path.isArrowFunctionExpression()) {
        return path;
      }

      // normal function, we've found our function context
      return null;
    }
  } while (path = path.parentPath);
  return null;
}
1203
def scary_path(path):
    
    if not path:
        return True
    assert isinstance(path, bytes)
    return not NOT_SCARY.match(path)
760630
def pathstrip(path, n):
  
  pathlist = [path]
  while os.path.dirname(pathlist[0]) != b'':
    pathlist[0:1] = os.path.split(pathlist[0])
  return b'/'.join(pathlist[n:])
41402
function build_full_paths(FI, FPD, FP, Paths) {
	var i = 0, L = 0, R = 0, C = 0, j = 0, pl = Paths.length;
	var dad = new Array(pl), q = new Array(pl);

	for(; i < pl; ++i) { dad[i]=q[i]=i; FP[i]=Paths[i]; }

	for(; j < q.length; ++j) {
		i = q[j];
		L = FI[i].L; R = FI[i].R; C = FI[i].C;
		if(dad[i] === i) {
			if(L !== -1 /*NOSTREAM*/ && dad[L] !== L) dad[i] = dad[L];
			if(R !== -1 && dad[R] !== R) dad[i] = dad[R];
		}
		if(C !== -1 /*NOSTREAM*/) dad[C] = i;
		if(L !== -1) { dad[L] = dad[i]; q.push(L); }
		if(R !== -1) { dad[R] = dad[i]; q.push(R); }
	}
	for(i=1; i !== pl; ++i) if(dad[i] === i) {
		if(R !== -1 /*NOSTREAM*/ && dad[R] !== R) dad[i] = dad[R];
		else if(L !== -1 && dad[L] !== L) dad[i] = dad[L];
	}

	for(i=1; i < pl; ++i) {
		if(FI[i].type === 0 /* unknown */) continue;
		j = dad[i];
		if(j === 0) FP[i] = FP[0] + "/" + FP[i];
		else while(j !== 0) {
			FP[i] = FP[j] + "/" + FP[i];
			j = dad[j];
		}
		dad[i] = 0;
	}

	FP[0] += "/";
	for(i=1; i < pl; ++i) {
		if(FI[i].type !== 2 /* stream */) FP[i] += "/";
		FPD[FP[i]] = FI[i];
	}
}
744102
function(p) {

            if (!p) return false;

            var segments = this.segments;
            var otherSegments = p.segments;

            var numSegments = segments.length;
            if (otherSegments.length !== numSegments) return false; // if the two paths have different number of segments, they cannot be equal

            for (var i = 0; i < numSegments; i++) {

                var segment = segments[i];
                var otherSegment = otherSegments[i];

                // as soon as an inequality is found in segments, return false
                if ((segment.type !== otherSegment.type) || (!segment.equals(otherSegment))) return false;
            }

            // if no inequality found in segments, return true
            return true;
        }
1354939
function walk(obj, path, initializeMissing = false) {
  let newObj = obj;

  if (path) {
    const ar = path.split('.');
    while (ar.length) {
      const k = ar.shift();
      if (initializeMissing && obj[k] == null) {
        newObj[k] = {};
        newObj = newObj[k];
      } else if (k in newObj) {
        newObj = newObj[k];
      } else {
        throw new Error(`cannot find configuration param '${path}'`);
      }
    }
  }

  return newObj;
}