text:
'use strict'

const expect = require('chai').expect
const DynamicMiddleware = require('./index.js')
const express4 = require('express')
const request = require('axios')

describe('DynamicMiddleware', function () {
	let dm, handler, m1, m2, app, mockResponse, engine

	describe('wraps a normal middleware function and', function () {
		it('forward all requests to it', function () {
			handler(null, mockResponse, null)

			expect(mockResponse.invocations[0]).to.equal('1')
		})

		it('allow it to be disabled during runtime', function () {
			dm.disable()

			handler(null, mockResponse, null)

			expect(mockResponse.statusCode).to.equal(404)
		})

		it('allow it to be enabled during runtime', function () {
			dm.disable()

			handler(null, mockResponse, null)

			expect(mockResponse.statusCode).to.equal(404)

			dm.enable()

			handler(null, mockResponse, null)

			expect(mockResponse.statusCode).to.equal(200)
		})

		it('allow it to be replaced during runtime', function () {
			dm.replace(function (req, res, next) {
				res.end('2')
			})

			handler(null, mockResponse, null)

			expect(mockResponse.invocations[0]).to.equal('2')
		})

		beforeEach(function () {
			dm = DynamicMiddleware.create(m1)

			handler = dm.handler()
		})
	})

	it('wraps an error middleware', (done) => {
		let error = {}
		let errorDm = DynamicMiddleware.create((err, req, res) => {
			expect(error).to.equal(error)
			done()
		})

		let errorHandler = errorDm.errorHandler()
		errorHandler(error)
	})

	// worksWith('connect 3', connect3(), function (app, handler) { app.use('/gee', handler) })
	// worksWith('express 3', express3(), function (app, handler) { app.use('/gee', handler) })
	// worksWith('express 3 get', express3(), function (app, handler) { app.get('/gee', handler) })
	// worksWith('express 4', express4(), function (app, handler) { app.use('/gee', handler) })
	// worksWith('express 4 get', express4(), function (app, handler) { app.get('/gee', handler) })

	// function worksWith(label, implementation, bind) {
	// 	it('works with ' + label, function(done) {

	// 		var dynamicMiddleware = DynamicMiddleware.create(function(req, res) {
	// 			res.statusCode = 200
	// 			res.end('1')
	// 		})

	// 		bind(implementation, dynamicMiddleware.handler())

	// 		var server = implementation.listen(3000, function() {
	// 			request('http://localhost:3000/gee', function(err, res, body) {
	// 				if (err) return done(err)
	// 				expect(body).to.equal('1')

	// 				dynamicMiddleware.replace(function(req, res) {
	// 					res.end('2')
	// 				})

	// 				request('http://localhost:3000/gee', function(err, res, body) {
	// 					if (err) return done(err)
	// 					expect(body).to.equal('2')

	// 					server.close(done)
	// 				})
	// 			})
	// 		})
	// 	})
	// }

	beforeEach(function () {
		m1 = function(req, res, next) {
			res.statusCode = 200
			res.end('1')
		}

		app = new App()

		mockResponse = new Response()
	})
})

function App() {
	this.stack = []
}

App.prototype.use = function(route, fn) {
	this.stack.push({ route: route, handle: fn })
};

function Response() {
	this.invocations = []
	this.statusCode = undefined
}

Response.prototype.end = function(v) {
	this.invocations.push(v)
}


text:
import template from './welcome.html';
import styles from './welcome.scss';

export default {
  template,
  controller
};

function controller() {
  this.styles = styles;
}

redpajama_set_name: RedPajamaGithub


text:
.language-picker {
    position: relative;
    display: inline-block
}

.language-picker div>a {
    text-decoration: none;
    color: white;
}

.language-picker li>a {
    text-decoration: none;
}

.language-picker ul {
    list-style: none;
    margin: 0;
    padding: 3px 0;
    border: 1px solid rgba(0, 0, 0, .15);
    border-radius: 4px;
    box-shadow: 0 6px 12px rgba(0, 0, 0, .176);
    position: absolute;
    top: 100%;
    z-index: 100;
    white-space: nowrap;
    left: -5px
}

.language-picker.dropdown-list ul {
    background: #fff
}

