text:
package org.clinical3PO.learn.util;

import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.TreeMap;
import java.util.Vector;

/**
 * class for handling the filtered patient data files written by Wim's filtering toolchain
 * Format is like this, per line: - see below.
 * THE IDEA IS YOU ALLOCATE ONE OF THESE, accumulate possibly several files with it, and then fetch its featuresFound and foundValues members
 *
 * @author sean
 *
 */

public class C3POFilteredPatientData {

	/**
	 * constants for the positions of fixed-position tokens within the input lines
	 */
	public static final int NumRequiredTokens = 2;		//number of fixed-position tokens expected
	public static final int IDToken = 0;
	public static final int FeatureNameToken = 1;

	//then the giant intermediate form of everything
	//outermost level maps patient ID string to:
	//  map of feature name string to a
	//    map indexed by bin 0..47 for hour to a vector of ValueStatus for each bin.
	//  and if there is no entry for that bin, do what?
	TreeMap<String,TreeMap<String,TreeMap<Integer,Vector<C3POPatientPropertyMeasurement>>>> foundValues;
	TreeMap<String,String> featuresFound;

	public TreeMap<String, TreeMap<String, TreeMap<Integer, Vector<C3POPatientPropertyMeasurement>>>> getFoundValues() {
		return foundValues;
	}

	public void setFoundValues(
			TreeMap<String, TreeMap<String, TreeMap<Integer, Vector<C3POPatientPropertyMeasurement>>>> foundValues) {
		this.foundValues = foundValues;
	}

	public TreeMap<String, String> getFeaturesFound() {
		return featuresFound;
	}

	public void setFeaturesFound(TreeMap<String, String> featuresFound) {
		this.featuresFound = featuresFound;
	}

	//ctor

	public C3POFilteredPatientData() {
		// TODO Auto-generated constructor stub
		foundValues = new TreeMap<String,TreeMap<String,TreeMap<Integer,Vector<C3POPatientPropertyMeasurement>>>>();
		featuresFound = new TreeMap<String,String>();
	}

	//getMinBinForAttr, given an attribute, returns the lowest numbered bin recorded for it, if any
	//-1 on error. Not sure if this is really useful.
	public int getMinBinForAttr(String attr) {
		if(foundValues == null) return -1;
		int MinBin = Integer.MAX_VALUE;
		for(String pid:foundValues.keySet()) {
			if(foundValues.get(pid).containsKey(attr)) {
				TreeMap<Integer,Vector<C3POPatientPropertyMeasurement>> bins = foundValues.get(pid).get(attr);
				//since this is a treemap, the first key is the minimum bin, yes?
				int localmin = bins.firstKey().intValue();
				if(localmin < MinBin) MinBin = localmin;
			}
		}
		//if minbin is integer max, we never found any bins...?
		if(MinBin == Integer.MAX_VALUE) return -1;
		return MinBin;
	}

	//getMaxBinForAttr, given an attribute, returns the lowest numbered bin recorded for it, if any
	//-1 on error. Not sure if this is really useful.
	public int getMaxBinForAttr(String attr) {
		if(foundValues == null) return -1;
		int MaxBin = Integer.MIN_VALUE;
		for(String pid:foundValues.keySet()) {
			if(foundValues.get(pid).containsKey(attr)) {
				TreeMap<Integer,Vector<C3POPatientPropertyMeasurement>> bins = foundValues.get(pid).get(attr);
				//since this is a treemap, the last key is the maximum bin, yes?
				int localmax = bins.lastKey().intValue();
				if(localmax > MaxBin) MaxBin = localmax;
			}
		}
		//if maxbin is integer min, we never found any bins...?
		if(MaxBin == Integer.MIN_VALUE) return -1;
		return MaxBin;
	}

	/**
	 * addValueToBin, once a timestamp:value pair has been vetted for a given attribute - including its passing muster
	 * wrt the timestamp and attribute filters used to derive the input file - just records it in foundValues.
	 * This method doesn't do any of that vetting itself, accepts all comers.
	 * @param patientID
	 * @param feature
	 * @param bin - index of bin to put value in: currently the same as the timestamp's hour
	 * although this will remain the same even if that changes (caller needs to worry about deriving bin index correctly)
	 * @param value
	 * @param status = true for OK, false for error - later may branch out
	 * @return
	 */

	public boolean addValueToBin(String patientID, String attr, int bin, double value, String status) throws Exception {
		//see if there's a feature set for this patient
		if(!foundValues.containsKey(patientID)) {
			foundValues.put(patientID, new TreeMap<String,TreeMap<Integer,Vector<C3POPatientPropertyMeasurement>>>());
		}

		//see if there's a set of values for this feature
		if(!foundValues.get(patientID).containsKey(attr)) {
			foundValues.get(patientID).put(attr, new TreeMap<Integer,Vector<C3POPatientPropertyMeasurement>>());
		}

		//see if there's a bin for this hour
		if(!foundValues.get(patientID).get(attr).containsKey(Integer.valueOf(bin))) {
			foundValues.get(patientID).get(attr).put(Integer.valueOf(bin),new Vector<C3POPatientPropertyMeasurement>());
		}

		//Add the new value/status to the bin for this hour
		Vector<C3POPatientPropertyMeasurement> vecvs = foundValues.get(patientID).get(attr).get(Integer.valueOf(bin));

		//TODO DANGER KLUDGE HORROR: I think this class is going to go away anyway, but for now need to patch
		//it by adding a timestamp. We'll just call it in seconds, 3600 * bin...?
		//TODO DANGER KLUDGE HARDCODE
		//TODO DANGER KLUDGE HARDCODE
		//TODO DANGER KLUDGE HARDCODE
		//TODO DANGER KLUDGE HARDCODE
		//TODO DANGER KLUDGE HARDCODE
		//TODO DANGER KLUDGE HARDCODE
		//TODO DANGER KLUDGE HARDCODE
		//TODO DANGER KLUDGE HARDCODE
		//TODO DANGER KLUDGE HARDCODE
		vecvs.add(new C3POPatientPropertyMeasurement(value,status,bin*3600));

		return true;
	}

	/**
	 * handleTSValuePairs assumes handleLine has been called and has verified that there are an even
	 * number of tokens after the required ones
	 *
	 * @param patientID - derived by caller (though for the moment it's also in toks)
	 * @param attr - "
	 * @param toks
	 * @param fcfg - filter configuration used for creating the given input file
	 * if null, use all attributes and all bins found? Sure. Includes global time range.
	 * @return
	 * @throws Exception
	 *
    *********************************
    10/22/13: NOTE FOR NOW I'M GOING TO DO HOUR BINS AND SAY WE TELL IT OUR GLOBAL RANGE IS 05:22 TO 07:17 I WILL
    REJECT VALUES EARLIER THAN 5:22 AND LATER THAN 7:16 BUT STILL HAVE BINS FOR 5:00-5:59, 6:00-6:59,
    7:00-7:59 - ASK RE WHAT TO DO ABOUT THAT - like normalize so that the first bin is 5:22-6:21, etc?
    *********************************
	 *
	 *
	 *
	 */
	public boolean handleTSValuePairs(String patientID, String attr, String[] toks, C3POFilterConfiguration fcfg) throws Exception {
		//called by handleLine

		//step by twos since these are ts/value pairs
		//so: hour is the bin we want to stick this in, minute can be discarded.
		//FIRST PASS we need to come up with the mean - so we need to know the individual values
		//and the numbers of them. Or really just running total and number of values -
		//PER PATIENT. But! more compatible with eventual map/reduce version and alternate versions
		//that do max or min or whatever (or all of those!)
		//this really just parses into a data structure which we then postprocess... woe.
		//sure, OK.

		//new 10/22/13: if fcfg is non-null:
		//- if the attr isn't in fcfg, bail.
		//ACTUALLY SPECIAL CASE IF USESATTR IS EMPTY OR NULL, ALLOW ANY. (this is how no-config-loaded is handled in arffgen2 - might want a better
		//way to express it...)
		//so actually. if fcfg == null, or attrs used is null/empty, accept; otherwise usesAttribute(attr) must be so.
		if(fcfg != null && fcfg.getPropertiesUsed() != null && !fcfg.getPropertiesUsed().isEmpty()) {
			//non-null config with non-null/empty attrs used. Must be in there to bother.
			if(!fcfg.usesProperty(attr)) {
				//this attribute isn't in config. Done!
				return true;
			}
		}

		for(int j=C3POFilteredPatientData.NumRequiredTokens; j < toks.length; j+=2) {

			//new 10/22/13: if fcfg is non-null:
			//- if the attr/timestamp pair isn't "interesting" (attr isn't in the list or timestamp out of range)
			//  don't bother doing any of this.
			//toks[j] should be the timestamp.
			//remember to allow any attr if attrs used is null/empty
			//or rather:
			//if fcfg is non-null and its attrs-used non-null/empty, check for interestingness.
			//so, if fcfg IS null or its attrs-used null/empty, assume interesting.
			if(fcfg == null || fcfg.getPropertiesUsed() == null || fcfg.getPropertiesUsed().isEmpty() || fcfg.interesting(attr, toks[j])) {

				//fetch ts/value numbers: format conversion from string throws exception if they're not legal
				//parse timestamp
				//LET'S STICK WITH THIS BECAUSE IT'S REALLY ABOUT BIN INDEX DERIVATION AND CURRENTLY
				//WE'RE DOING HOUR BINS...
				String[] tstoks = toks[j].split(":",2);		//format is hour:minute, so split on colon
				int hour = Integer.valueOf(tstoks[0]);
				//int min = Integer.valueOf(tstoks[1]);
				double value = 0.0;
				//but here's the variable that will still be right semantically when we do not-necessarily-hour bins
				int binIndex;
				//for now, it's the same as hour.
				binIndex = hour;

				try {
					value = Double.valueOf(toks[j+1]);

					//record!

					//OK THIS NEEDS TO BE FIDDLED TO HANDLE UNKOWNS... or no, that's at arff-generation time
					//it's not unknown if we found it here.

					//put the newly found value in the bin (HEY ERROR TRAP)
					addValueToBin(patientID, attr, binIndex, value, C3POPatientPropertyMeasurement.okFeatureStatus);

				} catch (NumberFormatException e) {
					//bad value; record an error status for it (HEY ERROR TRAP)
					addValueToBin(patientID, attr, binIndex, -1.0, C3POPatientPropertyMeasurement.errorFeatureStatus);
				}
			}

		}

		return true;
	}

