text:
import os
import sys
import subprocess
from libpredweb import myfunc
from libpredweb import webserver_common as webcom
import glob
import hashlib
import shutil
from datetime import datetime
from dateutil import parser as dtparser
from pytz import timezone
import time
import site
import fcntl
import json
import urllib.request, urllib.parse, urllib.error

FORMAT_DATETIME = webcom.FORMAT_DATETIME
TZ = webcom.TZ

progname =  os.path.basename(sys.argv[0])
wspace = ''.join([" "]*len(progname))
rundir = os.path.dirname(os.path.realpath(__file__))
webserver_root = os.path.realpath("%s/../../../"%(rundir))
activate_env="%s/env/bin/activate_this.py"%(webserver_root)
exec(compile(open(activate_env, "rb").read(), activate_env, 'exec'), dict(__file__=activate_env))

site.addsitedir("%s/env/lib/python2.7/site-packages/"%(webserver_root))
sys.path.append("/usr/local/lib/python2.7/dist-packages")

basedir = os.path.realpath("%s/.."%(rundir)) # path of the application, i.e. pred/
path_md5cache = "%s/static/md5"%(basedir)
path_cache = "%s/static/result/cache"%(basedir)
path_result = "%s/static/result/"%(basedir)
gen_errfile = "%s/static/log/%s.err"%(basedir, progname)
gen_logfile = "%s/static/log/%s.log"%(basedir, progname)

contact_email = "nanjiang.shu@scilifelab.se"
vip_email_file = "%s/config/vip_email.txt"%(basedir)
# note that here the url should be without http://

usage_short="""
Usage: %s seqfile_in_fasta
    %s -jobid JOBID -outpath DIR -tmpdir DIR
    %s -email EMAIL -baseurl BASE_WWW_URL
    %s -only-get-cache
"""%(progname, wspace, wspace, wspace)

usage_ext="""\
Description:
    run job

OPTIONS:
-h, --help        Print this help message and exit

Created 2016-12-01, 2017-05-26, Nanjiang Shu
"""
usage_exp="""
Examples:
    %s /data3/tmp/tmp_dkgSD/query.fa -outpath /data3/result/rst_mXLDGD -tmpdir /data3/tmp/tmp_dkgSD
"""%(progname)

def PrintHelp(fpout=sys.stdout):#{{{
    print(usage_short, file=fpout)
    print(usage_ext, file=fpout)
    print(usage_exp, file=fpout)#}}}

def CleanResult(name_software, query_para, outpath_this_seq, runjob_logfile, runjob_errfile):#{{{
    if name_software in ["prodres", "docker_prodres"]:
        if not 'isKeepTempFile' in query_para or query_para['isKeepTempFile'] == False:
            temp_result_folder = "%s/temp"%(outpath_this_seq)
            if os.path.exists(temp_result_folder):
                try:
                    shutil.rmtree(temp_result_folder)
                except Exception as e:
                    msg = "Failed to delete the folder %s with message \"%s\""%(temp_result_folder, str(e))
                    webcom.loginfo(msg, runjob_errfile)

            flist = [
                    "%s/outputs/%s"%(outpath_this_seq, "Alignment.txt"),
                    "%s/outputs/%s"%(outpath_this_seq, "tableOut.txt"),
                    "%s/outputs/%s"%(outpath_this_seq, "fullOut.txt")
                    ]
            for f in flist:
                if os.path.exists(f):
                    try:
                        os.remove(f)
                    except Exception as e:
                        msg =  "Failed to delete the file %s with message \"%s\""%(f, str(e))
                        webcom.loginfo(msg,  runjob_errfile)
    elif name_software in ["subcons", "docker_subcons"]:
        if not 'isKeepTempFile' in query_para or query_para['isKeepTempFile'] == False:
            temp_result_folder = "%s/tmp"%(outpath_this_seq)
            if os.path.exists(temp_result_folder):
                try:
                    shutil.rmtree(temp_result_folder)
                except Exception as e:
                    msg = "Failed to delete the folder %s with message \"%s\""%(
                            temp_result_folder, str(e))
                    webcom.loginfo(msg,  runjob_errfile)

#}}}

def GetCommand(name_software, seqfile_this_seq, tmp_outpath_result, tmp_outpath_this_seq, query_para):#{{{
    """Return the command for subprocess
    """

    try:
        docker_tmp_outpath_result = os.sep + os.sep.join(tmp_outpath_result.split(os.sep)[tmp_outpath_result.split(os.sep).index("static"):])
        docker_seqfile_this_seq = os.sep + os.sep.join(seqfile_this_seq.split(os.sep)[seqfile_this_seq.split(os.sep).index("static"):])
        docker_tmp_outpath_this_seq = os.sep + os.sep.join(tmp_outpath_this_seq.split(os.sep)[tmp_outpath_this_seq.split(os.sep).index("static"):])
    except:
        raise

    cmd = []
    if name_software in ['dummy']:
        runscript = "%s/%s"%(rundir, "soft/dummyrun.sh")
        cmd = ["bash", runscript, seqfile_this_seq,  tmp_outpath_this_seq]
    elif name_software in ['scampi2-single']:
        if not os.path.exists(tmp_outpath_this_seq):
            os.makedirs(tmp_outpath_this_seq)
        runscript = "%s/%s"%(rundir, "soft/scampi2/bin/scampi/SCAMPI_run.pl")
        outtopfile = "%s/query.top"%(tmp_outpath_this_seq)
        cmd = [runscript, seqfile_this_seq,  outtopfile]
    elif name_software in ['scampi2-msa']:
        if not os.path.exists(tmp_outpath_this_seq):
            os.makedirs(tmp_outpath_this_seq)
        runscript = "%s/%s"%(rundir,
                "soft/scampi2/bin/scampi-msa/run_SCAMPI_multi.pl")
        outtopfile = "%s/query.top"%(tmp_outpath_this_seq)
        blastdir = "%s/%s"%(rundir, "soft/blast/blast-2.2.26")
        os.environ['BLASTMAT'] = "%s/data"%(blastdir)
        os.environ['BLASTBIN'] = "%s/bin"%(blastdir)
        os.environ['BLASTDB'] = "%s/%s"%(rundir, "soft/blastdb")
        blastdb = "%s/%s"%(os.environ['BLASTDB'], "uniref90.fasta" )
        cmd = [runscript, seqfile_this_seq, outtopfile, blastdir, blastdb]
    elif name_software in ['topcons2']:
        runscript = "%s/%s"%(rundir,
                "soft/topcons2_webserver/workflow/pfam_workflow.py")
        blastdir = "%s/%s"%(rundir, "soft/blast/blast-2.2.26")
        os.environ['BLASTMAT'] = "%s/data"%(blastdir)
        os.environ['BLASTBIN'] = "%s/bin"%(blastdir)
        os.environ['BLASTDB'] = "%s/%s"%(rundir, "soft/blastdb")
        blastdb = "%s/%s"%(os.environ['BLASTDB'], "uniref90.fasta" )
        cmd = ["python", runscript, seqfile_this_seq,  tmp_outpath_result, blastdir, blastdb]
    elif name_software in ['docker_topcons2']:
        containerID = 'topcons2'
        apppath = '/app/topcons2'
        runscript = '%s/workflow/pfam_workflow.py'%(apppath)
        blastdir = "%s/%s"%(apppath, "tools/blast-2.2.26")
        blastdb = "%s/%s/%s"%(apppath, "database/blast", "uniref90.fasta" )
        cmd =  ["/usr/bin/docker", "exec", "--user", "user", containerID,
                "script", "/dev/null", "-c",
                "cd %s; export BLASTMAT=%s/data; export BLASTBIN=%s/bin; export BLASTDB=%s/database/blast; export HOME=/home/user; python %s %s %s %s %s"%(
                    docker_tmp_outpath_result, blastdir, blastdir, apppath,
                    runscript, docker_seqfile_this_seq,
                    docker_tmp_outpath_result, blastdir, blastdb)]
    elif name_software in ['singularity_topcons2']:
        path_image = '/data/singularity_images/topcons2.img'
        apppath = '/app/topcons2'
        runscript = '%s/workflow/pfam_workflow.py'%(apppath)
        blastdir = "%s/%s"%(apppath, "tools/blast-2.2.26")
        blastdb = "%s/%s/%s"%(apppath, "database/blast", "uniref90.fasta" )
        os.environ['BLASTMAT'] = "%s/data"%(blastdir)
        os.environ['BLASTBIN'] = "%s/bin"%(blastdir)
        os.environ['BLASTDB'] = "%s/%s"%(apppath, "database/blast")
        cmd =  ["singularity", "exec",
                "-B", "%s:%s"%('/scratch', '/scratch'),
                "-B", "%s:%s"%('/data', '/data'),
                "-B", "%s:%s"%('%s/static'%(basedir), '/static'),
                path_image,
                "python", runscript, docker_seqfile_this_seq, docker_tmp_outpath_result, blastdir, blastdb]
    elif name_software in ['subcons']:
        runscript = "%s/%s"%(rundir, "soft/subcons/master_subcons.sh")
        cmd = ["bash", runscript, seqfile_this_seq,  tmp_outpath_this_seq,
                "-verbose"]
    elif name_software in ['docker_subcons']:
        containerID = 'subcons'
        cmd =  ["/usr/bin/docker", "exec", "--user", "user", containerID,
                "script", "/dev/null", "-c",
                "cd %s; export HOME=/home/user; /app/subcons/master_subcons.sh %s %s"%(
                    docker_tmp_outpath_result, docker_seqfile_this_seq,
                    docker_tmp_outpath_this_seq)]
    elif name_software in ['singularity_subcons']:
        path_image = '/data/singularity_images/subcons.img'
        apppath = '/app/subcons'
        runscript = '%s/master_subcons.sh'%(apppath)
        cmd =  ["singularity", "exec",
                "-B", "%s:%s"%('/scratch', '/scratch'),
                "-B", "%s:%s"%('/data', '/data'),
                "-B", "%s:%s"%('%s/static'%(basedir), '/static'),
                path_image,
                runscript, docker_seqfile_this_seq, docker_tmp_outpath_result]
    elif name_software in ['docker_boctopus2']:
        containerID = 'boctopus2'
        cmd =  ["/usr/bin/docker", "exec", "--user", "user", containerID,
                "script", "/dev/null", "-c",
                "cd %s; export HOME=/home/user; python /app/boctopus2/boctopus_main.py %s %s"%(
                    docker_tmp_outpath_result, docker_seqfile_this_seq,
                    docker_tmp_outpath_this_seq)]

    elif name_software in ['docker_pathopred']:
        if not os.path.exists(tmp_outpath_this_seq):
            os.makedirs(tmp_outpath_this_seq)
        variant_text = query_para['variants']
        variant_file = "%s/variants.fa" % tmp_outpath_result
        myfunc.WriteFile(variant_text, variant_file)
        docker_variant_file = os.sep + os.sep.join(variant_file.split(os.sep)[variant_file.split(os.sep).index("static"):])
        identifier_name = query_para['identifier_name']
        containerID = 'pathopred'
        cmd =  ["docker", "exec", "--user", "user", containerID,
                "script", "/dev/null", "-c",
                "cd %s; export HOME=/home/user; /app/pathopred/master_pathopred.sh %s %s %s %s"%(
                    docker_tmp_outpath_result, docker_seqfile_this_seq,
                    docker_variant_file, docker_tmp_outpath_this_seq, identifier_name)]

    elif name_software in ['docker_predzinc']:
        containerID = 'predzinc'
        cmd =  ["/usr/bin/docker", "exec", "--user", "user", containerID,
                "script", "/dev/null", "-c",
                "cd %s; export HOME=/home/user; /app/predzinc/predzinc.sh --cpu 4 %s -outpath %s"%(
                    docker_tmp_outpath_result, docker_seqfile_this_seq,
                    docker_tmp_outpath_this_seq)]

    elif name_software in ['docker_frag1d']:
        containerID = 'frag1d'
        cmd =  ["/usr/bin/docker", "exec", "--user", "user", containerID,
                "script", "/dev/null", "-c",
                "cd %s; export HOME=/home/user; /app/frag1d/frag1d.sh --cpu 4 %s -outpath %s"%(
                    docker_tmp_outpath_result, docker_seqfile_this_seq,
                    docker_tmp_outpath_this_seq)]

    elif name_software in ['prodres']:#{{{
        runscript = "%s/%s"%(rundir, "soft/PRODRES/PRODRES/PRODRES.py")
        path_pfamscan = "%s/misc/PfamScan"%(webserver_root)
        path_pfamdatabase = "%s/soft/PRODRES/databases"%(rundir)
        path_pfamscanscript = "%s/pfam_scan.pl"%(path_pfamscan)
        blastdb = "%s/soft/PRODRES/databases/blastdb/uniref90.fasta"%(rundir)
        if 'PERL5LIB' not in os.environ:
            os.environ['PERL5LIB'] = ""
        os.environ['PERL5LIB'] = os.environ['PERL5LIB'] + ":" + path_pfamscan

        cmd = ["python", runscript, "--input", seqfile_this_seq, "--output",
                tmp_outpath_this_seq, "--pfam-dir", path_pfamdatabase,
                "--pfamscan-script", path_pfamscanscript, "--fallback-db-fasta",
                blastdb]

        if 'second_method' in query_para and query_para['second_method'] != "":
            cmd += ['--second-search', query_para['second_method']]

        if 'pfamscan_evalue' in query_para and query_para['pfamscan_evalue'] != "":
            cmd += ['--pfamscan_e-val', query_para['pfamscan_evalue']]
        elif ('pfamscan_bitscore' in query_para and
                query_para['pfamscan_bitscore'] != ""):
            cmd += ['--pfamscan_bitscore', query_para['pfamscan_bitscore']]

        if 'pfamscan_clanoverlap' in query_para:
            if query_para['pfamscan_clanoverlap'] == False:
                cmd += ['--pfamscan_clan-overlap', 'no']
            else:
                cmd += ['--pfamscan_clan-overlap', 'yes']

        if ('jackhmmer_iteration' in query_para and
                query_para['jackhmmer_iteration'] != ""):
            cmd += ['--jackhmmer_max_iter', query_para['jackhmmer_iteration']]

        if ('jackhmmer_threshold_type' in query_para and
                query_para['jackhmmer_threshold_type'] != ""):
            cmd += ['--jackhmmer-threshold-type',
                    query_para['jackhmmer_threshold_type']]

        if 'jackhmmer_evalue' in query_para and query_para['jackhmmer_evalue'] != "":
            cmd += ['--jackhmmer_e-val', query_para['jackhmmer_evalue']]
        elif ('jackhmmer_bitscore' in query_para and
                query_para['jackhmmer_bitscore'] != ""):
            cmd += ['--jackhmmer_bit-score', query_para['jackhmmer_bitscore']]

        if ('psiblast_iteration' in query_para and
                query_para['psiblast_iteration'] != ""):
            cmd += ['--psiblast_iter', query_para['psiblast_iteration']]
        if 'psiblast_outfmt' in query_para and query_para['psiblast_outfmt'] != "":
            cmd += ['--psiblast_outfmt', query_para['psiblast_outfmt']]