.language-picker li {
    padding: 5px;
    list-style: none
}

.language-picker.small li {
    padding: 2px 5px;
    list-style: none
}

.language-picker.button-list i {
    margin: 0 2px 0 -2px
}

.language-picker.button-list a {
    opacity: .4;
    float: left;
    display: block;
    margin: 0 4px
}

.language-picker.button-list .active {
    opacity: 1
}

.language-picker.dropdown-list ul, .language-picker.dropup-list ul {
    display: none
}

.language-picker.dropup-list ul {
    top: auto;
    bottom: 100%
}

.language-picker.dropdown-list ul.active, .language-picker.dropdown-list:hover ul, .language-picker.dropup-list ul.active, .language-picker.dropup-list:hover ul {
    display: block;
    background: #fff
}


text:
<!DOCTYPE html>

    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, user-scalable=0" charset="UTF-8">
    <title>NOJ</title>


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
null

#### Original name
Placodium geophilum Th. Fr.

### Remarks
null


text:
#ifndef TENSORFLOW_COMPILER_XLA_SERVICE_MULTI_OUTPUT_FUSION_H_
#define TENSORFLOW_COMPILER_XLA_SERVICE_MULTI_OUTPUT_FUSION_H_

#include <queue>
#include <vector>

#include "absl/container/flat_hash_map.h"
#include "absl/strings/string_view.h"
#include "tensorflow/compiler/xla/service/hlo_module.h"
#include "tensorflow/compiler/xla/service/hlo_pass_interface.h"
#include "tensorflow/compiler/xla/service/hlo_reachability.h"
#include "tensorflow/compiler/xla/statusor.h"

namespace xla {

// This class implements the fusing of sibling fusion instructions that sharing
// common operands.
// It constructs the following associated data structures.
//  (1) candidates_: stores the instruction and the set of instructions it can
//      fuse to.
//  (2) candidates_index_: maps instruction to id.
//  (3) reachability_: reachability map in this computation.
//  (4) all_fusion_candidates_: the vector of candidate instructions.
//  (5) worklist_: a priority queue that contains pairs of instructions to be
//      fused and their fusion profit scores.
//
//  Function Perform() applies the optimization. It picks up the most profitable
//  pair in the worklist_, checks if it's legal to fuse and fuses the pair.
//  After fusion, it updates the associated structures such as reachability_,
//  candidates_ and worklist_.
//  Note that the reachability map is updated based on the original computation.
//  This works because the reachability is monotonically increasing with
//  instruction fusion.
class MultiOutputFusion : public HloModulePass {
 public:
  MultiOutputFusion() = default;

  absl::string_view name() const override { return "multi_output_fusion"; }

  // Run multi-output fusion on the given module. Returns whether the module
  // was changed.
  StatusOr<bool> Run(HloModule* module) override;

 protected:
  // Main entry for the optimization. Returns true if the optimization happens.
  bool Perform();

  // Test if instr1 and instr2 have the compatible shapes that can be legally
  // fused.
  virtual bool ShapesCompatibleForFusion(HloInstruction* instr1,
                                         HloInstruction* instr2) = 0;

  // Whether the instruction is a candidate for fusion.
  virtual bool IsFusible(HloInstruction* instr) = 0;

  // This function estimates the savings by merging instr1 and instr2 into one
  // multi-output fusion instruction.
  virtual int64 GetProfit(HloInstruction* instr1, HloInstruction* instr2) = 0;

  // Whether fusing the instruction can reduce memory reads.
  virtual bool IsProfitableOperand(HloInstruction* instr);

  // Test if it's legal to fuse instr1 and instr2 into one fusion instruction.
  virtual bool LegalToFuse(HloInstruction* instr1, HloInstruction* instr2);

  // Fuse HloInstrctuion instr1 and instr2 and return the fused instruction.
  // The other instruction is removed from its parent computation.
  virtual HloInstruction* Fuse(HloInstruction* instr1, HloInstruction* instr2);

  // Recompute reachability for the current computation.
  void RecomputeReachability();

  // Returns the reachability map for the current computation.
  HloReachabilityMap* reachability() const { return reachability_.get(); }

  // Returns the computation for the pass.
  HloComputation* computation() const { return computation_; }

