Find preset from hub

    \b
    $ be find ad
    https://github.com/mottosso/be-ad.git
178559
def preset_find(query):
    

    if self.isactive():
        lib.echo("ERROR: Exit current project first")
        sys.exit(lib.USER_ERROR)

    found = _extern.github_presets().get(query)
    if found:
        lib.echo(found)
    else:
        lib.echo("Unable to locate preset \"%s\"" % query)
1032018
function (workingDirectory) {
        var gitPath = getClosestGitPath(workingDirectory);

        if (!gitPath) {
            throw new Error('git-hooks must be run inside a git repository');
        }

        var hooksPath = path.resolve(gitPath, HOOKS_DIRNAME);
        var pathToGitHooks = path.join(path.relative(hooksPath, __dirname), 'git-hooks');
 
        if (isWin32) {
            pathToGitHooks = pathToGitHooks.replace(/\\/g, '\\\\');
        }

        if (fsHelpers.exists(hooksOldPath)) {
            throw new Error('git-hooks already installed');
        }

        if (fsHelpers.exists(hooksPath)) {
            fs.renameSync(hooksPath, hooksOldPath);
        }

        var hookTemplate = fs.readFileSync(__dirname + '/' + HOOKS_TEMPLATE_FILE_NAME);
        var pathToGitHooks = path.relative(hooksPath, __dirname);
        // Fix non-POSIX (Windows) separators
        pathToGitHooks = pathToGitHooks.replace(new RegExp(path.sep.replace(/\\/g, '\\$&'), 'g'), '/');
        var hook = util.format(hookTemplate.toString(), pathToGitHooks);

        fsHelpers.makeDir(hooksPath);
        HOOKS.forEach(function (hookName) {
            var hookPath = path.resolve(hooksPath, hookName);
            try {
                fs.writeFileSync(hookPath, hook, {mode: '0777'});
            } catch (e) {
                // node 0.8 fallback
                fs.writeFileSync(hookPath, hook, 'utf8');
                fs.chmodSync(hookPath, '0777');
            }
        });
    }
50441
function gh(repo, project) {
  var base = 'https://github.com/'

  if (project) {
    repo = {user: repo, project: project}
  }

  if (repo) {
    base += repo.user + '/' + repo.project + '/'
  }

  return base
}
1363099
function findPluginPath(command) {
  if (command && /^\w+$/.test(command)) {
    try {
      return resolve.sync('nowa-' + command, {
        paths: moduleDirs
      });
    } catch (e) {
      console.log('');
      console.log('  ' + chalk.green.bold(command) + ' command is not installed.');
      console.log('  You can try to install it by ' + chalk.blue.bold('nowa install ' + command) + '.');
      console.log('');
    }
  }
}
974686
def find_submodule_git_dir(d):
    """"""
    if is_git_dir(d):
        return d

    try:
        with open(d) as fp:
            content = fp.read().rstrip()
    except (IOError, OSError):
        # it's probably not a file
        pass
    else:
        if content.startswith('gitdir: '):
            path = content[8:]

            if Git.is_cygwin():
                ## Cygwin creates submodules prefixed with `/cygdrive/...` suffixes.
                path = decygpath(path)
            if not osp.isabs(path):
                path = osp.join(osp.dirname(d), path)
            return find_submodule_git_dir(path)
    # end handle exception
    return None
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];
}
460487
def _braket_fmt(self, expr_type):
        """"""
        mapping = {
            True: {  # use braket package
                'bra': {
                    True: r'\Bra{{{label}}}^{{({space})}}',
                    'subscript': r'\Bra{{{label}}}_{{({space})}}',
                    False:  r'\Bra{{{label}}}'},
                'ket': {
                    True: r'\Ket{{{label}}}^{{({space})}}',
                    'subscript': r'\Ket{{{label}}}_{{({space})}}',
                    False:  r'\Ket{{{label}}}'},
                'ketbra': {
                    True:
                        r'\Ket{{{label_i}}}\!\Bra{{{label_j}}}^{{({space})}}',
                    'subscript':
                        r'\Ket{{{label_i}}}\!\Bra{{{label_j}}}_{{({space})}}',
                    False: r'\Ket{{{label_i}}}\!\Bra{{{label_j}}}'},
                'braket': {
                    True: r'\Braket{{{label_i} | {label_j}}}^({space})',
                    'subscript': r'\Braket{{{label_i} | {label_j}}}_({space})',
                    False:  r'\Braket{{{label_i} | {label_j}}}'}},
            False: {  # explicit tex macros
                'bra': {
                    True:
                        r'\left\langle {label} \right\rvert^{{({space})}}',
                    'subscript':
                        r'\left\langle {label} \right\rvert^{{({space})}}',
                    False:
                        r'\left\langle {label} \right\rvert'},
                'ket': {
                    True:
                        r'\left\lvert {label} \right\rangle^{{({space})}}',
                    'subscript':
                        r'\left\lvert {label} \right\rangle_{{({space})}}',
                    False:  r'\left\lvert {label} \right\rangle'},
                'ketbra': {
                    True:
                        r'\left\lvert {label_i} \middle\rangle\!'
                        r'\middle\langle {label_j} \right\rvert^{{({space})}}',
                    'subscript':
                        r'\left\lvert {label_i} \middle\rangle\!'
                        r'\middle\langle {label_j} \right\rvert_{{({space})}}',
                    False:
                        r'\left\lvert {label_i} \middle\rangle\!'
                        r'\middle\langle {label_j} \right\rvert'},
                'braket': {
                    True:
                        r'\left\langle {label_i} \middle\vert '
                        r'{label_j} \right\rangle^{{({space})}}',
                    'subscript':
                        r'\left\langle {label_i} \middle\vert '
                        r'{label_j} \right\rangle_{{({space})}}',
                    False:
                        r'\left\langle {label_i} \middle\vert '
                        r'{label_j} \right\rangle'}}
            }
        hs_setting = bool(self._settings['show_hs_label'])
        if self._settings['show_hs_label'] == 'subscript':
            hs_setting = 'subscript'
        return mapping[self._settings['tex_use_braket']][expr_type][hs_setting]