#}}}

    return cmd

#}}}
def RunJob_proq3(modelfile, targetseq, outpath, tmpdir, email, jobid, query_para, g_params):# {{{
    all_begin_time = time.time()
    rootname = os.path.basename(os.path.splitext(modelfile)[0])
    starttagfile   = "%s/runjob.start"%(outpath)
    runjob_errfile = "%s/runjob.err"%(outpath)
    runjob_logfile = "%s/runjob.log"%(outpath)
    app_logfile = "%s/app.log"%(outpath)
    finishtagfile = "%s/runjob.finish"%(outpath)
    failtagfile = "%s/runjob.failed"%(outpath)
    rmsg = ""
    webcom.WriteDateTimeTagFile(starttagfile, runjob_logfile, runjob_errfile)

    try:
        method_quality = query_para['method_quality']
    except KeyError:
        method_quality = 'sscore'

    try:
        isDeepLearning = query_para['isDeepLearning']
    except KeyError:
        isDeepLearning = True

    if isDeepLearning:
        m_str = "proq3d"
    else:
        m_str = "proq3"

    try:
        name_software = query_para['name_software']
    except KeyError:
        name_software = ""

    resultpathname = jobid

    outpath_result = "%s/%s"%(outpath, resultpathname)
    tmp_outpath_result = "%s/%s"%(tmpdir, resultpathname)

    zipfile = "%s.zip"%(resultpathname)
    zipfile_fullpath = "%s.zip"%(outpath_result)
    resultfile_text = "%s/%s"%(outpath_result, "query.proq3.txt")
    finished_model_file = "%s/finished_models.txt"%(outpath_result)

    for folder in [tmp_outpath_result]:
        if os.path.exists(folder):
            try:
                shutil.rmtree(folder)
            except Exception as e:
                msg = "Failed to delete folder %s with message %s"%(folder, str(e))
                webcom.loginfo(msg,  runjob_errfile)
                webcom.WriteDateTimeTagFile(failtagfile, runjob_logfile, runjob_errfile)
                return 1

        try:
            os.makedirs(folder)
        except Exception as e:
            msg = "Failed to create folder %s with return message \"%s\""%(folder, str(e))
            webcom.loginfo(msg,  runjob_errfile)
            webcom.WriteDateTimeTagFile(failtagfile, runjob_logfile, runjob_errfile)
            return 1

    tmp_outpath_this_model = "%s/%s"%(tmp_outpath_result, "model_%d"%(0))
    outpath_this_model = "%s/%s"%(outpath_result, "model_%d"%(0))

    # First try to retrieve the profile from archive
    isGetProfileSuccess = False# {{{
    if 'url_profile' in query_para:
        # try to retrieve the profile
        url_profile = query_para['url_profile']
        remote_id = os.path.splitext(os.path.basename(url_profile))[0]
        outfile_zip = "%s/%s.zip"%(tmp_outpath_result, remote_id)

        webcom.loginfo("Trying to retrieve profile from %s"%(url_profile),  runjob_logfile)

        isRetrieveSuccess = False
        if myfunc.IsURLExist(url_profile,timeout=5):
            try:
                myfunc.urlretrieve (url_profile, outfile_zip, timeout=10)
                isRetrieveSuccess = True
            except Exception as e:
                msg = "Failed to retrieve profile from  %s. Err = %s"%(url_profile, str(e))
                webcom.loginfo(msg,  runjob_errfile)
                pass
        if os.path.exists(outfile_zip) and isRetrieveSuccess:
            msg = "Retrieved profile from %s"%(url_profile)
            webcom.loginfo("Retrieved profile from %s"%(url_profile),  runjob_logfile)
            cmd = ["unzip", outfile_zip, "-d", tmp_outpath_result]
            try:
                subprocess.check_output(cmd)
                try:
                    os.rename("%s/%s"%(tmp_outpath_result, remote_id),
                            "%s/profile_0"%(tmp_outpath_result))
                    isGetProfileSuccess = True
                    try:
                        os.remove(outfile_zip)
                    except:
                        pass
                except:
                    pass
            except:
                pass
# }}}

    tmp_seqfile = "%s/query.fasta"%(tmp_outpath_result)
    tmp_outpath_profile = "%s/profile_0"%(tmp_outpath_result)

    docker_tmp_seqfile = os.sep + os.sep.join(tmp_seqfile.split(os.sep)[tmp_seqfile.split(os.sep).index("static"):])
    docker_modelfile= os.sep + os.sep.join(modelfile.split(os.sep)[modelfile.split(os.sep).index("static"):])
    docker_tmp_outpath_profile = os.sep + os.sep.join(tmp_outpath_profile.split(os.sep)[tmp_outpath_profile.split(os.sep).index("static"):])
    docker_tmp_outpath_this_model = os.sep + os.sep.join(tmp_outpath_this_model.split(os.sep)[tmp_outpath_this_model.split(os.sep).index("static"):])
    docker_tmp_outpath_result = os.sep + os.sep.join(tmp_outpath_result.split(os.sep)[tmp_outpath_result.split(os.sep).index("static"):])

    timefile = "%s/time.txt"%(tmp_outpath_result)
    runtime_in_sec_profile = -1.0
    runtime_in_sec_model = -1.0

    if name_software in ['docker_proq3']:
        myfunc.WriteFile(">query\n%s\n"%(targetseq), tmp_seqfile)

        containerID = 'proq3'
        if not isGetProfileSuccess:
            # try to generate profile
            cmd =  ["/usr/bin/docker", "exec", "--user", "user", containerID,
                "script", "/dev/null", "-c",
                "cd %s; export HOME=/home/user; /app/proq3/run_proq3.sh -fasta %s -outpath %s -only-build-profile"%(
                    docker_tmp_outpath_result, docker_tmp_seqfile,
                    docker_tmp_outpath_profile)]
            (t_success, runtime_in_sec) = webcom.RunCmd(cmd, runjob_logfile, runjob_errfile, verbose=True)
            myfunc.WriteFile("%s;%f\n"%("profile_0",runtime_in_sec), timefile, "a", True)
            runtime_in_sec_profile = runtime_in_sec

        # then run with the pre-created profile
        proq3opt = webcom.GetProQ3Option(query_para)
        cmd =  ["/usr/bin/docker", "exec",  "--user", "user", containerID,
            "script", "/dev/null", "-c",
            "cd %s; export HOME=/home/user; /app/proq3/run_proq3.sh --profile %s %s -outpath %s -verbose %s"%(
                docker_tmp_outpath_result, "%s/query.fasta"%(docker_tmp_outpath_profile),
                docker_modelfile, docker_tmp_outpath_this_model, " ".join(proq3opt))]
        (t_success, runtime_in_sec) = webcom.RunCmd(cmd, runjob_logfile, runjob_errfile, verbose=True)
        webcom.loginfo("cmdline: %s"%(" ".join(cmd)),  runjob_logfile)

        myfunc.WriteFile("%s;%f\n"%("model_0",runtime_in_sec), timefile, "a", True)
        runtime_in_sec_model = runtime_in_sec

    if os.path.exists(tmp_outpath_result):
        cmd = ["mv","-f", tmp_outpath_result, outpath_result]
        (isCmdSuccess, t_runtime) = webcom.RunCmd(cmd, runjob_logfile, runjob_errfile, True)
        # copy time.txt to within the model folder
        try:
            shutil.copyfile("%s/time.txt"%(outpath_result), "%s/model_0/time.txt"%(outpath_result))
        except Exception as e:
            webcom.loginfo("Copy time.txt failed with errmsg=%s"%(str(e)), runjob_errfile)

        CleanResult(name_software, query_para, outpath_result, runjob_logfile, runjob_errfile)

        if isCmdSuccess:
            globalscorefile = "%s/%s.%s.%s.global"%(outpath_this_model,  "query.pdb", m_str, method_quality)
            (globalscore, itemList) = webcom.ReadProQ3GlobalScore(globalscorefile)
            modelseqfile = "%s/%s.fasta"%(outpath_this_model, "query.pdb")
            modellength = myfunc.GetSingleFastaLength(modelseqfile)

            modelinfo = ["model_0", str(modellength), str(runtime_in_sec_model)]
            if globalscore:
                for i in range(len(itemList)):
                    modelinfo.append(str(globalscore[itemList[i]]))
            myfunc.WriteFile("\t".join(modelinfo)+"\n", finished_model_file, "a")
            modelFileList = ["%s/%s"%(outpath_this_model, "query.pdb")]
            webcom.WriteProQ3TextResultFile(resultfile_text, query_para, modelFileList,
                    runtime_in_sec_model, g_params['base_www_url'], proq3opt, statfile="")

    # make the zip file for all result
    os.chdir(outpath)
    cmd = ["zip", "-rq", zipfile, resultpathname]
    webcom.RunCmd(cmd, runjob_logfile, runjob_errfile)

    webcom.WriteDateTimeTagFile(finishtagfile, runjob_logfile, runjob_errfile)

    isSuccess = False
    if (os.path.exists(finishtagfile) and os.path.exists(zipfile_fullpath)):
        isSuccess = True
    else:
        isSuccess = False
        webcom.WriteDateTimeTagFile(failtagfile, runjob_logfile, runjob_errfile)

    if os.path.exists(runjob_errfile) and os.stat(runjob_errfile).st_size > 0:
        return 1
    else: # no error, delete the tmpdir
        try:
            webcom.loginfo("shutil.rmtree(%s)"%(tmpdir),  runjob_logfile)
            shutil.rmtree(tmpdir)
            return 0
        except Exception as e:
            msg =  "Failed to delete tmpdir %s with message \"%s\""%(tmpdir, str(e))
            webcom.loginfo(msg,  runjob_errfile)
            return 1

