Old/original duo code
main problem was all the hard coding of paths
162809
static function __duo($masterfile, $palette = null, $tint = null, array $overrides = null)
	{
		//	THEME vs. SCHEME vs. SKIN
		//	Theme = light/dark! AKA `tint` in the current system ... ie. `What theme would you like?` asking the user to choose a color scheme!
		//	Scheme = `Color Scheme` = club/brand colors = several headers/borders colored with this color scheme
		//	Skin = related to Scheme ... The club/brand skin is the backgrounds, like watermarks, background images representing a club/brand!
		static $basepath = '../app/duo/';
		static $cachepath = '../app/duo/cache/';
		static $duos = array();
		if (!isset($duos[$masterfile])) $duos[$masterfile] = require($basepath . $masterfile . '.php');
		$arr =& $duos[$masterfile];
		$files = array();
		$max_mtime = 0;
		if ($palette === null && $tint === null && $overrides === null)
		{
			if (isset($arr['static']))
				foreach ($arr['static'] as $static)
				{
					$mtime = filemtime($basepath . $static);
					$max_mtime = max($max_mtime, $mtime);
					$files[] = $cachepath . pathinfo($static, PATHINFO_FILENAME) . '-' . $mtime . /* '-' . md5($static) */ '.css';
				}
			$global_md5 = md5(serialize($arr['global']));
			foreach ($arr['themeable'] as $themeable)
			{
				$mtime = filemtime($basepath . $themeable);
				$max_mtime = max($max_mtime, $mtime);
				$files[] = $cachepath . pathinfo($themeable, PATHINFO_FILENAME) . '-' . $mtime . '-' . $global_md5 . '.css';
			}
			$result = 'styles/duo-' . $max_mtime . '-' . md5(serialize($files)) . '.css';
			if (file_exists($result)) return $result;
			//
			//	Global/base style file doesn't exists, create a new one!
			//
			$result_contents = null;	//	contents of the final file!
			require_once APP_LIB . 'duocss.php';
			$index = 0;	//	$files[$index] ... because static messes up the counter! ... can't we just add the count($arr['static']) ???
			if (isset($arr['static']))
				foreach ($arr['static'] as $static)
				{
					if (!file_exists($files[$index]))
					{
						$result_contents .= $contents = minify_css(file_get_contents($basepath . $static));
						file_put_contents($files[$index], $contents);
					}
					else
						$result_contents .= file_get_contents($files[$index]);
					$index++;
				}
			$global_keys = array_keys($arr['global']);	//	Get the global keys for str_replace()
			foreach ($arr['themeable'] as $themeable)
			{
				if (!file_exists($files[$index]))
				{
					$pattern = array();	//	Remove ALL lines with palette styles! Even if they include global styles!
					foreach ($arr['palette'] as $key => $unused)		//	We run the preg_replace() first, because it will reduce the contents, making str_replace() slightly faster!
						$pattern[] = '~[^{;]*' . $key . '[^;}]*;?~';
					//	We need to minify FIRST, because there might be some comments with styles! eg. border: BORDER /* BORDER-OLD */; But there might be other cases that screw up the regular expressions!
					$result_contents .= $contents = minify_css(str_replace($global_keys, $arr['global'], preg_replace($pattern, '', minify_css(file_get_contents($basepath . $themeable)))));
					file_put_contents($files[$index], $contents);
				}
				else
					$result_contents .= file_get_contents($files[$index]);
				$index++;
			}
			file_put_contents($result, $result_contents);
			return $result;
		}
		else
		{
		//	There `should` be too many variables and tints for an array_merge() to be feasable/viable! Also, this cannot account for $arr['palette'][$tint] coming before loading the palette file!
		//	$palettes = $palette === null ? $arr['palette'] : array_merge($arr['palette'], require '../app/duo/palettes/' . $palette . '.php');
			//
			//	Generate Palette
			//
			if ($palette !== null) $palette = require '../app/duo/palettes/' . $palette . '.php';
			//	`$files` is currently a blank array, so we use it as an empty array paceholder
			$palette = array_merge($arr['palette'], isset($arr['tints'][$tint]) ? $arr['tints'][$tint] : $files, isset($palette[0]) ? $palette[0] : $files, isset($palette[$tint]) ? $palette[$tint] : $files, $overrides === null ? $files : $overrides);
			//	Create an md5 hash of the palette. Used as part of the filename in each cached themeable file!
			$palette_md5 = md5(serialize($palette));	//	. serialize($arr['global']) .... DISABLED (the serialize) FOR NOW!  TEST  IT !! The reason why we need to include the global, is in-case a global value changed ... HOWEVER, in that case, wouldn't the files also change ??? However again, we might be using dynamic overrides !?!?
			//	Add each `themeable` file to the files array! To be serialized and md5 hashed later to test the existance of the final file!
			foreach ($arr['themeable'] as $themeable)
			{
				$mtime = filemtime($basepath . $themeable);
				$max_mtime = max($max_mtime, $mtime);
				$files[] = $cachepath . pathinfo($themeable, PATHINFO_FILENAME) . '-' . $mtime . '-' . $palette_md5 . '.css';
			}
			$result = 'styles/duo-' . $max_mtime . '-' . md5(serialize($files)) . '.css';
			if (file_exists($result)) return $result;
			//
			//	Public styled palette doesn't exist; test the existence of each cached themeable file
			//
			$result_contents = null;	//	contents of the final file!
			require_once APP_LIB . 'duocss.php';
			$keys = array_merge(array_keys($arr['global']), array_keys($arr['palette']));	//	Create an array of the merged global and palette keys!
			$keys_md5 = md5(serialize($keys));
			$patterns = array();
			//	Build an array of keys to extract! We will split each file into class names and content, then scan the content for our keys and extract them!
			foreach ($keys as $key)
				$patterns[] = '~[^;]*' . $key . '[^;]*~';
			$global_keys = array_keys($arr['global']);
			$palette_keys = array_keys($palette);
			$palette_patterns = array();
			foreach ($palette_keys as $key)
				$palette_patterns[] = '~[^;]*' . $key . '[^;]*~';	//	Build the palette patterns! Once we split the cached contents into classes and attributes, then we can run these patterns!

			foreach ($arr['themeable'] as $key => $themeable)
			{
				if (!file_exists($files[$key]))
				{	//	First test for the intermediate cached file. This file contains ALL the possible styleable global and palette variables/attributes/styles.
					$mtime = filemtime($basepath . $themeable);
					$filename = pathinfo($themeable, PATHINFO_FILENAME);
					$cache = $cachepath . $filename . '-' . $mtime . '-' . $keys_md5 . '.css';
					if (!file_exists($cache))
					{	//	Create the intermediate cached file with ALL possible overwriteable styles!
						$path = $basepath . $themeable;
						$contents = minify_css(file_get_contents($path));	//	Minify the contents, mainly to remove the comments, because they CAN interfere with the class names and the regular expression matches (because they can contain the following characters {;} !!!
						preg_match_all('~([^{;}]+){([^{}]+)}~', $contents, $split);	//	Split the file into classes and content!	eg. html{overflow:auto} => `html` && `overflow:auto`
						$preserve = array();	//	classes and attributes/styles to preserve, basically we `remove` all the styles which are not configurable (we do this by INCLUDING only valid styleable classes and attributes here)! Leaving only styles that include a global or palette constant!
						foreach ($split[2] as $index => $value)	//	loop through each class and attribute list and extract the customizeable styles!
							foreach ($patterns as $pattern)
								if (preg_match_all($pattern, $value, $matches))	//	our `$patterns` don't actually capture anything, so we are able to use $matches[0]!
									if (isset($preserve[$split[1][$index]]))
										$preserve[$split[1][$index]] .= ';' . implode(';', $matches[0]);
									else
										$preserve[$split[1][$index]] = implode(';', $matches[0]);
						$contents = ''; // reset & rebuild contents with our `preserved` classes and constants!
						foreach ($preserve as $class => $style)
							$contents .= $class . '{' . $style . '}';
						file_put_contents($cache, $contents);
					}
					else
						$contents = file_get_contents($cache);

					//	Now we have the intermediate content, which includes both global and palette styles! Now we need to extract only the styles we need! For example, many `global` styles will be dropped here!
					preg_match_all('~([^{;}]+){([^{}]+)}~', $contents, $split);
					$preserve = array();
					foreach ($split[2] as $index => $value)
						foreach ($palette_patterns as $pattern)
							if (preg_match_all($pattern, $value, $matches))
								if (isset($preserve[$split[1][$index]]))
									$preserve[$split[1][$index]] .= ';' . implode(';', $matches[0]);
								else
									$preserve[$split[1][$index]] = implode(';', $matches[0]);
					$contents = '';	//	rebuild the contents, unused styles should have been removed!?!?
					foreach ($preserve as $class => $style)
						$contents .= $class . '{' . $style . '}';

				/*	//	This is only necessary if we use the str_replace() variant !!!
					if (!env::$production && preg_match_all('|[A-Z]{2,}(?:-[A-Z]{2,})+|', $contents, $matches))
						foreach ($matches[0] as $match)
							if (!isset($palette[$match]))
								die('<b>ERROR</b> finding the CSS variable: <b>' . $match . '</b> in file: <b>' . $themeable);
				*/

					// Now we have rebuilt the content, we need to replace the style placeholders!
					//	First, we replace the PALETTE styles, which could include global style overrides! THEN we place the global styles, if there are any left over! This has to be done if we've mixed palette with global styles! eg. border: BORDER-WIDTH BORDER-COLOR ... where BORDER-WIDTH might be a global, and BORDER-COLOR is a palette value!
				//	$result_contents .= $contents = str_replace($global_keys, $arr['global'], str_replace($palette_keys, $palette, $contents));	//	we `could` run the minifier AGAIN, but it's already 99.9% minified! For example, the placeholders could be unminified eg. `BORDER` => `0 0 0 0` instead of just 0 ... or `0px` instead of 0
					$result_contents .= $contents = preg_replace_callback('|[A-Z]{2,}(?:-[A-Z]{2,})+|', function($matches)use($palette){return $palette[$matches[0]];}, $contents);	// The preg_replace_callback() variant was about 30% faster than str_replace() on a very large file (about +200K)! They still executed at 0.01s vs. 0.007 on a very large file with 30 other files!

					file_put_contents($files[$key], $contents);
				}
				else
					$result_contents .= file_get_contents($files[$key]);
			}

			file_put_contents($result, $result_contents);
			return $result;
		}
	}