  // Update the reachability map after fusing instr1 and instr2.
  void UpdateReachability(
      HloInstruction* instr1, HloInstruction* instr2,
      absl::Span<HloInstruction* const> instrs_to_update,
      const std::function<bool(HloInstruction*)>& skip = nullptr);

  // Hook for multi-output fusion along producer-consumer edges.
  // Returns whether any instructions were fused.
  //
  // TODO(b/80420762): Perform producer-consumer multi-output fusion in
  // InstructionFusion instead.
  virtual bool DoProducerConsumerMultiOutputFusion();

 private:
  // An internal data structure for each instruction in current computation.
  // When an instruction is removed, member 'hlo' is set to nullptr.
  struct FusionCandidate {
    HloInstruction* hlo;
    std::list<std::pair<HloInstruction*, int64>> fusibles;
    explicit FusionCandidate(HloInstruction* hlo) : hlo(hlo) {}
  };

  // The pair of candidates to be fused and the profit score.
  struct ToBeFused {
    HloInstruction* instr1;
    HloInstruction* instr2;
    int64 score;
    ToBeFused(HloInstruction* instr1, HloInstruction* instr2, int64 score)
        : instr1(instr1), instr2(instr2), score(score) {}
    bool operator<(const ToBeFused& rhs) const { return score < rhs.score; }
  };

  // Update the internal data structures after instr1 and instr2 are fused into
  // one fusion instruction.
  void Update(HloInstruction* instr1, HloInstruction* instr2);

  int64 get_candidate_id(HloInstruction* instr) {
    return FindOrDie(candidates_index_, instr);
  }

  bool is_fused(HloInstruction* instr) {
    return candidates_[get_candidate_id(instr)].hlo == nullptr;
  }

  void set_is_fused(HloInstruction* instr) {
    candidates_[get_candidate_id(instr)].hlo = nullptr;
  }

  bool is_connected(HloInstruction* instr1, HloInstruction* instr2) {
    return reachability_->IsConnected(instr1, instr2);
  }

  std::vector<FusionCandidate> candidates_;
  std::priority_queue<ToBeFused> worklist_;

  // A map that maps an instruction to the index_.
  absl::flat_hash_map<HloInstruction*, int> candidates_index_;

  // The reachability map of current computation.
  std::unique_ptr<HloReachabilityMap> reachability_;

  // This stores all the candidate instructions in current computation.
  std::vector<HloInstruction*> all_fusion_candidates_;

  // Computation for the pass.
  HloComputation* computation_;
};

}  // namespace xla

#endif  // TENSORFLOW_COMPILER_XLA_SERVICE_MULTI_OUTPUT_FUSION_H_


text:
package Jan2021Leetcode;

public class _0234PalindromeLinkedList {

	static public class ListNode {
		int val;
		ListNode next;

		ListNode() {
		}

		ListNode(int val) {
			this.val = val;
		}

		ListNode(int val, ListNode next) {
			this.val = val;
			this.next = next;
		}
	}

	public static void main(String[] args) {
		ListNode ln = new ListNode(1);
		ln.next = new ListNode(2);
		ln.next.next = new ListNode(3);
		ln.next.next.next = new ListNode(4);
		ln.next.next.next.next = new ListNode(5);
		ln.next.next.next.next.next = new ListNode(6);
		ln.next.next.next.next.next.next = new ListNode(7);
		System.out.println(isPalindrome(ln));

		ln = new ListNode(1);
		ln.next = new ListNode(2);
		ln.next.next = new ListNode(3);
		ln.next.next.next = new ListNode(4);
		ln.next.next.next.next = new ListNode(3);
		ln.next.next.next.next.next = new ListNode(2);
		ln.next.next.next.next.next.next = new ListNode(1);
		System.out.println(isPalindrome(ln));

		ln = new ListNode(1);
		ln.next = new ListNode(2);
		ln.next.next = new ListNode(2);
		ln.next.next.next = new ListNode(1);
		System.out.println(isPalindrome(ln));

		ln = new ListNode(1);
		ln.next = new ListNode(1);
		System.out.println(isPalindrome(ln));

		ln = new ListNode(1);
		ln.next = new ListNode(1);
		ln.next.next = new ListNode(2);
		ln.next.next.next = new ListNode(1);
		System.out.println(isPalindrome(ln));

		ln = new ListNode(1);
		ln.next = new ListNode(2);
		ln.next.next = new ListNode(1);
		System.out.println(isPalindrome(ln));

		ln = new ListNode(1);
		ln.next = new ListNode(2);
		System.out.println(isPalindrome(ln));

	}