	//note that timestamps appear to be given in random order.
	/*
	 140500      hr      47:22      58      40:22      65      27:22      89      04:22      85
	 	18:22      74      33:22      77      19:22      79      45:22      69      34:22      75
	 	04:52      77      32:22      81      05:22      78      03:22      71      20:22      93
	 	01:22      75      21:22      93      31:22      88      44:22      68      39:22      76
	 	22:22      86      06:22      76      38:22      76      30:22      91      23:22      88
	 	07:22      78      17:22      76      02:22      67      37:22      79      29:22      82
	 	07:37      78      16:22      77      36:22      73      01:52      68      15:22      78
	 	42:22      68      24:22      84      46:22      68      07:52      81      08:22      76
	 	25:22      83      14:22      76      28:22      87      09:22      80      13:22      77
	 	26:22      91      10:22      80      12:22      77

	 */
	public boolean handleLine(String theLine, C3POFilterConfiguration fcfg) throws Exception {
		//assume caller avoids blanks and nulls getting here
		//break it up by \s+ and handle it
		String[] toks = theLine.split("\\s+");

		if(toks.length >= C3POFilteredPatientData.NumRequiredTokens) {

			//sanity check - there should be an even number of tokens after the required
			if(((toks.length - C3POFilteredPatientData.NumRequiredTokens) % 2) == 0) {
				//deal with it - split off ID and feature
				String patientID = toks[C3POFilteredPatientData.IDToken];
				String featureName = toks[C3POFilteredPatientData.FeatureNameToken];

				//here record the feature in featuresFound - this is massively redundant
				//but that's what TreeMaps are all about - boil the redundant down to unique.
				//debug RIP OUT
				//if(!featuresFound.containsKey(featureName))	System.err.println("Found new feature: " + featureName);
				//TODO: DANGER! FOR NOW,
				featuresFound.put(featureName, "NUMERIC");

				//then digest the ts/val pairs
				//TODO ERROR TRAP
				handleTSValuePairs(patientID, featureName, toks, fcfg);
			} else {
				//??? badly formed - for now, warn
				System.err.println("C3POFilteredPatientData.handleLine WARNING: line with odd number of tokens after required");
				System.err.println(theLine);
			}

		} else {
			//??? badly formed - for now, warn
			System.err.println("C3POFilteredPatientData.handleLine WARNING: line with fewer than " + C3POFilteredPatientData.NumRequiredTokens + " tokens:");
			System.err.println(theLine);
		}

		return true;
	}

	/**
	 * accumulateInput adds the given file to its foundValues and featuresFound.
	 * @param isr - inputstreamreader for the file of filtered patient data
	 * @param fcfg - filter configuration used for creating the given input file
	 * if null, use all attributes and all bins found
	 * @return
	 * @throws Exception
	 */
	public boolean accumulateInput(InputStreamReader isr, C3POFilterConfiguration fcfg) throws Exception {

		LineNumberReader lnr = new LineNumberReader(isr);

		//debug RIP OUT
		//System.err.println("-- in C3POFPD.accumulateInput()");

		String theLine = lnr.readLine();

		while (theLine != null) {

			//ignore blank lines
			if(!theLine.isEmpty()) {

				//debug RIP OUT
				//System.err.println("-- line: |" + theLine + "|");

				if(!handleLine(theLine,fcfg)) {
					//ERROR?
					//return null;
				}
			}

			theLine = lnr.readLine();
			if(theLine!=null) theLine = theLine.trim();
		}

		return true;
	}

}


text:
from flask import render_template, url_for, redirect, flash, send_from_directory, jsonify, request, Markup, Response, make_response
from flask.ext.cache import Cache

#HTML Minifier
from htmlmin.minify import html_minify

# mandrill emailing
from flask.ext.mandrill import Mandrill

# MongoDB specific imports
from pymongo import MongoClient

# PQR specific imports
from pqr import pqr, secret_config

from settings import APP_JSON, APP_MOL2, APP_ARTICLES

# Python library imports
import os
import ujson as json
import markdown
import datetime
from Levenshtein import ratio

# Regular expressions for chemical formula parsing
import re

cache = Cache(pqr, config={'CACHE_TYPE': 'simple'})
cache.init_app(pqr)

redirect_table = {}
amount_mol = None
MOLECULE_OF_THE_WEEK = 'GZCGUPFRVQAUEE-SLPGGIOYSA-N'
WEEKLY_MOL_NAME = None
pqr.debug = True

last_updated_wm = datetime.datetime.strptime('Aug 7 1996', '%b %d %Y').date()

Masses = dict(H=1.01, He=4.00, Li=6.94, Be=9.01, B=10.81, C=12.01,
	  N=14.01, O=16.00, F=19.00, Ne=20.18, Na=22.99, Mg=24.31,
	  Al=26.98, Si=28.09, P=30.97, S=32.07, Cl=35.45, Ar=39.95,
	  K=39.10, Ca=40.08, Sc=44.96, Ti=47.87, V=50.94, Cr=52.00,
	  Mn=54.94, Fe=55.85, Co=58.93, Ni=58.69, Cu=63.55, Zn=65.39,
	  Ga=69.72, Ge=72.61, As=74.92, Se=78.96, Br=79.90, Kr=83.80,
	  Rb=85.47, Sr=87.62, Y=88.91, Zr=91.22, Nb=92.91, Mo=95.94,
	  Tc=98.00, Ru=101.07, Rh=102.91, Pd=106.42, Ag=107.87,
	  Cd=112.41, In=114.82, Sn=118.71, Sb=121.76, Te=127.60,
	  I=126.90, Xe=131.29, Cs=132.91, Ba=137.33, La=138.91,
	  Ce=140.12, Pr=140.91, Nd=144.24, Pm=145.00, Sm=150.36,
	  Eu=151.96, Gd=157.25, Tb=158.93, Dy=162.50, Ho=164.93,
	  Er=167.26, Tm=168.93, Yb=173.04, Lu=174.97, Hf=178.49,
	  Ta=180.95, W=183.84, Re=186.21, Os=190.23, Ir=192.22,
	  Pt=195.08, Au=196.97, Hg=200.59, Tl=204.38, Pb=207.2,
	  Bi=208.98, Po=209.00, At=210.00, Rn=222.00, Fr=223.00,
	  Ra=226.00, Ac=227.00, Th=232.04, Pa=231.04, U=238.03,
	  Np=237.00, Pu=244.00, Am=243.00, Cm=247.00, Bk=247.00,
	  Cf=251.00, Es=252.00, Fm=257.00, Md=258.00, No=259.00,
	  Lr=262.00, Rf=261.00, Db=262.00, Sg=266.00, Bh=264.00,
	  Hs=269.00, Mt=268.00)

##########################################################################

#@pqr.before_request
#def beforeRequest():
#    if 'https://' not in request.url:
#        return redirect(request.url.replace('http://', 'https://'))

@pqr.route('/')
@pqr.route('/home', strict_slashes=False)
@cache.cached(timeout=86400)
def index():
    global last_updated_wm
    global MOLECULE_OF_THE_WEEK
    global WEEKLY_MOL_NAME

    page = {'id': "page-home"}
    articles = [os.path.splitext(article)[0]
                       for article in next(os.walk(APP_ARTICLES))[2]]
    new_articles = sorted(get_new_articles(articles, 14), reverse=True)
    articles = sorted(list(set(articles) - set(new_articles)), reverse=True)

    # Merge articles with formatted titles
    titles = map(lambda x: x.split('-'), articles)
    titles = map(lambda x: "{0} ({1})".format(' '.join(x[3:]), x[2] + ' ' + x[1] + ' ' + x[0]), titles)
    articles = zip(articles, titles)

    # Do the same thing with new articles
    titles = map(lambda x: x.split('-'), new_articles)
    titles = map(lambda x: "{0} ({1})".format(' '.join(x[3:]), x[2] + ' ' + x[1] + ' ' + x[0]), titles)
    new_articles = zip(new_articles, titles)

    today = datetime.date.today()
    idx = (today.weekday() + 1) % 7
    sun = today - datetime.timedelta(7+idx)

    if last_updated_wm < sun:
        weekly_mol = get_weekly_molecule_list()[-1].split(',')
        MOLECULE_OF_THE_WEEK = weekly_mol[0]
        WEEKLY_MOL_NAME = weekly_mol[1]
        last_updated_wm = today

    week_mol = (MOLECULE_OF_THE_WEEK[:2] + "/" + MOLECULE_OF_THE_WEEK)

    rendered_html = render_template("home.html", page=page, amount_mol=amount_mol, articles=articles, new_articles=new_articles, week_mol=week_mol, week_mol_name=WEEKLY_MOL_NAME)
    min_html = html_minify(rendered_html.encode('utf8'))
    return min_html

##########################################################################
@pqr.route('/mol/<key>', strict_slashes=False)
@pqr.route('/mol', strict_slashes=False)  # if no key lets default to the molecule of the day
@cache.cached(timeout=43200)
def molecule(key="-1"):
    if key == "-1":
        key = MOLECULE_OF_THE_WEEK

    # Checks to see if the key passed in exists in the redirect table
    # If it does, it redirects to this same route, except with the proper key
    # It also flashes a message that shows the redirection
    if key in redirect_table.keys():
        flash("Redirected! " + str(key) +
              " is actually the same as " + str(redirect_table[key]), 'redirect')
        return redirect(url_for('molecule', key=redirect_table[key]))

    # This gets the first two characters of the key, allowing for directory
    # traversal
    key_first_two = key[:2]

    page = {'id': "page-molecule", 'moleculeKey': key,
            'key_first_two': key_first_two}

    try:
        # Loads the JSON file relevant to the InChI key requested
        with open(os.path.join(APP_JSON, key_first_two + '/' + key + '.json')) as j:
            json_dict = json.load(j)
    except IOError:
        # If we don't have the key, flash
        flash(
            "You entered a molecule that didn't exist, so you've been redirected to the molecule of the week!", 'redirect')
        return redirect(url_for('molecule', key=MOLECULE_OF_THE_WEEK))

    meta_description = "You are viewing an interactive 3D depiction of the molecule " + json_dict["name"] + " (" + json_dict["formula"] + ") from the PQR."

    # return the view
    return render_template("molecule.html", page=page, jsonDict=json_dict, metaDescription=meta_description)
    #min_html = html_minify(rendered_html.encode('utf8'))
    #return min_html

##########################################################################
@pqr.route('/news', strict_slashes=False)
@pqr.route('/news/<title>', strict_slashes=False)
@cache.cached(timeout=86400)
def news(title="-1"):
    page = {'id': "page-news"}

    try:
        # Loads the JSON file relevant to the InChI key requested
        with open(os.path.join(APP_ARTICLES,  title + '.md'), 'r') as f:
            opened = f.read().strip()
            html = markdown.markdown(opened)
            f.close()
    except IOError:
        # If we don't have the key, flash
        flash(
            "You entered a article that doesn't exist! You have been redirected to the home page.", 'redirect')
        return redirect(url_for('index'))

    output = Markup(html)

    rendered_html = render_template("news.html", output=output, page=page)
    min_html = html_minify(rendered_html.encode('utf8'))
    return min_html

##########################################################################