# }}}
def RunJob(infile, outpath, tmpdir, email, jobid, query_para, g_params):#{{{
    all_begin_time = time.time()

    rootname = os.path.basename(os.path.splitext(infile)[0])
    starttagfile   = "%s/runjob.start"%(outpath)
    runjob_errfile = "%s/runjob.err"%(outpath)
    runjob_logfile = "%s/runjob.log"%(outpath)
    app_logfile = "%s/app.log"%(outpath)
    finishtagfile = "%s/runjob.finish"%(outpath)
    failtagfile = "%s/runjob.failed"%(outpath)
    webcom.WriteDateTimeTagFile(starttagfile, runjob_logfile, runjob_errfile)

    rmsg = ""
    try:
        name_software = query_para['name_software']
    except KeyError:
        name_software = ""

    name_server = webcom.GetNameServerFromNameSoftware(name_software)

    resultpathname = jobid
    outpath_result = "%s/%s"%(outpath, resultpathname)
    tmp_outpath_result = "%s/%s"%(tmpdir, resultpathname)

    zipfile = "%s.zip"%(resultpathname)
    zipfile_fullpath = "%s.zip"%(outpath_result)
    resultfile_text = "%s/%s"%(outpath_result, "query.result.txt")
    finished_seq_file = "%s/finished_seqs.txt"%(outpath_result)

    for folder in [outpath_result, tmp_outpath_result]:
        if os.path.exists(folder):
            try:
                shutil.rmtree(folder)
            except Exception as e:
                msg = "Failed to delete folder %s with message %s"%(folder, str(e))
                webcom.loginfo(msg,  runjob_errfile)
                webcom.WriteDateTimeTagFile(failtagfile, runjob_logfile, runjob_errfile)
                return 1

        try:
            os.makedirs(folder)
        except Exception as e:
            msg = "Failed to create folder %s with message %s"%(folder, str(e))
            webcom.loginfo(msg,  runjob_errfile)
            webcom.WriteDateTimeTagFile(failtagfile, runjob_logfile, runjob_errfile)
            return 1

    try:
        open(finished_seq_file, 'w').close()
    except:
        pass

    (seqIDList , seqAnnoList, seqList) = myfunc.ReadFasta(infile)

    for ii in  range(len(seqIDList)):
        origIndex = ii
        seq = seqList[ii]
        seqid = seqIDList[ii]
        description = seqAnnoList[ii]

        subfoldername_this_seq = "seq_%d"%(origIndex)
        outpath_this_seq = "%s/%s"%(outpath_result, subfoldername_this_seq)
        tmp_outpath_this_seq = "%s/%s"%(tmp_outpath_result, "seq_%d"%(0))
        if os.path.exists(tmp_outpath_this_seq):
            try:
                shutil.rmtree(tmp_outpath_this_seq)
            except OSError:
                pass

        seqfile_this_seq = "%s/%s"%(tmp_outpath_result, "query_%d.fa"%(origIndex))
        seqcontent = ">query_%d\n%s\n"%(origIndex, seq)
        myfunc.WriteFile(seqcontent, seqfile_this_seq, "w")

        if not os.path.exists(seqfile_this_seq):
            msg = "Failed to generate seq index %d"%(origIndex)
            webcom.loginfo(msg,  runjob_errfile)
            continue

        cmd  = GetCommand(name_software, seqfile_this_seq, tmp_outpath_result, tmp_outpath_this_seq, query_para)
        if len(cmd) < 1:
            msg = "empty cmd for name_software = %s"%(name_software)
            webcom.loginfo(msg,  runjob_errfile)
            pass

        (t_success, runtime_in_sec) = webcom.RunCmd(cmd, runjob_logfile, runjob_errfile, verbose=True)

        aaseqfile = "%s/seq.fa"%(tmp_outpath_this_seq)
        if not os.path.exists(aaseqfile):
            seqcontent = ">%s\n%s\n"%(description, seq)
            myfunc.WriteFile(seqcontent, aaseqfile, "w")
        timefile = "%s/time.txt"%(tmp_outpath_this_seq)
        if not os.path.exists(timefile):
            myfunc.WriteFile("%s;%f\n"%(seqid,runtime_in_sec), timefile, "w")

        if os.path.exists(tmp_outpath_this_seq):
            fromdir = tmp_outpath_this_seq
            if name_software in ["prodres", "docker_prodres", "singularity_prodres"]:
                fromdir = fromdir + os.sep + "query_0"
                # for prodres, also copy the aaseqfile and timefile to the
                # fromdir
                try:
                    shutil.copy(aaseqfile, fromdir)
                    shutil.copy(timefile, fromdir)
                except Exception as e:
                    msg = "failed to copy aaseqfile or timefile to the folder %s"%(fromdir)
                    webcom.loginfo(msg, runjob_errfile)
                    pass
            cmd = ["mv","-f", fromdir, outpath_this_seq]
            (isCmdSuccess, t_runtime) = webcom.RunCmd(cmd, runjob_logfile, runjob_errfile, True)

            CleanResult(name_software, query_para, outpath_this_seq, runjob_logfile, runjob_errfile)

            if isCmdSuccess:
                runtime = runtime_in_sec #in seconds
                timefile = "%s/time.txt"%(outpath_this_seq)
                if os.path.exists(timefile):
                    content = myfunc.ReadFile(timefile).split("\n")[0]
                    strs = content.split(";")
                    try:
                        runtime = "%.1f"%(float(strs[1]))
                    except:
                        pass
                extItem1 = None
                extItem2 = None
                info_finish = [ "seq_%d"%origIndex, str(len(seq)),
                        str(extItem1), str(extItem2),
                        "newrun", str(runtime), description]
                myfunc.WriteFile("\t".join(info_finish)+"\n",
                        finished_seq_file, "a", isFlush=True)
                # now write the text output for this seq

                info_this_seq = "%s\t%d\t%s\t%s"%("seq_%d"%origIndex, len(seq), description, seq)
                resultfile_text_this_seq = "%s/%s"%(outpath_this_seq, "query.result.txt")
                webcom.loginfo("Write resultfile_text %s"%(resultfile_text_this_seq),  runjob_logfile)
                webcom.WriteDumpedTextResultFile(name_server, resultfile_text_this_seq,
                        outpath_result,
                        [info_this_seq], runtime_in_sec,
                        g_params['base_www_url'])

    all_end_time = time.time()
    all_runtime_in_sec = all_end_time - all_begin_time

    # make the zip file for all result
    statfile = "%s/%s"%(outpath_result, "stat.txt")
    os.chdir(outpath)
    cmd = ["zip", "-rq", zipfile, resultpathname]
    webcom.RunCmd(cmd, runjob_logfile, runjob_errfile)

    webcom.WriteDateTimeTagFile(finishtagfile, runjob_logfile, runjob_errfile)

    isSuccess = False
    if (os.path.exists(finishtagfile) and os.path.exists(zipfile_fullpath)):
        isSuccess = True
    else:
        isSuccess = False
        webcom.WriteDateTimeTagFile(failtagfile, runjob_logfile, runjob_errfile)

    # try to delete the tmpdir if there is no error
    if os.path.exists(runjob_errfile) and os.stat(runjob_errfile).st_size > 0:
        return 1
    else:
        try:
            webcom.loginfo("shutil.rmtree(%s)"%(tmpdir),  runjob_logfile)
            shutil.rmtree(tmpdir)
            return 0
        except Exception as e:
            msg =  "Failed to delete tmpdir %s with message \"%s\""%(tmpdir, str(e))
            webcom.loginfo(msg,  runjob_errfile)
            return 1
#}}}
def main(g_params):#{{{
    argv = sys.argv
    numArgv = len(argv)
    if numArgv < 2:
        PrintHelp()
        return 1

    outpath = ""
    infile = ""
    tmpdir = ""
    email = ""
    jobid = ""

    i = 1
    isNonOptionArg=False
    while i < numArgv:
        if isNonOptionArg == True:
            infile = argv[i]
            isNonOptionArg = False
            i += 1
        elif argv[i] == "--":
            isNonOptionArg = True
            i += 1
        elif argv[i][0] == "-":
            if argv[i] in ["-h", "--help"]:
                PrintHelp()
                return 1
            elif argv[i] in ["-outpath", "--outpath"]:
                (outpath, i) = myfunc.my_getopt_str(argv, i)
            elif argv[i] in ["-tmpdir", "--tmpdir"] :
                (tmpdir, i) = myfunc.my_getopt_str(argv, i)
            elif argv[i] in ["-jobid", "--jobid"] :
                (jobid, i) = myfunc.my_getopt_str(argv, i)
            elif argv[i] in ["-baseurl", "--baseurl"] :
                (g_params['base_www_url'], i) = myfunc.my_getopt_str(argv, i)
            elif argv[i] in ["-email", "--email"] :
                (email, i) = myfunc.my_getopt_str(argv, i)
            elif argv[i] in ["-q", "--q"]:
                g_params['isQuiet'] = True
                i += 1
            else:
                print("Error! Wrong argument:", argv[i], file=sys.stderr)
                return 1
        else:
            infile = argv[i]
            i += 1

    if jobid == "":
        print("%s: jobid not set. exit"%(sys.argv[0]), file=sys.stderr)
        return 1

    g_params['jobid'] = jobid
    # create a lock file in the resultpath when run_job.py is running for this
    # job, so that daemon will not run on this folder
    lockname = "runjob.lock"
    lock_file = "%s/%s/%s"%(path_result, jobid, lockname)
    g_params['lockfile'] = lock_file
    fp = open(lock_file, 'w')
    try:
        fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
    except IOError:
        print("Another instance of %s is running"%(progname), file=sys.stderr)
        return 1

    if myfunc.checkfile(infile, "infile") != 0:
        return 1
    if outpath == "":
        print("outpath not set. exit", file=sys.stderr)
        return 1
    elif not os.path.exists(outpath):
        try:
            subprocess.check_output(["mkdir", "-p", outpath])
        except subprocess.CalledProcessError as e:
            print(e, file=sys.stderr)
            return 1
    if tmpdir == "":
        print("tmpdir not set. exit", file=sys.stderr)
        return 1
    elif not os.path.exists(tmpdir):
        try:
            subprocess.check_output(["mkdir", "-p", tmpdir])
        except subprocess.CalledProcessError as e:
            print(e, file=sys.stderr)
            return 1

    if os.path.exists(vip_email_file):
        g_params['vip_user_list'] = myfunc.ReadIDList(vip_email_file)

    query_parafile = "%s/query.para.txt"%(outpath)
    query_para = {}
    content = myfunc.ReadFile(query_parafile)
    if content != "":
        query_para = json.loads(content)
    try:
        name_software = query_para['name_software']
    except KeyError:
        name_software = ""

    status = 0

    if name_software in ["proq3", "docker_proq3", "singularity_proq3"]:
        # for proq3, model is provided in query_para
        # provided in the query_para
        runjob_errfile = "%s/runjob.err"%(outpath)
        runjob_logfile = "%s/runjob.log"%(outpath)
        modelfile = "%s/query.pdb"%(outpath)
        if 'pdb_model' in query_para:
            model = query_para['pdb_model']
            myfunc.WriteFile(model, modelfile)
        elif 'url_pdb_model' in query_para:
            url_pdb_model =  query_para['url_pdb_model']
            webcom.loginfo("Trying to retrieve profile from %s"%(url_pdb_model),  runjob_logfile)
            isRetrieveSuccess = False
            if myfunc.IsURLExist(url_pdb_model,timeout=5):
                try:
                    myfunc.urlretrieve (url_pdb_model, modelfile, timeout=10)
                    isRetrieveSuccess = True
                except Exception as e:
                    msg = "Failed to retrieve modelfile from  %s. Err = %s"%(url_pdb_model, e)
                    webcom.loginfo(msg,  runjob_logfile)
                    return 1
        else:
            webcom.loginfo("Neither pdb_model nor url_pdb_model are provided. Exit", gen_errfile)
            return 1
        try:
            targetseq = query_para['targetseq']
        except:
            seqList = myfunc.PDB2Seq(modelfile)
            if len(seqList) >= 1:
                targetseq = seqList[0]
        print("Run proq3")
        status =  RunJob_proq3(modelfile, targetseq, outpath, tmpdir, email, jobid, query_para, g_params)
    else:
        status =  RunJob(infile, outpath, tmpdir, email, jobid, query_para, g_params)

    return status