227607
public function findChangedByGit(): ?\Generator
    {
        // -u expand dir's files
        [, $output,] = Sys::run('git status -s -u', $this->basePath);

        // 'D some.file'    deleted
        // ' M some.file'   modified
        // '?? some.file'   new file
        foreach (\explode("\n", \trim($output)) as $file) {
            $file = \trim($file);

            // only php file.
            if (!\strpos($file, '.php')) {
                continue;
            }

            // modified files
            if (\strpos($file, 'M ') === 0) {
                yield \substr($file, 2);

                // new files
            } elseif (\strpos($file, '?? ') === 0) {
                yield \substr($file, 3);
            }
        }
    }
1010838
function findPrev(type/*: string*/, element/*: Cheerio*/) {
  let tries = 5
  let prev = element

  do {
    if (prev.is(type)) {
      return prev
    }

    prev = prev.prev()
  }
  while (--tries)

  return prev
}
1009061
def _version_find_existing():
    
    _tool_run('git fetch origin -t')
    git_tags = [x for x in (y.strip() for y in (_tool_run('git tag -l')
                                                .stdout.split('\n'))) if x]
    return {tuple(int(n) if n else 0 for n in m.groups())
            for m in (_version_re.match(t) for t in git_tags) if m}
722444
def pkg_find(self):
        
        flag = []
        options = [
            "-F",
            "--FIND"
        ]
        additional_options = ["--case-ins"]
        for arg in self.args:
            if arg in additional_options:
                flag.append(arg)
                self.args.remove(arg)
        packages = self.args[1:]
        if len(self.args) > 1 and self.args[0] in options:
            FindFromRepos().find(packages, flag)
        else:
            usage("")
599848
def get(path, **kwargs):
    """"""
    token = os.environ.get(BE_GITHUB_API_TOKEN)
    if token:
        kwargs["headers"] = {
            "Authorization": "token %s" % token
        }

    try:
        response = requests.get(path, verify=False, **kwargs)
        if response.status_code == 403:
            lib.echo("Patience: You can't pull more than 60 "
                     "presets per hour without an API token.\n"
                     "See https://github.com/mottosso/be/wiki"
                     "/advanced#extended-preset-access")
            sys.exit(lib.USER_ERROR)
        return response
    except Exception as e:
        if self.verbose:
            lib.echo("ERROR: %s" % e)
        else:
            lib.echo("ERROR: Something went wrong. "
                     "See --verbose for more information")