@pqr.route('/browse', strict_slashes=False)
@pqr.route('/browse/<page_num>', strict_slashes=False)
#@cache.memoize(timeout=86400)
def browse(page_num="-1"):

    # Get the page number that is passed in
    # If negative, make it positive
    # If no page number is passed in, assume it is 1
    try:
        page_num = abs(int(page_num))
    except ValueError:
        page_num = 1

    # Set the query string
    query = request.args.get('query', '').lower()

    # this is the get variable type accepted values name,inchi, keyword,
    # formula
    searchType = request.args.get('type', '')

    # If there was no query searched for, flash and go to home
    if query == "-1":
        flash(
            "You didn't search for anything! You have been redirected to the home page.", 'redirect')
        return redirect(url_for('index'))

    # Initialize the Mongo client
    client = MongoClient()
    db = client.test

    results = []

    # Do a text search for the passed in query
    if searchType == 'formula':
        query = query.upper()
    elif searchType == 'tag':
        searchType = 'tags'
    elif searchType == 'synonym':
        searchType = 'synonyms'
    elif searchType == 'inchi':
        searchType = 'inchikey'
        query = query.upper()
        if query in redirect_table.keys():
            query = redirect_table[query]
    cursor = db.molecules.find({str(searchType): str(query)}).limit(500)

    # Append all dicts in the cursor to a results array
    for i in cursor:
        i["mol2url"] = i["inchikey"][:2] + "/" + i["inchikey"]
        i["json_data"] = get_json_data_file(i["inchikey"][:2], i["inchikey"])
        results.append(i)

    if len(results) == 0:
        cursor = db.molecules.find({"$text": {"$search": str(query)}})
        for i in cursor:
            i["mol2url"] = i["inchikey"][:2] + "/" + i["inchikey"]
            try:
                i["json_data"] = get_json_data_file(i["inchikey"][:2], i["inchikey"])
                results.append(i)
            except:
                if len(list(cursor)) == 0:
                    rendered_html = render_template("browse.html", page=page, results=[], query=query, searchType=searchType, typenum_pages=1, active=active, total_results=0)
                    min_html = html_minify(rendered_html.encode('utf8'))
                    return min_html

    # Find lightest molecule to normalize mass-based search
    temp = sorted(
        map(lambda x: x["formula"], results), key=lambda x: formula2mass(x))
    lightest = formula2mass(temp[0]) if temp else 1e12

    results = sorted(results, key=lambda x: similar(
        x[searchType], x['formula'], lightest, str(query)), reverse=True)

    # If there is only one result, show that molecule page directly
    total_results = len(results)
    if total_results == 1:
        return redirect(url_for('molecule', key=results[0]["inchikey"]))

    # Split the reults array into chunks of 50 each for search pagination - 50 for AJAX (May want to change)
    if request.args.get('ajax'):
        tempArr = list(chunks(results, 100))
    else:
        tempArr = list(chunks(results, 100))

    # The number of pages is just the total number of chunks
    num_pages = len(tempArr)

    # If the number of pages is more than 0, return the N-1th page to the template
    # If the number of pages is 0, that means there are no results, so results = None
    # If an index that doesn't exist is accessed (user manually making a URL query),
    # then just go to the first page of results
    try:
        if num_pages > 0:
            results = tempArr[page_num - 1]
        else:
            results = None
    except IndexError:
        results = tempArr[0]

    page = {'id': "page-browse"}

    # This is to tell the front-end which page the user is on
    # If no page_num was passed in and there are multiple pages, first page is active
    # Else if no page_num was passed in and there is one page, make active -1 to hide pager
    # If the user passes is a page_num greater than the number of pages, then first page
    # Else the active page is just whatever page the user is on
    if page_num == -1 and num_pages > 1:
        active = 1
    elif page_num == -1 and num_pages == 1:
        active = -1
    else:
        if page_num > num_pages:
            active = 1
        else:
            active = page_num

    if request.args.get('ajax'):
        return render_template("browse_ajax.html", results=results)
    else:
        rendered_html = render_template("browse.html", page=page, results=results, query=query, searchType=searchType, typenum_pages=num_pages, active=active, total_results=total_results)
        min_html = html_minify(rendered_html.encode('utf8'))
        return min_html

#################################################

@pqr.route('/suggestions', strict_slashes=False)
def searchSuggestions():
    if request.args.get('partial'):
        partial = request.args.get('partial').strip()
        return_items = get_suggestions(partial)
        return Response(json.dumps(return_items), mimetype='application/json')
    else:
        return Response(json.dumps([]), mimetype='application/json')

#################################################

@pqr.route('/api/weekly', strict_slashes=False)
@cache.cached(timeout=86400)
def weekly_molAPI():
    return_list = get_weekly_molecule_list()
    return Response("\n".join(return_list), mimetype='text/plain')

@pqr.route('/api/browse/<query>/<searchType>', strict_slashes=False)
def browseAPI(query, searchType):

    # Set the query string
    query = query.lower()

    # Initialize the Mongo client
    client = MongoClient()
    db = client.test

    results = []

    # Do a text search for the passed in query
    if searchType == 'formula':
        query = query.upper()
    elif searchType == 'tag':
        searchType = 'tags'
    elif searchType == 'synonym':
        searchType = 'synonym'
    elif searchType == 'inchi':
        searchType = 'inchikey'
        query = query.upper()
    else:
        searchType = 'name'

    cursor = db.molecules.find({str(searchType): str(query)})

    # Append all dicts in the cursor to a results array
    for i in cursor:
        i["mol2url"] = i["inchikey"][:2] + "/" + i["inchikey"]
        results.append(i)

    if len(results) == 0:
        cursor = db.molecules.find({"$text": {"$search": str(query)}})
        for i in cursor:
            i["mol2url"] = i["inchikey"][:2] + "/" + i["inchikey"]
            try:
                i["json_data"] = get_json_data_file(i["inchikey"][:2], i["inchikey"])
                results.append(i)
            except:
                if len(list(cursor)) == 0:
                    rendered_html = ""
                    min_html = html_minify(rendered_html.encode('utf8'))
                    return min_html

    # Find lightest molecule to normalize mass-based search
    # temp = sorted(map(lambda x: x["formula"], results), key=lambda x: formula2mass(x))
    # lightest = formula2mass(temp[0]) if temp else 1e12

    # results = sorted(results, key=lambda x: similar(x[searchType],
    # x['formula'], lightest, str(query)), reverse=True)

    for x in results:
        x["last_updated"] = x["last_updated"].isoformat()
        x.pop("_id", None)
        x.pop("properties_id", None)

    return Response(json.dumps(results), mimetype='application/json')

@pqr.route('/api/status', strict_slashes=False)
def getStatus():
    import os.path
    import time

    stuff_to_print = {}

    git_path = os.path.join(
        os.path.dirname(os.path.dirname(__file__)), ".git/")
    data_path = os.path.join(os.path.dirname(__file__), "static/data/")
    stuff_to_print['last_server_update'] = time.ctime(
        os.path.getmtime(git_path))
    stuff_to_print['last_data_update'] = time.ctime(
        os.path.getmtime(data_path))
    stuff_to_print['amount_of_molecules'] = amount_mol
    stuff_to_print['last_motw_update'] = str(last_updated_wm)

    return jsonify(stuff_to_print)

@pqr.route('/api/json/<key>', strict_slashes=False)
@cache.cached(timeout=86400)
def jsonAPI(key):

    # Open the relevant JSON file
    with open(os.path.join(APP_JSON, key[:2] + '/' + key + '.json')) as j:
        json_dict = json.load(j)

    # Return a JSON request with proper MIME type
    return jsonify(json_dict)

@pqr.route('/api/mol/<key>', strict_slashes=False)
@cache.cached(timeout=86400)
def molAPI(key):

    mol2 = []
    # Open the relevant mol2 file
    f = open(os.path.join(APP_MOL2, key[:2] + '/' + key + '.mol2'))

    # Return a MOL2 request with the proper MIME type
    response =  Response(f.read().strip(), mimetype='chemical/x-mol2')
    response.headers['Content-Disposition'] = 'attachment; filename=%s' % (key + '.mol2')
    return response

# Return a webpage with a list of all the InChIKeys

@pqr.route('/api/inchikeys', strict_slashes=False)
def inchiAPI():

    root = APP_JSON
    file_list = []

    for folder, subs, files in os.walk(root):
        for fn in files:
            file_list.append(fn.replace('.json', ''))

    return Response("\n".join(file_list), mimetype='text/plain')
##########################################################################

@pqr.route('/contact', methods=['POST', 'GET'], strict_slashes=False)
@cache.cached(timeout=259200)
def contact():
    page = {'id': "page-contact"}

    if request.method == 'GET':
            rendered_html = render_template("contact.html", page=page)
            min_html = html_minify(rendered_html.encode('utf8'))
            return min_html
    else:
        if(validate_contact_us(request.form)):
            send_email(request.form)
            rendered_html = render_template("contact.html", page=page)
            min_html = html_minify(rendered_html.encode('utf8'))
            return min_html

##########################################################################
@pqr.route('/sitemap/<index>', methods=['GET'], strict_slashes=False)
def sitemap(index):
    pages = []
    if index == "0":
        for rule in pqr.url_map.iter_rules():
            if "GET" in rule.methods and len(rule.arguments) == 0:
                pages.append([rule.rule])
        return render_template('sitemap.html', pages=pages, inchi=False)
    else:
        list_of_keys = getINCHIkeys(index)
        if(list_of_keys):
            return render_template('sitemap.html', pages=list_of_keys, inchi=True)
        else:
            return ""

##########################################################################
@pqr.route('/motw', strict_slashes=False)
@pqr.route('/molecules-of-the-week', strict_slashes=False)
def molecule_of_the_week():
    page = {'id': "page-motw"}
    week_molecules = []
    for week_molecule in get_weekly_molecule_list():
        week_molecules.append(week_molecule.split(','))

    print week_molecules
    rendered_html = render_template('molecule-of-the-week.html', page=page, week_molecules=week_molecules)
    min_html = html_minify(rendered_html.encode('utf8'))
    return min_html

##########################################################################

##########################################################################
@pqr.route('/sitemap.xml', methods=['GET'], strict_slashes=False)
def sitemapindex():
    directories = getINCHIfolders()
    return render_template('sitemapIndex.html', moldirs=directories)
##########################################################################

# Properly handle the favicon
@pqr.route('/favicon.ico', strict_slashes=False)
def favicon():
    return send_from_directory(os.path.join(pqr.root_path, 'static'),
                               'favicon.ico', mimetype='image/vnd.microsoft.icon')

# SEO
@pqr.route('/BingSiteAuth.xml', strict_slashes=False)
def BingSiteAuth():
    return send_from_directory(os.path.join(pqr.root_path, 'static'),
                               'BingSiteAuth.xml', mimetype='text/xml')

@pqr.route('/robots.txt', strict_slashes=False)
def RobotsTxt():
    return send_from_directory(os.path.join(pqr.root_path, 'static'),
                               'robots.txt', mimetype='text/plain')

##########################################################################

@pqr.route('/3spooky5me')
def clear_cache():
    if(not pqr.debug):
        return "You're not supposed to be here o_0"
    global cache
    cache.clear()
    cache = Cache(config={'CACHE_TYPE': 'null'})
    cache.init_app(pqr)
    print cache.config
    print pqr.debug
    flash('Cache cleared')
    return redirect(url_for('molecule', key=MOLECULE_OF_THE_WEEK))

##########################################################################
@pqr.route('/502/', strict_slashes=False)
def fiveohtwo():
  page = {'id': "page-error"}
  rendered_html = render_template("502.html", page=page, amount_mol=amount_mol)
  min_html = html_minify(rendered_html.encode('utf8'))
  return min_html

@pqr.errorhandler(404)
def page_not_found(e):
    #flash("Page not found", 404)
    return redirect(url_for('index'))

@pqr.errorhandler(500)
def page_not_found(e):
    flash("Page not found", 500)
    return redirect(url_for('index'))
##########################################################################

# Helper method to make chunks. Thanks StackOverflow
def chunks(l, n):
    """ Yield successive n-sized chunks from l.
    """
    for i in xrange(0, len(l), n):
        yield l[i:i + n]

# Validate the contact us form

def validate_contact_us(form):
    if(form['name'] and form['email'] and form['verify_email'] and form['subject'] and form['message']):
        if(form['email'] != form['verify_email']):
            flash("Emails don't match!", 'error')
            return False
        else:
            return True
    else:
        flash("Please make sure everything has been filled out!", "error")
        return False

# Send an email using mandrill