#}}}

def InitGlobalParameter():#{{{
    g_params = {}
    g_params['isQuiet'] = True
    g_params['base_www_url'] = ""
    g_params['jobid'] = ""
    g_params['lockfile'] = ""
    g_params['vip_user_list'] = []
    return g_params
#}}}
if __name__ == '__main__' :
    g_params = InitGlobalParameter()
    status = main(g_params)
    if os.path.exists(g_params['lockfile']):
        try:
            os.remove(g_params['lockfile'])
        except:
            myfunc.WriteFile("Failed to delete lockfile %s\n"%(g_params['lockfile']), gen_errfile, "a", True)

    sys.exit(status)


text:
local require = require

local mimetypes									= require("mimetypes")
local base64									  = require("hs.base64")
local fs										    = require("hs.fs")
local template									= require("resty.template")
local html										  = require("cp.web.html")

local compile									  = template.compile

local mod = {}

--------------------------------------------------------------------------------
-- CONSTANTS:
--------------------------------------------------------------------------------
mod.UI_CHECKBOX								= 1
mod.UI_HEADING								= 2
mod.UI_BUTTON							 	  = 3
mod.UI_DROPDOWN								= 4
mod.UI_TEXT									  = 5

--------------------------------------------------------------------------------
-- RANDOM STRING GENERATOR:
--------------------------------------------------------------------------------
local function randomLetter()
    local str="abcdefghijklmnopqrstuvwxyz"
    return string.char(str:byte(math.random(1, #str)))
end

--------------------------------------------------------------------------------
-- RANDOM WORD GENERATOR:
--------------------------------------------------------------------------------
local function randomWord(length)
    local result = ""
    for _ = 1,length do
        result = result .. randomLetter()
    end
    return result
end

--- cp.web.generate.setWebviewLabel() -> none
--- Function
--- Sets the WebView Label
---
--- Parameters:
---  * value - WebView Label as string
---
--- Returns:
---  * None
function mod.setWebviewLabel(value)
    mod._webviewLabel = value
end

--- cp.web.generate.checkbox() -> string
--- Function
--- Generates a HTML Checkbox
---
--- Parameters:
---  * data - Table containing the data you want to display on the Checkbox
---  * customTrigger - Custom label used for JavaScript Callback
---  * customID - Custom ID used for the HTML objects
---
--- Returns:
---  * String containing the HTML
function mod.checkbox(data, customTrigger, customID)

    local value = customTrigger or data.title

    local isChecked = data.checked and "checked" or ""

    local id = "checkbox" .. randomWord(20)
    if customID then id = customID end

    local result = html.p { class = "uiItem" } (
        html.input { type = "checkbox", id = id, value = "", isChecked } .. data.title
    ) .. mod.javascript([[
        var checkbox = document.getElementById("{{ id }}");
        checkbox.onchange = function (){
            try {
                var checked = checkbox.checked;
                var result = ["{{ value }}", checked];
                webkit.messageHandlers.{{ name }}.postMessage(result);
            } catch(err) {
                alert('An error has occurred. Does the controller exist yet?');
            }
        }
    ]], { id = id, value = value, name = mod._webviewLabel })

    return result

end

--- cp.web.generate.javascript(script, context) -> cp.web.html
--- Function
--- Generates a HTML Heading
---
--- Parameters:
---  * data - Table containing the data you want to display on the Checkbox
---
--- Returns:
---  * String containing the HTML
---
function mod.javascript(script, context)
    local t = compile(script, "no-cache", true)
    return html.script { type = "text/javascript" } (
        "(function(){\n" .. t(context) .. "\n})();", false
    )
end

--- cp.web.generate.heading() -> string
--- Function
--- Generates a HTML Heading
---
--- Parameters:
---  * data - Table containing the data you want to display on the Checkbox
---
--- Returns:
---  * String containing the HTML
function mod.heading(data)
    return html.h3 {} ( data.title )
end

--- cp.web.generate.text() -> string
--- Function
--- Generates a blank HTML
---
--- Parameters:
---  * data - Table containing the data you want to display.
---
--- Returns:
---  * String containing the HTML
function mod.text(data)

    return html(data.title) .. "\n"

end

--- cp.web.generate.button() -> string
--- Function
--- Generates a HTML Button
---
--- Parameters:
---  * data - Table containing the data you want to display on the Checkbox
---  * customTrigger - Custom label used for JavaScript Callback
---  * customWidth - Number to set the width of the button to
---  * customID - Overrides the random HTML ID
---
--- Returns:
---  * String containing the HTML
function mod.button(data, customTrigger, customWidth, customID)

    local value = customTrigger or data.title

    local id = "button" .. randomWord(20)
    if customID then id = customID end

    local style = nil
    if customWidth then
        style = "width: " .. customWidth .. "px;"
    end

    local result = html.p { class="uiItem" } (
        html.a { id=id, style=style, class="button", href="#" } (data.title)
    ) .. mod.javascript([[
        var button = document.getElementById("{{ id }}");
        button.onclick = function (){
            try {
                var result = ["{{ value }}"];
                webkit.messageHandlers.{{ name }}.postMessage(result);
            } catch(err) {
                alert('An error has occurred. Does the controller exist yet?');
            }
        }
    ]], { id=id, value=value, name=mod._webviewLabel})

    return result

end

--- cp.web.generate.dropdown() -> string
--- Function
--- Generates a HTML Dropdown
---
--- Parameters:
---  * title - Title to put in front of the Dropdown. Can be "".
---  * data - Table containing the data you want to display on the Checkbox
---  * customTrigger - Custom label used for JavaScript Callback
---
--- Returns:
---  * String containing the HTML
function mod.dropdown(title, data, customTrigger)

    local value = customTrigger or title

    if title ~= "" then title = title .. ": " end

    local id = "dropdown" .. randomWord(20)

    local options = ""

    for _,v in ipairs(data) do
        local selected = nil
        if v.checked then selected = "selected" end

        options = options .. html.option { value=v.title, selected } (v.title)
    end

    local result = html.p { class="uiItem" } (
        title .. html.select { id=id } (options)
    ) .. mod.javascript([[
        var dropdown = document.getElementById("{{ id }}");
        dropdown.onchange = function (){
            try {
                var dropdownResult = document.getElementById("{{ id }}").value;
                var result = ["{{ value }}", dropdownResult];
                webkit.messageHandlers.{{ name }}.postMessage(result);
            } catch(err) {
                alert('An error has occurred. Does the controller exist yet?');
            }
        }
    ]], { id=id, value=value, name=mod._webviewLabel })

    return result

end

function mod.imageBase64(pathToImage)
    local type = mimetypes.guess(pathToImage)
    if type and type:sub(1,6) == "image/" then
        local f, err = io.open(fs.pathToAbsolute(pathToImage), "rb")
        if not f then
            return nil, err
        end
        local data = f:read("*all")
        f:close()

        return "data:image/jpeg;base64, "..base64.encode(data)
    end
    return ""
end

return mod

redpajama_set_name: RedPajamaGithub


text:
<!DOCTYPE html>

        <title>Jaru Starter Kit</title>


text:
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;

/// <summary>
/// Provides <see cref="BindingMetadata"/> for a <see cref="DefaultModelMetadata"/>.
/// </summary>
public class BindingSourceMetadataProvider : IBindingMetadataProvider
{
    /// <summary>
    /// Creates a new <see cref="BindingSourceMetadataProvider"/> for the given <paramref name="type"/>.
    /// </summary>
    /// <param name="type">
    /// The <see cref="Type"/>. The provider sets <see cref="BindingSource"/> of the given <see cref="Type"/> or
    /// anything assignable to the given <see cref="Type"/>.
    /// </param>
    /// <param name="bindingSource">
    /// The <see cref="BindingSource"/> to assign to the given <paramref name="type"/>.
    /// </param>
    public BindingSourceMetadataProvider(Type type, BindingSource? bindingSource)
    {
        if (type == null)
        {
            throw new ArgumentNullException(nameof(type));
        }

        Type = type;
        BindingSource = bindingSource;
    }

    /// <summary>
    /// The <see cref="Type"/>. The provider sets <see cref="BindingSource"/> of the given <see cref="Type"/> or
    /// anything assignable to the given <see cref="Type"/>.
    /// </summary>
    public Type Type { get; }

    /// <summary>
    /// The <see cref="BindingSource"/> to assign to the Type.
    /// </summary>
    public BindingSource? BindingSource { get; }

    /// <inheritdoc />
    public void CreateBindingMetadata(BindingMetadataProviderContext context)
    {
        if (context == null)
        {
            throw new ArgumentNullException(nameof(context));
        }

        if (Type.IsAssignableFrom(context.Key.ModelType))
        {
            context.BindingMetadata.BindingSource = BindingSource;
        }
    }
}


text:
<TITLE>Review for Up at the Villa (2000)</TITLE>
<LINK REL="STYLESHEET" TYPE="text/css" HREF="/ramr.css">

Up at the Villa (2000)

reviewed by
Berge Garabedian

UP AT THE VILLA
RATING: 5 /10 --> Not a good movie

For more reviews and movie trailers, visit http://www.joblo.com/

You know how every now and then, a film comes out that just blows the roof
of the entire movie industry? I'm talking a film that not only challenges
your mind, but one that completely sweeps you into a world that you'd never
even thought about before? Sparks of originality, chemistry all around! Sure
you do, and so do I, which is why I could say in full confidence that this
film is anything but that kind of a movie.

PLOT:
A rich, snooty woman living the "good life" in Florence, Italy, during the
late 1930s, suddenly finds herself caught up in a messy love triangle
involving a wealthy, older gentleman, a younger, more abrasive American, and
an Austrian refugee. When a murder takes place, the politics of the day take
over, and the film switches its romance gears into those featuring intrigue.

CRITIQUE:
This film is full of pretty pictures, nice decorations and beautiful
scenery, but lacks any palpable romance, tension or chemistry. It's just
sort of "there". It's a film which never really bored me at any point, it
was like being a voyeur at a rich guy's party, but never really managed to
get me excited about anything either. Sean Penn, who has always been one of
favorite actors, despite continually bashing the craft that consistently
feeds him, is actually pretty so-so in this film, underplaying the part and
appearing strangely out of place. Of course, Kirsten Scott Thomas invented
these movies, so she certainly fit her role like a glove, but unfortunately
her character, who is the lead in the film, doesn't really provide the
audience with any tangible reasons to like her. I mean, she's obviously very
pretty but am I supposed to feel for a lady that dicks around with every
Tom, Dick and Arnold, while making decisions on her life based primarily
around finances? Sure, the film offers some insight as to the deep-rooted
misappropriations of values which these people apparently subscribed to at
the time, but I could only invest so much of myself into folks with  whom I
obviously have zero in common (besides the fact that every guy seemed to
want to dick Kirsten Scott Thomas). The romance level is also pretty thin in
this film, with only a tiny shred of it showing up between Penn and Thomas,
a little more in Thomas' relationship with Davies, but generally
non-existent.

Of course, the film turns into more of a "political" game during its second
half, but none of that really interested me much either. No real tension,
just a little politics here and there, nothing we haven't seen before. And
when is Jeremy Davies finally going to play a character different from every
single one that he portrays in all of his other movies? Dude, it's pretty
obvious that you could play the "shy, nervous, twitchy guy", but how about
taking a shot at a role with a little more range? The ending of the movie is
also pretty weak and foreseeable, with much of what goes on, predictable and
tidy. Having said all that, I did enjoy looking at this film, the scenery,
the actors and the wonderful city of Florence, which were all quite
spectacular. I also loved Anne Bancroft's performance, which let her chew up
and spit out most of the scenery around her. Great job, Mrs. Brooks! As well
as Derek Jacobi's comical turn as Lucky Leadbetter. And yes, Scott Thomas
does deliver a decent showing, but somehow it all seems to be a little "old
hat" with her. This film might ultimately entertain those content enough to
sit and watch some really pretty and pretentious people prance around in
lush surroundings with little more than a simple story to tell. But on the
whole, the film didn't manage to entertain me enough to recommend it to any
of my friends. And yes, dear reader...I consider you my friend (fluttering
eyelashes) :)

Little Known Facts about this film and its stars:
Anne Bancroft's birth name is Anna Maria Louisa Italiano (do you think she's
Italian?). She was born in The Bronx, New York in 1931, and has been married
to writer/actor/director Mel Brooks since 1964.
Kirsten Scott Thomas' younger sister Serena Scott Thomas, had a role in the
latest James Bond flick, THE WORLD IS NOT ENOUGH (7/10), in which she played
Dr. Molly Warmflash. Director Philip Haas also directed Kirsten in the 1995
movie ANGELS AND INSECTS.
Jeremy Davies' birth name was Jeremy Boring.
Actor Derek Jacobi was the mentor and acting instructor of fellow British
actor Kenneth Branagh. He also won a Tony in 1985 for "Much Ado About
Nothing", a play which friend Branagh turned into a movie in 1993. Also, Mr.
Jacobi was apparently one of the few runners-up for the part of Hannibal
Lecter in the original SILENCE OF THE LAMBS movie. Of course, that part
eventually went to fellow Brit Anthony Hopkins.
Director Philip Haas and screenwriter Belinda Haas are indeed husband and
wife.

Review Date: May 1, 2000
Director: Philip Haas
Writer: Belinda Haas
Producers: David Brown and Geoff Stier
Actors: Kirsten Scott Thomas as Mary Panton
Sean Penn as Mary Panton
Anne Bancroft as Princess
Genre: Drama
Year of Release: 2000
----------------------------------
JoBlo's Movie Emporium
http://www.joblo.com/
----------------------------------
(c) 2000 Berge Garabedian

The review above was posted to the
rec.arts.movies.reviews newsgroup (de.rec.film.kritiken for German reviews).

The Internet Movie Database accepts no responsibility for the contents of the
review and has no editorial control. Unless stated otherwise, the copyright
belongs to the author.

Please direct comments/criticisms of the review to relevant newsgroups.

Broken URLs inthe reviews are the responsibility of the author.

The formatting of the review is likely to differ from the original due
to ASCII to HTML conversion.

Related links: index of all rec.arts.movies.reviews reviews


text:
<?php

namespace Repository;

/**
 * Class CategoryRepositoryException
 * @package Repository
 */
class CategoryRepositoryException extends \Exception {}

/**
 * Class CategoryRepository
 * @package Repository
 */
class CategoryRepository extends EntityRepository {
    /**
     * @param \Doctrine\ORM\EntityManager $em
     * @param \Doctrine\ORM\Mapping\ClassMetadata $class
     */
    public function __construct(\Doctrine\ORM\EntityManager $em, \Doctrine\ORM\Mapping\ClassMetadata $class)
    {
        parent::__construct($em, $class);
    }
}


text:
package nl.acidcats.tumblrlikes.data.repo.photo.store.filters;

import org.greenrobot.greendao.query.QueryBuilder;

import nl.acidcats.tumblrlikes.data.repo.photo.store.entity.PhotoEntity;
import nl.acidcats.tumblrlikes.data.repo.photo.store.entity.PhotoEntityDao;

/**
 * Created by stephan on 19/05/2017.
 */

public class LatestFilterOptionImpl extends AbstractFilterOptionImpl {
    public LatestFilterOptionImpl(PhotoEntityDao photoEntityDao) {
        setPhotoEntityDao(photoEntityDao);
    }

    @Override
    protected QueryBuilder<PhotoEntity> getQueryBuilder() {
        return _photoEntityDao.queryBuilder()
                .where(PhotoEntityDao.Properties.IsHidden.eq(false))
                .orderDesc(PhotoEntityDao.Properties.Id);
    }
}


text:
#region License

#endregion License

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace Microsoft.Xna.Framework.Graphics
{
	[Serializable]
	[StructLayout(LayoutKind.Sequential)]
	public struct CompiledShader
	{

		public byte[] GetShaderCode() { throw new NotImplementedException(); }
		public string ErrorsAndWarnings { get { throw new NotImplementedException(); } }
		public bool Success { get { throw new NotImplementedException(); } }
		public CompiledShader(byte[] compiledShaderCode, string errors) { throw new NotImplementedException(); }
		public string[] GetSamplers() { throw new NotImplementedException(); }
		public ShaderSemantic[] GetInputSemantics() { throw new NotImplementedException(); }
		public ShaderSemantic[] GetOutputSemantics() { throw new NotImplementedException(); }
		public Version ShaderVersion { get { throw new NotImplementedException(); } }
		public int ShaderSize { get { throw new NotImplementedException(); } }
		public override string ToString() { throw new NotImplementedException(); }
	}
}


text:
    composer require kpicaza/gen-bundle dev-master

**1.** We need to activate and configure our new bundle and each dependencies.

    // app/config/AppKernel.php
    ...
            $bundles = [
                ...
                new JMS\SerializerBundle\JMSSerializerBundle(),
                new Nelmio\CorsBundle\NelmioCorsBundle(),
                new FOS\RestBundle\FOSRestBundle(),
                new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
                new AppBundle\AppBundle(),
            ]
    ...
            if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
                $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
                $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
                $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
                $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
                $bundles[] = new Kpicaza\GenBundle\KpicazaGenBundle();
            }