71697
def fix_code(code, directory):
    
    if not autopep8:
        raise Fault('autopep8 not installed, cannot fix code.',
                    code=400)
    old_dir = os.getcwd()
    try:
        os.chdir(directory)
        return autopep8.fix_code(code, apply_config=True)
    finally:
        os.chdir(old_dir)
971118
def path2unix(path, nojoin=False, fromwinpath=False):
    ''''''
    if fromwinpath:
        pathparts = list(PureWindowsPath(path).parts)
    else:
        pathparts = list(PurePath(path).parts)
    if nojoin:
        return pathparts
    else:
        return posixpath.join(*pathparts)
1299869
function getFromOld(old, pieces) {

	var length = pieces.length,
	    result,
	    path,
	    rest,
	    i;

	for (i = 0; i < length; i++) {
		path = pieces.slice(0, length - i).join('.');

		result = old[path];

		if (typeof result != 'undefined') {

			if (i == 0) {
				return result;
			}

			rest = pieces.slice(pieces.length - i);

			result = retrieveFromPath(result, rest);

			if (typeof result != 'undefined') {
				return result;
			}
		}
	}
}
771346
function setPathSet(
    value, path, depth, root, parent, node,
    requestedPaths, optimizedPaths, requestedPath, optimizedPath,
    version, expired, lru, comparator, errorSelector, replacedPaths) {

    var note = {};
    var branch = depth < path.length - 1;
    var keySet = path[depth];
    var key = iterateKeySet(keySet, note);
    var optimizedIndex = optimizedPath.index;

    do {

        requestedPath.depth = depth;

        var results = setNode(
            root, parent, node, key, value,
            branch, false, requestedPath, optimizedPath,
            version, expired, lru, comparator, errorSelector, replacedPaths
        );
        requestedPath[depth] = key;
        requestedPath.index = depth;
        optimizedPath[optimizedPath.index++] = key;
        var nextNode = results[0];
        var nextParent = results[1];
        if (nextNode) {
            if (branch) {
                setPathSet(
                    value, path, depth + 1,
                    root, nextParent, nextNode,
                    requestedPaths, optimizedPaths, requestedPath, optimizedPath,
                    version, expired, lru, comparator, errorSelector
                );
            } else {
                requestedPaths.push(requestedPath.slice(0, requestedPath.index + 1));
                optimizedPaths.push(optimizedPath.slice(0, optimizedPath.index));
            }
        }
        key = iterateKeySet(keySet, note);
        if (note.done) {
            break;
        }
        optimizedPath.index = optimizedIndex;
    } while (true);
}
156606
@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
    public static void fixPlatformPaths() {
        if (System.getProperty(LIB_PROP) == null) {
            // Set necessary parameters for seamless PC/SC access.
            // http://ludovicrousseau.blogspot.com.es/2013/03/oracle-javaxsmartcardio-failures.html
            if (System.getProperty("os.name").equalsIgnoreCase("Linux")) {
                // Only try loading 64b paths if JVM can use them.
                if (System.getProperty("os.arch").contains("64")) {
                    if (new File(debian64_path).exists()) {
                        System.setProperty(LIB_PROP, debian64_path);
                    } else if (new File(fedora64_path).exists()) {
                        System.setProperty(LIB_PROP, fedora64_path);
                    } else if (new File(ubuntu64_path).exists()) {
                        System.setProperty(LIB_PROP, ubuntu64_path);
                    }
                } else if (new File(ubuntu_path).exists()) {
                    System.setProperty(LIB_PROP, ubuntu_path);
                } else if (new File(ubuntu32_path).exists()) {
                    System.setProperty(LIB_PROP, ubuntu32_path);
                } else if (new File(raspbian_path).exists()) {
                    System.setProperty(LIB_PROP, raspbian_path);
                } else {
                    // XXX: dlopen() works properly on Debian OpenJDK 7
                    // System.err.println("Hint: pcsc-lite probably missing.");
                }
            } else if (System.getProperty("os.name").equalsIgnoreCase("FreeBSD")) {
                if (new File(freebsd_path).exists()) {
                    System.setProperty(LIB_PROP, freebsd_path);
                } else {
                    System.err.println("Hint: pcsc-lite is missing. pkg install devel/libccid");
                }
            }
        } else {
            // TODO: display some helpful information?
        }
    }