	public static void printNodes(ListNode head) {
		while (head != null) {
			System.out.print(head.val + "->");
			head = head.next;
		}
		System.out.println();
	}

	public static boolean isPalindrome(ListNode head) {
		if (head == null || head.next == null)
			return true;
		int length = getLength(head);
		ListNode headPtr = head;
		if (length % 2 == 0) {
			ListNode prev = null;
			int count = 0;
			while (count < length / 2) {
				prev = head;
				head = head.next;
				count++;
			}

			ListNode nextNode = prev.next;
			prev.next = null;
			nextNode = reverseLL(nextNode);
			head = headPtr;
			while (head != null) {
				if (head.val != nextNode.val)
					return false;
				head = head.next;
				nextNode = nextNode.next;
			}
		} else {
			ListNode prev = null;
			int count = 0;
			while (count < length / 2) {
				prev = head;
				head = head.next;
				count++;
			}

			ListNode nextNode = prev.next.next;
			prev.next.next = null;
			prev.next = null;
			nextNode = reverseLL(nextNode);
			head = headPtr;
			while (head != null) {
				if (head.val != nextNode.val)
					return false;
				head = head.next;
				nextNode = nextNode.next;
			}

		}

		return true;
	}

	public static int getLength(ListNode head) {
		if (head == null)
			return 0;
		return 1 + getLength(head.next);
	}

	public static ListNode reverseLL(ListNode head) {
		if (head == null || head.next == null)
			return head;
		ListNode nextNode = head.next;
		ListNode reverseNode = reverseLL(head.next);
		nextNode.next = head;
		head.next = null;
		return reverseNode;
	}

}


text:
package com.bhalodialabs.tictactoe;

import java.io.*;

public class TTTGame
{
	private static TTTChecker.Marker[][] board = new TTTChecker.Marker[3][3];
	private static BufferedReader br;

	public static void main(String[] args) throws Exception
	{
		System.out.println("*******************");
		System.out.println("*** Tic Tac Toe ***");
		System.out.println("*******************");

		System.out.println("Welcome to Tic Tac Toe!");

		System.out.println("To start playing press enter.");

		br = new BufferedReader(new InputStreamReader(System.in));
		br.readLine();

		for (int i = 0; i < 3; i++)
        {
			for (int j = 0; j < 3; j++)
            {
				board[i][j] = TTTChecker.Marker.NONE;
            }
        }

		int playerTurn = 0; // 0 or 1 only
		boolean gameOver = false;
		String winner = "NONE";

        while(!gameOver)
        {
			printCurrentBoard();
			inputMove(playerTurn);
			playerTurn = (playerTurn == 0)? 1 : 0;
			winner = TTTChecker.detectWinner(board);
			if (!winner.equals("NONE") || isBoardFull())
            {
				gameOver = true;
            }
		}

		printCurrentBoard();

		if(!winner.equals("NONE"))
        {
			System.out.println(TTTChecker.detectWinner(board) + " wins!");
        }
		else
        {
			System.out.println("Cat's game");
        }
	}

	private static boolean isBoardFull()
	{
		for (int i = 0; i < 3; i++)
        {
			for (int j = 0; j < 3; j++)
            {
				if (board[i][j] == TTTChecker.Marker.NONE)
                {
					return false;
                }
            }
        }
		return true;
	}

	private static boolean validateFormat(String input)
	{
		return true;
	}

	private static boolean validSpot(int row, int col)
	{
		if (row < 0 || row > 2)
        {
			System.out.print("Invalid row. Retry input. ");
			return false;
		}

		if (col < 0 || col > 2)
        {
			System.out.print("Invalid column. Retry input. ");
			return false;
		}

		if (board[row][col] != TTTChecker.Marker.NONE)
        {
			System.out.print("This square is already taken!" +
				" Retry input. ");
			return false;
		}

		return true;
	}