See [basic usage](basic-usage.md) for dependencies basic configurations.

**2.** Check if command is correctly enabled:

    php bin/console gen:generate:rest --help
    php bin/console gen:generate:form --help


text:
{% extends "django_contactme/base.html" %}

{% block content %}

Get in contact

Either write me an email at someone@example.com, or fill in the following form and click on the send button:

{% if form.message.value %}

Preview your message

	{{ form.message.value|linebreaks }}

{% endif %}

  {% include "django_contactme/form.html" %}

{% endblock %}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;

namespace osu.Framework.Screens
{
    /// <summary>
    /// A component which provides functionality for displaying and handling transitions between multiple <see cref="IScreen"/>s.
    /// </summary>
    public class ScreenStack : CompositeDrawable
    {
        /// <summary>
        /// Invoked when <see cref="ScreenExtensions.Push"/> is called on a <see cref="IScreen"/>.
        /// </summary>
        public event ScreenChangedDelegate ScreenPushed;

        /// <summary>
        /// Invoked when <see cref="ScreenExtensions.Exit"/> is called on a <see cref="IScreen"/>.
        /// </summary>
        public event ScreenChangedDelegate ScreenExited;

        /// <summary>
        /// The currently-active <see cref="IScreen"/>.
        /// </summary>
        public IScreen CurrentScreen => stack.FirstOrDefault();

        private readonly Stack<IScreen> stack = new Stack<IScreen>();

        /// <summary>
        /// Screens which are exited and require manual cleanup.
        /// </summary>
        private readonly List<Drawable> exited = new List<Drawable>();

        /// <summary>
        /// Creates a new <see cref="ScreenStack"/> with no active <see cref="IScreen"/>.
        /// </summary>
        public ScreenStack()
        {
        }

        /// <summary>
        /// Creates a new <see cref="ScreenStack"/>, and immediately pushes a <see cref="IScreen"/>.
        /// </summary>
        /// <param name="baseScreen"></param>
        public ScreenStack(IScreen baseScreen)
            : this()
        {
            Push(baseScreen);
        }

        /// <summary>
        /// Pushes a <see cref="IScreen"/> to this <see cref="ScreenStack"/>.
        /// </summary>
        /// <param name="screen">The <see cref="IScreen"/> to push.</param>
        public void Push(IScreen screen)
        {
            Push(null, screen);
        }

        /// <summary>
        /// Exits the current <see cref="IScreen"/>.
        /// </summary>
        public void Exit()
        {
            Exit(CurrentScreen);
        }

        internal void Push(IScreen source, IScreen newScreen)
        {
            if (stack.Contains(newScreen))
                throw new ScreenAlreadyEnteredException();

            if (newScreen.AsDrawable().RemoveWhenNotAlive)
                throw new ScreenWillBeRemovedOnPushException(newScreen.GetType());

            // Suspend the current screen, if there is one
            if (source != null)
            {
                if (source != stack.Peek())
                    throw new ScreenNotCurrentException(nameof(Push));

                source.OnSuspending(newScreen);
                source.AsDrawable().Expire();
            }

            // Push the new screen
            stack.Push(newScreen);
            ScreenPushed?.Invoke(source, newScreen);

            void finishLoad()
            {
                if (!newScreen.ValidForPush)
                {
                    exitFrom(null);
                    return;
                }

                AddInternal(newScreen.AsDrawable());
                newScreen.OnEntering(source);
            }

            if (source != null)
                LoadScreen((CompositeDrawable)source, newScreen.AsDrawable(), finishLoad);
            else if (LoadState >= LoadState.Ready)
                LoadScreen(this, newScreen.AsDrawable(), finishLoad);
            else
                Schedule(finishLoad);
        }

        /// <summary>
        /// Loads a <see cref="IScreen"/> through a <see cref="CompositeDrawable"/>.
        /// </summary>
        /// <param name="loader">The <see cref="CompositeDrawable"/> to load <paramref name="toLoad"/> with.</param>
        /// <param name="toLoad">The <see cref="IScreen"/> to load.</param>
        /// <param name="continuation">The <see cref="Action"/> to invoke after <paramref name="toLoad"/> has finished loading.</param>
        protected virtual void LoadScreen(CompositeDrawable loader, Drawable toLoad, Action continuation)
        {
            if (toLoad.LoadState >= LoadState.Ready)
                continuation?.Invoke();
            else
                loader.LoadComponentAsync(toLoad, _ => continuation?.Invoke(), scheduler: Scheduler);
        }