978791
def resolve_relpath(self, fullname, level):
        
        mod = sys.modules.get(fullname, None)
        if hasattr(mod, '__path__'):
            fullname += '.__init__'

        if level == 0 or not fullname:
            return ''

        bits = fullname.split('.')
        if len(bits) <= level:
            # This would be an ImportError in real code.
            return ''

        return '.'.join(bits[:-level]) + '.'
166822
function reformatPaths(paths) {
	let output = {};
	
	if (!paths) {
		return output;
	}
	
	let pathsKeys = Object.keys(paths);
	
	pathsKeys.forEach(function (eachKey) {
		let newKey = eachKey;
		
		if (eachKey.includes("{") && eachKey.includes("}")) {
			// replace : {params} by :params
			newKey = newKey.replace(new RegExp('{', 'g'), ':');
			newKey = newKey.replace(new RegExp('}', 'g'), '');
		}
		
		output[newKey] = paths[eachKey];
	});
	
	return output;
}
1063062
@Override
  public PathImpl schemeWalk(String userPath,
                         Map<String,Object> newAttributes,
                         String uri,
                         int offset)
  {
    int length = uri.length();

    if (length < 2 + offset
        || uri.charAt(offset) != '/'
        || uri.charAt(1 + offset) != '/')
      throw new RuntimeException("bad scheme");

    CharBuffer buf = new CharBuffer();
    int i = 2 + offset;
    int ch = 0;
    boolean isIpv6 = false;
    
    for (; 
          (i < length
           && (ch = uri.charAt(i)) != '/'
           && ch != '?'
           && ! (ch == ':' && ! isIpv6));
         i++) {
      if (ch == '[')
        isIpv6 = true;
      else if (ch == ']')
        isIpv6 = false;
      
      buf.append((char) ch);
    }

    String host = buf.toString();
    if (host.length() == 0)
      throw new RuntimeException("bad host");

    int port = 0;
    if (ch == ':') {
      for (i++; i < length && (ch = uri.charAt(i)) >= '0' && ch <= '9'; i++) {
        port = 10 * port + uri.charAt(i) - '0';
      }
    }

    return create(this, userPath, newAttributes, host, port);
  }