def send_email(form):
    mandrill = Mandrill(pqr)
    mandrill.send_email(
        from_email='webmaster@pqr.pitt.edu',
        subject=form['subject'],
        to=[{'email': pqr.config['DEFAULT_EMAIL']},
            {'email': 'jjr76@pitt.edu'}],
        text=form['subject'] + "\n" + "From: " +
        form['email'] + "\n" + form['message'],
        html=render_template("email/contact.html", date=datetime.now().strftime('%Y/%m/%d %H:%M:%S'),
                             name=form['name'], email=form['email'], subject=form['subject'], message=form['message']),
    )
    flash("Message has been sent!", 'sent')

def similar(x, f, m0, query):
    if isinstance(x, list):
        score_list = map(lambda z: similar(z, f, m0, query), x)
        return sum(score_list)
    else:
        # if x in query:
        try:
            if query in x:
                score = 10 + ratio(x.encode('utf8', 'ignore'), query.encode('utf8', 'ignore')) + m0 / formula2mass(f)
            else:
	            score = ratio(x.encode('utf8', 'ignore'), query.encode('utf8', 'ignore')) + m0 / formula2mass(f)
        except ZeroDivisionError:
            score = 100
    return score

def formula2mass(f):
    s = re.findall('([A-Z][a-z]?)([0-9]*)', f)
    compoundweight = 0
    for element, count in s:
        count = int(count or '1')
        compoundweight += Masses[element] * count
    return compoundweight

# Get a list of inchi keys for a specific folder (i.e folder AA)
def getINCHIkeys(folder):
    root = APP_JSON
    file_list = []
    path = root + folder.upper()
    if(os.path.isdir(path)):
        for root, dirs, files in os.walk(path):
            for fn in files:
                file_list.append(fn.replace('.json', ''))
        return file_list
    else:
        return False

def getINCHIfolders():
    return os.listdir(APP_JSON)

#Create a new list of 'new' articles based on how many days passed
def get_new_articles(articles, days):
    new_articles = []
    for article in articles:
        date = article[:10]
        try:
            dt = datetime.datetime.strptime(date, "%Y-%m-%d")
            if dt > datetime.datetime.now()-datetime.timedelta(days=days):
                new_articles.append(article)
        except ValueError:
            print "Invalid Date Format"
    return new_articles

#Get a list of the past weekly molecules
def get_weekly_molecule_list():
    # Gets todays date, then rewinds it to the last Sunday
    # (if today is Sunday it sticks with today)
    # Then it compares each line in the file to Sunday's date
    # And when it finds a match, it changes MOLECULE_OF_THE_WEEK in views
    # Also, this thread is run once per day
    return_list = []
    today = datetime.date.toordinal(datetime.datetime.now())
    sunday = today - (today % 7)
    sunday = datetime.date.fromordinal(sunday)
    sunday = datetime.date.isoformat(sunday)
    with open("./pqr/server_start/mol_of_the_week", "r") as molfile:
        for line in molfile:

            # Skips the header
            if line[0] == '#':
                continue

            tokens = line.strip().split(",")
            if len(tokens) < 3:
                continue
            if tokens[0] <= datetime.datetime.isoformat(datetime.datetime.now()).replace('-', ''):
                return_list.append( # inchikey, title, date
                    tokens[1] + "," + tokens[2].title() + "," + tokens[0][0:4] + '-' + tokens[0][4:6] + '-' + tokens[0][6:]
                )

            else: # We are now past the current date, don't show them yet
                return return_list

def get_json_data_file(key_first_two, key):
    try:
        # Loads the JSON file relevant to the InChI key requested
        with open(os.path.join(APP_JSON, key_first_two + '/' + key + '.json')) as j:
            return json.load(j)
    except IOError:
        # If we don't have the key, flash
        return False

# Return suggestions for autocomplete search
# db.molecules.find( { name: { $regex: /^meth/i } } )
def get_suggestions(partial):
    client = MongoClient()
    db = client.test
    cursor = db.molecules.find({'name': { '$regex': str(partial) }}).limit(10)
    results = []

    for i in cursor:
        item = {}
        item['name'] =  i["name"]
        item['inchikey'] =  i["inchikey"]
        item['formula'] =  i["formula"]
        results.append(item)
    return results

if __name__ == '__main__':
    pqr.run()

redpajama_set_name: RedPajamaGithub


text:
package pl.luxdev.lol.system.exception;

public class CoreException extends Exception {

	private static final long serialVersionUID = 1L;

	public CoreException(String cause) {
		super(cause);
	}

}


text:
package kadai3;

import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * @link{Stack} クラスの実装.
 * @author chihiro.hashitmo<a14z6ch@aiit.ac.jp>
 *
 */
public class StackImpl<E> extends AbstractCollection<E> implements Stack<E> {

	private static int INITIAL_SIZE = 5;

	/** 内部配列. */
	private Object[] stack = new Object[INITIAL_SIZE];
	private int counter = 0;

	public StackImpl() {
	}

	@Override
	public int size() {
		return this.counter;
	}

	@Override
	public Iterator<E> iterator() {
		final Object[] _stack = this.stack;
		final int _counter = this.counter;

		return new Iterator<E>() {

			private int counter = 0;

			@Override
			public boolean hasNext() {
				return counter < _counter;
			}

			@SuppressWarnings("unchecked")
			@Override
			public E next() {
				return (E) _stack[counter++];
			}
		};
	}

	@Override
    public boolean add(E e) {
		if (this.stack.length <= this.counter) {
			this.stack = Arrays.copyOf(this.stack, this.stack.length + INITIAL_SIZE);
		}
		this.stack[this.counter++] = e;
		return true;
	}

	@SuppressWarnings("unchecked")
	@Override
	public E pop() {
		if (this.size() == 0) {
			return null;
		}
		Object last = this.stack[this.counter - 1];
		this.stack[this.counter - 1] = null;
		return (E) last;
	}

	/**
	 * テスト用Main.
	 * @param args
	 */
	public static void main(String[] args) {
		Stack<String> stack = new StackImpl<String>();

		stack.add("1st");
		stack.add("2nd");
		stack.add("3rd");
		stack.add("4th");

		List<String> list = new ArrayList<String>();
		list.add("1st");
		list.add("2nd");

		// stackのsizeが正常なこと
		assert stack.size() == 4 : "Invalid size";
		// containsが正常なこと
		assert stack.contains("1st") : "Invalid contains";
		// containsAllが正常なこと
		assert stack.containsAll(list) : "Invalid containsAll";
		// 最期に加えた要素が取得出来ていること
		assert "4th".equals(stack.pop()) : "Invalid pop";

		System.out.println("all ok");
		System.exit(0);
	}
}


text:
```bash
cat /proc/sys/kernel/random/entropy_avail
```

### Edit mods-enabled/ssl.conf

https://wiki.mozilla.org/Security/Server_Side_TLS

- ECDSA certificate **Speed!**
- Entropy source **Speed!**
- Protocol **TLS1.2 Speed!**
- Ciphersuites **AES-NI Speed!**
- DH parameters
- SSL session cache **Speed!**
- OCSP stapling **Speed!**
- SNI
- HSTS
- HTTP/2 **Speed!**

https://istlsfastyet.com/