	private static boolean recordMove(String input, TTTChecker.Marker marker)
		throws Exception
	{
		if (!validateFormat(input))
        {
			return false;
		}

		int intCol;
		int intRow;

		try
        {
			int comma = input.indexOf(",");
			String col = input.substring(0, comma).trim();
			String row = input.substring(comma + 1).trim();

			intCol = col.toUpperCase().charAt(0) - 'A';
			intRow = Integer.parseInt(row) - 1;
		}
        catch (Exception e)
        {
			System.out.print("Incorrect format. The input" +
				" should be in the form \"A,1\". Try again: ");
			return false;
		}

		if (!validSpot(intRow, intCol))
        {
			return false;
        }

		board[intRow][intCol] = marker;
		return true;
	}

	private static void inputMove(int player) throws Exception
	{
		System.out.print("Player " + (player + 1) +
				 " make your move! (ex. A,1) ");
		String move;
		TTTChecker.Marker marker;
		do
        {
			move = br.readLine();
			marker = (player == 0)?
				TTTChecker.Marker.X : TTTChecker.Marker.O;
		} while (!recordMove(move, marker));
	}

	private static void printCurrentBoard()
	{
		System.out.println();
		System.out.println("Current Game Board:");
		System.out.println(" | A   B   C ");
		System.out.println("-|-----------");

		int currentRow = 0;
		for (int i = 0; i < 3; i++)
        {
			currentRow++;
			System.out.print(currentRow + "| ");

			for (int j = 0; j < 3; j++)
            {
				if (board[i][j] == TTTChecker.Marker.NONE)
                {
					System.out.print("*   ");
                }
				else
                {
					System.out.print(board[i][j] + "   ");
                }
			}

			System.out.print("\n");
		}

		System.out.println();
	}
}


text:
namespace IntegrateProject.Web.Models
{
    using Nancy;
    using IntegrateProject.Dal.Frame;
    using System.Linq;
    using System.Collections.Generic;
    using Nancy.ModelBinding;
    using IntegrateProject.Dal.Model;
    using System;

    public class MemberListModel  : baseModel
    {
        public class mbrList
        {
            public string mName { set; get; }
            public string tName { set; get; }
            public string Email { set; get; }
            public int  Age { set; get; }
        }

        public MemberListModel(IMember UseMember)
        {
            Get["/member"] = e =>
            {
                return View["MemberList.sshtml", UseMember.GetALLMember().Select(s => new
                {
                    mID = s.MemberID,
                    mName = s.MamberName,
                    mEmail = s.MamberEmail,
                    mAge = s.MemberAge,
                    mCdate = s.CreateDate,
                    tName = s.team.TeamName
                })];
            };

            Get["/memberadd"] = e =>
            {
                return View["MemberAdd.sshtml"];
            };

            Post["/memberadd"] = e =>
            {
                mbrList mPost = this.Bind<mbrList>();

                //找Team
                int cTeamID;
                IUseTeam UseTeam = new UseTeam();
                var checkTeam = UseTeam.GetTeamByName(mPost.tName);

                //已經存在就取ID出來,沒有就新增一個
                if (checkTeam.Count() > 0)
                {
                     cTeamID = checkTeam.Select(x=>x.TeamID).First();
                }
                else
                {
                    Team newTeam = new Team{
                        TeamName=mPost.tName,
                        TeamMemberCount=0
                    };
                    UseTeam.Add(newTeam);
                    var nTeam = UseTeam.GetTeamByName(mPost.tName);
                    cTeamID = nTeam.Select(x => x.TeamID).First();
                }

                Member memberNew = new Member
                {
                    MamberEmail = mPost.Email,
                    MamberName = mPost.mName,
                    MemberAge = mPost.Age,
                    TeamID=cTeamID
                };
                //新增一筆成員
                UseMember.Add(memberNew);

                return View["MemberList.sshtml", UseMember.GetALLMember().Select(s => new
                {
                    mID = s.MemberID,
                    mName = s.MamberName,
                    mEmail = s.MamberEmail,
                    mAge = s.MemberAge,
                    mCdate = s.CreateDate,
                    tName = s.team.TeamName
                })];
            };
        }

    }
}