976071
def resolve_frompath(pkgpath, relpath, level=0):
    """"""
    if level == 0:
        return relpath
    parts = pkgpath.split('.') + ['_']
    parts = parts[:-level] + (relpath.split('.') if relpath else [])
    return '.'.join(parts)
921265
private static void getResPathKeys(String path, int num, String[] keys, int start) {
        if (num == 0) {
            return;
        }
        if (num == 1) {
            keys[start] = path;
            return;
        }
        int i = 0;
        for (;;) {
            int j = path.indexOf(RES_PATH_SEP_CHAR, i);
            assert j >= i;
            keys[start++] = path.substring(i, j);
            if (num == 2) {
                assert path.indexOf(RES_PATH_SEP_CHAR, j + 1) < 0;
                keys[start] = path.substring(j + 1);
                break;
            } else {
                i = j + 1;
                --num;
            }
        }
    }
327193
function resolveDeps(ast, result) {
  const {
    from: selfPath,
    graph,
    resolve,
    rootPath,
    rootTree,
  } = result.opts;

  const cwd = dirname(selfPath);
  const rootDir = dirname(rootPath);
  const processor = result.processor;
  const self = graph[selfPath] = graph[selfPath] || {};

  self.mark = TEMPORARY_MARK;

  const moduleExports = {};
  const translations = {};

  ast.walkRules(moduleDeclaration, rule => {
    if (importDeclaration.exec(rule.selector)) {
      rule.walkDecls(decl => translations[decl.prop] = decl.value);

      const dependencyPath = RegExp.$1.replace(/['"]/g, '');
      const absDependencyPath = resolveModule(dependencyPath, {cwd, resolve});

      if (!absDependencyPath) throw new Error(
        'Can\'t resolve module path from `' +
        cwd + '` to `' + dependencyPath + '`'
      );

      if (
        graph[absDependencyPath] &&
        graph[absDependencyPath].mark === TEMPORARY_MARK
      ) throw new Error(
        'Circular dependency was found between `' +
        selfPath + '` and `' + absDependencyPath + '`. ' +
        'Circular dependencies lead to the unpredictable state and considered harmful.'
      );

      if (!(
        graph[absDependencyPath] &&
        graph[absDependencyPath].mark === PERMANENT_MARK
      )) {
        const css = readFileSync(absDependencyPath, 'utf8');
        const lazyResult = processor.process(css, Object.assign({}, result.opts, {from: absDependencyPath}));

        updateTranslations(translations, lazyResult.root.exports);
      } else {
        updateTranslations(translations, graph[absDependencyPath].exports);
      }

      return void rule.remove();
    }

    rule.walkDecls(decl => moduleExports[decl.prop] = decl.value);
    rule.remove();
  });

  replaceSymbols(ast, translations);

  for (const token in moduleExports)
    for (const genericId in translations)
      moduleExports[token] = moduleExports[token]
        .replace(genericId, translations[genericId]);

  self.mark = PERMANENT_MARK;
  self.exports = ast.exports = moduleExports;

  // resolve paths
  if (cwd !== rootDir) resolvePaths(ast, cwd, rootDir);

  const importNotes = comment({
    parent: rootTree,
    raws: {before: rootTree.nodes.length === 0 ? '' : '\n\n'},
    text: ` imported from ${normalizeUrl(relative(rootDir, selfPath))} `,
  });

  const childNodes = ast.nodes.map(i => {
    const node = i.clone({parent: rootTree});

    if (
      typeof node.raws.before === 'undefined' ||
      node.raws.before === ''
    ) node.raws.before = '\n\n';

    return node;
  });

  rootTree.nodes = rootTree.nodes.concat(importNotes, childNodes);
}
1036591
private static String encodePath(int dist, IAtom a, IAtom b) {
        return dist + "_" + a.getSymbol() + "_" + b.getSymbol();
    }
580748
public static Path sourcePathFromParityPath(Path parityPath, FileSystem fs) 
        throws IOException {
    String parityPathStr = parityPath.toUri().getPath();
    for (Codec codec : Codec.getCodecs()) {
      String prefix = codec.getParityPrefix();
      if (parityPathStr.startsWith(prefix)) {
        // Remove the prefix to get the source file.
        String src = parityPathStr.replaceFirst(prefix, Path.SEPARATOR);
        Path srcPath = new Path(src);
        if (fs.exists(srcPath)) {
          return srcPath;
        }
      }
    }
    return null;
  }
1171585
function allPaths (splitPath, partialPath, finalPaths, i) {
  i = i || 0
  finalPaths = finalPaths || []
  partialPath = (partialPath || '') + splitPath[i]

  if (i >= splitPath.length - 1) {
    finalPaths.push(partialPath)
  } else {
    allPaths(splitPath, partialPath + '/', finalPaths, i + 1)
    allPaths(splitPath, partialPath + '\\', finalPaths, i + 1)
  }

  return finalPaths
}
1120431
function () {
            // ensures the uncompressed Orchard code is inside the version directory
            // inside directory that contains local Orchard install. This is to
            // ensure a directory structure like `/local/1.8.1/Orchard-1.8.1`
            // doesn't occur becuase the download zip contents is within it's
            // own directory.
            var contents = helpers.getDirectories(options.tempDir),
                currentDirName = (contents.length === 1) ? path.join(options.tempDir, contents[0]) : options.tempDir;

            mv(currentDirName, options.localDir, {mkdirp: true}, function() {
                cleanUp(done);
            });
        }
623286
function replaceMacro(code) {
		if (!re) return getKeys(code);
		var match = code.match(re);
		if (!match) return getKeys(code);

		var includeFile = match[1];
		includeFile = path.relative(self.config.root, path.join(path.dirname(fileName), includeFile));

		self._parse(includeFile, function (err, includeCode) {
			if (err) return callback(err);
			includeCode = '\n\r-- ' + macro + ' ' + match[1] + ':\n'
				+ includeCode
				+ '\n\r-- End of ' + match[1];
			code = code.replace(match[0], includeCode);
			replaceMacro(code);
		});
	}