[Current master in Debian](https://salsa.debian.org/apache-team/apache2/blob/master/debian/config-dir/mods-available/ssl.conf)

See [/webserver/apache-conf-available/ssl-mozilla-intermediate.default](/webserver/apache-conf-available/ssl-mozilla-intermediate.default)

### Installing CA on a server

See [/security/ca/README.md](/security/ca/README.md)

### Client certificate authentication

```apache
SSLCACertificateFile /etc/ssl/localcerts/company-ca.pem
<Location /auth>
    SSLVerifyClient require
</Location>
```

```php
    // Check verification result, CA and client CN
    $verified = (
        array_key_exists( 'SSL_CLIENT_VERIFY', $_SERVER )
        && 'SUCCESS' === $_SERVER['SSL_CLIENT_VERIFY']
        && array_key_exists( 'SSL_CLIENT_I_DN', $_SERVER )
        && $client_issuer_dn === $_SERVER['SSL_CLIENT_I_DN']
        && array_key_exists( 'SSL_CLIENT_S_DN', $_SERVER )
        && in_array( $_SERVER['SSL_CLIENT_S_DN'], $ok_client_dns )
    );
```

### Sending client certificate to iOS devices

- Import to be exported client certificates
- [Download IPCU](http://mirror.szepe.net/software/iPhoneConfigUtilitySetup.exe)
- Extract .msi packages
- Install `AppleApplicationSupport.msi` and `AppleMobileDeviceSupport64.msi` and `iPhoneConfigUtility.msi`
- `copy "C:\Program Files (x86)\Common Files\Apple\Apple Application Support\SQLite3.dll" "C:\Program Files (x86)\iPhone Configuration Utility\"`

### DH parameters

https://weakdh.org/sysadmin.html

### HTTP/2, SPDY

- https://github.com/icing/mod_h2
- https://launchpad.net/~ondrej/+archive/ubuntu/apache2
- Reverse proxy: https://github.com/tatsuhiro-t/nghttp2
- https://github.com/h2o/h2o

### Tests

- SSL: https://www.ssllabs.com/ssltest/
- SSL: https://sslanalyzer.comodoca.com/
- SSL: [Certificate Search](https://crt.sh/)
- OCSP and CRL: https://certificate.revocationcheck.com/
- SNI: https://sni.velox.ch/
- HSTS: https://hstspreload.appspot.com/
- SPDY: https://spdycheck.org/
- SPDY CLI: https://github.com/tatsuhiro-t/spdylay
- HTTP/2: https://tools.keycdn.com/http2-test
- SSL: https://github.com/mozilla/tls-observatory
- SSL: [Browser warnings](https://cryptoreport.websecurity.symantec.com/checker/views/sslCheck.jsp)

### Moving to HTTPS

Search & Replace URL-s.

- Set CDN to HTTP/HTTPS
- Database
- Local files
- Inbound links on other websites
- Analytics does not detect referer on redirection

### Clear HSTS settings

http://classically.me/blogs/how-clear-hsts-settings-major-browsers


text:
var $  = require('jquery')

export function getQueriesLinks(links){
  return {
    type: 'GET_QUERY_LINKS',
    links
  }
}

export function requestQueriesLinks() {
  return(dispatch, getState) => {
    $.ajax({ url: 'http://localhost:9292/queries_links'}).done((res) => {
      dispatch(getQueriesLinks(JSON.parse(res)))
    })
  }
}


text:
<?php

namespace Proxies\__CG__\DahouetBundle\Entity;

/**
 * DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR
 */
class Serie extends \DahouetBundle\Entity\Serie implements \Doctrine\ORM\Proxy\Proxy
{
    /**
     * @var \Closure the callback responsible for loading properties in the proxy object. This callback is called with
     *      three parameters, being respectively the proxy object to be initialized, the method that triggered the
     *      initialization process and an array of ordered parameters that were passed to that method.
     *
     * @see \Doctrine\Common\Persistence\Proxy::__setInitializer
     */
    public $__initializer__;

    /**
     * @var \Closure the callback responsible of loading properties that need to be copied in the cloned object
     *
     * @see \Doctrine\Common\Persistence\Proxy::__setCloner
     */
    public $__cloner__;

    /**
     * @var boolean flag indicating if this object was already initialized
     *
     * @see \Doctrine\Common\Persistence\Proxy::__isInitialized
     */
    public $__isInitialized__ = false;

    /**
     * @var array properties to be lazy loaded, with keys being the property
     *            names and values being their default values
     *
     * @see \Doctrine\Common\Persistence\Proxy::__getLazyProperties
     */
    public static $lazyPropertiesDefaults = array();

    /**
     * @param \Closure $initializer
     * @param \Closure $cloner
     */
    public function __construct($initializer = null, $cloner = null)
    {

        $this->__initializer__ = $initializer;
        $this->__cloner__      = $cloner;
    }

    /**
     *
     * @return array
     */
    public function __sleep()
    {
        if ($this->__isInitialized__) {
            return array('__isInitialized__', '' . "\0" . 'DahouetBundle\\Entity\\Serie' . "\0" . 'codser', '' . "\0" . 'DahouetBundle\\Entity\\Serie' . "\0" . 'serie');
        }

        return array('__isInitialized__', '' . "\0" . 'DahouetBundle\\Entity\\Serie' . "\0" . 'codser', '' . "\0" . 'DahouetBundle\\Entity\\Serie' . "\0" . 'serie');
    }

    /**
     *
     */
    public function __wakeup()
    {
        if ( ! $this->__isInitialized__) {
            $this->__initializer__ = function (Serie $proxy) {
                $proxy->__setInitializer(null);
                $proxy->__setCloner(null);

                $existingProperties = get_object_vars($proxy);

                foreach ($proxy->__getLazyProperties() as $property => $defaultValue) {
                    if ( ! array_key_exists($property, $existingProperties)) {
                        $proxy->$property = $defaultValue;
                    }
                }
            };

        }
    }

    /**
     *
     */
    public function __clone()
    {
        $this->__cloner__ && $this->__cloner__->__invoke($this, '__clone', array());
    }

    /**
     * Forces initialization of the proxy
     */
    public function __load()
    {
        $this->__initializer__ && $this->__initializer__->__invoke($this, '__load', array());
    }

    /**
     * {@inheritDoc}
     * @internal generated method: use only when explicitly handling proxy specific loading logic
     */
    public function __isInitialized()
    {
        return $this->__isInitialized__;
    }

    /**
     * {@inheritDoc}
     * @internal generated method: use only when explicitly handling proxy specific loading logic
     */
    public function __setInitialized($initialized)
    {
        $this->__isInitialized__ = $initialized;
    }

    /**
     * {@inheritDoc}
     * @internal generated method: use only when explicitly handling proxy specific loading logic
     */
    public function __setInitializer(\Closure $initializer = null)
    {
        $this->__initializer__ = $initializer;
    }

    /**
     * {@inheritDoc}
     * @internal generated method: use only when explicitly handling proxy specific loading logic
     */
    public function __getInitializer()
    {
        return $this->__initializer__;
    }

    /**
     * {@inheritDoc}
     * @internal generated method: use only when explicitly handling proxy specific loading logic
     */
    public function __setCloner(\Closure $cloner = null)
    {
        $this->__cloner__ = $cloner;
    }

    /**
     * {@inheritDoc}
     * @internal generated method: use only when explicitly handling proxy specific cloning logic
     */
    public function __getCloner()
    {
        return $this->__cloner__;
    }

    /**
     * {@inheritDoc}
     * @internal generated method: use only when explicitly handling proxy specific loading logic
     * @static
     */
    public function __getLazyProperties()
    {
        return self::$lazyPropertiesDefaults;
    }

    /**
     * {@inheritDoc}
     */
    public function getCodser()
    {
        if ($this->__isInitialized__ === false) {
            return  parent::getCodser();
        }

        $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCodser', array());

        return parent::getCodser();
    }

    /**
     * {@inheritDoc}
     */
    public function setSerie($serie)
    {

        $this->__initializer__ && $this->__initializer__->__invoke($this, 'setSerie', array($serie));

        return parent::setSerie($serie);
    }

    /**
     * {@inheritDoc}
     */
    public function getSerie()
    {

        $this->__initializer__ && $this->__initializer__->__invoke($this, 'getSerie', array());

        return parent::getSerie();
    }

    /**
     * {@inheritDoc}
     */
    public function setCodser($codser)
    {

        $this->__initializer__ && $this->__initializer__->__invoke($this, 'setCodser', array($codser));

        return parent::setCodser($codser);
    }

}


text:
from __future__ import unicode_literals

from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ('about', '0006_auto_20160915_1320'),
    ]

    operations = [
        migrations.AlterField(
            model_name='team',
            name='facebook',
            field=models.URLField(blank=True),
        ),
        migrations.AlterField(
            model_name='team',
            name='linkedin',
            field=models.URLField(blank=True),
        ),
        migrations.AlterField(
            model_name='team',
            name='twitter',
            field=models.URLField(blank=True),
        ),
    ]


text:
package com.pvsagar.smartlockscreen.applogic_objects.passphrases;

import com.pvsagar.smartlockscreen.baseclasses.Passphrase;

/**
 * Created by aravind on 8/9/14.
 * Password class to deal with alphanumeric passwords.
 */
public class Password extends Passphrase<String> {

    public Password(){
        super(Passphrase.TYPE_PASSWORD);
    }

    public Password(String password){
        super(Passphrase.TYPE_PASSWORD, password);
    }

    @Override
    protected String getPassphraseStringFromPassphraseRepresentation(String passphrase) {
        return passphrase;
    }

    @Override
    protected String getPassphraseRepresentationFromPassphraseString(String passphrase) {
        return passphrase;
    }

    @Override
    protected boolean isPassphraseRepresentationValid(String passphrase) {
        return passphrase != null && !passphrase.isEmpty();
    }
}


text:
SHELL     := /usr/bin/env bash
TSTSRCS   = $(shell find . -name '*.hs' -or -name '*.lhs' | grep -v SBVUnitTest/SBVUnitTest.hs | grep -v SBVUnitTest/SBVBasicTests.hs | grep -v buildUtils/simplify.hs)
STAMPFILE = SBVUnitTest/SBVUnitTestBuildTime.hs
DEPSRCS   = $(shell find . -name '*.hs' -or -name '*.lhs' -or -name '*.cabal' | grep -v Paths_sbv.hs | grep -v $(STAMPFILE))
CABAL     = cabal
SIMPLIFY  = ./buildUtils/simplify
TIME      = /usr/bin/time

define mkStamp
	@echo "-- Auto-generated, don't edit"		       >  ${STAMPFILE}
	@echo "module SBVUnitTestBuildTime (buildTime) where"  >> ${STAMPFILE}
	@echo ""					       >> ${STAMPFILE}
	@echo "buildTime :: String"			       >> ${STAMPFILE}
	@echo "buildTime = \"$(shell date)\""		       >> ${STAMPFILE}
endef

define mkTags
	@find . -name \*.\*hs | xargs fast-tags
endef

.PHONY: all install test sdist clean docs gold stamp hlint tags

all: install

install: $(STAMPFILE)

$(STAMPFILE): $(DEPSRCS) Makefile
	@-ghc-pkg unregister --force sbv
	@(make -s -C buildUtils)
	$(call mkStamp)
	$(call mkTags)
	@$(CABAL) configure --disable-library-profiling --enable-tests
	@((set -o pipefail; $(CABAL) build --ghc-options="-Werror -Wall" 2>&1 | $(SIMPLIFY)) || (rm $(STAMPFILE) && false))
	@$(CABAL) copy
	@$(CABAL) register

test: install
	@echo "*** Starting inline tests.."
	@(set -o pipefail; $(TIME) doctest ${TSTSRCS} 2>&1)
	@echo "*** Starting external test suite.."
	@# Note we use "-s" here skipping no-solver tests; which are covered
	@# in the cabal test suite right below.
	@$(TIME) dist/build/SBVUnitTests/SBVUnitTests -s
	@echo "*** Starting internal cabal test suite.."
	@SBV_Z3=doesnotexist $(TIME) $(CABAL) test
	@cat dist/test/sbv*SBVBasicTests.log

sdist: install
	@(set -o pipefail; $(CABAL) sdist | $(SIMPLIFY))

veryclean: clean
	@make -C buildUtils clean
	@-ghc-pkg unregister sbv

clean:
	@rm -rf dist $(STAMPFILE)

docs:
	@(set -o pipefail; $(CABAL) haddock --haddock-option=--no-warnings --hyperlink-source 2>&1 | $(SIMPLIFY))

release: clean install sdist hlint docs test
	@echo "*** SBV is ready for release!"

# use this as follows: make gold TGTS="cgUSB5"
# where the tag is one (or many) given in the SBVUnitTest.hs file
# if TGTS is not specified, then all gold files are regenerated
gold: install
	dist/build/SBVUnitTests/SBVUnitTests -c ${TGTS}

hlint:
	@rm -f hlintReport.html
	@echo "Running HLint.."
	@hlint Data SBVUnitTest -q -rhlintReport.html -i "Use otherwise" -i "Parse error" -i "Use fewer imports"

tags:
	$(call mkTags)


text:
layout: page
title: "Secure"
date: 2013-12-27 22:29
comments: true
sharing: true
footer: true
---

Text: Kris Shaffer (2010), based on Isaiah 46 and Romans 9
Music: Kris Shaffer (2010)
Demo recording: Heidi Betts

[recording]({{ site.url }}worship-music/audio/Secure.mp3)

[lead sheet in C]({{ site.url }}/worship-music/PDFs/Secure-lead-C.pdf)
[lead sheet in D]({{ site.url }}/worship-music/PDFs/Secure-lead-D.pdf)
[lead sheet in E]({{ site.url }}/worship-music/PDFs/Secure-lead-E.pdf)
[SAT arrangement in C]({{ site.url }}/worship-music/PDFs/Secure-SAT-C.pdf)
[SAT arrangement in D]({{ site.url }}/worship-music/PDFs/Secure-SAT-D.pdf)


text:
package sdlab;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Verbs {

	List<String> verbs;
	int count;

	public Verbs() throws IOException {
		buildVerbs();
	}

	void buildVerbs() throws IOException {
		verbs = new ArrayList<String>();

		File file = new File("C:\\Users\\user\\workspace\\PoemFeatureExtractor\\src\\sdlab\\verbs.txt");
		FileInputStream fis = new FileInputStream(file);
		BufferedReader br = new BufferedReader(new InputStreamReader(fis));
		String str;

		while((str = br.readLine()) != null) {
			for(String spl : str.split("\\s+|;\\s*|,\\s*|\\.\\s*")) {
				verbs.add(spl);
				count++;
			}

		}
		br.close();
	}

	public static void main(String args[]) {

	}
}


text:
//  Copyright 2019 Google Inc. All Rights Reserved.
//
//  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.

using NtApiDotNet.Utilities.Reflection;
using System;
using System.Runtime.InteropServices;

namespace NtApiDotNet
{
#pragma warning disable 1591
    [Flags]
    public enum RegistryTransactionAccessRights : uint
    {
        [SDKName("TRANSACTION_QUERY_INFORMATION")]
        QueryInformation = 0x01,
        [SDKName("TRANSACTION_SET_INFORMATION")]
        SetInformation = 0x02,
        [SDKName("TRANSACTION_ENLIST")]
        Enlist = 0x04,
        [SDKName("TRANSACTION_COMMIT")]
        Commit = 0x08,
        [SDKName("TRANSACTION_ROLLBACK")]
        Rollback = 0x10,
        [SDKName("TRANSACTION_PROPAGATE")]
        Propagate = 0x20,
        [SDKName("GENERIC_READ")]
        GenericRead = GenericAccessRights.GenericRead,
        [SDKName("GENERIC_WRITE")]
        GenericWrite = GenericAccessRights.GenericWrite,
        [SDKName("GENERIC_EXECUTE")]
        GenericExecute = GenericAccessRights.GenericExecute,
        [SDKName("GENERIC_ALL")]
        GenericAll = GenericAccessRights.GenericAll,
        [SDKName("DELETE")]
        Delete = GenericAccessRights.Delete,
        [SDKName("READ_CONTROL")]
        ReadControl = GenericAccessRights.ReadControl,
        [SDKName("WRITE_DAC")]
        WriteDac = GenericAccessRights.WriteDac,
        [SDKName("WRITE_OWNER")]
        WriteOwner = GenericAccessRights.WriteOwner,
        [SDKName("SYNCHRONIZE")]
        Synchronize = GenericAccessRights.Synchronize,
        [SDKName("MAXIMUM_ALLOWED")]
        MaximumAllowed = GenericAccessRights.MaximumAllowed,
        [SDKName("ACCESS_SYSTEM_SECURITY")]
        AccessSystemSecurity = GenericAccessRights.AccessSystemSecurity
    }

    public static partial class NtSystemCalls
    {
        [DllImport("ntdll.dll")]
        public static extern NtStatus NtCreateRegistryTransaction(out SafeKernelObjectHandle Handle, RegistryTransactionAccessRights DesiredAccess,
            ObjectAttributes ObjectAttributes, int Flags);

        [DllImport("ntdll.dll")]
        public static extern NtStatus NtOpenRegistryTransaction(out SafeKernelObjectHandle Handle, RegistryTransactionAccessRights DesiredAccess,
            ObjectAttributes ObjectAttributes);

        [DllImport("ntdll.dll")]
        public static extern NtStatus NtCommitRegistryTransaction(SafeKernelObjectHandle Handle, bool Wait);

        [DllImport("ntdll.dll")]
        public static extern NtStatus NtRollbackRegistryTransaction(SafeKernelObjectHandle Handle, bool Wait);
    }
#pragma warning restore 1591
}


text:
<?php
namespace Poirot\Filesystem\Interfaces\Filesystem;

interface iFileInfo extends iCommonInfo
{
    /**
     * Gets the file size in bytes for the file referenced
     *
     * @return int
     */
    function getSize();
}


text:
package org.springframework.cloud.client.circuitbreaker;

import java.util.concurrent.atomic.AtomicInteger;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class CustomizerTests {

	@Test
	public void testCustomizedOnlyOnce() {
		AtomicInteger counter = new AtomicInteger(0);
		final Customizer<AtomicInteger> customizer = Customizer.once(AtomicInteger::incrementAndGet, Object::hashCode);
		customizer.customize(counter);
		customizer.customize(counter);
		customizer.customize(counter);
		Assertions.assertThat(counter.get()).isEqualTo(1);

		AtomicInteger anotherCounter = new AtomicInteger(0);
		customizer.customize(anotherCounter);
		customizer.customize(anotherCounter);
		Assertions.assertThat(counter.get()).isEqualTo(1);
	}

}


text:
import gzip
import glob
import tarfile
from snakemake.shell import shell

def fasta_postprocess(origfn, newfn):
    """
    The fasta from UCSC comes as a tarball of fastas. So we extract them all to
    a temp directory and then cat them all together into the final fa.gz file.
    """
    assert (
        (isinstance(origfn, list)) and (len(origfn) == 1)
    ), 'unexpected input: %s' % origfn
    origfn = origfn[0]
    t = tarfile.open(origfn)
    shell('mkdir -p {origfn}.tmp')
    t.extractall(origfn + '.tmp')
    with gzip.open(newfn, 'wt') as fout:
        for fa in sorted(glob.glob(origfn + '.tmp/*.fa')):
            print(fa)
            fout.write(open(fa).read())
    shell('rm -r {origfn}.tmp')


text:
package jj.engine;

import org.mozilla.javascript.Scriptable;

/**
 * All host objects implement this
 * @author jason
 *
 */
public interface HostObject extends Scriptable {

	String name();

	boolean constant();

	boolean readonly();

	boolean permanent();

	boolean dontenum();
}


text:
var Traverse = require('traverse');
var EventEmitter = require('events').EventEmitter;
var stream = process.title === 'browser' ? {} : require('stream');
var json = typeof JSON === 'object' ? JSON : require('jsonify');

var exports = module.exports = function (wrapper) {
    var self = {};

    self.sessions = {};

    self.create = function () {
        var id = null;
        do {
            id = Math.floor(
                Math.random() * Math.pow(2,32)
            ).toString(16);
        } while (self.sessions[id]);

        var s = Session(id, wrapper);
        self.sessions[id] = s;
        return s;
    };

    self.destroy = function (id) {
        delete self.sessions[id];
    };

    return self;
};

var Session = exports.Session = function (id, wrapper) {
    var self = new EventEmitter;

    self.id = id;
    self.remote = {};

    var instance = self.instance =
        typeof(wrapper) == 'function'
            ? new wrapper(self.remote, self)
            : wrapper || {}
    ;

    self.localStore = new Store;
    self.remoteStore = new Store;

    self.localStore.on('cull', function (id) {
        self.emit('request', {
            method : 'cull',
            arguments : [id],
            callbacks : {}
        });
    });

    self.remoteStore.on('cull', function (id) {
        self.emit('request', {
            method : 'cullYours',
            arguments : [id],
            callbacks : {}
        });
    });

    var scrubber = new Scrubber(self.localStore);

    self.start = function () {
        self.request('methods', [ instance ]);
    };

    self.request = function (method, args) {
        var scrub = scrubber.scrub(args);

        self.emit('request', {
            method : method,
            arguments : scrub.arguments,
            callbacks : scrub.callbacks,
            links : scrub.links
        });
    };

    self.parse = function (line) {
        var msg = null;
        try { msg = json.parse(line) }
        catch (err) {
            self.emit('error', new SyntaxError(
                'Error parsing JSON message: ' + json.stringify(line))
            );
            return;
        }

        try { self.handle(msg) }
        catch (err) { self.emit('error', err) }
    };

    self.handle = function (req) {
        var args = scrubber.unscrub(req, function (id) {
            if (!self.remoteStore.has(id)) {
                // create a new function only if one hasn't already been created
                // for a particular id
                self.remoteStore.add(function () {
                    self.request(id, [].slice.apply(arguments));
                }, id);
            }
            return self.remoteStore.get(id);
        });

        if (req.method === 'methods') {
            handleMethods(args[0]);
        }
        else if (req.method === 'error') {
            var methods = args[0];
            self.emit('remoteError', methods);
        }
        else if (req.method === 'cull') {
            args.forEach(function (id) {
                self.remoteStore.cull(id);
            });
        }
        else if (req.method === 'cullYours') {
            args.forEach(function (id) {
                self.localStore.cull(id);
            });
        }
        else if (typeof req.method === 'string') {
            if (self.instance.propertyIsEnumerable(req.method)) {
                apply(self.instance[req.method], self.instance, args);
            }
            else {
                self.emit('error', new Error(
                    'Request for non-enumerable method: ' + req.method
                ));
            }
        }
        else if (typeof req.method == 'number') {
            apply(self.localStore.get(req.method), self.instance, args);
        }
    }

    function handleMethods (methods) {
        if (typeof methods != 'object') {
            methods = {};
        }

        // copy since assignment discards the previous refs
        Object.keys(self.remote).forEach(function (key) {
            delete self.remote[key];
        });

        Object.keys(methods).forEach(function (key) {
            self.remote[key] = methods[key];
        });

        self.emit('remote', self.remote);
        self.emit('ready');
    }

    function apply(f, obj, args) {
        try { f.apply(obj, args) }
        catch (err) { self.emit('error', err) }
    }

    return self;
};

// scrub callbacks out of requests in order to call them again later
var Scrubber = exports.Scrubber = function (store) {
    var self = {};
    store = store || new Store;

    // Take the functions out and note them for future use
    self.scrub = function (obj) {
        var paths = {};
        var links = [];

        var args = Traverse(obj).map(function (node) {
            if (typeof(node) == 'function') {
                var i = store.indexOf(node);
                if (i >= 0 && !(i in paths)) {
                    // Keep previous function IDs only for the first function
                    // found. This is somewhat suboptimal but the alternatives
                    // are worse.
                    paths[i] = this.path;
                }
                else {
                    var id = store.add(node);
                    paths[id] = this.path;
                }

                this.update('[Function]');
            }
            else if (this.circular) {
                links.push({ from : this.circular.path, to : this.path });
                this.update('[Circular]');
            }
        });

        return {
            arguments : args,
            callbacks : paths,
            links : links
        };
    };

    // Replace callbacks. The supplied function should take a callback id and
    // return a callback of its own.
    self.unscrub = function (msg, f) {
        var args = msg.arguments || [];
        Object.keys(msg.callbacks || {}).forEach(function (strId) {
            var id = parseInt(strId,10);
            var path = msg.callbacks[id];
            args = setAt(args, path, f(id));
        });

        (msg.links || []).forEach(function (link) {
            var value = getAt(args, link.from);
            args = setAt(args, link.to, value);
        });

        return args;
    };

    function setAt (ref, path, value) {
        var node = ref;
        for (var i = 0; i < path.length - 1; i++) {
            var key = path[i];
            if (Object.propertyIsEnumerable.call(node, key)) {
                node = node[key];
            }
            else return undefined;
        };
        var last = path.slice(-1)[0];
        if (last === undefined) {
            return value;
        }
        else {
            node[last] = value;
            return ref;
        }
    }

    function getAt (node, path) {
        for (var i = 0; i < path.length; i++) {
            var key = path[i];
            if (Object.propertyIsEnumerable.call(node, key)) {
                node = node[key];
            }
            else return undefined;
        }
        return node;
    }

    return self;
}

var Store = exports.Store = function() {
    var self = new EventEmitter;
    var items = self.items = {};
    var counter = 1;

    self.has = function (id) {
        return items[id] != undefined;
    };

    self.get = function (id) {
        if (!self.has(id)) return null;
        return wrap(items[id].f);
    };

    self.add = function (fn, id) {
        if (id == undefined) id = counter++;
        items[id] = {f: fn};
        self.emit('wrapped', id, items);
        return id;
    };

    self.cull = function (i) {
        if (typeof i === 'function') {
            Object.keys(items).some(function(key) {
                if (key === i) {
                    i = key;
                    return true;
                }
            });
        }
        if (!items.hasOwnProperty(i)) return -1;
        delete items[i];
        return i;
    };

    self.indexOf = function (fn) {
        var result = -1;
        Object.keys(items).some(function(key) {
            if (items[key] === fn) {
                result = key;
                return true;
            }
        })
        return result;
    };

    function wrap (fn) {
        return function() {
            fn.apply(this, arguments);
            autoCull(fn);
        };
    }

    function autoCull (fn) {
        if (typeof fn.times == 'number') {
            fn.times--;
            if (fn.times == 0) {
                var id = self.cull(fn);
                self.emit('cull', id);
            }
        }
    }

    return self;
};

var parseArgs = exports.parseArgs = function (argv) {
    var params = {};

    [].slice.call(argv).forEach(function (arg) {
        if (typeof arg === 'string') {
            if (arg.match(/^\d+$/)) {
                params.port = parseInt(arg, 10);
            }
            else if (arg.match('^/')) {
                params.path = arg;
            }
            else {
                params.host = arg;
            }
        }
        else if (typeof arg === 'number') {
            params.port = arg;
        }
        else if (typeof arg === 'function') {
            params.block = arg;
        }
        else if (typeof arg === 'object') {
            if (arg.__proto__ === Object.prototype) {
                // merge vanilla objects into params
                Object.keys(arg).forEach(function (key) {
                    params[key] = arg[key];
                });
            }
            else if (stream.Stream && arg instanceof stream.Stream) {
                params.stream = arg;
            }
            else {
                // and non-Stream, non-vanilla objects are probably servers
                params.server = arg;
            }
        }
        else if (typeof arg === 'undefined') {
            // ignore
        }
        else {
            throw new Error('Not sure what to do about '
                + typeof arg + ' objects');
        }
    });

    return params;
};


text:
package org.lwjgl.egl;

/**
 * Native bindings to the NV_depth_nonlinear extension.
 *
 *
Due to the perspective divide, conventional integer Z-buffers have a hyperbolic distribution of encodings between the near plane and the far plane.
 * This can result in inaccurate depth testing, particularly when the number of depth buffer bits is small and objects are rendered near the far plane.

 *
 *
Particularly when the number of depth buffer bits is limited (desirable and/or required in low-memory environments), artifacts due to this loss of
 * precision may occur even with relatively modest far plane-to-near plane ratios (e.g., greater than 100:1).

 *
 *
Many attempts have been made to provide alternate encodings for Z-buffer (or alternate formulations for the stored depth) to reduce the artifacts
 * caused by perspective division, such as W-buffers, Z-complement buffers and floating-point 1-Z buffers.

 *
 *
This extension adds a non-linear encoded Z buffer to OpenGL, which can improve the practically useful range of, e.g. 16-bit depth buffers by up to a
 * factor of 16, greatly improving depth test quality in applications where the ratio between the near and far planes can not be as tightly controlled.

 *
 *
Requires {@link EGL11 EGL L.1}.

 */
public final class NVDepthNonlinear {

	/**  */
	public static final int
		EGL_DEPTH_ENCODING_NV           = 0x30E2,
		EGL_DEPTH_ENCODING_NONE_NV      = 0,
		EGL_DEPTH_ENCODING_NONLINEAR_NV = 0x30E3;

	private NVDepthNonlinear() {}

}


text:
<!DOCTYPE html>

  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>Esas canciones que quiebran y reparan  · Partially Random</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="description" content="" />

<meta name="keywords" content="Music, ">

<meta property="og:title" content="Esas canciones que quiebran y reparan  · Partially Random ">
<meta property="og:site_name" content="Partially Random"/>
<meta property="og:url" content="/2017/07/17/2017-07-17-esas-canciones-que-quiebran-y-reparan/" />
<meta property="og:locale" content="en">

<meta property="og:type" content="article" />
<meta property="og:description" content=""/>
<meta property="og:article:published_time" content="2017-07-17T00:00:00Z" />
<meta property="og:article:modified_time" content="2017-07-17T00:00:00Z" />

<meta property="og:article:tag" content="Music">

<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@opoyc" />
<meta name="twitter:creator" content="@opoyc" />
<meta name="twitter:title" content="Esas canciones que quiebran y reparan" />
<meta name="twitter:description" content="" />
<meta name="twitter:url" content="/2017/07/17/2017-07-17-esas-canciones-que-quiebran-y-reparan/" />
<meta name="twitter:domain" content="/">

<link rel="canonical" href="/2017/07/17/2017-07-17-esas-canciones-que-quiebran-y-reparan/" />
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/touch-icon-144-precomposed.png">
<link rel="icon" href="/favicon.png">
<meta name="generator" content="Hugo 0.54.0" />

    <link rel="stylesheet" href="/css/bootswatch/paper/bootstrap.min.css">

<link rel="stylesheet" href="/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/style.css">

<link rel="stylesheet" href="/css/style_custom.css">

  <link rel="stylesheet" href="/css/highlight/xcode.css">

        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
          Toggle navigation

        </button>

          Partially Random

                  About me

                  Website

                 Social/Contact

                         Email

                         Github

                  Tags

Esas canciones que quiebran y reparan

  <time datetime="2017-07-17">17 Jul, 2017</time>

    · by Obryan Poser

  · Read in about 1 min
  · (115 words)
  ·
Share this on:

  Music

Hoy por cosas de youtube (a todos nos ha pasado que terminamos viendo videos de Corgies, CIERTO? VERDAD?) terminé con esta interpretación por parte de Playing For Change de la canción Sittin' on the dock of the bay de Otis Redding (palabras mayores).

Lo cierto es que en lo que a Soul respecta, se gana el MVP, es de esas canciones que te llegan sin filtro al pecho y es imposible no conmoverse. Lo admito, hoy me quebró, y por más tristeza que uno sienta en ese preciso momento, el sentimiendo de alivio en el alma que viene después no tiene precio. ¿Creen que no? Escuchenla con la voz de estos maes y después hablamos…

Share this on:

            ←Previous

            Next →

Please enable JavaScript to view the comments powered by Disqus.

Latest Posts

          My early thoughts on Atomic Habits

          Visual selection of optimal lag length in VAR models

          What is to be rational?

          How to cope with the media bias in the news market?

          Creating a binary discrete variable: the Tidy way

          Dígame Costarriqueño por favor

          World Cup players' hype on Instagram

          Getting research titles from science direct

          Incertidumbre y otros cuentos: Entre los Alvarados ¿cuál es mejor apuesta?

          Bayes y el cajero automático

category

personal

r-language

economics

opinion

statistics

time-series

lang

español

english

tag

decision-making

bayesian-thinking

web-scraping

book-review

comunicación

costa-rica

education

factor-variable

instagram

journal-articles

  back to top

Disclaimer ·

Terms

  Partially Random by Obryan Poyser | Theme: appernetic

  © 2018 Copyright Partially Random


text:
require 'optparse'

module Staticizer
  class Command
    # Parse command line arguments and print out any errors
    def Command.parse(args)
      options = {}
      initial_page = nil

      parser = OptionParser.new do |opts|
        opts.banner = "Usage: staticizer initial_url [options]\nExample: staticizer http://squaremill.com --output-dir=/tmp/crawl"

        opts.separator ""
        opts.separator "Specific options:"

        opts.on("--aws-s3-bucket [STRING]", "Name of S3 bucket to write to") do |v|
          options[:aws] ||= {}
          options[:aws][:bucket_name] = v
        end

        opts.on("--aws-region [STRING]", "AWS Region of S3 bucket") do |v|
          options[:aws] ||= {}
          options[:aws][:region] = v
        end

        opts.on("--aws-access-key [STRING]", "AWS Access Key ID") do |v|
          options[:aws] ||= {}
          options[:aws][:access_key_id] = v
        end

        opts.on("--aws-secret-key [STRING]", "AWS Secret Access Key") do |v|
          options[:aws] ||= {}
          options[:aws][:secret_access_key] = v
        end

        opts.on("-d", "--output-dir [DIRECTORY]", "Write crawl to disk in this directory, will be created if it does not exist") do |v|
          options[:output_dir] = v
        end

        opts.on("-v", "--verbose", "Run verbosely (sets log level to Logger::DEBUG)") do |v|
          options[:log_level] = Logger::DEBUG
        end

        opts.on("--log-level [NUMBER]", "Set log level 0 = most verbose to 4 = least verbose") do |v|
          options[:log_level] = v.to_i
        end

        opts.on("--log-file [PATH]", "Log file to write to") do |v|
          options[:logger] = Logger.new(v)
        end

        opts.on("--skip-write [PATH]", "Don't write out files to disk or s3") do |v|
          options[:skip_write] = true
        end

        opts.on("--valid-domains x,y,z", Array, "Comma separated list of domains that should be crawled, other domains will be ignored") do |v|
          options[:valid_domains] = v
        end

        opts.on_tail("-h", "--help", "Show this message") do
          puts "test"
          puts opts
          exit
        end
      end

      begin
        parser.parse!(args)
        initial_page = ARGV.pop
        raise ArgumentError, "Need to specify an initial URL to start the crawl" unless initial_page
      rescue StandardError => e
        puts e
        puts parser
        exit(1)
      end

      return options, initial_page
    end
  end
end

=begin

=end


text:
package net.jxta.peer;

import java.util.EventListener;

/**
 *  The listener interface for receiving PeerInfoService events.
 *
 *  The following example illustrates how to implement a PeerInfoListener:
 *
 *
 *

 *        PeerInfoListener myPeerListener = new PeerInfoListener() {
 *            public void peerInfoResponse(PeerInfoEvent e) {
 *                PeerInfoResponseMessage adv = e.getPeerInfoResponse();
 *                if (myQueryID == e.getQueryID()) {
 *                 ...
 *                 ...
 *                }
 *            }
 *        peerinfo.addPeerInfoListener(myPeerListener);
 *        int myQueryID = peerinfo.getRemotePeerInfo(peer);
 *

 */

public interface PeerInfoListener extends EventListener {

    /**
     * PeerInfoService Event
     *
     * @param event the peer info event
     */
    void peerInfoResponse(PeerInfoEvent event);

}


text:
<?php

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
class Version20170426201111 extends AbstractMigration
{
    /**
     * @param Schema $schema
     */
    public function up(Schema $schema)
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('CREATE TABLE chat (id INT AUTO_INCREMENT NOT NULL, offer_id INT DEFAULT NULL, user1 INT DEFAULT NULL, user2 INT DEFAULT NULL, status TINYINT(1) NOT NULL, created DATETIME NOT NULL, UNIQUE INDEX UNIQ_659DF2AA53C674EE (offer_id), INDEX IDX_659DF2AA8C518555 (user1), INDEX IDX_659DF2AA1558D4EF (user2), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
        $this->addSql('CREATE TABLE chat_line (id INT AUTO_INCREMENT NOT NULL, chat_id INT DEFAULT NULL, author_id INT DEFAULT NULL, message LONGTEXT NOT NULL, date DATETIME NOT NULL, INDEX IDX_778829B71A9A7125 (chat_id), INDEX IDX_778829B7F675F31B (author_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
        $this->addSql('CREATE TABLE job_industry (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
        $this->addSql('CREATE TABLE job_title (id INT AUTO_INCREMENT NOT NULL, jobindustry_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, INDEX IDX_2A6AC51B2225C751 (jobindustry_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
        $this->addSql('CREATE TABLE location (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(200) NOT NULL, asciiname VARCHAR(200) NOT NULL, alternatenames VARCHAR(4000) NOT NULL, latitude DOUBLE PRECISION NOT NULL, longitude DOUBLE PRECISION NOT NULL, fclass VARCHAR(1) NOT NULL, fcode VARCHAR(10) NOT NULL, country VARCHAR(2) NOT NULL, cc2 VARCHAR(60) NOT NULL, admin1 VARCHAR(20) NOT NULL, admin2 VARCHAR(80) NOT NULL, admin3 VARCHAR(20) NOT NULL, admin4 VARCHAR(20) NOT NULL, population INT NOT NULL, elevation INT NOT NULL, gtopo30 INT NOT NULL, timezone VARCHAR(40) NOT NULL, moddate DATE NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
        $this->addSql('CREATE TABLE notification (id INT AUTO_INCREMENT NOT NULL, offer_id INT DEFAULT NULL, created DATETIME NOT NULL, attended TINYINT(1) DEFAULT NULL, accepted TINYINT(1) DEFAULT NULL, UNIQUE INDEX UNIQ_BF5476CA53C674EE (offer_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
        $this->addSql('CREATE TABLE offer (id INT AUTO_INCREMENT NOT NULL, user_from INT DEFAULT NULL, user_to INT DEFAULT NULL, subject VARCHAR(255) NOT NULL, message VARCHAR(255) DEFAULT NULL, date DATETIME NOT NULL, INDEX IDX_29D6873EC39BEDB9 (user_from), INDEX IDX_29D6873ECFD06601 (user_to), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
        $this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, location_id INT DEFAULT NULL, jobindustry_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, surname VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, password LONGTEXT NOT NULL, active TINYINT(1) NOT NULL, created DATETIME DEFAULT NULL, modified DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), INDEX IDX_8D93D64964D218E (location_id), INDEX IDX_8D93D6492225C751 (jobindustry_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
        $this->addSql('CREATE TABLE users_jobtitles (user_id INT NOT NULL, jobtitle_id INT NOT NULL, INDEX IDX_2C5C6AAEA76ED395 (user_id), INDEX IDX_2C5C6AAEE438D15B (jobtitle_id), PRIMARY KEY(user_id, jobtitle_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
        $this->addSql('ALTER TABLE chat ADD CONSTRAINT FK_659DF2AA53C674EE FOREIGN KEY (offer_id) REFERENCES offer (id)');
        $this->addSql('ALTER TABLE chat ADD CONSTRAINT FK_659DF2AA8C518555 FOREIGN KEY (user1) REFERENCES user (id)');
        $this->addSql('ALTER TABLE chat ADD CONSTRAINT FK_659DF2AA1558D4EF FOREIGN KEY (user2) REFERENCES user (id)');
        $this->addSql('ALTER TABLE chat_line ADD CONSTRAINT FK_778829B71A9A7125 FOREIGN KEY (chat_id) REFERENCES chat (id)');
        $this->addSql('ALTER TABLE chat_line ADD CONSTRAINT FK_778829B7F675F31B FOREIGN KEY (author_id) REFERENCES user (id)');
        $this->addSql('ALTER TABLE job_title ADD CONSTRAINT FK_2A6AC51B2225C751 FOREIGN KEY (jobindustry_id) REFERENCES job_industry (id)');
        $this->addSql('ALTER TABLE notification ADD CONSTRAINT FK_BF5476CA53C674EE FOREIGN KEY (offer_id) REFERENCES offer (id)');
        $this->addSql('ALTER TABLE offer ADD CONSTRAINT FK_29D6873EC39BEDB9 FOREIGN KEY (user_from) REFERENCES user (id)');
        $this->addSql('ALTER TABLE offer ADD CONSTRAINT FK_29D6873ECFD06601 FOREIGN KEY (user_to) REFERENCES user (id)');
        $this->addSql('ALTER TABLE user ADD CONSTRAINT FK_8D93D64964D218E FOREIGN KEY (location_id) REFERENCES location (id)');
        $this->addSql('ALTER TABLE user ADD CONSTRAINT FK_8D93D6492225C751 FOREIGN KEY (jobindustry_id) REFERENCES job_industry (id)');
        $this->addSql('ALTER TABLE users_jobtitles ADD CONSTRAINT FK_2C5C6AAEA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
        $this->addSql('ALTER TABLE users_jobtitles ADD CONSTRAINT FK_2C5C6AAEE438D15B FOREIGN KEY (jobtitle_id) REFERENCES job_title (id)');
    }

    /**
     * @param Schema $schema
     */
    public function down(Schema $schema)
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('ALTER TABLE chat_line DROP FOREIGN KEY FK_778829B71A9A7125');
        $this->addSql('ALTER TABLE job_title DROP FOREIGN KEY FK_2A6AC51B2225C751');
        $this->addSql('ALTER TABLE user DROP FOREIGN KEY FK_8D93D6492225C751');
        $this->addSql('ALTER TABLE users_jobtitles DROP FOREIGN KEY FK_2C5C6AAEE438D15B');
        $this->addSql('ALTER TABLE user DROP FOREIGN KEY FK_8D93D64964D218E');
        $this->addSql('ALTER TABLE chat DROP FOREIGN KEY FK_659DF2AA53C674EE');
        $this->addSql('ALTER TABLE notification DROP FOREIGN KEY FK_BF5476CA53C674EE');
        $this->addSql('ALTER TABLE chat DROP FOREIGN KEY FK_659DF2AA8C518555');
        $this->addSql('ALTER TABLE chat DROP FOREIGN KEY FK_659DF2AA1558D4EF');
        $this->addSql('ALTER TABLE chat_line DROP FOREIGN KEY FK_778829B7F675F31B');
        $this->addSql('ALTER TABLE offer DROP FOREIGN KEY FK_29D6873EC39BEDB9');
        $this->addSql('ALTER TABLE offer DROP FOREIGN KEY FK_29D6873ECFD06601');
        $this->addSql('ALTER TABLE users_jobtitles DROP FOREIGN KEY FK_2C5C6AAEA76ED395');
        $this->addSql('DROP TABLE chat');
        $this->addSql('DROP TABLE chat_line');
        $this->addSql('DROP TABLE job_industry');
        $this->addSql('DROP TABLE job_title');
        $this->addSql('DROP TABLE location');
        $this->addSql('DROP TABLE notification');
        $this->addSql('DROP TABLE offer');
        $this->addSql('DROP TABLE user');
        $this->addSql('DROP TABLE users_jobtitles');
    }
}


text:
module Azure::Compute::Mgmt::V2020_12_01
  module Models
    #
    # The result summary of an installation operation.
    #
    class VirtualMachineInstallPatchesResult

      include MsRestAzure

      # @return [PatchOperationStatus] The overall success or failure status of
      # the operation. It remains "InProgress" until the operation completes.
      # At that point it will become "Failed", "Succeeded", "Unknown" or
      # "CompletedWithWarnings.". Possible values include: 'Unknown',
      # 'InProgress', 'Failed', 'Succeeded', 'CompletedWithWarnings'
      attr_accessor :status

      # @return [String] The activity ID of the operation that produced this
      # result. It is used to correlate across CRP and extension logs.
      attr_accessor :installation_activity_id

      # @return [VMGuestPatchRebootStatus] The reboot state of the VM following
      # completion of the operation. Possible values include: 'Unknown',
      # 'NotNeeded', 'Required', 'Started', 'Failed', 'Completed'
      attr_accessor :reboot_status

      # @return [Boolean] Whether the operation ran out of time before it
      # completed all its intended actions.
      attr_accessor :maintenance_window_exceeded

      # @return [Integer] The number of patches that were not installed due to
      # the user blocking their installation.
      attr_accessor :excluded_patch_count

      # @return [Integer] The number of patches that were detected as available
      # for install, but did not meet the operation's criteria.
      attr_accessor :not_selected_patch_count

      # @return [Integer] The number of patches that were identified as meeting
      # the installation criteria, but were not able to be installed. Typically
      # this happens when maintenanceWindowExceeded == true.
      attr_accessor :pending_patch_count

      # @return [Integer] The number of patches successfully installed.
      attr_accessor :installed_patch_count

      # @return [Integer] The number of patches that could not be installed due
      # to some issue. See errors for details.
      attr_accessor :failed_patch_count

      # @return [Array<PatchInstallationDetail>] The patches that were
      # installed during the operation.
      attr_accessor :patches

      # @return [DateTime] The UTC timestamp when the operation began.
      attr_accessor :start_date_time

      # @return [ApiError] The errors that were encountered during execution of
      # the operation. The details array contains the list of them.
      attr_accessor :error

      #
      # Mapper for VirtualMachineInstallPatchesResult class as Ruby Hash.
      # This will be used for serialization/deserialization.
      #
      def self.mapper()
        {
          client_side_validation: true,
          required: false,
          serialized_name: 'VirtualMachineInstallPatchesResult',
          type: {
            name: 'Composite',
            class_name: 'VirtualMachineInstallPatchesResult',
            model_properties: {
              status: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'status',
                type: {
                  name: 'String'
                }
              },
              installation_activity_id: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'installationActivityId',
                type: {
                  name: 'String'
                }
              },
              reboot_status: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'rebootStatus',
                type: {
                  name: 'String'
                }
              },
              maintenance_window_exceeded: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'maintenanceWindowExceeded',
                type: {
                  name: 'Boolean'
                }
              },
              excluded_patch_count: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'excludedPatchCount',
                type: {
                  name: 'Number'
                }
              },
              not_selected_patch_count: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'notSelectedPatchCount',
                type: {
                  name: 'Number'
                }
              },
              pending_patch_count: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'pendingPatchCount',
                type: {
                  name: 'Number'
                }
              },
              installed_patch_count: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'installedPatchCount',
                type: {
                  name: 'Number'
                }
              },
              failed_patch_count: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'failedPatchCount',
                type: {
                  name: 'Number'
                }
              },
              patches: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'patches',
                type: {
                  name: 'Sequence',
                  element: {
                      client_side_validation: true,
                      required: false,
                      serialized_name: 'PatchInstallationDetailElementType',
                      type: {
                        name: 'Composite',
                        class_name: 'PatchInstallationDetail'
                      }
                  }
                }
              },
              start_date_time: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'startDateTime',
                type: {
                  name: 'DateTime'
                }
              },
              error: {
                client_side_validation: true,
                required: false,
                read_only: true,
                serialized_name: 'error',
                type: {
                  name: 'Composite',
                  class_name: 'ApiError'
                }
              }
            }
          }
        }
      end
    end
  end