        internal void Exit(IScreen source)
        {
            if (!stack.Contains(source))
                throw new ScreenNotCurrentException(nameof(Exit));

            if (CurrentScreen != source)
                throw new ScreenHasChildException(nameof(Exit), $"Use {nameof(ScreenExtensions.MakeCurrent)} instead.");

            exitFrom(null);
        }

        internal void MakeCurrent(IScreen source)
        {
            if (CurrentScreen == source)
                return;

            if (!stack.Contains(source))
                throw new ScreenNotInStackException(nameof(MakeCurrent));

            exitFrom(null, () =>
            {
                foreach (var child in stack)
                {
                    if (child == source)
                        break;
                    child.ValidForResume = false;
                }
            });
        }

        internal bool IsCurrentScreen(IScreen source) => source == CurrentScreen;

        internal IScreen GetChildScreen(IScreen source)
            => stack.TakeWhile(s => s != source).LastOrDefault();

        /// <summary>
        /// Exits the current <see cref="IScreen"/>.
        /// </summary>
        /// <param name="source">The <see cref="IScreen"/> which last exited.</param>
        /// <param name="onExiting">An action that is invoked when the current screen allows the exit to continue.</param>
        private void exitFrom([CanBeNull] IScreen source, Action onExiting = null)
        {
            if (stack.Count == 0)
                return;

            // The current screen is at the top of the stack, it will be the one that is exited
            var toExit = stack.Pop();

            // The next current screen will be resumed
            if (toExit.OnExiting(CurrentScreen))
            {
                stack.Push(toExit);
                return;
            }

            // we will probably want to change this logic when we support returning to a screen after exiting.
            toExit.ValidForResume = false;
            toExit.ValidForPush = false;

            onExiting?.Invoke();

            if (source == null)
            {
                // This is the first screen that exited
                toExit.AsDrawable().Expire();
            }

            exited.Add(toExit.AsDrawable());

            ScreenExited?.Invoke(toExit, CurrentScreen);

            // Resume the next current screen from the exited one
            resumeFrom(toExit);
        }

        /// <summary>
        /// Resumes the current <see cref="IScreen"/>.
        /// </summary>
        /// <param name="source">The <see cref="IScreen"/> which exited.</param>
        private void resumeFrom([NotNull] IScreen source)
        {
            if (CurrentScreen == null)
                return;

            if (CurrentScreen.ValidForResume)
            {
                CurrentScreen.OnResuming(source);

                // Screens are expired when they are suspended - lifetime needs to be reset when resumed
                CurrentScreen.AsDrawable().LifetimeEnd = double.MaxValue;
            }
            else
                exitFrom(source);
        }

        protected override bool UpdateChildrenLife()
        {
            if (!base.UpdateChildrenLife()) return false;

            // In order to provide custom suspend/resume logic, screens always have RemoveWhenNotAlive set to false.
            // We need to manually handle removal here (in the opposite order to how the screens were pushed to ensure bindable sanity).
            if (exited.FirstOrDefault()?.IsAlive == false)
            {
                foreach (var s in exited)
                {
                    RemoveInternal(s);
                    DisposeChildAsync(s);
                }

                exited.Clear();
            }

            return true;
        }

        public class ScreenNotCurrentException : InvalidOperationException
        {
            public ScreenNotCurrentException(string action)
                : base($"Cannot perform {action} on a non-current screen.")
            {
            }
        }

        public class ScreenHasChildException : InvalidOperationException
        {
            public ScreenHasChildException(string action, string description)
                : base($"Cannot perform {action} when a child is already present. {description}")
            {
            }
        }

        public class ScreenAlreadyEnteredException : InvalidOperationException
        {
            public ScreenAlreadyEnteredException()
                : base("Cannot push a screen in an entered state.")
            {
            }
        }

        public class ScreenWillBeRemovedOnPushException : InvalidOperationException
        {
            public ScreenWillBeRemovedOnPushException(Type type)
                : base($"The pushed ({type.ReadableName()}) has {nameof(RemoveWhenNotAlive)} = true and will be removed when a child screen is pushed. "
                       + $"Screens must set {nameof(RemoveWhenNotAlive)} to false.")
            {
            }
        }

        public class ScreenNotInStackException : InvalidOperationException
        {
            public ScreenNotInStackException(string action)
                : base($"Cannot perform {action} on a screen not in a {nameof(ScreenStack)}.")
            {
            }
        }
    }

    /// <param name="lastScreen">The <see cref="IScreen"/> that was exited or suspended.</param>
    /// <param name="newScreen">The <see cref="IScreen"/> that was pushed or resumed.</param>
    public delegate void ScreenChangedDelegate(IScreen lastScreen, IScreen newScreen);
}


text:
		by Vinny Fonseca

Matter


text:
var menor = 11
var calificacion = 0.0