114292
static function findSubitems( $dir, $types = false, $fullPath = false, $includeHidden = false, $excludeItems = false )
    {
        if ( !$types )
            $types = 'dfl';
        $dirArray = array();
        if ( $handle = @opendir( $dir ) )
        {
            while ( ( $element = readdir( $handle ) ) !== false )
            {
                if ( $element === '.' || $element === '..' )
                    continue;
                if ( !$includeHidden && $element[0] === '.' )
                    continue;
                if ( $excludeItems && preg_match( $excludeItems, $element ) )
                    continue;
                if ( strpos( $types, 'd' ) === false && is_dir( $dir . '/' . $element ) )
                    continue;
                if ( strpos( $types, 'l' ) === false && is_link( $dir . '/' . $element ) )
                    continue;
                if ( strpos( $types, 'f' ) === false && is_file( $dir . '/' . $element ))
                    continue;
                if ( $fullPath )
                {
                    if ( is_string( $fullPath ) )
                        $dirArray[] = $fullPath . '/' . $element;
                    else
                        $dirArray[] = $dir . '/' . $element;
                }
                else
                    $dirArray[] = $element;
            }
            @closedir( $handle );
        }
        return $dirArray;
    }
253418
function toGithubHash(title) {
  var GITHUB_ILLEGAL = new RegExp('[\\[\\]{}()<>^$#@!%&*+\/\\|~`"\':;,.]', 'g');
  return title.toLowerCase().replace(/ /g, '-').replace(GITHUB_ILLEGAL, '');
}
1250916
function bemDirs(bemdeps) {
  const dirFilter = {};
  bemdeps.forEach((dep) => {
    const depPath = bemPath(dep);
    const depDir = path.dirname(depPath);
    dirFilter[depDir] = true;
  });

  return Object.keys(dirFilter);
}
247558
function findASMBlocks(code, description, callback){

    function match(str, type) {
      if (str!==undefined && tok.str!=str) {
        Espruino.Core.Notifications.error("Expecting '"+str+"' but got '"+tok.str+description+"'. Should have E.asm('arg spec', 'asmline1', ..., 'asmline2'");
        return false;
      }
      if (type!==undefined && tok.type!=type) {
        Espruino.Core.Notifications.error("Expecting a "+type+" but got "+tok.type+description+". Should have E.asm('arg spec', 'asmline1', ..., 'asmline2'");
        return false;
      }
      tok = lex.next();
      return true;
    }

    var foundAsm = true;
    var assembledCode = "";
    var asmBlockCount = 1;
    while (foundAsm) {
      foundAsm = false;
      var lex = Espruino.Core.Utils.getLexer(code);
      var tok = lex.next();
      var state = 0;
      var startIndex = -1;
      while (tok!==undefined) {
        if (state==0 && tok.str=="E") { state=1; startIndex = tok.startIdx; tok = lex.next();
        } else if (state==1 && tok.str==".") { state=2; tok = lex.next();
        } else if (state==2 && (tok.str=="asm")) { state=3; tok = lex.next();
        } else if (state==3 && (tok.str=="(")) {
          foundAsm = true;
          state=0;
          tok = lex.next(); // skip (
          var argSpec = tok.value;
          var asmLines = [];
          if (!match(undefined,"STRING")) return;
          if (!match(",",undefined)) return;
          while (tok && tok.str!=")") {
            var lines = tok.value.split("\n");
            lines.forEach(function(l) {
              asmLines.push(l);
            });
            if (!match(undefined,"STRING")) return;
            if (tok.str!=")")
              if (!match(",",undefined)) return;
          }
          if (!match(")",undefined)) return;
          var endIndex = tok.endIdx;

          var machineCode = assembleBlock(asmLines, description);
          //console.log(machineCode);
          if (machineCode===undefined) return; // There was an error - just leave and don't try to flash
          var raw = "";
          machineCode.forEach(function(short) {
            var v = parseInt(short,16);
            raw += String.fromCharCode(v&255,v>>8);
          });
          var base64 = base64_encode(raw);
          code = code.substr(0,startIndex) +
                 'E.nativeCall(1, '+JSON.stringify(argSpec)+', atob('+JSON.stringify(base64)+'))'+
                 code.substr(endIndex);
          asmBlockCount++;

          // Break out
          tok = undefined;
        } else {
          state = 0;
          tok = lex.next();
        }
      }
    }

    if (assembledCode!="") {
      code = "var ASM_BASE=process.memory().stackEndAddress;\n"+
             assembledCode+
             code;
    }
    callback(code);
  }
1196907
def admin_set
      return AdminSet.find(source_id) if AdminSet.exists?(source_id)
      raise ActiveFedora::ObjectNotFoundError
    rescue ActiveFedora::ActiveFedoraError # TODO: remove the rescue when active_fedora issue #1276 is fixed
      raise ActiveFedora::ObjectNotFoundError
    end