end


text:
import requests
from django.conf import settings
from django.core.mail.backends.base import BaseEmailBackend
from django.core.mail.message import sanitize_address

try:
    from cStringIO import StringIO
except ImportError:
    from StringIO import StringIO

class MailgunAPIError(Exception):
    pass

class MailgunBackend(BaseEmailBackend):
    """A Django Email backend that uses mailgun.
    """

    def __init__(self, fail_silently=False, *args, **kwargs):
        access_key, server_name = (kwargs.pop('access_key', None),
                                   kwargs.pop('server_name', None))

        super(MailgunBackend, self).__init__(
                        fail_silently=fail_silently,
                        *args, **kwargs)

        try:
            self._access_key = access_key or getattr(settings, 'MAILGUN_ACCESS_KEY')
            self._server_name = server_name or getattr(settings, 'MAILGUN_SERVER_NAME')
        except AttributeError:
            if fail_silently:
                self._access_key, self._server_name = None
            else:
                raise

        self._api_url = "https://api.mailgun.net/v2/%s/" % self._server_name

    def open(self):
        """Stub for open connection, all sends are done over HTTP POSTs
        """
        pass

    def close(self):
        """Close any open HTTP connections to the API server.
        """
        pass

    def _send(self, email_message):
        """A helper method that does the actual sending."""
        if not email_message.recipients():
            return False
        from_email = sanitize_address(email_message.from_email, email_message.encoding)
        recipients = [sanitize_address(addr, email_message.encoding)
                      for addr in email_message.recipients()]

        try:
            r = requests.\
                post(self._api_url + "messages.mime",
                     auth=("api", self._access_key),
                     data={
                            "to": ", ".join(recipients),
                            "from": from_email,
                         },
                     files={
                            "message": StringIO(email_message.message().as_string()),
                         }
                     )
        except:
            if not self.fail_silently:
                raise
            return False

        if r.status_code != 200:
            if not self.fail_silently:
                raise MailgunAPIError(r)
            return False

        return True

    def send_messages(self, email_messages):
        """Sends one or more EmailMessage objects and returns the number of
        email messages sent.
        """
        if not email_messages:
            return

        num_sent = 0
        for message in email_messages:
            if self._send(message):
                num_sent += 1

        return num_sent