for (i <- 1 to 40) {

println ("Ingresa tu calificacion: ") {
calificacion = readFloat ()

if (calificacion < menor ) {
menor = calificacion
}

}
 println ("La calificacion menor obtenida es: " + menor)


text:
<?php

namespace ZfbUser;

use Zend\Authentication\Result;
use ZfbUser\Entity\UserInterface;

/**
 * Class AuthenticationResult
 *
 * @package ZfbUser
 */
class AuthenticationResult extends Result
{
    /**
     * Учетная запись не подтверждена
     */
    const FAILURE_IDENTITY_NOT_CONFIRMED = -90;

    /**
     * Не удалось подтвердить учетную запись
     */
    const FAILURE_IDENTITY_CONFIRMATION = -91;

    /**
     * Не удалось сбросить пароль
     */
    const FAILURE_RECOVER_PASSWORD = -92;

    /**
     * Invalid token
     */
    const FAILURE_TOKEN_INVALID = -93;

    /**
     * Change password error
     */
    const FAILURE_CHANGE_PASSWORD = -94;

    /**
     * Invalid old password
     */
    const FAILURE_OLD_PASSWORD_INVALID = -95;

    /**
     * Fail set password
     */
    const FAILURE_SET_PASSWORD = -96;

    const MESSAGE_TEMPLATES = [
        self::FAILURE                        => "Authentication failed. Please try again.",
        self::FAILURE_IDENTITY_NOT_FOUND     => "Authentication failed. Please try again.",
        self::FAILURE_IDENTITY_AMBIGUOUS     => "Authentication failed. Please try again.",
        self::FAILURE_CREDENTIAL_INVALID     => "Authentication failed. Please try again.",
        self::FAILURE_UNCATEGORIZED          => "Authentication failed. Please try again.",
        self::FAILURE_IDENTITY_NOT_CONFIRMED => "Identity is not confirmed",
        self::FAILURE_IDENTITY_CONFIRMATION  => "Confirmation failed. Please try again.",
        self::FAILURE_RECOVER_PASSWORD       => "Password reset failed. Please try again.",
        self::FAILURE_TOKEN_INVALID          => "Token invalid. Please try again.",
        self::FAILURE_CHANGE_PASSWORD        => "Change password error. Please try again.",
        self::FAILURE_OLD_PASSWORD_INVALID   => "Old password invalid. Please try again.",
        self::FAILURE_SET_PASSWORD           => "Set password error. Please try again.",

        self::SUCCESS => "Authentication success",
    ];

    /**
     * @var UserInterface
     */
    protected $identity;

    /**
     * AuthenticationResult constructor.
     *
     * @param string                             $code
     * @param null|\ZfbUser\Entity\UserInterface $identity
     * @param array                              $messages
     */
    public function __construct(string $code, ?UserInterface $identity, array $messages = [])
    {
        parent::__construct($code, $identity, $messages);
    }

    /**
     * @return null|\ZfbUser\Entity\UserInterface
     */
    public function getIdentity(): ?UserInterface
    {
        return $this->identity;
    }
}


text:
package com.amazonaws.services.securityhub.model;

import java.io.Serializable;
import javax.annotation.Generated;
import com.amazonaws.protocol.StructuredPojo;
import com.amazonaws.protocol.ProtocolMarshaller;

/**
 *

 * Stateless rules and custom actions for a stateless rule group.
 *

 *
 * @see AWS API Documentation
 */
@Generated("com.amazonaws:aws-java-sdk-code-generator")
public class RuleGroupSourceStatelessRulesAndCustomActionsDetails implements Serializable, Cloneable, StructuredPojo {

    /**
     *

     * Custom actions for the rule group.
     *

     */
    private java.util.List<RuleGroupSourceCustomActionsDetails> customActions;
    /**
     *

     * Stateless rules for the rule group.
     *

     */
    private java.util.List<RuleGroupSourceStatelessRulesDetails> statelessRules;

    /**
     *

     * Custom actions for the rule group.
     *

     *
     * @return Custom actions for the rule group.
     */

    public java.util.List<RuleGroupSourceCustomActionsDetails> getCustomActions() {
        return customActions;
    }

    /**
     *

     * Custom actions for the rule group.
     *

     *
     * @param customActions
     *        Custom actions for the rule group.
     */

    public void setCustomActions(java.util.Collection<RuleGroupSourceCustomActionsDetails> customActions) {
        if (customActions == null) {
            this.customActions = null;
            return;
        }

        this.customActions = new java.util.ArrayList<RuleGroupSourceCustomActionsDetails>(customActions);
    }

    /**
     *

     * Custom actions for the rule group.
     *

     *

     * NOTE: This method appends the values to the existing list (if any). Use
     * {@link #setCustomActions(java.util.Collection)} or {@link #withCustomActions(java.util.Collection)} if you want
     * to override the existing values.
     *

     *
     * @param customActions
     *        Custom actions for the rule group.
     * @return Returns a reference to this object so that method calls can be chained together.
     */

    public RuleGroupSourceStatelessRulesAndCustomActionsDetails withCustomActions(RuleGroupSourceCustomActionsDetails... customActions) {
        if (this.customActions == null) {
            setCustomActions(new java.util.ArrayList<RuleGroupSourceCustomActionsDetails>(customActions.length));
        }
        for (RuleGroupSourceCustomActionsDetails ele : customActions) {
            this.customActions.add(ele);
        }
        return this;
    }

    /**
     *

     * Custom actions for the rule group.
     *

     *
     * @param customActions
     *        Custom actions for the rule group.
     * @return Returns a reference to this object so that method calls can be chained together.
     */

    public RuleGroupSourceStatelessRulesAndCustomActionsDetails withCustomActions(java.util.Collection<RuleGroupSourceCustomActionsDetails> customActions) {
        setCustomActions(customActions);
        return this;
    }

    /**
     *

     * Stateless rules for the rule group.
     *

     *
     * @return Stateless rules for the rule group.
     */

    public java.util.List<RuleGroupSourceStatelessRulesDetails> getStatelessRules() {
        return statelessRules;
    }

    /**
     *

     * Stateless rules for the rule group.
     *

     *
     * @param statelessRules
     *        Stateless rules for the rule group.
     */

    public void setStatelessRules(java.util.Collection<RuleGroupSourceStatelessRulesDetails> statelessRules) {
        if (statelessRules == null) {
            this.statelessRules = null;
            return;
        }

        this.statelessRules = new java.util.ArrayList<RuleGroupSourceStatelessRulesDetails>(statelessRules);
    }

    /**
     *

     * Stateless rules for the rule group.
     *

     *

     * NOTE: This method appends the values to the existing list (if any). Use
     * {@link #setStatelessRules(java.util.Collection)} or {@link #withStatelessRules(java.util.Collection)} if you want
     * to override the existing values.
     *

     *
     * @param statelessRules
     *        Stateless rules for the rule group.
     * @return Returns a reference to this object so that method calls can be chained together.
     */

    public RuleGroupSourceStatelessRulesAndCustomActionsDetails withStatelessRules(RuleGroupSourceStatelessRulesDetails... statelessRules) {
        if (this.statelessRules == null) {
            setStatelessRules(new java.util.ArrayList<RuleGroupSourceStatelessRulesDetails>(statelessRules.length));
        }
        for (RuleGroupSourceStatelessRulesDetails ele : statelessRules) {
            this.statelessRules.add(ele);
        }
        return this;
    }

    /**
     *

     * Stateless rules for the rule group.
     *

     *
     * @param statelessRules
     *        Stateless rules for the rule group.
     * @return Returns a reference to this object so that method calls can be chained together.
     */

    public RuleGroupSourceStatelessRulesAndCustomActionsDetails withStatelessRules(java.util.Collection<RuleGroupSourceStatelessRulesDetails> statelessRules) {
        setStatelessRules(statelessRules);
        return this;
    }

    /**
     * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
     * redacted from this string using a placeholder value.
     *
     * @return A string representation of this object.
     *
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        if (getCustomActions() != null)
            sb.append("CustomActions: ").append(getCustomActions()).append(",");
        if (getStatelessRules() != null)
            sb.append("StatelessRules: ").append(getStatelessRules());
        sb.append("}");
        return sb.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;

        if (obj instanceof RuleGroupSourceStatelessRulesAndCustomActionsDetails == false)
            return false;
        RuleGroupSourceStatelessRulesAndCustomActionsDetails other = (RuleGroupSourceStatelessRulesAndCustomActionsDetails) obj;
        if (other.getCustomActions() == null ^ this.getCustomActions() == null)
            return false;
        if (other.getCustomActions() != null && other.getCustomActions().equals(this.getCustomActions()) == false)
            return false;
        if (other.getStatelessRules() == null ^ this.getStatelessRules() == null)
            return false;
        if (other.getStatelessRules() != null && other.getStatelessRules().equals(this.getStatelessRules()) == false)
            return false;
        return true;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int hashCode = 1;

        hashCode = prime * hashCode + ((getCustomActions() == null) ? 0 : getCustomActions().hashCode());
        hashCode = prime * hashCode + ((getStatelessRules() == null) ? 0 : getStatelessRules().hashCode());
        return hashCode;
    }

    @Override
    public RuleGroupSourceStatelessRulesAndCustomActionsDetails clone() {
        try {
            return (RuleGroupSourceStatelessRulesAndCustomActionsDetails) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new IllegalStateException("Got a CloneNotSupportedException from Object.clone() " + "even though we're Cloneable!", e);
        }
    }

    @com.amazonaws.annotation.SdkInternalApi
    @Override
    public void marshall(ProtocolMarshaller protocolMarshaller) {
        com.amazonaws.services.securityhub.model.transform.RuleGroupSourceStatelessRulesAndCustomActionsDetailsMarshaller.getInstance().marshall(this,
                protocolMarshaller);
    }
}


text:
Kustomize is a tool that introduces a template-free way to customize application configuration, simplifying the use of off-the-shelf applications. It's available as a stand alone utility and is built into kubectl through `kubectl apply -k` of can be used as a stand alone CLI. For additional details read more at [kustomize.io](https://kustomize.io/).
## Objectives

In this tutorial you work through some of the core concepts of Kustomize and use it to manage variations in the applications and environments.

You will:

-  Utilize kustomize command line client
-  Override common elements
-  Patch larger yaml structures
-  Utilize multiple layers of overlays

## Preparing your workspace

1. Open Cloud Shell editor by visiting the following url

```
https://ide.cloud.google.com
```

2. In the terminal window create a working directory for this tutorial

```
mkdir kustomize-lab
```

3. Change into the directory and set the IDE workspace

```
cd kustomize-lab && cloudshell workspace .
```

## Utilizing kustomize command line client

The power of kustomize comes from the ability to overlay and modify base Kubernetes yamls with custom values. In order to do this kustomize requires a base file with instructions on where the files are and what to override. Kustomize is included in the Kubernetes ecosystem and can be executed through various methods.

In this section you will create a base kustomize configuration and process the files with the stand alone kustomize command line client.

1. To start, you will create a folder to hold your base configuration files

```
mkdir -p chat-app/base
```

2. Create a simple kubernetes ``deployment.yaml`` in the base folder

```
cat <<EOF > chat-app/base/deployment.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
  name: app
spec:
  template:
    metadata:
      name: chat-app
    spec:
      containers:
      - name: chat-app
        image: chat-app-image
EOF
```

3. Create the base `kustomization.yaml`

   Kustomize looks for a file called kustomization.yaml as an entry point. This file contains references to the various base and override files as well as specific override values.

   Create a `kustomization.yaml` file that references the `deployment.yaml` as the base resources.
```
cat <<EOF > chat-app/base/kustomization.yaml
bases:
  - deployment.yaml
EOF
```

4. Run the kustomize command on the base folder. Doing so outputs the deployment YAML files with no changes, which is expected since you haven't included any variations yet.

```
kustomize build chat-app/base
```

This standalone client can be combined with the kubectl client to apply the output directly as in the following example. Doing so streams the output of the build command directly into the kubectl apply command.

(Do Not Execute - Included for reference only)

kustomize build chat-app/base | kubectl apply -f -

This technique is useful if a specific version of the kustomize client is needed.

Alternatively kustomize can be executed with the tooling integrated within kubectl itself. As in the following example.

(Do Not Execute - Included for reference only)

kubectl apply -k chat-app/base

## Overriding common elements

Now that your workspace is configured and you verified kustomize is working, it's time to override some of the base values.

Images, namespaces and labels are very commonly customized for each application and environment. Since they are commonly changed, Kustomize lets you declare them directly in the `kustomize.yaml`, eliminating the need to create many patches for these common scenarios.

This technique is often used to create a specific instance of a template. One base set of resources can now be used for multiple implementations by simply changing the name and its namespace.

In this example, you will add a namespace, name prefix and add some labels to your `kustomization.yaml`.

1. Update the `kustomization.yaml` file to include common labels and namespaces.

   Copy and execute the following commands in your terminal

```
cat <<EOF > chat-app/base/kustomization.yaml
bases:
  - deployment.yaml

namespace: my-namespace
nameprefix: my-
commonLabels:
  app: my-app

EOF
```

2. Execute the build command

   Executing the build at this point shows that the resulting YAML file now contains the namespace, labels and prefixed names in both the service and deployment definitions.

```
kustomize build chat-app/base
```

Note how the output contains labels and namespaces that are not in the deployment YAML file. Note also how the name was changed from `chat-app` to `my-chat-app`

(Output do not copy)

kind: Deployment
metadata:
  labels:
    app: my-app
  name: my-chat-app
  namespace: my-namespace

## Patching larger yaml structures

Kustomize also provides the ability to apply patches that overlay the base resources. This technique is often used to provide variability between applications and environments.

In this step, you will create environment variations for a single application that use the same base resources.

1. Start by creating folders for the different environments

```
mkdir -p chat-app/dev
mkdir -p chat-app/prod
```

2. Write the stage patch with the following command

```
cat <<EOF > chat-app/dev/deployment.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
  name: app
spec:
  template:
    spec:
      containers:
      - name: chat-app
        env:
        - name: ENVIRONMENT
          value: dev
EOF
```

3. Now Write the prod patch with the following command

```
cat <<EOF > chat-app/prod/deployment.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
  name: app
spec:
  template:
    spec:
      containers:
      - name: chat-app
        env:
        - name: ENVIRONMENT
          value: prod
EOF
```

Notice that the patches above do not contain the container image name. That value is provided in the base/deployment.yaml you created in the previous step. These patches do however contain unique environment variables for dev and prod.

4. Implement the kustomize YAML files for the base directory

Rewrite the base kustomization.yaml, remove the namespace and name prefix as this is just the base config with no variation. Those fields will be moved to the environment files in just a moment.

```
cat <<EOF > chat-app/base/kustomization.yaml
bases:
  - deployment.yaml

commonLabels:
  app: chat-app

EOF
```
5. Implement the kustomize YAML files for the dev directory

Now implement the variations for dev and prod by executing the following commands in your terminal.

```
cat <<EOF > chat-app/dev/kustomization.yaml
bases:
- ../base

namespace: dev
nameprefix: dev-
commonLabels:
  env: dev

patches:
- deployment.yaml
EOF
```

Note the addition of the `patches`:  section of the file. This indicates that kustomize should overlay those files on top of the base resources.

6. Implement the kustomize YAML files for the prod directory

```
cat <<EOF > chat-app/prod/kustomization.yaml
bases:
- ../base

namespace: prod
nameprefix: prod-
commonLabels:
  env: prod

patches:
- deployment.yaml
EOF
```

7. Run kustomize to merge the files
With the base and environment files created, you can execute the kustomize process to patch the base files.

   Run the following command for dev to see the merged result.

```
kustomize build chat-app/dev
```

Note the output contains merged results such as labels from base and dev configurations as well as the container image name from the base and the environment variable from the dev folders.

## Utilizing multiple layers of overlays

Many organizations have a team that helps support the app teams and manage the platform. Frequently these teams will want to include specific details that are to be included in all apps across all environments, such as a logging agent.

In this example, you will create a `shared-kustomize` folder and resources which will be included by all applications and regardless of which environment they're deployed.

1. Create the shared-kustomize folder

```
mkdir shared-kustomize
```

2. Create a simple `deployment.yaml` in the shared folder

```
cat <<EOF > shared-kustomize/deployment.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
  name: app
spec:
  template:
    spec:
      containers:
      - name: logging-agent
        image: logging-agent-image
EOF
```

3. Create a kustomization.yaml in the shared folder

```
cat <<EOF > shared-kustomize/kustomization.yaml
bases:
  - deployment.yaml
EOF
```

4. Reference the shared-kustomize folder from your application

Since you want the `shared-kustomize` folder to be the base for all your applications, you will need to update your `chat-app/base/kustomization.yaml` to use `shared-kustomize` as the base. Then patch its own deployment.yaml on top. The environment folders will then patch again on top of that.

Copy and execute the following commands in your terminal

```
cat <<EOF > chat-app/base/kustomization.yaml
bases:
  - ../../shared-kustomize

commonLabels:
  app: chat-app

patches:
- deployment.yaml

EOF
```

5. Run kustomize and view the merged results for dev

```
kustomize build chat-app/dev
```

Note the output contains merged results from the app base, the app environment, and the `shared-kustomize` folders. Specifically, you can see in the containers section values from all three locations.

(output do not copy)

```
    containers:
          - env:
            - name: ENVIRONMENT
              value: dev
            name: chat-app
          - image: image
            name: app
          - image: logging-agent-image
            name: logging-agent
```


text:
package org.eck.json.validators;

import org.eck.json.JsonValidationResult;
import org.eck.json.JsonValidator;
import org.eck.json.validators.NotNullValidator;
import org.junit.Assert;
import org.junit.Test;

import com.google.gson.JsonNull;
import com.google.gson.JsonObject;

public class NotNullValidatorTest {

    @Test
    public void testValidate() {
        JsonValidator validator = new JsonValidator();
        validator.addValidator("someField", new NotNullValidator());

        JsonObject obj = new JsonObject();

        JsonValidationResult result = validator.validate(obj);
        Assert.assertEquals(true, result.hasErrors());
        Assert.assertEquals(1, result.fieldsInError().size());
        Assert.assertEquals("someField", result.fieldsInError().get(0));
        Assert.assertEquals("NotNull", result.getError("someField"));

        obj = new JsonObject();
        obj.add("someField", JsonNull.INSTANCE);

        result = validator.validate(obj);
        Assert.assertEquals(true, result.hasErrors());

        obj = new JsonObject();
        obj.addProperty("someField", "Some content");

        result = validator.validate(obj);
        Assert.assertEquals(false, result.hasErrors());
    }
}


text:
{% extends "default.html" %}
{% block content %}

{{ allergies['total'] }} allergies

{% for entry in allergies['entry'] %}

        {{ entry['resource']['substance']['text'] }} -
        {% for reaction in entry['resource']['reaction'] %}
            {% for manifestation in reaction['manifestation'] %}
                {{ manifestation['text'] }}
            {% endfor %}
        ({{ reaction['status'] }} onset {{ reaction['onset'] }})
        {% endfor %}

{% endfor %}

{% endblock %}


text:
/**
 * SwaBindingImpl.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis 1.2alpha Dec 07, 2003 (08:01:12 EST) WSDL2Java emitter.
 */
package samples.swa;

import org.apache.axis.AxisFault;
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.attachments.AttachmentPart;
import org.apache.axis.attachments.Attachments;

import javax.activation.DataHandler;
import javax.mail.internet.MimeBodyPart;
import java.util.Iterator;

/**
 * Class SwaBindingImpl
 *
 * @version %I%, %G%
 */
public class SwaBindingImpl implements samples.swa.SwaPort {

    /**
     * Method swaSend
     *
     * @param applicationName
     * @param content
     * @return
     * @throws java.rmi.RemoteException
     */
    public java.lang.String swaSend(
            java.lang.String applicationName, javax.mail.internet.MimeMultipart content)
            throws java.rmi.RemoteException {

        MimeBodyPart mpb = null;

        System.out.println("Application: " + applicationName);

        /*
         * Now do some printing to get information about the multipart
         * content and the associated attachments.  Axis performs
         * several steps during deserialization of this SOAP
         * call. Only the steps of interesst are described here.
         *
         * The MIME multipart that contains the other parts (because
         * it's multipart/mixed or multipart/related) is handled as
         * ONE Axis attachment during the first part of
         * deserialization. This attachment is identified by the CID:
         * prefixed string generated during serialization.
         *
         * The next step (see
         * MimeMultipartDataHandlerDeserializer.java) gets the data
         * handler of the Axis attachment and creates a MimeMultipart
         * object using the data source as input of the new
         * MimeMultipart object. The MimeMultipart object parses the
         * input (on demand? -> this need to be clarified) and builds
         * the associated body parts.
         *
         * The Axis attachment part is not disposed or otherwise
         * managed after it was serialized into the MimeMultipart
         * object. Therefore it is a good idea to call the dispose()
         * method of the Axis attachment part after processing is
         * complete.  Doing so releases all used resources, also
         * deleting disk cache files if necessary, of this attachment
         * part.
         */
        try {
            int contCount = content.getCount();

            System.out.println("Number of Mimeparts: " + contCount);

            for (int i = 0; i < contCount; i++) {
                mpb = (MimeBodyPart) content.getBodyPart(i);

                DataHandler dh = mpb.getDataHandler();

                System.out.println("Mime data type: " + dh.getContentType());
            }
        } catch (javax.mail.MessagingException ex) {
        }

        /*
         * the next prints are just for information only
         */
        AttachmentPart[] attParts = getMessageAttachments();

        System.out.println("Number of attachements: " + attParts.length);

        if (attParts.length > 0) {
            try {
                System.out.println("Att[0] type: "
                        + attParts[0].getContentType());
                System.out.println(
                        "Att[0] dh type: "
                        + attParts[0].getDataHandler().getContentType());
                System.out.println("Att[0] file: "
                        + attParts[0].getAttachmentFile());
            } catch (javax.xml.soap.SOAPException ex) {
            }
        }

        /*
         * Now process the parametes including the MimeMultipart
         */

        /*
         * Processing is done, now dispose the attachements. This is not done
         * by Axis, should be done by service.
         */
        MessageContext msgContext = MessageContext.getCurrentContext();
        Message reqMsg = msgContext.getRequestMessage();
        Attachments messageAttachments = reqMsg.getAttachmentsImpl();

        messageAttachments.dispose();

        return null;
    }

    /**
     * extract attachments from the current request
     *
     * @return a list of attachmentparts or
     *         an empty array for no attachments support in this axis
     *         buid/runtime
     * @throws AxisFault
     */
    private AttachmentPart[] getMessageAttachments() throws AxisFault {

        MessageContext msgContext = MessageContext.getCurrentContext();
        Message reqMsg = msgContext.getRequestMessage();
        Attachments messageAttachments = reqMsg.getAttachmentsImpl();
        int attachmentCount =
                messageAttachments.getAttachmentCount();
        AttachmentPart attachments[] = new AttachmentPart[attachmentCount];
        Iterator it =
                messageAttachments.getAttachments().iterator();
        int count = 0;

        while (it.hasNext()) {
            AttachmentPart part = (AttachmentPart) it.next();
            attachments[count++] = part;
        }
        return attachments;
    }
}


text:
package mahalanobis

import (
	"errors"
	"github.com/skelterjohn/go.matrix"
	"math"
)

// Given a set a points, return the mean vector.
// points.Rows() = dimensions. points.Cols() = number of points.
func MeanVector(points *matrix.DenseMatrix) *matrix.DenseMatrix {
	mean := matrix.Zeros(points.Rows(), 1)
	for i := 0; i < points.Rows(); i++ {
		sum := 0.0
		for j := 0; j < points.Cols(); j++ {
			sum += points.Get(i, j)
		}
		mean.Set(i, 0, sum/float64(points.Cols()))
	}
	return mean
}

func sample_covariance_matrix(points, mean *matrix.DenseMatrix) *matrix.DenseMatrix {
	dim := points.Rows()
	cov := matrix.Zeros(dim, dim)
	for i := 0; i < dim; i++ {
		for j := 0; j < dim; j++ {
			if i > j {
				// symetric matrix
				continue
			}
			// TODO in go routines ?
			sum := 0.0
			for k := 0; k < points.Cols(); k++ {
				sum += (points.Get(i, k) - mean.Get(i, 0)) * (points.Get(j, k) - mean.Get(j, 0))
			}

			// this is the sample covariance, divide by (N - 1)
			covariance := sum / (float64(points.Cols() - 1))

			cov.Set(i, j, covariance)
			// symetric matrix
			cov.Set(j, i, covariance)

		}
	}
	return cov
}

// Return the covariance matrix for this set of points (sample covariance is used)
// points.Rows() = dimensions. points.Cols() = number of points.
func CovarianceMatrix(points *matrix.DenseMatrix) *matrix.DenseMatrix {
	mean := MeanVector(points)
	return sample_covariance_matrix(points, mean)
}

// Return the square of the Mahalanobis distance
// points.Rows() = dimensions. points.Cols() = number of points.
// target.Cols = 1
func DistanceSquare(points, target *matrix.DenseMatrix) (float64, error) {
        // TODO support multiple points for target, and return a matrix of distances
	if target.Rows() != points.Rows() {
		err := errors.New("target does not have the same dimension than points")
		return -1, err
	}

	mean := MeanVector(points)

	delta := target.Copy()
	delta.SubtractDense(mean)

	cov := sample_covariance_matrix(points, mean)

	inv, err := cov.Inverse()
	if err != nil {
		return -1, err
	}

	product1, err := inv.TimesDense(delta)
	if err != nil {
		return -1, err
	}
	delta_t := delta.Transpose()
	product2, err := delta_t.TimesDense(product1)
	if err != nil {
		return -1, err
	}

	return product2.Get(0, 0), nil
}

// Return the Mahalanobis distance
// points.Rows() = dimensions. points.Cols() = number of points.
// target.Cols = 1
func Distance(points, target *matrix.DenseMatrix) (float64, error) {
	square, err := DistanceSquare(points, target)
	if err != nil {
		return -1, err
	}
	return math.Sqrt(square), nil

}


text:
package org.cloudfoundry.operations.organizationadmin;

import org.junit.Test;

public final class DeleteQuotaRequestTest {

    @Test(expected = IllegalStateException.class)
    public void noName() {
        DeleteQuotaRequest.builder()
            .build();
    }

    @Test
    public void valid() {
        DeleteQuotaRequest.builder()
            .name("test-quota")
            .build();
    }

}


text:
<?php

namespace Nette\Application;

use Nette;

/**
 * The exception that is thrown when user attempts to terminate the current presenter or application.
 * This is special "silent exception" with no error message or code.
 */
class AbortException extends \Exception
{
}

/**
 * Application fatal error.
 */
class ApplicationException extends \Exception
{
}

/**
 * The exception that is thrown when a presenter cannot be loaded.
 */
class InvalidPresenterException extends \Exception
{
}

/**
 * Bad HTTP / presenter request exception.
 */
class BadRequestException extends \Exception
{
	/** @var int */
	protected $defaultCode = 404;

	public function __construct($message = '', $code = 0, \Exception $previous = NULL)
	{
		parent::__construct($message, $code < 200 || $code > 504 ? $this->defaultCode : $code, $previous);
	}

}

/**
 * Forbidden request exception - access denied.
 */
class ForbiddenRequestException extends BadRequestException
{
	/** @var int */
	protected $defaultCode = 403;

}


text:
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package gaderian.test.services;

import gaderian.test.services.SimpleService;
import gaderian.test.FrameworkTestCase;

import org.ops4j.gaderian.ApplicationRuntimeException;
import org.ops4j.gaderian.Registry;

/**
 * Tests the ability for a module to specify a default service factory id
 *
 * @author Johan Lindquist
 */
public class TestSimpleModuleWithDefaultFactoryServiceId extends FrameworkTestCase
{
    public void testSimpleModuleWithUnknownDefaultFactoryServiceId() throws Exception
    {
        Registry r = buildFrameworkRegistry("SimpleModuleWithUnknownDefaultServiceFactory.xml", false );

        try
        {
            final SimpleService serviceDefaultFactory = r.getService("gaderian.test.services.default.service.factory.SimpleDefault", SimpleService.class);
            assertEquals(3, serviceDefaultFactory.add(1,2));
            final SimpleService serviceBuilderFactory = r.getService("gaderian.test.services.default.service.factory.SimpleBuilderFactory", SimpleService.class);
            assertEquals(3, serviceBuilderFactory.add(2, 1));
        }
        catch (ApplicationRuntimeException e)
        {
            e.printStackTrace();
        }
    }

}


text:
module ArticleFeed
  VERSION = "0.0.1"
end


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
null

#### Original name
Gyrostomum scyphuliferum var. scyphuliferum (Ach.) Nyl.

### Remarks
null


text:
<?php

namespace Cake\Test\TestCase\View\Widget;

use Cake\TestSuite\TestCase;
use Cake\View\StringTemplate;
use Cake\View\Widget\Textarea;

/**
 * Textarea input test.
 */
class TextareaTest extends TestCase {

/**
 * setup
 *
 * @return void
 */
	public function setUp() {
		parent::setUp();
		$templates = [
			'textarea' => '<textarea name="{{name}}"{{attrs}}>{{value}}</textarea>',
		];
		$this->templates = new StringTemplate($templates);
	}

/**
 * Test render in a simple case.
 *
 * @return void
 */
	public function testRenderSimple() {
		$input = new Textarea($this->templates);
		$result = $input->render(['name' => 'comment']);
		$expected = [
			'textarea' => ['name' => 'comment'],
			'/textarea',
		];
		$this->assertTags($result, $expected);
	}

/**
 * Test render with a value
 *
 * @return void
 */
	public function testRenderWithValue() {
		$input = new Textarea($this->templates);
		$data = ['name' => 'comment', 'data-foo' => '<val>', 'val' => 'some <html>'];
		$result = $input->render($data);
		$expected = [
			'textarea' => ['name' => 'comment', 'data-foo' => '<val>'],
			'some <html>',
			'/textarea',
		];
		$this->assertTags($result, $expected);

		$data['escape'] = false;
		$result = $input->render($data);
		$expected = [
			'textarea' => ['name' => 'comment', 'data-foo' => '<val>'],
			'some <html>',
			'/textarea',
		];
		$this->assertTags($result, $expected);
	}

}