code stringlengths 4 1.01M |
|---|
import {Component, ViewEncapsulation, ViewChild, ElementRef} from '@angular/core';
import {InteractivityChecker} from './interactivity-checker';
/**
* Directive for trapping focus within a region.
*
* NOTE: This directive currently uses a very simple (naive) approach to focus trapping.
* It assumes that the tab order is the same as DOM order, which is not necessarily true.
* Things like tabIndex > 0, flex `order`, and shadow roots can cause to two to misalign.
* This will be replaced with a more intelligent solution before the library is considered stable.
*/
@Component({
moduleId: module.id,
selector: 'focus-trap',
templateUrl: 'focus-trap.html',
encapsulation: ViewEncapsulation.None,
})
export class FocusTrap {
@ViewChild('trappedContent') trappedContent: ElementRef;
constructor(private _checker: InteractivityChecker) { }
/** Focuses the first tabbable element within the focus trap region. */
focusFirstTabbableElement() {
let rootElement = this.trappedContent.nativeElement;
let redirectToElement = rootElement.querySelector('[md-focus-start]') as HTMLElement ||
this._getFirstTabbableElement(rootElement);
if (redirectToElement) {
redirectToElement.focus();
}
}
/** Focuses the last tabbable element within the focus trap region. */
focusLastTabbableElement() {
let rootElement = this.trappedContent.nativeElement;
let focusTargets = rootElement.querySelectorAll('[md-focus-end]');
let redirectToElement: HTMLElement = null;
if (focusTargets.length) {
redirectToElement = focusTargets[focusTargets.length - 1] as HTMLElement;
} else {
redirectToElement = this._getLastTabbableElement(rootElement);
}
if (redirectToElement) {
redirectToElement.focus();
}
}
/** Get the first tabbable element from a DOM subtree (inclusive). */
private _getFirstTabbableElement(root: HTMLElement): HTMLElement {
if (this._checker.isFocusable(root) && this._checker.isTabbable(root)) {
return root;
}
// Iterate in DOM order.
let childCount = root.children.length;
for (let i = 0; i < childCount; i++) {
let tabbableChild = this._getFirstTabbableElement(root.children[i] as HTMLElement);
if (tabbableChild) {
return tabbableChild;
}
}
return null;
}
/** Get the last tabbable element from a DOM subtree (inclusive). */
private _getLastTabbableElement(root: HTMLElement): HTMLElement {
if (this._checker.isFocusable(root) && this._checker.isTabbable(root)) {
return root;
}
// Iterate in reverse DOM order.
for (let i = root.children.length - 1; i >= 0; i--) {
let tabbableChild = this._getLastTabbableElement(root.children[i] as HTMLElement);
if (tabbableChild) {
return tabbableChild;
}
}
return null;
}
}
|
declare interface KernelOpts {
//
}
declare interface StonehengeOpts {
//
}
declare namespace NodeJS {
interface Global {
kernel: StonehengeKernel
opts: StonehengeOpts
hardReset: () => void
}
}
// Extended Screeps globals
interface Memory {
pidCounter: number
kernel: KernelMemory
stats: any
}
|
#!/usr/bin/env sh
set -e
silent=true
run() {
if [[ $silent == false ]] ; then
eval "$1 "
else
eval "$1 &> /dev/null"
fi
}
bold=$(tput bold)
reset=$(tput sgr0)
function print_important_message {
if [[ $silent == false ]]; then
echo ""
printf "${bold}$1${reset}. "
echo ""
fi
}
srcdir=`dirname $0`
srcdir=`cd $srcdir; pwd`
run "pushd ${srcdir}/test2"
print_important_message "Removing previous test data"
run "rm -rf _site"
run "rm -rf .build"
run "rm -f ../actual.tree"
print_important_message "Creating makefile"
run "coffee nmake.coffee"
run "mkdir .build"
print_important_message "Running pre-test"
run "make all"
print_important_message "Cleaning up"
run "make clean"
print_important_message "Checking if cleaned"
tree -a > ../actual.tree
diff-files ../actual.tree orig.tree -m "Test base 1 - Cleaned"
print_important_message "Building for final check"
run "make all"
tree -a > ../actual.tree
diff-files ../actual.tree final.tree -m "Test base 1 - Exec"
run "rm -f ../actual.tree"
run "popd" |
//
// CLCAppDelegate.h
// CLCBannerNotifications
//
// Created by CocoaPods on 06/02/2015.
// Copyright (c) 2014 Calvin Cestari. All rights reserved.
//
@import UIKit;
@interface CLCAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Cart do
before :each do
cart_item = Cart.new :product_id => 18, :unit_price => 6.50, :quantity => 7, :session_id => 999
cart_item2 = Cart.new :product_id => 29, :unit_price => 12.50, :quantity => 10, :session_id => 999
cart_item.save
cart_item2.save
end
it { should belong_to :product }
it "should get the right total" do
expect(described_class.total(999)).to eq(170.50)
end
it "should have the correct items" do
described_class.any_instance.stub(:as_json).and_return('product' => {'name' => 'Soap','description' => "Some desc" },
'quantity' => 10, 'unit_price' => 5
)
result = [{:name=>"Soap", :description=>"Some desc", :quantity=>10, :amount=>50}, {:name=>"Soap", :description=>"Some desc", :quantity=>10, :amount=>50}]
expect(described_class.items_in_cart(999)).to eq(result)
end
end |
require 'metricity-server/version'
require 'metricity-server/log'
require 'metricity-server/config'
require 'metricity-server/daemon'
require 'metricity-server/metric'
require 'metricity-server/receiver'
require 'metricity-server/dashboard'
module Metricity
# Server
module Server
end
end
|
#include <algorithm>
#include <utility>
#include "ini_doc.hpp"
namespace Utility {
namespace {
std::string& trim(std::string& str) {
auto pos = str.find_first_not_of(" \t");
str.erase(0, pos);
pos = str.find_last_not_of(" \t");
if (pos != str.npos) {
str.erase(pos + 1);
}
return str;
}
IniDoc::Section::value_type parseParameter(std::string& line) {
auto pos = line.find('=');
if (pos == line.npos) {
throw InvalidIniDoc(std::string("Invalid parameter: \"").append(line).append("\""));
}
std::string parameterName = line.substr(0, pos);
IniDoc::Property parameterValue{line.substr(pos + 1)};
return std::make_pair(std::move(parameterName), std::move(parameterValue));
}
void writeSection(std::ostream& os, const IniDoc::Section& section) {
for (const auto& propertyPair : section) {
os << propertyPair.first << "=" << propertyPair.second.string() << std::endl;
}
os << std::endl;
}
} //
void IniDoc::Property::syncStr() const {
if (strSync_) return;
str_.clear();
if (!items_.empty()) {
auto itbeg = items_.cbegin();
str_.append(getValue<std::string>(*itbeg++));
std::for_each(itbeg, items_.cend(), [this](const value_type& item){
str_.append(1, ',').append(item);
});
}
strSync_ = true;
}
void IniDoc::Property::syncItems() const {
if (itemsSync_) return;
Cont_ value;
auto itbeg = str_.cbegin();
auto itend = str_.cend();
auto it0 = itbeg;
decltype(it0) it1;
items_.clear();
do {
it1 = std::find(it0, itend, ',');
items_.emplace_back(it0, it1);
it0 = it1;
} while (it1 != itend && ++it0 != itbeg);
itemsSync_ = true;
}
void IniDoc::merge(const IniDoc &toMerge, DuplicateAction daction) {
const auto& rdoc = toMerge.doc();
for (const auto& rs: rdoc) {
if (!doc_.count(rs.first) || daction == DuplicateAction::overwriteSection) {
doc_[rs.first] = rs.second;
} else {
auto& s = doc_[rs.first];
for (const auto& rp: rs.second) {
if (!s.count(rp.first) || daction == DuplicateAction::overwriteProperty) {
s[rp.first] = rp.second;
} else if (daction == DuplicateAction::combineProperty) {
auto& is = s[rp.first].items();
for (const auto& ri: rp.second.items()) {
is.push_back(ri);
}
} else if (daction == DuplicateAction::fail) {
throw std::runtime_error(std::string{
"duplicated property: \""}.append(rp.first).append("\" in section \"").append(rp.first));
}
}
}
}
}
std::istream& read(std::istream& is, IniDoc& inidoc) {
auto& doc = inidoc.doc();
IniDoc::SectionName sname{};
doc[sname];
for (std::string line; std::getline(is, line);) {
// trim line
trim(line);
// skip empty and comments
if (line.empty() || line[0] == ';') {
continue;
}
if (*line.cbegin() == '[') {
if (*line.crbegin() != ']') {
throw InvalidIniDoc(std::string("Invalid line: \"").append(line).append("\""));
}
doc[sname = line.substr(1, line.size() - 2)];
continue;
}
doc[sname].insert(parseParameter(line));
}
return is;
}
std::ostream& write(std::ostream& os, const IniDoc& inidoc) {
const auto& doc = inidoc.doc();
if (doc.empty()) {
return os;
}
auto it = doc.cbegin();
if (it->first.empty()) {
// default section
writeSection(os, it->second);
++it;
}
std::for_each(it, doc.cend(), [&os](const IniDoc::Doc::value_type& sectionPair) {
os << "[" << sectionPair.first << "]" << std::endl;
writeSection(os, sectionPair.second);
});
return os;
}
} // Utility
|
//
// AppDelegate.h
// JRTLeftSliderController
//
// Created by Juan Garcia on 1/7/16.
// Copyright © 2016 jerti. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
|
require "active_model"
class Document
include ActiveModel::Model
attr_accessor(
:title,
:description,
:base_path,
:public_updated_at,
:end_date,
:change_note,
:format,
:content_store_document_type,
:organisations,
:image_url,
)
end
|
# Turtle
Just a Rack Middleware to SlowDown too many requests client. :D
|
require 'rubygems'
require 'test-unit'
|
* {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
}
body {
background-image:url('../images/bg.png');
font-family: Trebuchet MS;
max-width: 1400px;
}
#container {
margin: 0 auto;
width: 70%;
background-color: #ffffff;
}
#header {
background-color: #ff5628;
padding: 3px 3px 3px 7px;
color: #ffffff;
border-bottom: 1px solid #696969;
}
#content {
width: 75%;
float: left;
background-color: #ebebeb;
margin: 10px 3px 10px 3px;
padding: 10px 5px 5px 5px;
}
.subcontent {
font-size: 12px;
line-height: 15px;
margin-bottom: 10px;
}
p {
margin: 5px 3px 5px 3px;
}
.large-cap {
font-size: 15px;
font-weight:bolder;
color: #ff5628;
}
.green {
color: #779e00;
}
#sidebar {
width: 22%;
float: right;
height:100%;
margin: 10px 3px 10px 0px;
}
#sidebar a {
display: block;
border-right: 10px solid #a4cb2d;
background-color: #e1ff85;
margin-top: 1px;
padding: 2px 2px 2px 5px;
text-decoration: none;
}
#sidebar a:visited {
background-color: #b9e043;
}
#sidebar a:hover, a:active {
background-color: #d4d4d4;
color: #ff5628;
}
#footer {
clear: both;
background-color: #ff5628;
padding: 3px 3px 3px 3px;
text-align: center;
}
.caption {
width: 75%;
margin: 0 auto;
border-radius: 10px;
background-color: #ffffff;
border: 1px solid #ababab;
padding: 5px 5px 5px 5px;
}
.caption img {
display: block;
margin: 0 auto;
padding: 15px 0px 15px 0px;
}
.caption .caption-text {
display: block;
width: 450px;
position: relative;
left: 10px;
top: -100px;
color: #ffffff;
background-color: #000000;
opacity: 0.6;
padding: 5px 10px 5px 10px;
} |
import angular from 'angular';
import uiRouter from 'angular-ui-router';
import uiBoostrap from 'angular-ui-bootstrap';
import angularJwt from 'angular-jwt';
let librariesModules = angular.module('app.libraries', [
uiRouter,
uiBoostrap,
angularJwt
]);
export default librariesModules; |
/**
* Copyright (C) 2013-2015
*
* @author coding.tom@gmail.com
* @date 2013-7-9
*
* @file tiny_malloc.h
*
* @remark
* set tabstop=4
* set shiftwidth=4
* set expandtab
*
*/
#ifndef __TINY_MALLOC_H__
#define __TINY_MALLOC_H__
#if defined(__ANDROID__)
#include "linux/tiny_malloc.h"
#elif defined(ESP32)
#include "esp32/tiny_malloc.h"
#elif defined(ESP8266)
#include "esp8266/tiny_malloc.h"
#elif defined(__OPENWRT_MT7688__)
#include "openwrt_mt7688/tiny_malloc.h"
#elif defined(__LINUX__)
#include "linux/tiny_malloc.h"
#elif defined(__WIN32__)
#include "windows/tiny_malloc.h"
#elif defined(__MACOS__)
#include "macos/tiny_malloc.h"
#else
error "tiny_malloc not implemented!!!"
#endif
#endif /* __TINY_MALLOC_H__ */ |
---
layout: post
title: The Streak
date: 2005-06-27 17:39
author: admin
comments: true
categories: [Life]
---
The streak keeps on keeping on. My first couch arrived this weekend and, well, it wouldn't fit in the elevator. It was 3 inches too long! What are the odds?
To top it off about an hour after the delivery guys left I found out that there was one elevator that had a ceiling that was a few inches higher, so it might have fit. Since it has been returned now though they won't try and re-deliver it.
So, I have to pick out a new shorter couch from the ones available at the store. Unfortunately the one I picked was the only one I really liked there. It's hard to find a kick-ass navy blue couch for some reason.
I have my fingers crossed that my other couch will fit when it arrives. It's almost time to get curtains as well. Woot!
The place is coming together and looking better with each thing that gets added. Hopefully by the end of July everything will be in place and then maybe I'll have a party!
I think Ilona is happy right now, that's so cool :) I love it when my friends are happy :) We have one of those long deep talks coming up, just giving you a warning :)
A congratulations goes out to my friend Lindsay and her new status as a successful triathlete! That kicks butt!
For Amanda, I'll get to your wedding somehow. I mean, how could I miss it? I want to be there for all of the big days :)
For anyone else who might read this have a lovely day/week/month/year/life! Hope is all we have sometimes, never give up on it all :)
Oh yeah, I like smileys ;)
|
require 'mock/bot/server_mock'
require 'mock/bot/role_mock'
require 'mock/bot/channel_mock'
require 'mock/bot/command_mock'
require 'mock/bot/command_event_mock'
require 'mock/bot/log_events_mock'
module Mock
class CommandBot
def initialize
@commands = {}
end
def command(name, *attributes, &block)
@commands[name] = Command.new(name, attributes, block)
end
def call(command, args)
@commands[command].call(CommandEvent.new, args)
end
def sync; end
def member_join(&block)
event = MemberJoinEvent.new
block.call(event)
end
end
end
|
package cn.newcapec.jwxt.jcxxgl.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* JwxtPkxtBjkb entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name="JWXT_PKXT_BJKB"
,schema="JWXT"
)
public class JwxtPkxtBjkb extends cn.newcapec.function.digitalcampus.common.model.AbstractModel implements java.io.Serializable {
// Fields
private String id;
private String xnxqid;
private String pkjxbid;
private String bz;
private String cjr;
private String jlssdw;
private Date whsj;
private Date cjsj;
// Constructors
/** default constructor */
public JwxtPkxtBjkb() {
}
/** minimal constructor */
public JwxtPkxtBjkb(String id, String xnxqid, String pkjxbid, String cjr, String jlssdw, Date cjsj) {
this.id = id;
this.xnxqid = xnxqid;
this.pkjxbid = pkjxbid;
this.cjr = cjr;
this.jlssdw = jlssdw;
this.cjsj = cjsj;
}
/** full constructor */
public JwxtPkxtBjkb(String id, String xnxqid, String pkjxbid, String bz, String cjr, String jlssdw, Date whsj, Date cjsj) {
this.id = id;
this.xnxqid = xnxqid;
this.pkjxbid = pkjxbid;
this.bz = bz;
this.cjr = cjr;
this.jlssdw = jlssdw;
this.whsj = whsj;
this.cjsj = cjsj;
}
// Property accessors
@Id
@Column(name="ID", unique=true, nullable=false, length=32)
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
@Column(name="XNXQID", nullable=false, length=32)
public String getXnxqid() {
return this.xnxqid;
}
public void setXnxqid(String xnxqid) {
this.xnxqid = xnxqid;
}
@Column(name="PKJXBID", nullable=false, length=32)
public String getPkjxbid() {
return this.pkjxbid;
}
public void setPkjxbid(String pkjxbid) {
this.pkjxbid = pkjxbid;
}
@Column(name="BZ", length=2000)
public String getBz() {
return this.bz;
}
public void setBz(String bz) {
this.bz = bz;
}
@Column(name="CJR", nullable=false, length=32)
public String getCjr() {
return this.cjr;
}
public void setCjr(String cjr) {
this.cjr = cjr;
}
@Column(name="JLSSDW", nullable=false, length=32)
public String getJlssdw() {
return this.jlssdw;
}
public void setJlssdw(String jlssdw) {
this.jlssdw = jlssdw;
}
@Temporal(TemporalType.DATE)
@Column(name="WHSJ", length=7)
public Date getWhsj() {
return this.whsj;
}
public void setWhsj(Date whsj) {
this.whsj = whsj;
}
@Temporal(TemporalType.DATE)
@Column(name="CJSJ", nullable=false, length=7)
public Date getCjsj() {
return this.cjsj;
}
public void setCjsj(Date cjsj) {
this.cjsj = cjsj;
}
} |
#!/usr/bin/env python3
import sys
import os
import urllib.request
import path_utils
# credit: https://stackoverflow.com/questions/22676/how-to-download-a-file-over-http
def download_url(source_url, target_path):
if os.path.exists(target_path):
return False, "Target path [%s] already exists" % target_path
contents = None
try:
with urllib.request.urlopen(source_url) as f:
contents = f.read().decode("utf8")
except urllib.error.HTTPError as httpex:
return False, "Downloading failed: [%s]" % httpex
with open(target_path, "w") as f:
f.write(contents)
return True, None
def puaq():
print("Usage: %s source_url target_path" % path_utils.basename_filtered(__file__))
sys.exit(1)
if __name__ == "__main__":
if len(sys.argv) < 3:
puaq()
source_url = sys.argv[1]
target_path = sys.argv[2]
v, r = download_url(source_url, target_path)
if not v:
print(r)
sys.exit(1)
|
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Core\User;
use Symfony\Component\Security\Core\Role\Role;
/**
* Represents the interface that all user classes must implement.
*
* This interface is useful because the authentication layer can deal with
* the object through its lifecycle, using the object to get the encoded
* password (for checking against a submitted password), assigning roles
* and so on.
*
* Regardless of how your user are loaded or where they come from (a database,
* configuration, web service, etc), you will have a class that implements
* this interface. Objects that implement this interface are created and
* loaded by different objects that implement UserProviderInterface
*
* @see UserProviderInterface
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface UserInterface
{
/**
* Returns the roles granted to the user.
*
* public function getRoles()
* {
* return ['ROLE_USER'];
* }
*
* Alternatively, the roles might be stored on a ``roles`` property,
* and populated in any number of different ways when the user object
* is created.
*
* @return (Role|string)[] The user roles
*/
public function getRoles();
/**
* Returns the password used to authenticate the user.
*
* This should be the encoded password. On authentication, a plain-text
* password will be salted, encoded, and then compared to this value.
*
* @return string|null The encoded password if any
*/
public function getPassword();
/**
* Returns the salt that was originally used to encode the password.
*
* This can return null if the password was not encoded using a salt.
*
* @return string|null The salt
*/
public function getSalt();
/**
* Returns the username used to authenticate the user.
*
* @return string The username
*/
public function getUsername();
/**
* Removes sensitive data from the user.
*
* This is important if, at any given point, sensitive information like
* the plain-text password is stored on this object.
*/
public function eraseCredentials();
}
|
ar_menu=new Array('downloaded','featured','popular','new','free','random');
str=1;
id_component=0;
ctype_component="";
flag_auto=true;
res="";
function zcomponent(id,ctype,page)
{
if(id!=id_component)
{
document.getElementById('home_boxes').innerHTML = "";
}
str=page;
var req = new JsHttpRequest();
// Code automatically called on load finishing.
req.onreadystatechange = function() {
if (req.readyState == 4) {
for(i=0;i<ar_menu.length;i++)
{
if(ar_menu[i]==ctype)
{
document.getElementById('menu_'+ctype).className="tact";
}
else
{
document.getElementById('menu_'+ar_menu[i]).className="tact2";
}
}
if(page==1)
{
document.getElementById('home_boxes').innerHTML =req.responseText;
res=req.responseText;
check_carts('');
}
else
{
document.getElementById('home_boxes').innerHTML = document.getElementById('home_boxes').innerHTML + req.responseText;
res=req.responseText;
check_carts('');
}
$('#home_boxes').masonry({
itemSelector: '.home_box'
});
$('#home_boxes').masonry('reload') ;
$('.home_preview').each(function(){
$(this).animate({opacity:'1.0'},1);
$(this).mouseover(function(){
$(this).stop().animate({opacity:'0.6'},600);
});
$(this).mouseout(function(){
$(this).stop().animate({opacity:'1.0'},300);
});
$(".hb_cart").mouseover(function(){
$(this).stop().animate({ opacity: 1}, 600);
});
$(".hb_cart").mouseout(function(){
$(this).stop().animate({ opacity: 0.5}, 600);
});
$(".hb_lightbox").mouseover(function(){
$(this).stop().animate({ opacity: 1}, 600);
});
$(".hb_lightbox").mouseout(function(){
$(this).stop().animate({ opacity: 0.5}, 600);
});
$(".hb_free").mouseover(function(){
$(this).stop().animate({ opacity: 1}, 600);
});
$(".hb_free").mouseout(function(){
$(this).stop().animate({ opacity: 0.5}, 600);
});
});
}
}
req.open(null, 'members/component_light2.php', true);
req.send( {id: id, ctype: ctype,str: str} );
str++;
id_component=id;
ctype_component=ctype;
}
$(document).ready(function(){
$(window).scroll(function(){
if($(document).height() - $(window).height() - $(window).scrollTop() <150)
{
if(str!=1 && flag_auto)
{
flag_auto=false;
if(res!="")
{
//zcomponent(id_component,ctype_component,str);
}
}
}
else
{
flag_auto=true;
}
});
$('#slides').superslides({
slide_easing: 'easeInOutCubic',
slide_speed: 800,
pagination: false,
hashchange: true,
scrollable: false,
inherit_width_from: '#wrapper_slideshow',
inherit_height_from: '#wrapper_slideshow',
animation:'fade',
play:5000
});
$(".prev1").css({ opacity: 0.5});
$(".next1").css({ opacity: 0.5});
$(".next1").mouseover(function(){
$(this).stop().animate({ opacity: 1}, 600);
});
$(".next1").mouseout(function(){
$(this).stop().animate({ opacity: 0.5}, 600);
});
$(".prev1").mouseover(function(){
$(this).stop().animate({ opacity: 1}, 600);
});
$(".prev1").mouseout(function(){
$(this).stop().animate({ opacity: 0.5}, 600);
});
}); |
// <copyright file="Delegates.cs" company="Autonomic Systems, Quamotion">
// Copyright (c) Autonomic Systems. All rights reserved.
// Copyright (c) Quamotion. All rights reserved.
// </copyright>
using System;
using System.Runtime.InteropServices;
namespace TurboJpegWrapper
{
/// <summary>
/// A callback function that can be used to modify the DCT coefficients
/// after they are losslessly transformed but before they are transcoded to a
/// new JPEG image. This allows for custom filters or other transformations
/// to be applied in the frequency domain.
/// </summary>
/// <param name="coeffs">
/// Pointer to an array of transformed DCT coefficients. (NOTE
/// this pointer is not guaranteed to be valid once the callback returns, so
/// applications wishing to hand off the DCT coefficients to another function
/// or library should make a copy of them within the body of the callback.)
/// </param>
/// <param name="arrayRegion">
/// <see cref="TJRegion"/> structure containing the width and height of
/// the array pointed to by <paramref name="coeffs"/> as well as its offset relative to
/// the component plane. TurboJPEG implementations may choose to split each
/// component plane into multiple DCT coefficient arrays and call the callback
/// function once for each array.
/// </param>
/// <param name="planeRegion">
/// <see cref="TJRegion"/> structure containing the width and height of
/// the component plane to which <paramref name="coeffs"/> belongs.
/// </param>
/// <param name="componentIndex">
/// ID number of the component plane to which
/// <paramref name="coeffs"/> belongs (Y, Cb, and Cr have, respectively, ID's of 0, 1,
/// and 2 in typical JPEG images.)
/// </param>
/// <param name="transformIndex">
/// ID number of the transformed image to which
/// <paramref name="coeffs"/> belongs. This is the same as the index of the transform
/// in the "transforms" array that was passed to <see cref="TurboJpegImport.TjTransform"/>.
/// </param>
/// <param name="transform">
/// A pointer to a <see cref="TjTransform"/> structure that specifies the
/// parameters and/or cropping region for this transform.
/// </param>
/// <returns>0 if the callback was successful, or -1 if an error occurred.</returns>
/// <remarks>
/// Original signature is:
/// <para><c>int customFilter(short *coeffs, tjregion arrayRegion, tjregion planeRegion, int componentIndex, int transformIndex, struct tjtransform * transform)</c>.</para>
/// </remarks>
public delegate int CustomFilter(IntPtr coeffs, IntPtr arrayRegion, IntPtr planeRegion, int componentIndex, int transformIndex, IntPtr transform);
} |
import Ember from 'ember';
import config from './config/environment';
import googlePageview from './mixins/google-pageview';
const Router = Ember.Router.extend(googlePageview, {
location: config.locationType
});
Router.map(function() {
this.route('routes', function(){
this.route('route', { path: "/:route-id" });
this.route('loading');
});
this.route('stops', function(){
this.route('by-frequency');
this.route('walkshed');
this.route('transitshed');
this.route('stop', { path: "/:stop-id" });
});
this.route('operators', function(){
this.route('service-areas');
this.route('operator', { path: "/:operator-id" });
});
this.route('route-stop-patterns', function(){
});
this.route('error', { path: "*path" });
this.route('isochrones');
this.route('map-matching');
});
export default Router;
|
---
layout: default
---
<div class="post">
<h1>{{ page.title }}</h1>
<span class="post-date">{{ page.date | date_to_string }}</span>
{{ content }}
</div>
<div class="related">
<h2>Related Posts</h2>
<ul class="related-posts">
{% for post in site.related_posts limit:3 %}
<li>
<h3>
<a href="{{ post.url }}">
{{ post.title }}
<small>{{ post.date | date_to_string }}</small>
</a>
</h3>
</li>
{% endfor %}
</ul>
</div>
|
# Plot histogram
import os
import numpy as np
from plantcv.plantcv.threshold import binary as binary_threshold
from plantcv.plantcv import params
from plantcv.plantcv import fatal_error
from plantcv.plantcv._debug import _debug
import pandas as pd
from plotnine import ggplot, aes, geom_line, labels, scale_color_manual
def _hist_gray(gray_img, bins, lower_bound, upper_bound, mask=None):
""" Prepare the ready to plot histogram data
Inputs:
gray_img = grayscale image to analyze
bins = divide the data into n evenly spaced bins
lower_bound = the lower bound of the bins (x-axis min value)
upper_bound = the upper bound of the bins (x-axis max value)
mask = binary mask, calculate histogram from masked area only (default=None)
Returns:
bin_labels = an array of histogram bin labels
hist_percent = an array of histogram represented by percent values
hist_gray_data = an array of histogram (original values)
:param gray_img: numpy.ndarray
:param bins: int
:param lower_bound: int
:param upper_bound: int
:param mask: numpy.ndarray
:return bin_labels: numpy.ndarray
:return hist_percent: numpy.ndarray
:return hist_gray_data: numpy.ndarray
"""
params.device += 1
debug = params.debug
# Apply mask if one is supplied
if mask is not None:
min_val = np.min(gray_img)
pixels = len(np.where(mask > 0)[0])
# apply plant shaped mask to image
params.debug = None
mask1 = binary_threshold(mask, 0, 255, 'light')
mask1 = (mask1 / 255)
masked = np.where(mask1 != 0, gray_img, min_val - 5000)
else:
pixels = gray_img.shape[0] * gray_img.shape[1]
masked = gray_img
params.debug = debug
# Store histogram data
hist_gray_data, hist_bins = np.histogram(masked, bins, (lower_bound, upper_bound))
# make hist percentage for plotting
hist_percent = (hist_gray_data / float(pixels)) * 100
# use middle value of every bin as bin label
bin_labels = np.array([np.average([hist_bins[i], hist_bins[i+1]]) for i in range(0, len(hist_bins) - 1)])
return bin_labels, hist_percent, hist_gray_data
# hist_data = pd.DataFrame({'pixel intensity': bin_labels, 'proportion of pixels (%)': hist_percent})
# return hist_data
def histogram(img, mask=None, bins=100, lower_bound=None, upper_bound=None, title=None, hist_data=False):
"""Plot histograms of each input image channel
Inputs:
img = an RGB or grayscale image to analyze
mask = binary mask, calculate histogram from masked area only (default=None)
bins = divide the data into n evenly spaced bins (default=100)
lower_bound = the lower bound of the bins (x-axis min value) (default=None)
upper_bound = the upper bound of the bins (x-axis max value) (default=None)
title = a custom title for the plot (default=None)
hist_data = return the frequency distribution data if True (default=False)
Returns:
fig_hist = histogram figure
hist_df = dataframe with histogram data, with columns "pixel intensity" and "proportion of pixels (%)"
:param img: numpy.ndarray
:param mask: numpy.ndarray
:param bins: int
:param lower_bound: int
:param upper_bound: int
:param title: str
:param hist_data: bool
:return fig_hist: plotnine.ggplot.ggplot
:return hist_df: pandas.core.frame.DataFrame
"""
if not isinstance(img, np.ndarray):
fatal_error("Only image of type numpy.ndarray is supported input!")
if len(img.shape) < 2:
fatal_error("Input image should be at least a 2d array!")
if mask is not None:
masked = img[np.where(mask > 0)]
img_min, img_max = np.nanmin(masked), np.nanmax(masked)
else:
img_min, img_max = np.nanmin(img), np.nanmax(img)
# for lower / upper bound, if given, use the given value, otherwise, use the min / max of the image
lower_bound = lower_bound if lower_bound is not None else img_min
upper_bound = upper_bound if upper_bound is not None else img_max
if len(img.shape) > 2:
if img.shape[2] == 3:
b_names = ['blue', 'green', 'red']
else:
b_names = [str(i) for i in range(img.shape[2])]
if len(img.shape) == 2:
bin_labels, hist_percent, hist_ = _hist_gray(img, bins=bins, lower_bound=lower_bound, upper_bound=upper_bound,
mask=mask)
hist_df = pd.DataFrame(
{'pixel intensity': bin_labels, 'proportion of pixels (%)': hist_percent, 'hist_count': hist_,
'color channel': ['0' for _ in range(len(hist_percent))]})
else:
# Assumption: RGB image
# Initialize dataframe column arrays
px_int = np.array([])
prop = np.array([])
hist_count = np.array([])
channel = []
for (b, b_name) in enumerate(b_names):
bin_labels, hist_percent, hist_ = _hist_gray(img[:, :, b], bins=bins, lower_bound=lower_bound,
upper_bound=upper_bound, mask=mask)
# Append histogram data for each channel
px_int = np.append(px_int, bin_labels)
prop = np.append(prop, hist_percent)
hist_count = np.append(hist_count, hist_)
channel = channel + [b_name for _ in range(len(hist_percent))]
# Create dataframe
hist_df = pd.DataFrame(
{'pixel intensity': px_int, 'proportion of pixels (%)': prop, 'hist_count': hist_count,
'color channel': channel})
fig_hist = (ggplot(data=hist_df,
mapping=aes(x='pixel intensity', y='proportion of pixels (%)', color='color channel'))
+ geom_line())
if title is not None:
fig_hist = fig_hist + labels.ggtitle(title)
if len(img.shape) > 2 and img.shape[2] == 3:
fig_hist = fig_hist + scale_color_manual(['blue', 'green', 'red'])
# Plot or print the histogram
_debug(visual=fig_hist, filename=os.path.join(params.debug_outdir, str(params.device) + '_hist.png'))
if hist_data is True:
return fig_hist, hist_df
return fig_hist
|
import { Data } from 'fake-types-lib-2/data';
export declare type MyData = Data | string;
export {};
|
//
// SPTestRailReporter.h
// DocsAtWork
//
// Created by Siddartha Polisetty on 3/22/16.
// Copyright (c) 2016 Siddartha Polisetty
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#import <Foundation/Foundation.h>
#import <AFNetworking/AFNetworking.h>
#import "SPTestRailConfigurationBuilder.h"
#import "SPTestRailProject.h"
#import "SPTestRailSuite.h"
#import "SPTestRailProject.h"
#import "SPTestRailCase.h"
#import "SPTestRailMileStone.h"
#import "SPTestRailRun.h"
#import "SPTestRailUser.h"
#import "SPTestRailSection.h"
#import "SPTestRailPlan.h"
#import "SPTestRailConfigGroup.h"
#import "SPTestRailTest.h"
#import "SPTestRailResult.h"
@interface SPTestRailReporter : NSObject
+ (instancetype)sharedReporter;
#pragma mark - Result CRUD
- (NSArray *)getAllResultsforTestId:(NSNumber *)testId Error:(NSError *__autoreleasing *)error;
- (NSArray *)getAllResultsforCaseId:(NSNumber *)caseId ForRunId:(NSNumber *)runId Error:(NSError *__autoreleasing *)error;
- (NSArray *)getAllResultsforRunId:(NSNumber *)runId Error:(NSError *__autoreleasing *)error;
- (SPTestRailResult *)addResult:(SPTestRailResult *)result ForTestId:(NSNumber *)testId Error:(NSError *__autoreleasing *)error;
- (SPTestRailResult *)addResult:(SPTestRailResult *)result ForRunId:(NSNumber *)runId ForCaseId:(NSNumber *)caseId Error:(NSError *__autoreleasing *)error;
- (NSArray *)addResults:(NSArray *)testResults ForRunId:(NSNumber *)runId Error:(NSError *__autoreleasing *)error;
- (NSArray *)addResultsForCases:(NSArray *)testResults ForRunId:(NSNumber *)runId Error:(NSError *__autoreleasing *)error;
#pragma mark - Test CRUD
- (SPTestRailTest *)getTestWithId:(NSNumber *)testId Error:(NSError *__autoreleasing *)error;
- (NSArray *)getAllTestsWithRunId:(NSNumber *)runId Error:(NSError *__autoreleasing *)error;
#pragma mark - Case CRUD
- (SPTestRailCase *)getCaseWithId:(NSNumber *)caseId Error:(NSError *__autoreleasing *)error;
- (NSArray *)getAllCasesForProjectId:(NSNumber *)projectId WithSectionId:(NSNumber *)sectionId WithSuiteId:(NSNumber *)suiteId Error:(NSError *__autoreleasing *)error;
- (SPTestRailCase *)addCase:(SPTestRailCase *)testCase WithSectionId:(NSNumber *)sectionId Error:(NSError *__autoreleasing *)error;
- (SPTestRailCase *)updateCase:(SPTestRailCase *)testCase Error:(NSError *__autoreleasing *)error;
- (BOOL)deleteCaseWithId:(NSNumber *)caseId Error:(NSError *__autoreleasing *)error;
#pragma mark - Configuration CRUD
- (NSArray *)getAllConfigGroupsForProjectId:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
- (BOOL)deleteConfigWithId:(NSNumber *)configId Error:(NSError *__autoreleasing *)error;
- (BOOL)deleteConfigGroupWithId:(NSNumber *)configGroupId Error:(NSError *__autoreleasing *)error;
- (SPTestRailConfig *)addConfig:(SPTestRailConfig *)config InConfigGroupId:(NSNumber *)configGroupId Error:(NSError *__autoreleasing *)error;
- (SPTestRailConfigGroup *)addConfigGroup:(SPTestRailConfigGroup *)configGroup InProjectId:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
- (SPTestRailConfig *)updateConfig:(SPTestRailConfig *)config Error:(NSError *__autoreleasing *)error;
- (SPTestRailConfigGroup *)updateConfigurationGroup:(SPTestRailConfigGroup *)configGroup Error:(NSError *__autoreleasing *)error;
#pragma mark - Plan CRUD
- (NSArray *)getAllPlansForProjectId:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
- (SPTestRailPlan *)getPlanWithId:(NSNumber *)planId Error:(NSError *__autoreleasing *)error;
- (BOOL)closePlanWithId:(NSNumber *)planId Error:(NSError *__autoreleasing *)error;
- (BOOL)deletePlanWithId:(NSNumber *)planId Error:(NSError *__autoreleasing *)error;
- (SPTestRailPlan *)addPlan:(SPTestRailPlan *)plan ForProjectId:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
- (SPTestRailPlan *)updatePlan:(SPTestRailPlan *)plan Error:(NSError *__autoreleasing *)error;
- (SPTestRailPlanEntry *)addPlanEntry:(SPTestRailPlanEntry *)entry InPlanId:(NSNumber *)planId Error:(NSError *__autoreleasing *)error;
- (SPTestRailPlanEntry *)updatePlanEntry:(SPTestRailPlanEntry *)entry InPlanId:(NSNumber *)planId Error:(NSError *__autoreleasing *)error;
- (BOOL)deletePLanEntryWithEntryId:(NSString *)entryId InPlanId:(NSNumber *)planId Error:(NSError *__autoreleasing *)error;
#pragma mark - Run CRUD
- (NSArray *)getAllRunsForProjectId:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
- (SPTestRailRun *)getRunWithId:(NSNumber *)runId Error:(NSError *__autoreleasing *)error;
- (BOOL)closeRunWithId:(NSNumber *)runId Error:(NSError *__autoreleasing *)error;
- (BOOL)deleteRunWithId:(NSNumber *)runId Error:(NSError *__autoreleasing *)error;
- (SPTestRailRun *)addRun:(SPTestRailRun *)run ForProjectId:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
- (SPTestRailRun *)updateRun:(SPTestRailRun *)run Error:(NSError *__autoreleasing *)error;
#pragma mark - Suite CRUD
- (SPTestRailSuite *)addSuite:(SPTestRailSuite *)suite ForProjectId:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
- (SPTestRailSuite *)updateSuite:(SPTestRailSuite *)suite Error:(NSError *__autoreleasing *)error;
- (BOOL)deleteSuiteWithId:(NSNumber *)suiteId Error:(NSError *__autoreleasing *)error;
- (NSArray *)getAllSuitesForProject:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
- (SPTestRailSuite *)getSuiteWithId:(NSNumber *)suiteId Error:(NSError *__autoreleasing *)error;
#pragma mark - Section CRUD
- (SPTestRailSection *)addSection:(SPTestRailSection *)section ForProjectId:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
- (SPTestRailSection *)updateSection:(SPTestRailSection *)section Error:(NSError *__autoreleasing *)error;
- (BOOL)deleteSectionWithId:(NSNumber *)sectionId Error:(NSError *__autoreleasing *)error;
- (NSArray *)getAllSectionsForProjectWithId:(NSNumber *)projectId WithSuiteId:(NSNumber *)suiteId Error:(NSError *__autoreleasing *)error;
- (SPTestRailSection *)getSectionWithId:(NSNumber *)sectionId Error:(NSError *__autoreleasing *)error;
#pragma mark - Milestone CRUD
- (SPTestRailMileStone *)addMileStone:(SPTestRailMileStone *)mileStone ForProjectId:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
- (SPTestRailMileStone *)updateMileStone:(SPTestRailMileStone *)mileStone Error:(NSError *__autoreleasing *)error;
- (BOOL)deleteMileStoneWithId:(NSNumber *)mileStoneId Error:(NSError *__autoreleasing *)error;
- (NSArray *)getAllMileStonesForProjectWithId:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
- (SPTestRailMileStone *)getMileStoneWithId:(NSNumber *)mileStoneId Error:(NSError *__autoreleasing *)error;
#pragma mark - User CRUD
- (NSArray *)getAllUsersError:(NSError *__autoreleasing *)error;
- (SPTestRailUser *)getUserWithId:(NSNumber *)userId Error:(NSError *__autoreleasing *)error;
- (SPTestRailUser *)getUserWithEmail:(NSString *)email Error:(NSError *__autoreleasing *)error;
#pragma mark - Project CRUD
- (SPTestRailProject *)addProject:(SPTestRailProject *)project Error:(NSError *__autoreleasing *)error;
- (SPTestRailProject *)updateProject:(SPTestRailProject *)project Error:(NSError *__autoreleasing *)error;
- (BOOL)deleteProjectWithId:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
- (NSArray *)getAllProjectsError:(NSError *__autoreleasing *)error;
- (SPTestRailProject *)getProjectWithId:(NSNumber *)projectId Error:(NSError *__autoreleasing *)error;
@end
|
package com.jayway.rps.game;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import com.jayway.es.api.Event;
public class EventStringUtil {
public static String toString(Event event) {
String simpleName = event.getClass().getSimpleName();
Map<String, Object> values = new HashMap<String, Object>();
for (Field field : event.getClass().getFields()) {
try {
Object object = field.get(event);
if (object instanceof UUID) {
object = ((UUID)object).getLeastSignificantBits() % 255;
}
values.put(field.getName(), object);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return simpleName + values;
}
}
|
<?php
/**
* Recursively iterates files starting from a base path, replacing strings in any files matching a valid Mime type
* @param $aBasePaths - Array of base paths which will each be iterated recursively to find files for string replacement
* @param $aStringReplacements - Associative array of strings to replace in files. Any keys found in this array will be replaced by their corresponding value
*/
function recursiveStringReplace($aBasePaths = array(), $aStringReplacements = array())
{
// Replacement will only occur in files of the following Mime types
$aValidFileMimeTypes = array(
"text/css",
"text/html",
"text/x-php",
"text/plain",
"application/xml",
"application/json",
"application/javascript"
);
// Iterate through each directory recursively, starting at the base path
foreach ($aBasePaths as $strBasePath)
{
$hDirectoryIterator = new RecursiveDirectoryIterator($strBasePath);
foreach (new RecursiveIteratorIterator($hDirectoryIterator) as $strFilePath)
{
// Get the Mime type of the file
$hFileInfo = finfo_open(FILEINFO_MIME_TYPE);
$strFileMimeType = finfo_file($hFileInfo, $strFilePath);
finfo_close($hFileInfo);
// If file is of a valid Mime type, attempt to get its contents
if(in_array($strFileMimeType, $aValidFileMimeTypes)) {
$strFileContents = file_get_contents($strFilePath);
// If we were able to get the contents of the file, replace all string instances in aReplacements
if($strFileContents) {
$strFileContents = strtr($strFileContents, $aStringReplacements);
file_put_contents($strFilePath, $strFileContents);
}
}
}
}
}
recursiveStringReplace(
array(
"./files/",
"./more-files/"
),
array(
"Hello" => "Howdy",
"World" => "Planet",
"Howdy" => "Hello",
"Planet" => "World"
)
); |
require 'fathom_authorization_system'
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
include FathomAuthorizationSystem
def stylesheet_files
if APPLICATION_DOMAIN == 'shanti.virginia.edu'
#['fathom', 'jquery-ui','jquery.autocomplete', 'jquery.checktree', 'jquery.draggable.popup'] + super
['fathom', 'jquery-ui'] + super
else #'thlib.org'
if @current_style == :details
super + ['fathom','thickbox','communications', 'jquery-ui-tabs', 'jquery-ui']
else
super + ['fathom','communications', 'jquery-ui-tabs', 'jquery-ui', 'Hypertreebase', 'Hypertree']
end
end
end
def javascript_files
if @current_style == :home
if APPLICATION_DOMAIN == 'shanti.virginia.edu'
if logged_in?
super + ['togglesections','jquery.jcarousel','thickbox-compressed','jquery-plugins','load-latest-news']
else
super + ['jquery.jcarousel','thickbox-compressed','jquery-plugins','load-latest-news']
end
else #'thlib.org'
#super + ['jquery.jcarousel','jquery-plugins'] #neither news or toggle action is used on connections
['min/jquery.jcarousel'] #jquery loaded from thl template
end
else
if @current_style == :details
if APPLICATION_DOMAIN == 'shanti.virginia.edu'
if logged_in?
##['category_selector','application','togglesections','thickbox-compressed','jquery-plugins','encodemailto','profile-detail-view','yahoo-dom-event','element-beta-min','tabview-min'] + super
#super + ['category_selector','application','togglesections','thickbox-compressed','encodemailto','profile-detail-view','yahoo-dom-event','element-beta-min','tabview-min']
super + ['jquery.autocomplete', 'jquery.checktree', 'model-searcher', 'jquery.draggable.popup','application','togglesections','thickbox-compressed','encodemailto','profile-detail-view','yahoo-dom-event','element-beta-min','tabview-min']
else
super + ['category_selector','application','thickbox-compressed','jquery-plugins','encodemailto','profile-detail-view','yahoo-dom-event','element-beta-min','tabview-min']
end
else #'thlib.org'
if logged_in?
#super + ['category_selector','application','thickbox-compressed','encodemailto','profile-detail-view','yahoo-dom-event','element-beta-min','tabview-min']
super + ['category_selector','thickbox-compressed','encodemailto','profile-detail-view','yahoo-dom-event','element-beta-min','tabview-min'] #jquery loaded from thl template
else
#super + ['category_selector','application','thickbox-compressed','encodemailto','profile-detail-view','yahoo-dom-event','element-beta-min','tabview-min']
super + ['category_selector','thickbox-compressed','encodemailto','profile-detail-view','yahoo-dom-event','element-beta-min','tabview-min'] #jquery loaded from thl template
end
end
else
if @current_style == :showview
if APPLICATION_DOMAIN == 'shanti.virginia.edu'
if logged_in?
super + ['category_selector','application','togglesections','thickbox-compressed','jquery-plugins','encodemailto','profile-detail-view','yahoo-dom-event','element-beta-min','tabview-min']
else
super + ['category_selector','application','thickbox-compressed','jquery-plugins','encodemailto','profile-detail-view','yahoo-dom-event','element-beta-min','tabview-min']
end
else #'thlib.org'
if logged_in?
['encodemailto','profile-detail-view','yahoo-dom-event','element-beta-min','tabview-min'] #jquery loaded from thl template
else
['encodemailto','profile-detail-view','yahoo-dom-event','element-beta-min','tabview-min'] #jquery loaded from thl template
end
end
else
if APPLICATION_DOMAIN == 'shanti.virginia.edu'
if logged_in?
super + ['category_selector','application','togglesections','thickbox-compressed','jquery-plugins','encodemailto']
else
super + ['category_selector','application','thickbox-compressed','jquery-plugins','encodemailto']
end
else
if logged_in?
if params[:inline]
['jquery','jrails'] + ['encodemailto'] #jquery loaded locally since modal window loads no template
else
['jrails'] + ['encodemailto','jit'] #jquery loaded from thl template
end
else
if params[:inline]
['jquery','jrails'] + ['encodemailto'] #jquery loaded locally since modal window loads no template
else
['jrails'] + ['encodemailto', 'jit'] #jquery loaded from thl template
end
end
end
end
end
end
end
def javascripts
if APPLICATION_DOMAIN == 'shanti.virginia.edu'
[super, include_tiny_mce_if_needed].join("\n").html_safe
else #'thlib.org'
if @current_style == :details #edit mode then needs tiny_mce
#Commented - on May 21, 2013 - temporary removal of tinymce
#[super, include_tiny_mce_if_needed].join("\n").html_safe
super
else
super
end
end
end
#Commented - on May 21, 2013 - temporary removal of tinymce
#def tinymce_reinitialization_script
# str = "<script type='text/javascript'>"+ "\n"
# str += "//<![CDATA[" + "\n"
# str += "tinyMCE.init({" + "\n"
# str += "editor_selector : 'mceEditor'," + "\n"
# str += "strict_loading_mode : tinymce.isWebKit," + "\n"
# str += "height : '220px'," + "\n"
# str += "mode : 'textareas'," + "\n"
# str += "relative_urls : false," + "\n"
# str += "noneditable_leave_contenteditable : 'true'," + "\n"
# str += "plugins : 'contextmenu,paste,media,fullscreen,template,noneditable, table, spellchecker'," + "\n"
# str += "template_external_list_url : '/templates/templates.js'," + "\n"
# str += "content_css : '/stylesheets/customtinymce.css'," + "\n"
# str += "theme : 'advanced'," + "\n"
# str += "theme_advanced_blockformats : 'p,h1,h2,h3,h4,h5,h6'," + "\n"
# str += "theme_advanced_buttons1 : ' fullscreen,separator,bold,italic,underline,strikethrough,separator,undo,redo,separator,link,unlink,template,formatselect, code'," + "\n"
# str += "theme_advanced_buttons2 : 'cut,copy,paste,separator,pastetext,pasteword,separator,bullist,numlist,outdent,indent,separator,justifyleft,justifycenter,justifyright,justifiyfull,separator,removeformat,charmap'," + "\n"
# str += "theme_advanced_buttons3 : 'spellchecker,tablecontrols '," + "\n"
# str += "spellchecker_languages : '+English=en'," + "\n"
# str += "spellchecker_rpc_url : '/application/spellchecker'," + "\n"
# str += "gecko_spellcheck : 'true'," + "\n"
# str += "table_styles : 'Header 1=header1;Header 2=header2;Header 3=header3'," + "\n"
# str += "table_cell_styles : 'Header 1=header1;Header 2=header2;Header 3=header3;Table Cell=tableCel1'," + "\n"
# str += "table_row_styles : 'Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1'," + "\n"
# str += "theme_advanced_resizing : 'true'," + "\n"
# str += "theme_advanced_toolbar_align : 'left'," + "\n"
# str += "theme_advanced_toolbar_location : 'top'," + "\n"
# str += "width : '550px'" + "\n"
# str += "});" + "\n"
# str += "//]]>" + "\n"
# str += "</script> "
# return str.html_safe
#end
def site_title(opts={:html=>true})
opts[:html] ? 'SHANTI UVa' : 'SHANTI UVa' #'SHANTI at the University of Virginia' : 'SHANTI at the University of Virginia'
end
def banner_title(opts={:html=>true})
opts[:html] ? 'SHANTI - Sciences, Humanities, and Arts Network of Technological Initiatives' : 'SHANTI - Sciences, Humanities, and Arts Network of Technological Initiatives'
end
# takes :person_profile / :profile_profile etc. for the "profile_type"
# The "fields" is a hash where the keys match the profiles' tag attributes (see PersonProfile etc..)
# and the values map to HTML elements (the id attribute)
# EXAMPLE:
#
# generate_js_for_tag_autocomplete(:person_profile, {:general_interests=>'person_profile_general_interest_list'})
#
def generate_js_tag_jquery_ui_autocomplete(tag_combiner, profile_type, fields)
js = ''
fields.each_pair do |tag_field,tag_field_input_id|
# list of tag values, var name prefixed by the tag field
js << %(var #{tag_field}_profile_tags = [];\n)
# Get a hash of the tags for this field
tag_set = tag_combiner.tag_counts(tag_field)
tag_set.keys.sort.each do |tag|
js << %(#{tag_field}_profile_tags.push({value: '#{escape_javascript tag}' , label:'#{escape_javascript tag} (#{tag_set[tag].to_i})' });\n)
end
end
js.html_safe
end
# takes :person_profile / :profile_profile etc. for the "profile_type"
# The "fields" is a hash where the keys match the profiles' tag attributes (see PersonProfile etc..)
# and the values map to HTML elements (the id attribute)
# EXAMPLE:
#
# generate_js_for_tag_autocomplete(:person_profile, {:general_interests=>'person_profile_general_interest_list'})
#
def generate_js_for_tag_autocomplete(tag_combiner, profile_type, fields)
js = ''
fields.each_pair do |tag_field,tag_field_input_id|
# list of tag values, var name prefixed by the tag field
js << %(var #{tag_field}_profile_tags = [];\n)
# the key is the tag, the value is the hit count, var name prefixed by the tag field
js << %(var #{tag_field}_profile_tag_counts = {};\n)
# Get a hash of the tags for this field
tag_set = tag_combiner.tag_counts(tag_field)
tag_set.keys.each do |tag|
js << %(#{tag_field}_profile_tags.push('#{escape_javascript tag}');\n)
js << %(#{tag_field}_profile_tag_counts['#{escape_javascript tag}'] = #{tag_set[tag].to_i};\n)
end
js << %($("##{escape_javascript tag_field_input_id}").autocomplete(#{tag_field}_profile_tags, {
multiple : true,
formatItem : function(row) {
return row + " (" + #{tag_field}_profile_tag_counts[row] + ")";
},
formatResult : function(row) {
return row
}
});\n)
end
js.html_safe
end
def entity_profile_tag_block(tag_combiner, entity, tag_list_name, label)
entity_name = entity.class.to_s.downcase
# the organization model extends the project model
# so switch back to project if the "entity" is an "organization"
entity_name = 'project' if entity_name=='organization'
profile_method = entity_name + '_profile'
associated_tag_list = entity.send(profile_method).send(tag_list_name)
complete_tag_list = tag_combiner.tag_counts(tag_list_name)
unless associated_tag_list.empty?
# create the url path and :f param (facet) in the form f[FACET_FIELD][]=VALUE
#html = "<h3>#{label}</h3>"
html = "<dt>#{label}</dt>"
html += "<dd>"
html += associated_tag_list.map do |t|
link_params = search_path({:f=>{(tag_list_name.to_s + '_facet')=>[t.name]}})
"#{link_to(t.name.s, link_params)} <em>(#{complete_tag_list[t.name]})</em>"
end.sort.join(', ')
html += "</dd>"
html.html_safe
end
end
#
# Convert the Textile/RedCloth input text to HTML
#
def rc(string)
RedCloth.new(string).to_html
end
#
# Add a
#
def th(area)
#return "<div class='textarea_wrapper'>" + area + "</div><a class='text_help_icon' onclick=\"window.open('" + compute_public_path('index.html', 'text_help', '.html') + "','mywindow','width=550,height=700, scrollbars=yes')\">?</a>"
return area
end
def ssl_link(path)
SSL_ENABLED ? "https://#{request.env['SERVER_NAME']}#{path}" : path
end
def ssl_stylesheet_link(stylesheet, media_type = 'screen' )
"<link rel=\"stylesheet\" href=\"#{ssl_link('/stylesheets/'+stylesheet)}\" type=\"text/css\" media=\"#{media_type}\" />"
end
def ssl_javascript_link( javascript )
"<script type=\"text/javascript\" src=\"#{ssl_link('/javascripts/'+javascript)}\"></script>"
end
def main_navigation_items()
return @main_navigation_items if @main_navigation_items
# basic menu options
if APPLICATION_DOMAIN == 'shanti.virginia.edu'
home_text_link = 'Home' #'UVa Profiles'
else
home_text_link = 'Connections'
end
if APPLICATION_DOMAIN != 'shanti.virginia.edu'
@main_navigation_items = [
{ :id => :home, :text => home_text_link, :link => home_page_path },
{ :id => :profile, :text => 'My Profile', :link => me_path },
{ :id => :people, :text => 'People', :link => people_path },
{ :id => :projects, :text => 'Projects', :link => projects_path },
{ :id => :organizations, :text => 'Organizations', :link => organizations_path },
{ :id => :tools, :text => 'Tools', :link => tools_path },
{ :id => :posts, :text => 'Posts', :link => posts_path },
{ :id => :knowledge_base, :text => 'Knowledge Base', :link => 'https://wiki.shanti.virginia.edu/display/KB/SHANTI+Knowledge+Base' },
{ :id => :events, :text => 'Activities', :link => '/wordpress/?page_id=414' },
{ :id => :news, :text => 'News', :link => '/wordpress/?page_id=400' },
#{ :id => :about_us, :text => 'SHANTI Activities', :link => '/wordpress/?page_id=6' },
]
# don't display my profile if I am not logged in (on main navigation)
if not logged_in?
my_profile = main_navigation_items.select { |item| item[:id] == :profile }.first
@main_navigation_items.delete(my_profile)
end
else
@main_navigation_items = [
{ :id => :home, :text => home_text_link, :link => home_page_path },
{ :id => :uva_profiles, :text => "UVa Profiles", :link => people_path },
#{ :id => :profile, :text => 'My Profile', :link => me_path },
#{ :id => :people, :text => 'People', :link => people_path },
#{ :id => :projects, :text => 'Projects', :link => projects_path },
#{ :id => :organizations, :text => 'Organizations', :link => organizations_path },
#{ :id => :tools, :text => 'Tools', :link => tools_path },
#{ :id => :posts, :text => 'Posts', :link => posts_path },
{ :id => :knowledge_base, :text => 'Knowledge Base', :link => 'https://wiki.shanti.virginia.edu/x/o4G' },
#{ :id => :community_tools, :text => 'Community Tools', :link => '/wordpress/?page_id=116' },
#{ :id => :uva_profiles, :text => "UVa Profiles", :link => home_page_path },
{ :id => :events, :text => 'Activities', :link => '/wordpress/?page_id=414' },
{ :id => :news, :text => 'News', :link => '/wordpress/?page_id=400' },
#{ :id => :about_us, :text => 'SHANTI Activities', :link => '/wordpress/?page_id=6' },
]
end
#verification, to handle different menus for shanti & thl
if APPLICATION_DOMAIN != 'shanti.virginia.edu'
tools = main_navigation_items.select { |item| item[:id] == :tools }.first
@main_navigation_items.delete(tools)
kbase = main_navigation_items.select { |item| item[:id] == :knowledge_base }.first
@main_navigation_items.delete(kbase)
events = main_navigation_items.select { |item| item[:id] == :events }.first
@main_navigation_items.delete(events)
news = main_navigation_items.select { |item| item[:id] == :news }.first
@main_navigation_items.delete(news)
aboutus = main_navigation_items.select { |item| item[:id] == :about_us }.first
@main_navigation_items.delete(aboutus)
end
return @main_navigation_items
end
# Sub navigation items.
def secondary_navigation_items()
return @secondary_navigation_items if @secondary_navigation_items
@secondary_navigation_items = [
#{ :id => :home, :text => "Profiles", :link => home_page_path },
{ :id => :profile, :text => 'My Profile', :link => me_path },
{ :id => :people, :text => 'People', :link => people_path },
{ :id => :projects, :text => 'Projects', :link => projects_path },
{ :id => :organizations, :text => 'Organizations', :link => organizations_path },
{ :id => :tools, :text => 'Tools', :link => tools_path },
{ :id => :posts, :text => 'Posts', :link => posts_path }
]
# don't display my profile if I am not logged in
if not logged_in?
my_profile = secondary_navigation_items.select { |item| item[:id] == :profile }.first
@secondary_navigation_items.delete(my_profile)
end
return @secondary_navigation_items
end
# Secondary navigation items.
def ancillary_navigation_items()
return @ancillary_navigation_items if @ancillary_navigation_items
@ancillary_navigation_items = [
# FUTURE: Shanti-specific.
{ :id => :about_us, :text => 'SHANTI', :link => '/wordpress/?page_id=6' },
# FUTURE: Shanti-specific.
{ :id => :resources, :text => 'Resources', :link => '/wordpress/?page_id=7' },
# FUTURE: Shanti-specific.
{ :id => :news, :text => 'News', :link => '/wordpress/?page_id=4' }
]
return @ancillary_navigation_items
end
# Override side_column_links method that come from thl_integration plugin
def side_column_links
str = "<h3 class=\"head\">#{link_to 'Communications THL', '#nogo', {:hreflang => 'Fathom Communications THL.'}}</h3>\n<ul>\n"
str += "<li>#{link_to 'Home', root_path, {:hreflang => 'Home communications.'}}</li>\n"
#str += "<li>#{link_to 'My Profile', me_path, {:hreflang => 'My Profile.'}}</li>\n" if logged_in?
#str += "<li>#{link_to 'People', people_path, {:hreflang => 'Manage People'}}</li>\n"
#str += "<li>#{link_to 'Projects', projects_path, {:hreflang => 'Manage Projects.'}}</li>\n"
#str += "<li>#{link_to 'Organizations', organizations_path, {:hreflang => 'Manage Organizations.'}}</li>\n"
#str += "<li>#{link_to 'Tools', tools_path, {:hreflang => 'Manage Tools.'}}</li>\n"
str += "</ul>"
return str
end
# Override flash_notice method that come from thl_integration plugin
def flash_notice(options = Hash.new)
return ""
end
# Override language_option_links method that come from thl_integration plugin
def language_option_links
return ""
end
#Override login_status so we don't show thl integration login status, but fathom one
def login_status
return ""
end
def editor_note_tip
return '<p class="text-editor-note">NEVER paste text directly from other programs. Use the W button to paste from Word; use the T button to paste from other programs.</p>'.html_safe
end
def page_title()
return "Search Results" if @current_nav_item == :search
return "CONTROL PANEL" if @current_nav_item == :admin
return "Banned Email" if @current_nav_item == :banned
return "" if @current_nav_item == :users
# Supply reasonable default if no current_nav_item is given.
if @current_nav_item
main_navigation_items.select { |item| item[:id] == @current_nav_item }.first[:text]
else
''
end
end
def simple_date( date )
"#{date.month}/#{date.day}/#{date.year}"
end
def collection_select_multiple(object, method,
collection, value_method, text_method,
options = {}, html_options = {})
real_method = "#{method.to_s.singularize}_ids".to_sym
collection_select(
object, real_method,
collection, value_method, text_method,
options,
html_options.merge({
:multiple => true,
:name => "#{object}[#{real_method}][]"
})
)
end
def collection_select_multiple_categories(object, method,
options = {}, html_options = {})
collection_select_multiple(
object, method,
Category.find(:all), :id, :title,
options, html_options
)
end
def join_with_and(list)
size = list.size
case size
when 0 then nil
when 1 then list.first
when 2 then list.join(' and ')
when 3 then [list[0..size-2].join(', '), list[size-1]].join(', and ')
end
end
def entity_for_post(p)
Entity.find(p.entity_id)
end
def user_access_levels
[ "Pending", "Guest", "Full", "Admin" ]
end
def disciplines
[ "English", "Media Studies", "Computer Science", "History", "Religious Studies" ]
end
def professional_profile_options
[ '', 'Faculty', 'Undergraduate', 'Graduate Student', 'Technologist', 'Administrator', 'Independent Scholar','Businessperson', 'Artist', 'Singer/Musician', 'Community Service Person', 'Writer']
end
def country_names
[
[ "Afghanistan", "AF" ],
[ "Albania", "AL" ],
[ "Algeria", "DZ" ],
[ "American Samoa", "AS" ],
[ "Andorra", "AD" ],
[ "Angola", "AO" ],
[ "Anguilla", "AI" ],
[ "Antarctica", "AQ" ],
[ "Antigua and Barbuda", "AG" ],
[ "Argentina", "AR" ],
[ "Armenia", "AM" ],
[ "Aruba", "AW" ],
[ "Australia", "AU" ],
[ "Austria", "AT" ],
[ "Azerbaijan", "AZ" ],
[ "Bahrain", "BH" ],
[ "Bangladesh", "BD" ],
[ "Barbados", "BB" ],
[ "Belarus", "BY" ],
[ "Belgium", "BE" ],
[ "Belize", "BZ" ],
[ "Benin", "BJ" ],
[ "Bermuda", "BM" ],
[ "Bhutan", "BT" ],
[ "Bolivia", "BO" ],
[ "Bosnia and Herzegovina", "BA" ],
[ "Botswana", "BW" ],
[ "Bouvet Island", "BV" ],
[ "Brazil", "BR" ],
[ "British Indian Ocean Territory", "IO" ],
[ "British Virgin Islands", "VG" ],
[ "Brunei", "BN" ],
[ "Bulgaria", "BG" ],
[ "Burkina Faso", "BF" ],
[ "Burundi", "BI" ],
[ "Côte d'Ivoire", "CI" ],
[ "Cambodia", "KH" ],
[ "Cameroon", "CM" ],
[ "Canada", "CA" ],
[ "Cape Verde", "CV" ],
[ "Cayman Islands", "KY" ],
[ "Central African Republic", "CF" ],
[ "Chad", "TD" ],
[ "Chile", "CL" ],
[ "China", "CN" ],
[ "Christmas Island", "CX" ],
[ "Cocos (Keeling) Islands", "CC" ],
[ "Colombia", "CO" ],
[ "Comoros", "KM" ],
[ "Congo", "CG" ],
[ "Cook Islands", "CK" ],
[ "Costa Rica", "CR" ],
[ "Croatia", "HR" ],
[ "Cuba", "CU" ],
[ "Cyprus", "CY" ],
[ "Czech Republic", "CZ" ],
[ "Democratic Republic of the Congo", "CD" ],
[ "Denmark", "DK" ],
[ "Djibouti", "DJ" ],
[ "Dominica", "DM" ],
[ "Dominican Republic", "DO" ],
[ "East Timor", "TL" ],
[ "Ecuador", "EC" ],
[ "Egypt", "EG" ],
[ "El Salvador", "SV" ],
[ "Equatorial Guinea", "GQ" ],
[ "Eritrea", "ER" ],
[ "Estonia", "EE" ],
[ "Ethiopia", "ET" ],
[ "Faeroe Islands", "FO" ],
[ "Falkland Islands", "FK" ],
[ "Fiji", "FJ" ],
[ "Finland", "FI" ],
[ "Former Yugoslav Republic of Macedonia", "MK" ],
[ "France", "FR" ],
[ "French Guiana", "GF" ],
[ "French Polynesia", "PF" ],
[ "French Southern Territories", "TF" ],
[ "Gabon", "GA" ],
[ "Georgia", "GE" ],
[ "Germany", "DE" ],
[ "Ghana", "GH" ],
[ "Gibraltar", "GI" ],
[ "Greece", "GR" ],
[ "Greenland", "GL" ],
[ "Grenada", "GD" ],
[ "Guadeloupe", "GP" ],
[ "Guam", "GU" ],
[ "Guatemala", "GT" ],
[ "Guinea", "GN" ],
[ "Guinea-Bissau", "GW" ],
[ "Guyana", "GY" ],
[ "Haiti", "HT" ],
[ "Heard Island and McDonald Islands", "HM" ],
[ "Honduras", "HN" ],
[ "Hong Kong", "HK" ],
[ "Hungary", "HU" ],
[ "Iceland", "IS" ],
[ "India", "IN" ],
[ "Indonesia", "ID" ],
[ "Iran", "IR" ],
[ "Iraq", "IQ" ],
[ "Ireland", "IE" ],
[ "Israel", "IL" ],
[ "Italy", "IT" ],
[ "Jamaica", "JM" ],
[ "Japan", "JP" ],
[ "Jordan", "JO" ],
[ "Kazakhstan", "KZ" ],
[ "Kenya", "KE" ],
[ "Kiribati", "KI" ],
[ "Kuwait", "KW" ],
[ "Kyrgyzstan", "KG" ],
[ "Laos", "LA" ],
[ "Latvia", "LV" ],
[ "Lebanon", "LB" ],
[ "Lesotho", "LS" ],
[ "Liberia", "LR" ],
[ "Libya", "LY" ],
[ "Liechtenstein", "LI" ],
[ "Lithuania", "LT" ],
[ "Luxembourg ", "LU" ],
[ "Macau", "MO" ],
[ "Madagascar", "MG" ],
[ "Malawi", "MW" ],
[ "Malaysia", "MY" ],
[ "Maldives", "MV" ],
[ "Mali", "ML" ],
[ "Malta", "MT" ],
[ "Marshall Islands", "MH" ],
[ "Martinique", "MQ" ],
[ "Mauritania", "MR" ],
[ "Mauritius", "MU" ],
[ "Mayotte", "YT" ],
[ "Mexico", "MX" ],
[ "Micronesia", "FM" ],
[ "Moldova", "MD" ],
[ "Monaco", "MC" ],
[ "Mongolia", "MN" ],
[ "Montserrat", "MS" ],
[ "Morocco", "MA" ],
[ "Mozambique", "MZ" ],
[ "Myanmar", "MM" ],
[ "Namibia", "NA" ],
[ "Nauru", "NR" ],
[ "Nepal", "NP" ],
[ "Netherlands", "NL" ],
[ "Netherlands Antilles", "AN" ],
[ "New Caledonia", "NC" ],
[ "New Zealand", "NZ" ],
[ "Nicaragua", "NI" ],
[ "Niger", "NE" ],
[ "Nigeria", "NG" ],
[ "Niue", "NU" ],
[ "Norfolk Island", "NF" ],
[ "North Korea", "KP" ],
[ "Northern Marianas", "MP" ],
[ "Norway", "NO" ],
[ "Oman", "OM" ],
[ "Pakistan", "PK" ],
[ "Palau", "PW" ],
[ "Panama", "PA" ],
[ "Papua New Guinea", "PG" ],
[ "Paraguay", "PY" ],
[ "Peru", "PE" ],
[ "Philippines", "PH" ],
[ "Pitcairn Islands", "PN" ],
[ "Poland", "PL" ],
[ "Portugal", "PT" ],
[ "Puerto Rico", "PR" ],
[ "Qatar", "QA" ],
[ "Réunion", "RE" ],
[ "Romania", "RO" ],
[ "Russia", "RU" ],
[ "Rwanda", "RW" ],
[ "São Tomé and Príncipe", "ST" ],
[ "Saint Helena", "SH" ],
[ "Saint Kitts and Nevis", "KN" ],
[ "Saint Lucia", "LC" ],
[ "Saint Pierre and Miquelon", "PM" ],
[ "Saint Vincent and the Grenadines", "VC" ],
[ "Samoa", "WS" ],
[ "San Marino", "SM" ],
[ "Saudi Arabia", "SA" ],
[ "Senegal", "SN" ],
[ "Seychelles", "SC" ],
[ "Sierra Leone", "SL" ],
[ "Singapore", "SG" ],
[ "Slovakia", "SK" ],
[ "Slovenia", "SI" ],
[ "Solomon Islands", "SB" ],
[ "Somalia", "SO" ],
[ "South Africa", "ZA" ],
[ "South Georgia and the South Sandwich Islands", "GS" ],
[ "South Korea", "KR" ],
[ "Spain", "ES" ],
[ "Sri Lanka", "LK" ],
[ "Sudan", "SD" ],
[ "Suriname", "SR" ],
[ "Svalbard and Jan Mayen", "SJ" ],
[ "Swaziland", "SZ" ],
[ "Sweden", "SE" ],
[ "Switzerland", "CH" ],
[ "Syria", "SY" ],
[ "Taiwan", "TW" ],
[ "Tajikistan", "TJ" ],
[ "Tanzania", "TZ" ],
[ "Thailand", "TH" ],
[ "The Bahamas", "BS" ],
[ "The Gambia", "GM" ],
[ "Togo", "TG" ],
[ "Tokelau", "TK" ],
[ "Tonga", "TO" ],
[ "Trinidad and Tobago", "TT" ],
[ "Tunisia", "TN" ],
[ "Turkey", "TR" ],
[ "Turkmenistan", "TM" ],
[ "Turks and Caicos Islands", "TC" ],
[ "Tuvalu", "TV" ],
[ "US Virgin Islands", "VI" ],
[ "Uganda", "UG" ],
[ "Ukraine", "UA" ],
[ "United Arab Emirates", "AE" ],
[ "United Kingdom", "GB" ],
[ "United States", "US" ],
[ "United States Minor Outlying Islands", "UM" ],
[ "Uruguay", "UY" ],
[ "Uzbekistan", "UZ" ],
[ "Vanuatu", "VU" ],
[ "Vatican City", "VA" ],
[ "Venezuela", "VE" ],
[ "Vietnam", "VN" ],
[ "Wallis and Futuna", "WF" ],
[ "Western Sahara", "EH" ],
[ "Yemen", "YE" ],
[ "Yugoslavia", "YU" ],
[ "Zambia", "ZM" ],
[ "Zimbabwe", "ZW" ]
]
end
def state_names
[
[ "Alabama", "AL" ],
[ "Alaska", "AK" ],
[ "Arizona", "AZ" ],
[ "Arkansas", "AR" ],
[ "California", "CA" ],
[ "Colorado", "CO" ],
[ "Connecticut", "CT" ],
[ "Delaware", "DE" ],
[ "District Of Columbia", "DC" ],
[ "Florida", "FL" ],
[ "Georgia", "GA" ],
[ "Hawaii", "HI" ],
[ "Idaho", "ID" ],
[ "Illinois", "IL" ],
[ "Indiana", "IN" ],
[ "Iowa", "IA" ],
[ "Kansas", "KS" ],
[ "Kentucky", "KY" ],
[ "Louisiana", "LA" ],
[ "Maine", "ME" ],
[ "Maryland", "MD" ],
[ "Massachusetts", "MA" ],
[ "Michigan", "MI" ],
[ "Minnesota", "MN" ],
[ "Mississippi", "MS" ],
[ "Missouri", "MO" ],
[ "Montana", "MT" ],
[ "Nebraska", "NE" ],
[ "Nevada", "NV" ],
[ "New Hampshire", "NH" ],
[ "New Jersey", "NJ" ],
[ "New Mexico", "NM" ],
[ "New York", "NY" ],
[ "North Carolina", "NC" ],
[ "North Dakota", "ND" ],
[ "Ohio", "OH" ],
[ "Oklahoma", "OK" ],
[ "Oregon", "OR" ],
[ "Pennsylvania", "PA" ],
[ "Rhode Island", "RI" ],
[ "South Carolina", "SC" ],
[ "South Dakota", "SD" ],
[ "Tennessee", "TN" ],
[ "Texas", "TX" ],
[ "Utah", "UT" ],
[ "Vermont", "VT" ],
[ "Virginia", "VA" ],
[ "Washington", "WA" ],
[ "West Virginia", "WV" ],
[ "Wisconsin", "WI" ],
[ "Wyoming", "WY" ]
]
end
# create the <li> element for the specified tab
def tab_tag( tab_id, tab_label, selected_id )
tab_name = tab_id.to_s
selected = tab_id == selected_id ? "class='selected'" : ""
"<li id='#{tab_name}-tab-button' #{selected}><a href='##{tab_name}-tab'><span>#{tab_label}</span></a></li>".html_safe
end
end
|
nav{height:64px;line-height:64px;border-bottom:1px solid gray}nav::after{content:'';display:block;clear:both}#nav-head{float:left;height:20px;line-height:20px}#nav-p{float:right;height:20px;line-height:20px}footer{position:fixed;bottom:0;left:0;right:0;text-align:center} |
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot, Router, Route,
CanActivate, CanActivateChild, CanLoad } from '@angular/router';
import { AuthService } from './auth.service';
@Injectable()
export class AuthGuard implements CanActivate, CanActivateChild, CanLoad {
constructor(private authService: AuthService,
private router: Router) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
console.log('In canActivate: ' + state.url);
return this.checkLoggedIn(state.url);
}
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
console.log('In canActivateChild: ' + state.url);
return this.checkLoggedIn(state.url);
}
canLoad(route: Route): boolean {
console.log('In canLoad: ' + route.path);
return this.checkLoggedIn(route.path);
}
checkLoggedIn(url: string): boolean {
if (this.authService.isLoggedIn()) {
return true;
}
// Retain the attempted URL for redirection
this.authService.redirectUrl = url;
this.router.navigate(['/login']);
return false;
}
}
|
<?php
/*
* Sendanor SimpleREST PHP Framework
* Copyright 2017-2020 Jaakko Heusala <jheusala@iki.fi>
*/
namespace SimpleREST\Legacy;
/* Security check */
if(!defined('REST_PHP')) {
die("Direct access not permitted\n");
}
/** Collection of elements */
abstract class Collection extends Resource implements iCollection {
}
|
import assert from 'assert'
import { planetposition, julian, sexagesimal as sexa } from '../src/index.js'
import data from '../data/index.js'
describe('#planetposition', function () {
describe('position2000', function () {
it('Mars at 2415020.0', function () {
// Mars 1899 spherical data from vsop87.chk.
const jd = 2415020.0
const planet = new planetposition.Planet(data.mars)
const res = planet.position2000(jd)
assert.strictEqual(res.lon, 5.018579265623366)
assert.strictEqual(res.lat, -0.02740734998738619)
assert.strictEqual(res.range, 1.421877771845356)
})
it('Mars at 2415020.0 VSOP D', function () {
// Mars 1899 spherical data from vsop87.chk.
const jd = 2415020.0
const planet = new planetposition.Planet(data.vsop87Dmars)
const res = planet.position2000(jd)
assert.strictEqual(res.lon, 5.01857925809491)
assert.strictEqual(res.lat, -0.02740737901167283)
assert.strictEqual(res.range, 1.4218777705060395)
})
it('Venus at 1992-12-20', function () {
// Example 32.a, p. 219
const jd = julian.CalendarGregorianToJD(1992, 12, 20)
const planet = new planetposition.Planet(data.venus)
const res = planet.position2000(jd)
assert.strictEqual(res.lon, 0.45749253478276586) // rad
assert.strictEqual(res.lat, -0.045729822980889484) // rad
assert.strictEqual(res.range, 0.7246016739689574) // AU
})
})
describe('position', function () {
it('Venus at 1992-12-20', function () {
// Example 32.a, p. 219
const jd = julian.CalendarGregorianToJD(1992, 12, 20)
const planet = new planetposition.Planet(data.venus)
const res = planet.position(jd)
assert.strictEqual(new sexa.Angle(res.lon).toDegString(5), '26°.11412')
assert.strictEqual(new sexa.Angle(res.lat).toDegString(5), '-2°.6206')
assert.strictEqual(res.range, 0.7246016739689574)
})
it('Venus at 1992-12-20 VSOPD', function () {
// Example 32.a, p. 219
const jd = julian.CalendarGregorianToJD(1992, 12, 20)
const planet = new planetposition.Planet(data.vsop87Dvenus)
const res = planet.position(jd)
assert.strictEqual(new sexa.Angle(res.lon).toDegString(5), '26°.11412')
assert.strictEqual(new sexa.Angle(res.lat).toDegString(5), '-2°.6206')
assert.strictEqual(res.range, 0.7246016759555222)
})
})
describe('toFK5', function () {
it('Venus at 1992-12-20', function () {
// Meeus provides no worked example for the FK5 conversion given by
// formula 32.3, p. 219. This at least displays the result when applied
// to the position of Example 32.a on that page.
const jd = julian.CalendarGregorianToJD(1992, 12, 20)
const planet = new planetposition.Planet(data.venus)
const pos = planet.position(jd)
const fk5 = planetposition.toFK5(pos.lon, pos.lat, jd)
assert.strictEqual(new sexa.Angle(fk5.lon).toDegString(5), '26°.11409')
assert.strictEqual(new sexa.Angle(fk5.lat).toDegString(5), '-2°.6206')
})
})
})
|
//Pathway model
var FormModel = function () {
var self = this;
self.id = undefined;
self.name = undefined;
self.dataElements = []
ko.track(self);
self.previewForm = function(){
console.log('need to add form preview here')
window.location = '../../formDesign/show/' + self.id
}
} |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('basicviz', '0002_auto_20160717_1939'),
]
operations = [
migrations.AlterField(
model_name='document',
name='name',
field=models.CharField(unique=True, max_length=32),
),
]
|
version https://git-lfs.github.com/spec/v1
oid sha256:3e0c436bb4be5a94bea0b2ce84121c3a8c6fbe226e7559f80cd0db5b4b93fdb0
size 17334
|
<% if(data.date) { %>
<p class="chat-message-date"><%= data.date %></p>
<% } %>
<li class="chat-message <%= (data.mine ? 'chat-message-mine' : '') %>" data-message-id="<%= data.cid %>" >
<h3 class="chat-message-user" ><%= data.user %></h3>
<p class="chat-message-text"><%= data.body %></p>
</li> |
# Development
## How to build a project
To build the project you need to install [.NET Core 5.0 SDK](https://www.microsoft.com/net/download).
```bash
git clone https://github.com/thinking-home/migrator.git
cd migrator
dotnet restore
dotnet build
```
## How to run tests
The basic logic of the migrator and the logic of the transformation providers are covered by the integration tests. To run tests, you need access to running instances of the DBMS. The current test settings are designed to run the DBMS in [Docker containers](https://guides.hexlet.io/docker/).
### Running MS SQL Server for tests
```sh
docker run --name mssql -d -p 1433:1433\
-e 'ACCEPT_EULA=Y'\
-e 'SA_PASSWORD=x987(!)654'\
-v $(pwd)/bash/init-mssql.sh:/init-mssql.sh\
microsoft/mssql-server-linux
docker exec mssql /init-mssql.sh
```
### Running MySql for tests
```sh
docker run --name mysql1 -d -p 3306:3306\
-e 'MYSQL_ROOT_HOST=%'\
-e 'MYSQL_ALLOW_EMPTY_PASSWORD=true'\
-v $(pwd)/bash/init-mysql.sh:/init-mysql.sh\
mysql/mysql-server
docker exec mysql1 /init-mysql.sh
```
### Running PostgreSQL for tests
```sh
docker run --name postgres -d -p 5432:5432\
-v $(pwd)/bash/init-postgres.sh:/init-postgres.sh\
postgres
docker exec postgres /init-postgres.sh
```
### Running Oracle for tests
```sh
docker run --name orcl -d -p 1521:1521\
-v $(pwd)/bash/init-oracle.sh:/init-oracle.sh\
wnameless/oracle-xe-11g-r2
docker exec orcl /init-oracle.sh
```
### Running tests
After starting all the necessary DBMS, you can run the tests with the command `dotnet test`:
```bash
dotnet test ./ThinkingHome.Migrator.Tests -c Release -f net5.0
```
## Own transformation providers
If you need to use a migrator with a DBMS for which there is no ready-made provider, you can write it yourself - it's easy.
Connect [ThinkingHome.Migrator](https://www.nuget.org/packages/ThinkingHome.Migrator) and [Microsoft.Extensions.Logging](https://www.nuget.org/packages/Microsoft.Extensions.Logging/) libraries from NuGet to your project.
Also include a library that provides a class that implements the `System.Data.IDbConnection` interface for the DBMS you need.
### Provider implementation
A DBMS provider is a class inherited from `ThinkingHome.Migrator.TransformationProvider<TConnection>`, where `TConnection` is a class that implements the System.`Data.IDbConnection` interface for the DBMS you need.
```c#
public class MyTransformationProvider : TransformationProvider<MyConnection>
{
public MyTransformationProvider(MyConnection connection, ILogger logger)
: base(connection, logger)
{
// ...
}
// ...
}
```
Most of the differences between DBMS are usually related to data types and syntax of SQL queries.
#### Provider factory
To perform migrations using your provider, you also need a *provider factory* - a common entry point for working with a specific DBMS. A factory is a class that creates instances of your provider while the migrator is running and opens connections to the database.
The provider factory class must inherit from `ProviderFactory<TProvider, TConnection>` and must implement its `CreateProviderInternal` and `CreateConnectionInternal` abstract methods.
```c#
public class MyProviderFactory :
ProviderFactory<MyTransformationProvider, MyConnection>
{
protected override MyTransformationProvider CreateProviderInternal(MyConnection connection, ILogger logger)
{
return new MyTransformationProvider(connection, logger);
}
protected override MyConnection CreateConnectionInternal(string connectionString)
{
return new MyConnection(connectionString);
}
}
```
After that, you can perform migrations using your provider, specifying the class of your **provider factory** (full class name with the assembly name) instead of the DBMS name:
```bash
migrate-database "MyAssembly.MyNamespace.MyTransformationProvider, MyAssembly" "my-connection-string" /path/to/migrations.dll
```
#### Data tyes
Different DBMSs use different keywords for the same data types. For example, PostgreSQL uses the `int4` type for a 32-bit integer, while MySQL uses the `INTEGER` type.
The migrator API uses the `System.Data.DbType` enumeration to work with column types, and each provider sets its own rules for mapping the `DbType` value to the DBMS types.
Type mapping settings are available in the provider class in the `typeMap` field. You can add matching rules you want, for example, in the constructor.
```c#
public class MyTransformationProvider : TransformationProvider<MyConnection>
{
public MyTransformationProvider(MyConnection connection, ILogger logger)
: base(connection, logger)
{
// типы данных
typeMap.Put(DbType.Int16, "SMALLINT");
typeMap.Put(DbType.Int32, "INTEGER");
typeMap.Put(DbType.Int64, "BIGINT");
}
}
```
The migrator API allows you to specify the size for column values. For example, you can create a column to store strings that are no more than 80 characters long:
```c#
Database.AddColumn("my_table",
new Column("test_string_column", DbType.String.WithSize(80)));
```
You can specify different types of DBMS, depending on the specified size. The stub `$l` (length) will be replaced with the desired size.
```c#
// if the size is not specified, use the NVARCHAR (255) type
typeMap.Put(DbType.String, "NVARCHAR(255)");
// if the specified size is less than 4 thousand characters, then use the type "NVARCHAR (<size>)
typeMap.Put(DbType.String, 4000, "NVARCHAR($l)");
// if the specified size is more than 4 thousand characters, then use NVARCHAR (MAX)
typeMap.Put(DbType.String, int.MaxValue, "NVARCHAR(MAX)");
```
You can use the `$ s` (scale) stub, which will be replaced with the specified precision value for the type. You can also specify the last optional parameter when calling the `Put` method - the default precision value.
```c#
typeMap.Put(DbType.Decimal, "DECIMAL");
typeMap.Put(DbType.Decimal, 38, "DECIMAL($l, $s)", 2);
// ...
// DECIMAL
Database.AddColumn("my_table",
new Column("test_decimal_column", DbType.Decimal));
// DECIMAL(10, 4)
Database.AddColumn("my_table",
new Column("test_decimal_column", DbType.Decimal.WithSize(10, 4)));
// DECIMAL(10, 2)
Database.AddColumn("my_table",
new Column("test_decimal_column", DbType.Decimal.WithSize(10)));
```
#### Generating SQL queries
The syntax of SQL queries in different DBMSs sometimes coincides and sometimes differs. The base class `ThinkingHome.Migrator.TransformationProvider<T>` already implements request generation for all API methods. The SQL formation logic has been moved to virtual methods. If your DBMS needs to form SQL queries differently, override the methods of the base class.
Take a look at [provider code](https://github.com/thinking-home/migrator/blob/master/ThinkingHome.Migrator.Providers.SqlServer/SqlServerTransformationProvider.cs) for MS SQL Server as an example.
### Tests
The transformation providers API is covered with integration tests. Tests are a convenient tool for checking the work of your own provider.
- Describe your provider class inherited from `ThinkingHome.Migrator.TransformationProvider<T>`
- Describe a class for tests, inherited from the base class [TransformationProviderTestBase](https://github.com/thinking-home/migrator/blob/master/ThinkingHome.Migrator.Tests/TransformationProviderTestBase.cs)
- Override the virtual methods and properties of the class with tests:
- Method `CreateProvider` - create an instance of your own provider here
- method `GetSchemaForCompare` - should return the default schema name for the DBMS
- Property `BatchSql` - should return the text of a query, consisting of several simple queries separated by the necessary separator (for example,`GO` for MS SQL Server)
- Property `ResourceSql` - should return the path to the test file`.sql` in the resources of the current dll (it will be used to check the execution of requests from the resources of the dll)
- Run the tests, see what has fallen and fix it (usually, this requires overriding the generation of the request in the provider, but sometimes you need to override the test and change its logic)
|
<?php // .pomm_cli_bootstrap.php
$loader = require_once __DIR__.'/app/bootstrap.php.cache';
require_once __DIR__.'/app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$kernel->boot();
return $kernel->getContainer()->get('pomm'); |
// Demonstrate using qpilotsync for carrier recovery.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <getopt.h>
#include <assert.h>
#include "liquid.h"
void usage()
{
printf("%s [options]\n", __FILE__);
printf(" h : print usage\n");
printf(" n : payload length [symbols], default: 400\n");
printf(" p : pilot spacing [symbols], default: 20\n");
printf(" s : SNR [dB], default: 20\n");
printf(" m : modulation scheme, default: qam16\n");
liquid_print_modulation_schemes();
}
int main(int argc, char *argv[])
{
//srand( time(NULL) );
// options
int ms = LIQUID_MODEM_QAM16; // mod. scheme
unsigned int payload_len = 400; // payload length
unsigned int pilot_spacing = 20; // pilot spacing
float SNRdB = 20.0f; // signal-to-noise ratio [dB]
const char filename[] = "qpilotsync_example.m"; // output filename
float dphi = -0.0075f; // carrier frequency offset
float phi = 2.1800f; // carrier phase offset
float gain = 0.5f; // channel gain
// get options
int dopt;
while((dopt = getopt(argc,argv,"hn:p:s:m:")) != EOF){
switch (dopt) {
case 'h': usage(); return 0;
case 'n': payload_len = atoi(optarg); break;
case 'p': pilot_spacing = atoi(optarg); break;
case 's': SNRdB = atof(optarg); break;
case 'm': ms = liquid_getopt_str2mod(optarg); break;
default:
exit(-1);
}
}
unsigned int i;
// derived values
float nstd = powf(10.0f, -SNRdB/20.0f);
// create pilot generator and synchronizer objects
qpilotgen pg = qpilotgen_create( payload_len, pilot_spacing);
qpilotsync ps = qpilotsync_create(payload_len, pilot_spacing);
qpilotgen_print(pg);
// get frame length
unsigned int frame_len = qpilotgen_get_frame_len(pg);
// allocate arrays
unsigned char payload_sym_tx[payload_len]; // transmitted payload symbols
float complex payload_tx [payload_len]; // transmitted payload samples
float complex frame_tx [frame_len]; // transmitted frame samples
float complex frame_rx [frame_len]; // received frame samples
float complex payload_rx [payload_len]; // received payload samples
unsigned char payload_sym_rx[payload_len]; // received payload symbols
// create modem objects for payload
modemcf mod = modemcf_create(ms);
modemcf dem = modemcf_create(ms);
// assemble payload symbols
for (i=0; i<payload_len; i++) {
// generate random symbol
payload_sym_tx[i] = modemcf_gen_rand_sym(mod);
// modulate
modemcf_modulate(mod, payload_sym_tx[i], &payload_tx[i]);
}
// assemble frame
qpilotgen_execute(pg, payload_tx, frame_tx);
// add channel impairments
for (i=0; i<frame_len; i++) {
frame_rx[i] = frame_tx[i] * cexpf(_Complex_I*dphi*i + _Complex_I*phi);
frame_rx[i] += nstd*(randnf() + _Complex_I*randnf())*M_SQRT1_2;
frame_rx[i] *= gain;
}
// recieve frame
qpilotsync_execute(ps, frame_rx, payload_rx);
// demodulate
for (i=0; i<payload_len; i++) {
unsigned int sym_demod;
modemcf_demodulate(dem, payload_rx[i], &sym_demod);
payload_sym_rx[i] = (unsigned char)sym_demod;
}
// count errors
unsigned int bit_errors = 0;
for (i=0; i<payload_len; i++)
bit_errors += count_bit_errors(payload_sym_rx[i], payload_sym_tx[i]);
printf("received bit errors : %u / %u\n", bit_errors, payload_len * modemcf_get_bps(mod));
// destroy allocated objects
qpilotgen_destroy(pg);
qpilotsync_destroy(ps);
modemcf_destroy(mod);
modemcf_destroy(dem);
// write symbols to output file for plotting
FILE * fid = fopen(filename,"w");
if (!fid) {
fprintf(stderr,"error: could not open '%s' for writing\n", filename);
return -1;
}
fprintf(fid,"%% %s : auto-generated file\n", filename);
fprintf(fid,"clear all;\n");
fprintf(fid,"close all;\n");
fprintf(fid,"payload_len = %u;\n", payload_len);
fprintf(fid,"frame_len = %u;\n", frame_len);
fprintf(fid,"frame_tx = zeros(1,frame_len);\n");
fprintf(fid,"payload_rx = zeros(1,payload_len);\n");
for (i=0; i<frame_len; i++)
fprintf(fid,"frame_rx(%6u) = %12.4e + 1i*%12.4e;\n", i+1, crealf(frame_rx[i]), cimagf(frame_rx[i]));
for (i=0; i<payload_len; i++)
fprintf(fid,"payload_rx(%6u) = %12.4e + 1i*%12.4e;\n", i+1, crealf(payload_rx[i]), cimagf(payload_rx[i]));
fprintf(fid,"figure('Color','white','position',[100 100 950 400]);\n");
fprintf(fid,"subplot(1,2,1);\n");
fprintf(fid," plot(real(frame_rx), imag(frame_rx), 'x','MarkerSize',3);\n");
fprintf(fid," axis([-1 1 -1 1]*1.5);\n");
fprintf(fid," axis square;\n");
fprintf(fid," grid on;\n");
fprintf(fid," xlabel('real');\n");
fprintf(fid," ylabel('imag');\n");
fprintf(fid," title('received');\n");
fprintf(fid,"subplot(1,2,2);\n");
fprintf(fid," plot(real(payload_rx),imag(payload_rx),'x','MarkerSize',3);\n");
fprintf(fid," axis([-1 1 -1 1]*1.5);\n");
fprintf(fid," axis square;\n");
fprintf(fid," grid on;\n");
fprintf(fid," xlabel('real');\n");
fprintf(fid," ylabel('imag');\n");
fprintf(fid," title('recovered');\n");
fclose(fid);
printf("results written to '%s'\n", filename);
printf("done.\n");
return 0;
}
|
using System;
namespace C5
{
/// <summary>
/// An exception thrown when an operation attempts to create a duplicate in a collection with set semantics
/// (<see cref="P:C5.IExtensible`1.AllowsDuplicates"/> is false) or attempts to create a duplicate key in a dictionary.
/// <para>With collections this can only happen with Insert operations on lists, since the Add operations will
/// not try to create duplictes and either ignore the failure or report it in a bool return value.
/// </para>
/// <para>With dictionaries this can happen with the <see cref="M:C5.IDictionary`2.Add(`0,`1)"/> metod.</para>
/// </summary>
[Serializable]
public class DuplicateNotAllowedException : Exception
{
/// <summary>
/// Create a simple exception with no further explanation.
/// </summary>
public DuplicateNotAllowedException() : base() { }
/// <summary>
/// Create the exception with an explanation of the reason.
/// </summary>
/// <param name="message"></param>
public DuplicateNotAllowedException(string message) : base(message) { }
}
} |
@extends('app')
@section('content')
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Register</div>
<div class="panel-body">
@if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form class="form-horizontal" role="form" method="POST" action="/auth/register">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input type="text" class="form-control" name="name" value="{{ old('name') }}">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password_confirmation">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Register
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
|
# PHP ISVU REST API Client (Pirac)
Pirac can be used to easily communicate with the [ISVU REST API v2](https://www.isvu.hr/api/dokumentacija/v2-hal/index.html).
## Installation
Add these lines to your composer.json file:
```javascript
"require": {
"cicnavi/pirac": "dev-master"
}
```
Next, run _composer update_ command.
## Configuration
Pirac utilizes the [DotEnv PHP library](https://github.com/vlucas/phpdotenv) by Vance Lucas.
In the root directory of your application, you have to create a .env file.
In .env file, Pirac will look for these two variables:
```text
ISVU_USERNAME=exampleusername
ISVU_PASSWORD=examplepassword
```
Make sure you assign your ISVU REST API username and password to those variables, since
those will be used on every request to ISVU REST API. We suggest that you enter
production API credentials to those two variables.
You can also set credentials for test API. If you want to use the test API, also add
these variables:
```text
ISVU_USE_TEST_API=true
ISVU_TEST_USERNAME=someTestUserName
ISVU_TEST_PASSWORD=someTestPassword
```
Important note: your .env file should not be committed to your application's source control!
## Usage
Pirac uses [Httpful by nategood](http://phphttpclient.com/) to send requests to
ISVU REST API. The returned resource will be instance of PHP stdClass.
Httpful uses cURL component, so make sure you have it installed and enabled.
In general, you can use Pirac to communicate with single institution ISVU REST API.
The first thing we can do now is to fetch available starting resources and their links.
We can do that with the following line:
$pirac->getIndex();
This will return available resources thogether with their links. We can use those links
in another Pirac method:
$pirac->get('url');
By default, Pirac uses "application/hal+json" as Accept HTTP header. This can be changed
by providing an array of headers as the second parameter.
By setting the appropriate Accept header, we can actually use ISVU REST API version 1.
For example, to use ISVU REST API v1, we can enter the 'application/xml' as Accept header:
$pirac->get('url', ['Accept' => 'application/xml']);
Check ISVU REST API documentation for more information.
## Example
```php
use Pirac\Pirac;
// Create Pirac instance.
$pirac = new Pirac();
// Get index links.
$indexLinks = $pirac->getIndex();
// Get specific resource.
$nastavniplan = $pirac->get($indexLinks->nastavniplan->href);
```
## Multi Institution API
If you have access to multi institution API, you can use getIndex() method to
get the list of all available institutions. This will return an array containing
all institutions.
$allInstitutions = $pirac->getIndex();
However, if you use a single institution API, getIndex() method will return
a stdClass object containing available resources and their links.
## License
Pirac is open-sourced software licensed under the
[MIT license](http://opensource.org/licenses/MIT)
|
# redispool
hack redis-py, add overlimit for connection pool
|
<?php
/*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*/
namespace AppBundle\Test;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* Tests for dead links.
*/
class URLTest extends WebTestCase
{
/**
* @Test
* @dataProvider provideUrl
*
* Test if pages are alive
*
* @param string $url Relative page url
*/
public function testResponseOK(string $url)
{
$client = (new TestClient('test', 'test'))->auth();
$client->request('GET', $url);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
/**
* @return array
*/
public function provideUrl(): array
{
return [UrlSet::getUrls()];
}
}
|
---
layout: post
title: Vim 基础命令
date: 2016-11-30 21:00:00
author: hweining
header-img: "img/post-bg-unix-linux.jpg"
---
## Vim
以前玩 Python 及之前用 Git 因为不熟悉 Vim 遇到了很多坑,进而导致屡次学习各项语言的放弃...惨痛教训就源于这莫名其妙的 Vim...
整理一下思路,重新出发。
Vi/Vim 常用的有三种模式:
1. 普通 模式 默认进入界面时的模式,此时只支持 Vi/Vim 的指令
2. Insert 模式 此模式下才能插入文本
3. 选择模式
## 常用指令
* i 在指令模式下,按「i」激活编辑模式;
* esc 在非指令模式下,按 esc 键退出
* :wq 保存并退出
## 编辑(插入模式)模式常用指令
### 进入 Insert 模式
在普通模式下使用下面的键将进入插入模式,并可以从相应的位置开始输入
| CMD | Description |
|---|---|
| i | 光标位置开始编辑 |
| I | 行首插入 |
| A | 行末插入 |
| a | 自光标后编辑 |
| o | 当前行之后插入一行 |
| O | 当前行之前插入一行 |
| cw | 替换从光标所在位置后到一个单词结尾的字符 |
在指令模式下的一些其他选项
### 编辑快捷键
| CMD | Description |
|---|---|
| :w | 保存当前文件 |
| :q | 退出,如文件有修改则需用强制模式退出 |
| :q! | 强制退出,不保存修改 |
| :wq | 保存并退出 |
| :x | 保存并退出 |
| :w <path> | 另存为 |
| :saveas <path> | 另存为 |
## 选择模式常用指令
### 光标移动快捷键
k - 上 j - 下 h - 左 l - 右
|...|**k**|...|
|---|---|---|
|**h**|...|**l**|
|...|**j**|...|
w 移动到下一个单词
b 移动到上一个单词
### 翻页
Control + f
Control + b
### 删除
| Key | Description |
|---|---|
| x | 删除光标所在字符 |
| Delete | 删除光标所在字符 |
| X | 删除光标所在前一个字符 |
| dd | 删除整行 |
| dw | 删除一个单词 |
| d$ / D | 从当前位置删除至行尾 |
| d^ | 从当前位置删除至行首 |
| dG | 删除到文档结尾处 |
| d1G | 删至文档首部 |
### 命令行进入设定退出
Ctrl + C 退出
### 参考
*[简明 Vim 练级攻略|CoolShell](http://coolshell.cn/articles/5426.html)
|
/*!
\file update.h
\brief Update definition
\author Ivan Shynkarenka
\date 09.08.2017
\copyright MIT License
*/
#ifndef CPPTRADER_MATCHING_UPDATE_H
#define CPPTRADER_MATCHING_UPDATE_H
#include "utility/iostream.h"
#include <cstdint>
namespace CppTrader {
namespace Matching {
//! Update type
enum class UpdateType : uint8_t
{
NONE,
ADD,
UPDATE,
DELETE
};
template <class TOutputStream>
TOutputStream& operator<<(TOutputStream& stream, UpdateType type);
} // namespace Matching
} // namespace CppTrader
#include "update.inl"
#endif // CPPTRADER_MATCHING_UPDATE_H
|
---
title: Thoughts about recruitment
date: 2019-05-28 11:18:00 Z
categories:
- recruitment
tags:
- recruitment
- hr
---
In may I faced some non typical situation.
My new customer canceled our contract before it started.
I was left without any project. Initially I was disappointed and angry about this situation, but it's no good crying over spilt milk :)
I started to looking for new opportunities, I had a lot of interview calls and meetings. I want to share with You my thoughts how hiring Java Developers looks in Poland.
Firstly I want to describe what I unlike in recruitment. The worst interview call I had with one of bigger outsourcing companies. It took more than hour, interviewer had a long list of theoretical questions about Java and working in Scrum methodology. After exhausting answering these questions I had chance to ask him about company and about project where I would work. He couldn't answer any of my question. All answers where about that it's depends on project, team and he barely doesn't know where I would work in their company. So the first thougth is:
DO NOT TRY TO PROOF CANDIDATE HIS LACK OF KNOWLEDGE IF YOU CAN NOT ANSWER ANY OF CANDIDATE QUESTION
Second interview which I didn't enjoy was in smaller software company. We had discussed typical Java interview questions, but after this part I had do write code on whiteboard and then I got second coding task on interviewer computer, where he had different short cuts in Intellij than defaults ones. He looked over my shoulder how I write code on his computer. It was really stressful. Hopefully I did that task correctly but the second thought is:
DO NOT FORCE CANDIDATE TO LIVE CODING DURING INTERVIEW ON COMPUTER HE NEVER HAD CHANCE TO WORK ON
Let's go to the things which I liked in some interviews. Some companies have recruitment tasks to solve them in home. I think that is fair and square. Company what to see how candidate solves this task, but candidate can work on computer he knows, he has time to think about project. He can make some research about open source tools which can help him. Recently I wrote 3 interview programs, but only one company checked my code in details, they even measured test code coverange! They also had some questions, about decisions which I made in project. I think that this type of discussion can be inspirational for both sides. So the third thought is:
ASK ABOUT SOLVING CODING TASKS IN HOME, NOT DURING INTERVIEW
Another practice which I never met but I liked from the first time, is to show candidate his feature office, his desk and tools. It's also great opportunity to meet feature colleagues. The fourth thought is:
SHOW CANDIDATE HIS FEATURE OFFICE AND LET TALK TO THE TEAM
That's my thoughts about recruitment from candidate perspective.
Maybe some interviewers will change their methods and some candidates will feel more comfortable during interviews.
Hope you enjoy this post. If You have any questions or problems leave a comment or send email. |
package com.smash.player.Models;
import com.orm.*;
public class Artista extends SugarRecord
{
public String name;
public Artista()
{}
public Artista(Long id,String name){
setId(id);setName(name);save();
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
}
|
import { Recipe, RecipeContainer } from '../class/recipe';
import { Items as i } from '../constants/items';
import { Equipment as e } from '../class/equipment';
import { Categories as c } from '../constants/categories';
import { Units as u } from '../constants/units';
import { Text as text } from '../class/text';
import { Timer } from '../class/timer';
export class MealRecipe extends RecipeContainer {
constructor() {
super();
this.recipeGroup = c.meal;
this.recipeName = 'Spaghetti'
this.variations = [
LentilPenne, LentilSpaghetti, LentilSpaghettiInstantPot, DontUseModernBrandLentilPenne
]
}
}
export class LentilPenne extends Recipe {
constructor() {
super();
this.steps = [
e.pot().add([
i.water(18, u.second),
]),
Timer.set(10, 'm', 'Wait for water to boil'),
i.Groups.mushroom(4, u.unit).cutIntoStrips(),
Timer.end(),
e.pot().add([
i.lentilSpaghetti(8, u.ounce),
]),
Timer.set(10, 'm', 'let lentil penne cook'),
e.pan().add([
i.Groups.mushroom(4, u.unit),
]),
e.pan().cook(8, 'm'),
e.pan().add([
i.spaghettiSauce(25, u.ounce),
]),
e.pan().cook(2, 'm'),
Timer.end(),
Timer.end(['pan']),
Timer.end(['pot']),
text.set(['Top with', i.parmesanCheese(8, u.ounce)]),
];
}
}
export class LentilSpaghetti extends Recipe {
constructor() {
super();
this.steps = [
e.pot().add([
i.water(25, u.second),
]),
Timer.set(15, 'm', 'Wait for water to boil'),
i.Groups.mushroom(4, u.unit).cutIntoStrips(),
Timer.end(),
e.pot().add([
i.lentilSpaghetti(8, u.ounce),
]),
Timer.set(18, 'm', 'let lentil spaghetti cook'),
e.pan().add([
i.Groups.mushroom(4, u.unit),
]),
e.pan().cook(8, 'm'),
e.pan().add([
i.spaghettiSauce(25, u.ounce),
]),
e.pan().cook(8, 'm'),
Timer.end(),
Timer.end(),
Timer.end(),
text.set(['Top with', i.parmesanCheese(8, u.ounce)]),
];
}
}
export class LentilSpaghettiInstantPot extends Recipe {
constructor() {
super();
this.steps = [
e.instantPot().add([
i.spaghettiSauce(25, u.ounce),
i.water(1, u.cup),
i.lentilSpaghetti(8, u.ounce),
i.oliveOil(1, u.ounce)
]),
text.set(['Stir instant pot and break up pasta']),
e.instantPot().pressureCook(15, 13, 'm'),
text.set(['Top with', i.parmesanCheese(8, u.ounce)]),
];
}
}
export class DontUseModernBrandLentilPenne extends Recipe {
constructor() {
super();
this.steps = [
e.instantPot().add([
i.spaghettiSauce(25, u.ounce),
i.water(1, u.cup),
i.penneLentil(8, u.ounce),
i.oliveOil(1, u.ounce)
]),
text.set(['Stir instant pot and break up pasta']),
e.instantPot().pressureCook(15, 7, 'm'),
Timer.end(),
];
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using Foundation;
using UIKit;
using Alliance.Carousel;
namespace Sample
{
public class ZeroItemLinearViewController : UIViewController
{
public List<nint> items;
CarouselView carousel;
public ZeroItemLinearViewController() : base()
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Setup the item list we will display
// your carousel should always be driven by an array/list of
// data of some kind - don't store data in your item views
// or the recycling mechanism will destroy your data once
// your item views move off-screen
items = new List<nint>();
// Setup Background image
var imgView = new UIImageView(UIImage.FromBundle("background"))
{
ContentMode = UIViewContentMode.ScaleToFill,
AutoresizingMask = UIViewAutoresizing.All,
Frame = View.Bounds
};
View.AddSubview(imgView);
// Setup CarouselView view
carousel = new CarouselView(View.Bounds);
carousel.DataSource = new ZeroItemLinearDataSource(this);
carousel.Delegate = new ZeroItemLinearDelegate(this);
carousel.CarouselType = CarouselType.Linear;
carousel.ConfigureView();
View.AddSubview(carousel);
}
public class ZeroItemLinearDataSource : CarouselViewDataSource
{
ZeroItemLinearViewController vc;
public ZeroItemLinearDataSource(ZeroItemLinearViewController vc)
{
this.vc = vc;
}
public override nint NumberOfItems(CarouselView carousel)
{
return (nint)vc.items.Count;
}
public override UIView ViewForItem(CarouselView carousel, nint index, UIView reusingView)
{
UILabel label;
// create new view if no view is available for recycling
if (reusingView == null)
{
// don't do anything specific to the index within
// this `if (view == null) {...}` statement because the view will be
// recycled and used with other index values later
var imgView = new UIImageView(new RectangleF(0, 0, 200, 200))
{
Image = UIImage.FromBundle("page"),
ContentMode = UIViewContentMode.Center
};
label = new UILabel(imgView.Bounds)
{
BackgroundColor = UIColor.Clear,
TextAlignment = UITextAlignment.Center,
Tag = 1
};
label.Font = label.Font.WithSize(50);
imgView.AddSubview(label);
reusingView = imgView;
}
else
{
// get a reference to the label in the recycled view
label = (UILabel)reusingView.ViewWithTag(1);
}
// set item label
// remember to always set any properties of your carousel item
// views outside of the `if (view == null) {...}` check otherwise
// you'll get weird issues with carousel item content appearing
// in the wrong place in the carousel
label.Text = vc.items[(int)index].ToString();
return reusingView;
}
}
public class ZeroItemLinearDelegate : CarouselViewDelegate
{
ZeroItemLinearViewController vc;
public ZeroItemLinearDelegate(ZeroItemLinearViewController vc)
{
this.vc = vc;
}
public override nfloat ValueForOption(CarouselView carousel, CarouselOption option, nfloat aValue)
{
if (option == CarouselOption.Spacing)
{
return aValue * 1.1f;
}
return aValue;
}
public override void DidSelectItem(CarouselView carousel, nint index)
{
Console.WriteLine("Selected: " + ++index);
}
}
}
}
|
set artifacts=%~dp0artifacts
if exist %artifacts% rd /q /s %artifacts%
call dotnet restore src/Es.Extensions.Logging.NLog
call dotnet pack src/Es.Extensions.Logging.NLog -c release -o %artifacts%
pause |
declare namespace Xrm {
interface EntityDefinition {
EntitySetName: string;
}
namespace Attributes {
interface LookupAttribute {
getLookupTypes(): LookupValue[];
}
}
namespace Controls {
interface Control {
getAttribute(): Xrm.Attributes.Attribute;
}
}
namespace Page {
interface LookupValue {
type: string;
typename: string;
}
}
interface Ui {
getCurrentControl(): Xrm.Controls.Control;
}
interface XrmStatic {
Internal: XrmInternal;
}
interface XrmInternal {
getEntityCode(entityName: string): number;
isUci(): boolean;
}
interface GlobalContext {
isOffice365(): boolean;
isOnPremises(): boolean;
}
}
|
export interface DetectedFeatures {
draggable:boolean;
dragEvents:boolean;
userAgentSupportingNativeDnD:boolean;
}
export function detectFeatures():DetectedFeatures {
let features:DetectedFeatures = {
dragEvents: ("ondragstart" in document.documentElement),
draggable: ("draggable" in document.documentElement),
userAgentSupportingNativeDnD: undefined
};
const isBlinkEngine = !!((<any>window).chrome) || /chrome/i.test( navigator.userAgent );
features.userAgentSupportingNativeDnD = !(
// if is mobile safari or android browser -> no native dnd
(/iPad|iPhone|iPod|Android/.test( navigator.userAgent ))
|| // OR
//if is blink(chrome/opera) with touch events enabled -> no native dnd
(isBlinkEngine && ("ontouchstart" in document.documentElement))
);
return features;
}
export function supportsPassiveEventListener():boolean {
let supportsPassiveEventListeners = false;
// reference https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
try {
let opts = Object.defineProperty( {}, "passive", {
get: function() {
supportsPassiveEventListeners = true;
}
} );
window.addEventListener( "test", null, opts );
}
// tslint:disable-next-line:no-empty
catch( e ) {
}
return supportsPassiveEventListeners;
}
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>quickchick: Not compatible 👼</title>
<link rel="shortcut icon" type="image/png" href="../../../../../favicon.png" />
<link href="../../../../../bootstrap.min.css" rel="stylesheet">
<link href="../../../../../bootstrap-custom.css" rel="stylesheet">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<script src="../../../../../moment.min.js"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="../../../../.."><i class="fa fa-lg fa-flag-checkered"></i> Coq bench</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="../..">clean / released</a></li>
<li class="active"><a href="">8.11.2 / quickchick - 1.4.0</a></li>
</ul>
</div>
</div>
</div>
<div class="article">
<div class="row">
<div class="col-md-12">
<a href="../..">« Up</a>
<h1>
quickchick
<small>
1.4.0
<span class="label label-info">Not compatible 👼</span>
</small>
</h1>
<p>📅 <em><script>document.write(moment("2021-11-01 03:33:26 +0000", "YYYY-MM-DD HH:mm:ss Z").fromNow());</script> (2021-11-01 03:33:26 UTC)</em><p>
<h2>Context</h2>
<pre># Packages matching: installed
# Name # Installed # Synopsis
base-bigarray base
base-threads base
base-unix base
conf-findutils 1 Virtual package relying on findutils
coq 8.11.2 Formal proof management system
num 1.4 The legacy Num library for arbitrary-precision integer and rational arithmetic
ocaml 4.09.1 The OCaml compiler (virtual package)
ocaml-base-compiler 4.09.1 Official release 4.09.1
ocaml-config 1 OCaml Switch Configuration
ocamlfind 1.9.1 A library manager for OCaml
# opam file:
opam-version: "2.0"
maintainer: "llamp@seas.upenn.edu"
synopsis: "Randomized Property-Based Testing Plugin for Coq"
homepage: "https://github.com/QuickChick/QuickChick"
dev-repo: "git+https://github.com/QuickChick/QuickChick.git"
bug-reports: "https://github.com/QuickChick/QuickChick/issues"
license: "MIT"
build: [ make "-j" jobs ]
install: [
[make "-j" jobs "install" ]
[make "-j" jobs "tests"] {with-test}
]
depends: [
"ocaml" {>= "4.07"}
"coq" {>= "8.12" < "8.13~"}
"coq-ext-lib"
"coq-mathcomp-ssreflect"
"ocamlbuild"
"ocamlfind"
"menhir" {build}
"coq-simple-io"
]
authors: [
"Leonidas Lampropoulos <>"
"Zoe Paraskevopoulou <>"
"Maxime Denes <>"
"Catalin Hritcu <>"
"Benjamin Pierce <>"
"Li-yao Xia <>"
"Arthur Azevedo de Amorim <>"
"Yishuai Li <>"
"Antal Spector-Zabusky <>"
]
tags: [
"keyword:extraction"
"category:Miscellaneous/Coq Extensions"
"logpath:QuickChick"
]
url {
src: "https://github.com/QuickChick/QuickChick/archive/v1.4.0.tar.gz"
checksum: "md5=6a6712834eb3d9820ae10c55fd1b7d54"
}
</pre>
<h2>Lint</h2>
<dl class="dl-horizontal">
<dt>Command</dt>
<dd><code>true</code></dd>
<dt>Return code</dt>
<dd>0</dd>
</dl>
<h2>Dry install 🏜️</h2>
<p>Dry install with the current Coq version:</p>
<dl class="dl-horizontal">
<dt>Command</dt>
<dd><code>opam install -y --show-action coq-quickchick.1.4.0 coq.8.11.2</code></dd>
<dt>Return code</dt>
<dd>5120</dd>
<dt>Output</dt>
<dd><pre>[NOTE] Package coq is already installed (current version is 8.11.2).
The following dependencies couldn't be met:
- coq-quickchick -> coq >= 8.12
Your request can't be satisfied:
- No available version of coq satisfies the constraints
No solution found, exiting
</pre></dd>
</dl>
<p>Dry install without Coq/switch base, to test if the problem was incompatibility with the current Coq/OCaml version:</p>
<dl class="dl-horizontal">
<dt>Command</dt>
<dd><code>opam remove -y coq; opam install -y --show-action --unlock-base coq-quickchick.1.4.0</code></dd>
<dt>Return code</dt>
<dd>0</dd>
</dl>
<h2>Install dependencies</h2>
<dl class="dl-horizontal">
<dt>Command</dt>
<dd><code>true</code></dd>
<dt>Return code</dt>
<dd>0</dd>
<dt>Duration</dt>
<dd>0 s</dd>
</dl>
<h2>Install 🚀</h2>
<dl class="dl-horizontal">
<dt>Command</dt>
<dd><code>true</code></dd>
<dt>Return code</dt>
<dd>0</dd>
<dt>Duration</dt>
<dd>0 s</dd>
</dl>
<h2>Installation size</h2>
<p>No files were installed.</p>
<h2>Uninstall 🧹</h2>
<dl class="dl-horizontal">
<dt>Command</dt>
<dd><code>true</code></dd>
<dt>Return code</dt>
<dd>0</dd>
<dt>Missing removes</dt>
<dd>
none
</dd>
<dt>Wrong removes</dt>
<dd>
none
</dd>
</dl>
</div>
</div>
</div>
<hr/>
<div class="footer">
<p class="text-center">
Sources are on <a href="https://github.com/coq-bench">GitHub</a> © Guillaume Claret 🐣
</p>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="../../../../../bootstrap.min.js"></script>
</body>
</html>
|
(function () {
window.onload = function () {
var stage,
layer,
layerBG,
ball,
constants,
onJump,
isOver;
stage = new Kinetic.Stage({
container: 'kinetic-container',
width: document.body.clientWidth,
height: document.body.clientHeight
});
layer = new Kinetic.Layer();
layerBG = new Kinetic.Layer();
constants = {
BALL_X: 25,
BALL_Y: stage.getHeight() * 0.75 - 25,
BALL_RADIUS: 25,
BALL_X_ACCELERATION: 0.1,
BALL_X_DECELERATION: 0.15,
BALL_Y_ACCELERATION: 0.2,
BALL_Y_DECELERATION: 0.25,
FUNDAMENTALS_WIDTH: 175,
FUNDAMENTALS_HEIGHT: 50,
GAME_OVER_IMG: 'https://lh3.googleusercontent.com/-hk3-q7XFs1w/U5105G5F8SI/AAAAAAAAAfQ/OMHmsK6-Dco/zoom_games_18.normal.color_000000.png',
IMAGES_SOURCES: ['http://3.bp.blogspot.com/-zt_wXhDvv_Q/VI0u3M65zFI/AAAAAAAAAM0/eQHiw5EuhFI/s1600/apple-logo-black.png',
'http://4.bp.blogspot.com/-kp9dUl08xCA/UODmryuwAYI/AAAAAAAApn4/-nFoS6F0cFE/s1600/AxFoCM-CMAEH868.jpg',
'http://hdw.datawallpaper.com/nature/the-beauty-of-nature-wide-wallpaper-499995.jpg',
'http://cs304304.vk.me/v304304772/59cc/DStHQW-F20A.jpg']
};
window.onkeydown = function(ev){
switch (ev.keyCode) {
case 32:
if (!onJump) {
onJump = true;
ball.deltaY = -1;
ball.speedY = constants.BALL_Y_ACCELERATION * 50;
}
break;
case 37:
if (onJump) {
ball.deltaX = -1;
ball.speedX += constants.BALL_X_ACCELERATION * 5;
} else {
ball.deltaX = -1;
ball.speedX += constants.BALL_X_ACCELERATION * 10;
}
break;
case 39:
if (onJump) {
ball.deltaX = 1;
ball.speedX += constants.BALL_X_ACCELERATION * 5;
} else {
ball.deltaX = 1;
ball.speedX += constants.BALL_X_ACCELERATION * 10;
}
break;
default:
break;
}
};
function start() {
onJump = false;
isOver = false;
ball = getBall();
for (var i = 0; i < 6; i += 1) {
getFundamental(i * 200, stage.getHeight() * 0.75 - i * 100);
}
getTrophy((i - 1) * 200, stage.getHeight() * 0.75 - (i - 1) * 100 - constants.FUNDAMENTALS_HEIGHT * 2);
layer.add(ball);
stage.add(layerBG);
stage.add(layer);
step();
}
function step() {
// y
if (ball.deltaY === 1) {
if (checkFundamentals()) {
onJump = false;
ball.deltaY = 0;
ball.speedY = 0;
} else if (ball.getY() >= stage.getHeight() - ball.getRadius()) {
gameOverText();
gameOverImage();
}
} else if (ball.deltaY === -1) {
if (ball.getY() <= 0 + ball.getRadius()) {
happyEnd();
ball.deltaY = 1;
} else if (ball.speedY <= 0) {
ball.deltaY = 1;
ball.speedY = 0;
}
} else {
if (!checkFundamentals()) {
ball.deltaY = 1;
}
}
// x
if (ball.deltaX === 1) {
if (ball.getX() >= stage.getWidth() - ball.getRadius()) {
ball.deltaX = 0;
} else if (ball.speedX <= 0) {
ball.deltaX = 0;
ball.speedX = 0;
}
} else if (ball.deltaX === -1) {
if (ball.getX() <= 0 + ball.getRadius()) {
ball.deltaX = 0;
} else if (ball.speedX <= 0) {
ball.deltaX = 0;
ball.speedX = 0;
}
}
moveBall();
layer.draw();
if (!isOver) {
requestAnimationFrame(step);
} else {
window.onkeydown = null;
}
}
function checkFundamentals() {
return layerBG.find('Rect').some(function (fundamental) {
if (ball.getX() > fundamental.getX() &&
ball.getX() < fundamental.getX() + fundamental.getWidth() &&
ball.getY() > fundamental.getY() - ball.getRadius() &&
ball.getY() <= fundamental.getY() + fundamental.getHeight() - ball.getRadius()) {
ball.setY(fundamental.getY() - ball.getRadius());
return true
}
return false;
});
}
function moveBall() {
if (ball.deltaX === 1) {
ball.speedX -= ball.decelerationX;
} else if (ball.deltaX === -1) {
ball.speedX -= ball.decelerationX;
} else {
ball.speedX = 0;
}
if (ball.deltaY === 1) {
ball.speedY += ball.accelerationY;
} else if (ball.deltaY === -1) {
ball.speedY -= ball.decelerationY;
} else {
ball.speedY = 0;
}
ball.setX(ball.getX() + ball.deltaX * ball.speedX);
ball.setY(ball.getY() + ball.deltaY * ball.speedY);
}
function getBall() {
var ball = new Kinetic.Circle({
x: constants.BALL_X,
y: constants.BALL_Y,
radius: constants.BALL_RADIUS,
fill: getRandomColor()
});
ball.deltaX = 0;
ball.deltaY = 0;
ball.speedX = 0;
ball.speedY = 0;
ball.accelerationX = constants.BALL_X_ACCELERATION;
ball.decelerationX = constants.BALL_X_DECELERATION;
ball.accelerationY = constants.BALL_Y_ACCELERATION;
ball.decelerationY = constants.BALL_Y_DECELERATION;
return ball;
}
function getFundamental(x, y) {
layerBG.add(new Kinetic.Rect({
x: x,
y: y,
width: constants.FUNDAMENTALS_WIDTH,
height: constants.FUNDAMENTALS_HEIGHT,
fill: 'purple'
}));
layerBG.draw();
}
function getTrophy(x, y) {
var canvasImage,
kineticImage;
canvasImage = new Image();
canvasImage.src = constants.IMAGES_SOURCES[0];
canvasImage.onload = function () {
kineticImage = new Kinetic.Image({
x: x,
y: y,
width: 150,
height: 100,
image: canvasImage,
draggable: true
});
layerBG.add(kineticImage);
layerBG.draw();
};
}
function happyEnd() {
var canvasImage,
kineticImage;
canvasImage = new Image();
canvasImage.src = constants.IMAGES_SOURCES[3];
canvasImage.onload = function () {
kineticImage = new Kinetic.Image({
x: 0,
y: 0,
width: stage.getWidth(),
height: stage.getHeight(),
image: canvasImage,
draggable: true
});
layerBG.add(kineticImage);
layerBG.draw();
};
isOver = true;
}
function gameOverText() {
var gameOver = 'GAME OVER';
var text = new Kinetic.Text({
x: (stage.getWidth() - gameOver.length * 36) / 2,
y: stage.getHeight() / 2,
text: gameOver,
fontSize: 72,
fontFamily: 'Calibri',
align: 'center',
fill: 'blue'
});
layerBG.add(text);
layerBG.draw();
isOver = true;
}
function gameOverImage() {
var canvasImage,
kineticImage;
canvasImage = new Image();
canvasImage.src = constants.GAME_OVER_IMG;
canvasImage.onload = function () {
kineticImage = new Kinetic.Image({
x: 0,
y: 0,
width: stage.getWidth(),
height: stage.getHeight(),
image: canvasImage,
draggable: true
});
layerBG.add(kineticImage);
layerBG.draw();
};
isOver = true;
}
function getRandomColor() {
const COLOR_STRING_LENGTH = 6;
const HEXADECIMAL_BASE = 16;
const HEXADECIMAL_SIGNS = '0123456789ABCDEF';
var letters = HEXADECIMAL_SIGNS.split('');
var color = '#';
for (var i = 0; i < COLOR_STRING_LENGTH; i += 1) {
color += letters[Math.floor(Math.random() * HEXADECIMAL_BASE)];
}
return color;
}
return start();
};
}()); |
package com.github.twitch4j.helix.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Data
@Setter(AccessLevel.PRIVATE)
@NoArgsConstructor
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ExtensionTransaction {
/**
* Unique identifier of the Bits in Extensions Transaction.
*/
private String id;
/**
* UTC timestamp when this transaction occurred.
*/
private String timestamp;
/**
* Twitch User ID of the channel the transaction occurred on.
*/
private String broadcasterId;
/**
* Twitch Display Name of the broadcaster.
*/
private String broadcasterName;
/**
* Twitch User ID of the user who generated the transaction.
*/
private String userId;
/**
* Twitch Display Name of the user who generated the transaction.
*/
private String userName;
/**
* Enum of the product type. Currently only BITS_IN_EXTENSION.
*/
private String productType;
/**
* Known "product_type" enum values.
*/
public static class ProductType {
// "Currently" only valid product type
public static String BITS_IN_EXTENSION = "BITS_IN_EXTENSION";
}
/**
* JSON Object representing the product acquired, as it looked at the time of the transaction.
*/
private ProductData productData;
@Data
@Setter(AccessLevel.PRIVATE)
@NoArgsConstructor
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public static class ProductData {
/**
* Unique identifier for the product across the extension.
*/
private String sku;
/**
* JSON Object representing the cost to acquire the product.
*/
private Cost cost;
/**
* Display Name of the product.
*/
@JsonProperty("displayName")
private String displayName;
/**
* Flag used to indicate if the product is in development. Either true or false.
*/
@JsonProperty("inDevelopment")
private Boolean inDevelopment;
@Data
@Setter(AccessLevel.PRIVATE)
@NoArgsConstructor
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public static class Cost {
/**
* Number of Bits required to acquire the product.
*/
private Integer amount;
/**
* Always the string “Bits”.
*/
private String type;
/**
* Known "type" enum values
*/
public static class CostType {
// "Currently" only valid cost type.
public static final String BITS = "bits";
}
}
}
}
|
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
//Core
require('../../rxjs-extensions');
var core_1 = require('@angular/core');
var platform_browser_1 = require('@angular/platform-browser');
var forms_1 = require('@angular/forms');
var http_1 = require('@angular/http');
var app_routing_1 = require('./app.routing');
//Services
//Common Components
var page_footer_component_1 = require('../userinterface/page-footer.component');
var page_header_component_1 = require('../userinterface/page-header.component');
//Module Components
var app_component_1 = require('./app.component');
var home_content_component_1 = require('./home-content.component');
var AppModule = (function () {
function AppModule() {
}
AppModule = __decorate([
core_1.NgModule({
imports: [
platform_browser_1.BrowserModule,
forms_1.FormsModule,
forms_1.ReactiveFormsModule,
http_1.HttpModule,
app_routing_1.routing
],
declarations: [
app_component_1.AppComponent,
page_footer_component_1.PageFooterComponent,
page_header_component_1.PageHeaderComponent,
home_content_component_1.HomeContentComponent
],
bootstrap: [app_component_1.AppComponent]
}),
__metadata('design:paramtypes', [])
], AppModule);
return AppModule;
}());
exports.AppModule = AppModule;
//# sourceMappingURL=app.module.js.map |
/**
* MIT License
*
* Copyright (c) 2017 ITGorillaz
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
'use strict';
const HttpException = require('./http-exception');
const HttpStatus = require('http-status-codes');
/**
* The GoneException class.
*
* This is a concrete class of the the HttpException class.
* It represents a gone http response.
*
* @author tommelo
*/
class GoneException extends HttpException {
/**
* The class constructor
*
* @param {Object} entity The object to be serialized as response body
* @param {Error} cause The error cause
*/
constructor(entity, cause) {
cause = cause || new Error('GoneException');
super(entity, HttpStatus.GONE, cause);
}
}
module.exports = GoneException; |
<?php
/**
* Class CreateTableLogger
*/
class CreateTableLogger extends SQLLoggerAbstract
{
/**
*
*/
function prepare()
{
}
/**
*
*/
function setHint()
{
$this->hint = "Добавлена таблица";
}
} |
using System;
using NetOffice;
using NetOffice.Attributes;
namespace NetOffice.MSHTMLApi.Enums
{
/// <summary>
/// SupportByVersion MSHTML 4
/// </summary>
[SupportByVersion("MSHTML", 4)]
[EntityType(EntityType.IsEnum)]
public enum _styleWordWrap
{
/// <summary>
/// SupportByVersion MSHTML 4
/// </summary>
/// <remarks>0</remarks>
[SupportByVersion("MSHTML", 4)]
styleWordWrapNotSet = 0,
/// <summary>
/// SupportByVersion MSHTML 4
/// </summary>
/// <remarks>1</remarks>
[SupportByVersion("MSHTML", 4)]
styleWordWrapOff = 1,
/// <summary>
/// SupportByVersion MSHTML 4
/// </summary>
/// <remarks>2</remarks>
[SupportByVersion("MSHTML", 4)]
styleWordWrapOn = 2,
/// <summary>
/// SupportByVersion MSHTML 4
/// </summary>
/// <remarks>2147483647</remarks>
[SupportByVersion("MSHTML", 4)]
styleWordWrap_Max = 2147483647
}
} |
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$this->load->view('layout/header');
$fname = isset($cust[0])? $cust[0]->name : '';
$ntn = isset($cust[0])? $cust[0]->ntn : '';
$adress= isset($cust[0])? $cust[0]->adress : '';
$email = isset($cust[0])? $cust[0]->email : '';
$phone = isset($cust[0])? $cust[0]->phone : '';
$contact1 = isset($cust[0])? $cust[0]->contact1 : '';
$contact1_name = isset($cust[0])? $cust[0]->contact1_name: '';
$contact1_email = isset($cust[0])? $cust[0]->contact1_email : '';
$contact2 = isset($cust[0])? $cust[0]->contact2 : '';
$contact2_name = isset($cust[0])? $cust[0]->contact2_name : '';
$contact2_email = isset($cust[0])? $cust[0]->contact2_email : '';
$contact3 = isset($cust[0])? $cust[0]->contact3 : '';
$contact3_name= isset($cust[0])? $cust[0]->contact3_name : '';
$contact3_email = isset($cust[0])? $cust[0]->contact3_email : '';
$contact4 = isset($cust[0])? $cust[0]->contact4 : '';
$contact4_name = isset($cust[0])? $cust[0]->contact4_name : '';
$contact4_email = isset($cust[0])? $cust[0]->contact4_email : '';
$citySel= isset($desig[0])? $desig[0]->city : '';
//$cityId = array('id'=>'cityId','type'=>'text','class'=>'col-xs-10 col-sm-5','value'=>'','name'=>'cityId','placeholder'=>'City ID' );
$fname = array('id'=>'fname','type'=>'text','class'=>'col-xs-10 ','value'=>$fname,'name'=>'name','placeholder'=>'Company Name' );
$ntn = array('id'=>'lname','type'=>'text','class'=>'col-xs-10 ','value'=>$ntn,'name'=>'ntn','placeholder'=>'NTN' );
$adress= array('id'=>'adress','type'=>'text','class'=>'col-xs-10','value'=>$adress,'name'=>'adress','placeholder'=>'Home Address' );
$email= array('id'=>'email','type'=>'text','class'=>'col-xs-10','value'=>$email,'name'=>'email','placeholder'=>'Email Address' );
$phone = array('id'=>'phone','type'=>'text','class'=>'col-xs-10','value'=>$phone,'name'=>'phone','placeholder'=>'Mobile Number' );
$contact1 = array('id'=>'contact1 ','type'=>'text','class'=>'col-xs-10','value'=>$contact1,'name'=>'contact1','placeholder'=>'Contact Person' );
$contact1_name = array('id'=>'contact1_name ','type'=>'text','class'=>'col-xs-10','value'=>$contact1_name,'name'=>'contact1_name','placeholder'=>'Contact Person Name' );
$contact1_email = array('id'=>'contact1_email ','type'=>'text','class'=>'col-xs-10','value'=>$contact1_email,'name'=>'contact1_email','placeholder'=>'Contact Person Email' );
$cityName = array('id'=>'cityName','type'=>'text','class'=>'col-xs-10','value'=>$citySel,'name'=>'city','placeholder'=>'City Name' );
?>
<div id="container">
<div class="main-content">
<div class="main-content-inner">
<div class="breadcrumbs" id="breadcrumbs">
<script type="text/javascript">
try {
ace.settings.check('breadcrumbs', 'fixed')
} catch (e) {
}
</script>
<ul class="breadcrumb">
<li>
<i class="ace-icon fa fa-home home-icon"></i>
<a>Home</a>
</li>
<li>
<a>Admin</a>
</li>
<li class="active">
<a href="<?php echo site_url('Person/customerManage'); ?>">Create Customer</a>
</li>
<li class="active">Edit Customer</li>
</ul><!-- /.breadcrumb -->
</div>
<div class="page-content">
<div class="page-header">
<h1>
Customer Management
<small>
<i class="ace-icon fa fa-angle-double-right"></i>
Edit Customer
</small>
</h1>
</div><!-- /.page-header -->
<?php
if($this->session->flashdata('error_message'))
{
?>
<div class="alert alert-danger">
<button data-dismiss="alert" class="close" type="button">
<i class="ace-icon fa fa-times"></i>
</button>
<strong>
<i class="ace-icon fa fa-times"></i>
<?php
echo $this->session->flashdata('error_message');
?>
</strong>
</div>
<?php
}
else if($this->session->flashdata('sucess_message'))
{
?>
<div class="alert alert-block alert-success">
<button data-dismiss="alert" class="close" type="button">
<i class="ace-icon fa fa-times"></i>
</button>
<p>
<strong>
<i class="ace-icon fa fa-check"></i>
<?php
echo $this->session->flashdata('sucess_message');
?>
</strong>
</p>
</div>
<?php
}
?>
<div class="row">
<div class="col-xs-12">
<!-- PAGE CONTENT BEGINS -->
<?php
// if(!isset($id))
// {
// $id = '';
// }
$hidden = array('class'=>'form-horizontal','role'=>'form','custid'=>$id);
echo form_open_multipart('Person/updateCustomer',$hidden );
?>
<input type="hidden" name="custid" value="<?php echo $id; ?>">
<div class="form-group col-lg-4">
<label class="col-sm-12" for="form-field-1"> Company Name </label>
<div class="col-sm-12">
<?php echo form_input($fname); ?>
</div>
</div>
<div class="form-group col-lg-4">
<label class="col-sm-12" for="form-field-1"> NTN </label>
<div class="col-sm-12">
<?php echo form_input($ntn); ?>
</div>
</div>
<div class="form-group col-lg-4">
<label class="col-sm-12" for="form-field-1"> Home Address </label>
<div class="col-sm-12">
<?php echo form_input($adress); ?>
</div>
</div>
<div class="form-group col-lg-4">
<label class="col-sm-12" for="form-field-1">Company Phone </label>
<div class="col-sm-12">
<?php echo form_input($phone); ?>
</div>
</div>
<div class="form-group col-lg-4">
<label class="col-sm-12" for="form-field-1"> Contact Person Name</label>
<div class="col-sm-12">
<?php echo form_input($contact1_name); ?>
</div>
</div>
<div class="form-group col-lg-4">
<label class="col-sm-12" for="form-field-1"> Contact Person Email</label>
<div class="col-sm-12">
<?php echo form_input($contact1_email); ?>
</div>
</div>
<div class="form-group col-lg-4">
<label class="col-sm-12" for="form-field-1"> Contact Person Number</label>
<div class="col-sm-12">
<?php echo form_input($contact1); ?>
</div>
</div>
<div class="form-group col-xs-4">
<label class="col-sm-12" for="form-field-1"> City </label>
<div class="col-sm-12">
<?php echo form_dropdown($cityName,$cities,$citySel);?>
</div>
</div>
<div class="form-group col-lg-4">
<label class="col-sm-12" for="form-field-1"> Company Email Address </label>
<div class="col-sm-12">
<?php echo form_input($email); ?>
</div>
</div>
<div class="form-group col-lg-12">
<h3 class="header smaller lighter">Contact Persons<small>(Optional )</small></h3>
<div class="input_fields_wrap col-lg-12">
<div class="form-group col-lg-12">
<button type="button" class="btn btn-primary add_field_button">Add Contacts</button>
</div>
<?php // foreach ($hidden as $value) { ?>
<div class="form-group col-lg-12" >
<label class="col-sm-4" for="form-field-1"> Contact Person </label>
<label class="col-sm-4" for="form-field-1"> Email </label>
<label class="col-sm-4" for="form-field-1"> Contact Person Number </label>
<div class="col-sm-4">
<input class="col-lg-12" type="text" value="<?php echo $contact2_name; ?>" name="contact_name[]"/>
</div>
<div class="col-sm-4">
<input class="col-lg-12 " type="text" value="<?php echo $contact2_email; ?>" name="contact_email[]"/>
</div>
<input class="col-lg-3 dynamic-field" type="text" value="<?php echo $contact2; ?>" name="contact[]"/>
<a href="#" class="col-lg-1 btn fa fa-close btn-danger remove_field"></a>
</div>
<div class="form-group col-lg-12" >
<label class="col-sm-4" for="form-field-1"> Contact Person </label>
<label class="col-sm-4" for="form-field-1"> Email </label>
<label class="col-sm-4" for="form-field-1"> Contact Person Number </label>
<div class="col-sm-4">
<input class="col-lg-12" type="text" value="<?php echo $contact3_name; ?>" name="contact_name[]"/>
</div>
<div class="col-sm-4">
<input class="col-lg-12 " type="text" value="<?php echo $contact3_email; ?>" name="contact_email[]"/>
</div>
<input class="col-lg-3 dynamic-field" type="text" value="<?php echo $contact3; ?>" name="contact[]"/>
<a href="#" class="col-lg-1 btn fa fa-close btn-danger remove_field"></a>
</div>
<div class="form-group col-lg-12" >
<label class="col-sm-4" for="form-field-1"> Contact Person </label>
<label class="col-sm-4" for="form-field-1"> Email </label>
<label class="col-sm-4" for="form-field-1"> Contact Person Number </label>
<div class="col-sm-4">
<input class="col-lg-12" type="text" value="<?php echo $contact4_name; ?>" name="contact_name[]"/>
</div>
<div class="col-sm-4">
<input class="col-lg-12 " type="text" value="<?php echo $contact4_email; ?>" name="contact_email[]"/>
</div>
<input class="col-lg-3 dynamic-field" type="text" value="<?php echo $contact4; ?>" name="contact[]"/>
<a href="#" class="col-lg-1 btn fa fa-close btn-danger remove_field"></a>
</div>
<?php // } ?>
</div>
</div>
<div class="modal-footer col-lg-12">
<a href="<?php echo site_url('Person/customerManage'); ?>" class="btn btn-sm btn-primary pull-left">
<i class="ace-icon fa fa-chevron-left"></i>
Back
</a>
<button type="submit" class="btn btn-sm btn-primary">
<i class="ace-icon fa fa-pencil"></i>
Update
</button>
</div>
<?php echo form_close(); ?>
</div>
</div>
<!--USER DATA--->
<div class="row">
<div class="col-xs-12">
<h3 class="header smaller lighter blue">Customer Record</h3>
<div class="clearfix">
<div class="pull-right tableTools-container"></div>
</div>
<!-- div.table-responsive -->
<!-- div.dataTables_borderWrap -->
<div>
<table id="customer_table" class="display" cellspacing="0" width="100%" >
<thead>
<tr>
<th class="center">Sr. No.</th>
<th class="center">Company Name</th>
<th class="center">NTN</th>
<th class="center">City</th>
<th class="center">Email Address</th>
<th class="center">Home Address</th>
<th class="center">Company Phone</th>
<th class="center">Contact Person Name</th>
<th class="center">Contact Person Email</th>
<th class="center">Contact Person Number</th>
<th class="center">Action</th>
</tr>
</thead>
<tbody>
<?php
$count = 0;
foreach ($customers as $customer)
{
?>
<tr>
<td class="hidden-480 center">
<?php echo $count++; ?>
</td>
<td class="hidden-480 center"><?php echo $customer->name; ?></td>
<td class="hidden-480 center"><?php echo $customer->ntn; ?></td>
<td class="hidden-480 center"><?php echo $cities[$customer->city]; ?></td>
<td class="hidden-480 center"><?php echo $customer->email; ?></td>
<td class="hidden-480 center"><?php echo $customer->adress; ?></td>
<td class="hidden-480 center"><?php echo $customer->phone; ?></td>
<td class="hidden-480 center"><?php echo $customer->contact1_name; ?></td>
<td class="hidden-480 center"><?php echo $customer->contact1_email; ?></td>
<td class="hidden-480 center"><?php echo $customer->contact1; ?></td>
<td class="hidden-480 center">
<div class="hidden-sm hidden-xs action-buttons">
<a class="green" href="<?php echo base_url();?>Person/updateCustomer/<?php echo $customer->id; ?>" >
<i class="ace-icon fa fa-pencil bigger-130"></i>
</a>
<a class="red" href="<?php echo base_url();?>Person/deleteCustomer/<?php echo $customer->id; ?>">
<i class="ace-icon fa fa-trash-o bigger-130"></i>
</a>
</div>
<div class="hidden-md hidden-lg">
<div class="inline pos-rel">
<button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown" data-position="auto">
<i class="ace-icon fa fa-caret-down icon-only bigger-120"></i>
</button>
<ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
<li>
<a href="#" class="tooltip-info" data-rel="tooltip" title="View">
<span class="blue">
<i class="ace-icon fa fa-search-plus bigger-120"></i>
</span>
</a>
</li>
<li>
<a href="#" class="tooltip-success" data-rel="tooltip" title="Edit">
<span class="green">
<i class="ace-icon fa fa-pencil-square-o bigger-120"></i>
</span>
</a>
</li>
<li>
<a href="#" class="tooltip-error" data-rel="tooltip" title="Delete">
<span class="red">
<i class="ace-icon fa fa-trash-o bigger-120"></i>
</span>
</a>
</li>
</ul>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<!-- PAGE CONTENT ENDS -->
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- PAGE CONTENT ENDS -->
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.page-content -->
</div>
</div><!-- /.main-content -->
</div>
<?php $this->load->view('layout/footer'); ?>
|
<?php
namespace Bedrijven\FicheBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/hello/Fabien');
$this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
}
}
|
dining-at-cu
============
Ever wanted 2 look at the menu?
If u are developing:
After you edit any javascript or whatever, just run "make" before u try to
load it. You also need browserify installed lol.
|
package com.wavesplatform.state.diffs
import cats.instances.map._
import cats.syntax.semigroup._
import com.wavesplatform.account.Address
import com.wavesplatform.features.BlockchainFeatures
import com.wavesplatform.lang.ValidationError
import com.wavesplatform.state._
import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves}
import com.wavesplatform.transaction.TxValidationError
import com.wavesplatform.transaction.TxValidationError.GenericError
import com.wavesplatform.transaction.transfer._
import scala.util.Right
import scala.util.control.NonFatal
object TransferTransactionDiff {
def apply(blockchain: Blockchain, blockTime: Long)(tx: TransferTransaction): Either[ValidationError, Diff] = {
val sender = Address.fromPublicKey(tx.sender)
val isSmartAsset = tx.feeAssetId match {
case Waves => false
case asset @ IssuedAsset(_) =>
blockchain
.assetDescription(asset)
.flatMap(_.script)
.isDefined
}
for {
recipient <- blockchain.resolveAlias(tx.recipient)
_ <- Either.cond(!isSmartAsset, (), GenericError("Smart assets can't participate in TransferTransactions as a fee"))
_ <- validateOverflow(blockchain, blockchain.height, tx)
portfolios = (tx.assetId match {
case Waves =>
Map(sender -> Portfolio(-tx.amount, LeaseBalance.empty, Map.empty)).combine(
Map(recipient -> Portfolio(tx.amount, LeaseBalance.empty, Map.empty))
)
case asset @ IssuedAsset(_) =>
Map(sender -> Portfolio(0, LeaseBalance.empty, Map(asset -> -tx.amount))).combine(
Map(recipient -> Portfolio(0, LeaseBalance.empty, Map(asset -> tx.amount)))
)
}).combine(
tx.feeAssetId match {
case Waves => Map(sender -> Portfolio(-tx.fee, LeaseBalance.empty, Map.empty))
case asset @ IssuedAsset(_) =>
val senderPf = Map(sender -> Portfolio(0, LeaseBalance.empty, Map(asset -> -tx.fee)))
if (blockchain.height >= Sponsorship.sponsoredFeesSwitchHeight(blockchain)) {
val sponsorPf = blockchain
.assetDescription(asset)
.collect {
case desc if desc.sponsorship > 0 =>
val feeInWaves = Sponsorship.toWaves(tx.fee, desc.sponsorship)
Map(desc.issuer.toAddress -> Portfolio(-feeInWaves, LeaseBalance.empty, Map(asset -> tx.fee)))
}
.getOrElse(Map.empty)
senderPf.combine(sponsorPf)
} else senderPf
}
)
assetIssued = tx.assetId.fold(true)(blockchain.assetDescription(_).isDefined)
feeAssetIssued = tx.feeAssetId.fold(true)(blockchain.assetDescription(_).isDefined)
_ <- Either.cond(
blockTime <= blockchain.settings.functionalitySettings.allowUnissuedAssetsUntil || (assetIssued && feeAssetIssued),
(),
GenericError(
s"Unissued assets are not allowed after allowUnissuedAssetsUntil=${blockchain.settings.functionalitySettings.allowUnissuedAssetsUntil}"
)
)
} yield Diff(
portfolios = portfolios,
scriptsRun = DiffsCommon.countScriptRuns(blockchain, tx)
)
}
private def validateOverflow(blockchain: Blockchain, height: Int, tx: TransferTransaction) =
if (blockchain.isFeatureActivated(BlockchainFeatures.Ride4DApps, height))
Right(()) // lets transaction validates itself
else
try {
Math.addExact(tx.fee, tx.amount)
Right(())
} catch {
case NonFatal(_) => Left(TxValidationError.OverflowError)
}
}
|
(function($){
DashboardModel = Backbone.Model.extend({
url: "/sync"
});
SyncStatusModel = Backbone.Model.extend({
url: "/sync/status"
});
DeleteModel = Backbone.Model.extend();
DashboardView = Backbone.View.extend({
el: $("#form_block"),
events: {
"click .sync-now": "syncNow",
"click .delete-now": "deleteNow",
"deleteMessage": "showDeleteMessage",
},
showMessage: function(message) {
$("#message").animate({height: 90}, 5000);
$("#message span").text(message);
$("#message").animate({height: 0}, 1000);
},
showDeleteMessage: function(e, message) {
this.showMessage(message);
},
syncNow: function(e) {
var id = $(e.currentTarget).attr("data-id");
prepareAjaxCall();
this.syncmodel = new SyncStatusModel({
"idAttribute": id
});
this.model = new DashboardModel({
"idAttribute": id
});
this.model.save({}, {
success: function(model, response) {
$(e.currentTarget).text("Importing ...").show();
$("#progress").animate({height: 90}, 1000);
},
});
var syncmodel = this.syncmodel;
var self = this;
syncStatusInterval = setInterval(function(){
syncmodel.save({}, {
success: function(model, response) {
if (response.status != "error") {
$("#status").animate({width: response.progress + "%"}, 1000);
if (response.status === "running")
{
var insertedRows = response.inserted_rows;
var rowsToBeInserted = response.rows_to_be_inserted;
$("#progress span").text("Syncing: " + insertedRows + " out of " + rowsToBeInserted);
}
else if (response.status === "completed") {
clearInterval(syncStatusInterval);
var parent = $(e.currentTarget).parent();
parent.prev().text("0");
parent.prev().prev().text(response.last_synced);
parent.find(".all_synced").show();
$(e.currentTarget).hide();
$("#progress span").text(response.message);
$("#progress").animate({height: 0}, 1000);
}
}
else { // error
clearInterval(syncStatusInterval);
$(e.currentTarget).text("Sync Now");
self.showMessage(response.message);
$("#progress").animate({height: 0}, 1000);
}
}});
}, 5000);
},
deleteNow: function(e) {
if (confirm("Are you sure?")) {
var id = $(e.currentTarget).attr("data-id");
prepareAjaxCall();
this.model = new DeleteModel({
"id": id
});
this.model.url = "/sync/delete/" + id;
this.model.destroy();
$(e.currentTarget).parent().parent().remove();
this.$el.trigger("deleteMessage", ["Sync successfully removed."]);
}
}
});
window.view = new DashboardView;
// Dashboard functions
$(".tooltip").tooltip({ position: "top center", offset: [-3, 0]});
})(jQuery); |
// Copyright 2008 Gautam Sewani
// Copyright 2013 Paul A. Bristow
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifdef _MSC_VER
# pragma warning (disable : 4127) // conditional expression is constant.
# pragma warning (disable : 4512) // assignment operator could not be generated.
#endif
#include <boost/config.hpp>
#ifndef BOOST_NO_EXCEPTIONS
#define BOOST_MATH_UNDERFLOW_ERROR_POLICY throw_on_error
#define BOOST_MATH_OVERFLOW_ERROR_POLICY throw_on_error
#endif
#include <boost/math/tools/test.hpp>
#include <boost/math/concepts/real_concept.hpp> // for real_concept
#include <boost/math/distributions/logistic.hpp>
using boost::math::logistic_distribution;
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp> // Boost.Test
#include <boost/test/floating_point_comparison.hpp>
#include "test_out_of_range.hpp"
#include <iostream>
using std::cout;
using std::endl;
using std::setprecision;
template <class RealType>
void test_spot(RealType location, RealType scale, RealType x, RealType p, RealType q, RealType tolerance)
{
BOOST_CHECK_CLOSE(
::boost::math::cdf(
logistic_distribution<RealType>(location,scale),
x),
p,
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::cdf(
complement(logistic_distribution<RealType>(location,scale),
x)),
q,
tolerance); // %
if(p < 0.999)
{
BOOST_CHECK_CLOSE(
::boost::math::quantile(
logistic_distribution<RealType>(location,scale),
p),
x,
tolerance); // %
}
if(q < 0.999)
{
BOOST_CHECK_CLOSE(
::boost::math::quantile(
complement(logistic_distribution<RealType>(location,scale),
q)),
x,
2 * tolerance); // %
}
}
template <class RealType>
void test_spots(RealType T)
{
// Basic sanity checks.
// 50 eps as a percentage, up to a maximum of double precision
// Test data taken from Mathematica 6
RealType tolerance = (std::max)(
static_cast<RealType>(1e-33L),
boost::math::tools::epsilon<RealType>());
cout<<"Absolute tolerance:"<<tolerance<<endl;
tolerance *= 50 * 100;
// # pragma warning(disable: 4100) // unreferenced formal parameter.
// prevent his spurious warning.
if (T != 0)
{
cout << "Expect parameter T == 0!" << endl;
}
cout << "Tolerance for type " << typeid(T).name() << " is " << tolerance << " %" << endl;
test_spot(
static_cast<RealType>(1), // location
static_cast<RealType>(0.5L), // scale
static_cast<RealType>(0.1L), // x
static_cast<RealType>(0.141851064900487789594278108470953L), // p
static_cast<RealType>(0.858148935099512210405721891529047L), //q
tolerance);
test_spot(
static_cast<RealType>(5), // location
static_cast<RealType>(2), // scale
static_cast<RealType>(3.123123123L),//x
static_cast<RealType>(0.281215878622547904873088053477813L), // p
static_cast<RealType>(0.718784121377452095126911946522187L), //q
tolerance);
test_spot(
static_cast<RealType>(1.2345L), // location
static_cast<RealType>(0.12345L), // scale
static_cast<RealType>(3.123123123L),//x
static_cast<RealType>(0.999999773084685079723328282229357L), // p
static_cast<RealType>(2.26915314920276671717770643005212e-7L), //q
tolerance);
//High probability
test_spot(
static_cast<RealType>(1), // location
static_cast<RealType>(0.5L), // scale
static_cast<RealType>(10), // x
static_cast<RealType>(0.99999998477002048723965105559179L), // p
static_cast<RealType>(1.5229979512760348944408208801237e-8L), //q
tolerance);
//negative x
test_spot(
static_cast<RealType>(5), // location
static_cast<RealType>(2), // scale
static_cast<RealType>(-0.1L), // scale
static_cast<RealType>(0.0724264853615177178439235061476928L), // p
static_cast<RealType>(0.927573514638482282156076493852307L), //q
tolerance);
test_spot(
static_cast<RealType>(5), // location
static_cast<RealType>(2), // scale
static_cast<RealType>(-20), // x
static_cast<RealType>(3.72663928418656138608800947863869e-6L), // p
static_cast<RealType>(0.999996273360715813438613911990521L), //q
tolerance);
// Test value to check cancellation error in straight/complemented quantile.
// The subtraction in the formula location-scale*log term introduces catastrophic
// cancellation error if location and scale*log term are close.
// For these values, the tests fail at tolerance, but work at 100*tolerance.
test_spot(
static_cast<RealType>(-1.2345L), // location
static_cast<RealType>(1.4555L), // scale
static_cast<RealType>(-0.00125796420642514024493852425918807L),// x
static_cast<RealType>(0.7L), // p
static_cast<RealType>(0.3L), //q
80*tolerance);
test_spot(
static_cast<RealType>(1.2345L), // location
static_cast<RealType>(0.12345L), // scale
static_cast<RealType>(0.0012345L), // x
static_cast<RealType>(0.0000458541039469413343331170952855318L), // p
static_cast<RealType>(0.999954145896053058665666882904714L), //q
80*tolerance);
test_spot(
static_cast<RealType>(5L), // location
static_cast<RealType>(2L), // scale
static_cast<RealType>(0.0012345L), // x
static_cast<RealType>(0.0759014628704232983512906076564256L), // p
static_cast<RealType>(0.924098537129576701648709392343574L), //q
80*tolerance);
//negative location
test_spot(
static_cast<RealType>(-123.123123L), // location
static_cast<RealType>(2.123L), // scale
static_cast<RealType>(3), // x
static_cast<RealType>(0.999999999999999999999999984171276L), // p
static_cast<RealType>(1.58287236765203121622150720373972e-26L), //q
tolerance);
//PDF Testing
BOOST_CHECK_CLOSE(
::boost::math::pdf(
logistic_distribution<RealType>(5,2),
static_cast<RealType>(0.125L) ),//x
static_cast<RealType>(0.0369500730133475464584898192104821L), // probability
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::pdf(
logistic_distribution<RealType>(static_cast<RealType>(1.2345L), static_cast<RealType>(0.12345L)),
static_cast<RealType>(0.0012345L) ),//x
static_cast<RealType>(0.000371421639109700748742498671686243L), // probability
tolerance); // %
BOOST_CHECK_CLOSE(
::boost::math::pdf(
logistic_distribution<RealType>(2,1),
static_cast<RealType>(2L) ),//x
static_cast<RealType>(0.25L), // probability
tolerance); // %
//Extreme value testing
if(std::numeric_limits<RealType>::has_infinity)
{
BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(), +std::numeric_limits<RealType>::infinity()), 0); // x = + infinity, pdf = 0
BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(), -std::numeric_limits<RealType>::infinity()), 0); // x = - infinity, pdf = 0
BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(), +std::numeric_limits<RealType>::infinity()), 1); // x = + infinity, cdf = 1
BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(), -std::numeric_limits<RealType>::infinity()), 0); // x = - infinity, cdf = 0
BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(), +std::numeric_limits<RealType>::infinity())), 0); // x = + infinity, c cdf = 0
BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(), -std::numeric_limits<RealType>::infinity())), 1); // x = - infinity, c cdf = 1
}
BOOST_MATH_CHECK_THROW(quantile(logistic_distribution<RealType>(), static_cast<RealType>(1)), std::overflow_error); // x = + infinity, cdf = 1
BOOST_MATH_CHECK_THROW(quantile(logistic_distribution<RealType>(), static_cast<RealType>(0)), std::overflow_error); // x = - infinity, cdf = 0
BOOST_MATH_CHECK_THROW(quantile(complement(logistic_distribution<RealType>(), static_cast<RealType>(1))), std::overflow_error); // x = - infinity, cdf = 0
BOOST_MATH_CHECK_THROW(quantile(complement(logistic_distribution<RealType>(), static_cast<RealType>(0))), std::overflow_error); // x = + infinity, cdf = 1
BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(), +boost::math::tools::max_value<RealType>()), 1); // x = + infinity, cdf = 1
BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(), -boost::math::tools::max_value<RealType>()), 0); // x = - infinity, cdf = 0
BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(), +boost::math::tools::max_value<RealType>())), 0); // x = + infinity, c cdf = 0
BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(), -boost::math::tools::max_value<RealType>())), 1); // x = - infinity, c cdf = 1
BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(), +boost::math::tools::max_value<RealType>()), 0); // x = + infinity, pdf = 0
BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(), -boost::math::tools::max_value<RealType>()), 0); // x = - infinity, pdf = 0
//
// Things that are errors:
// 1. Domain errors for scale and location.
// 2. x being NAN.
// 3. Probabilies being outside (0,1).
check_out_of_range<logistic_distribution<RealType> >(0, 1);
if(std::numeric_limits<RealType>::has_infinity)
{
RealType inf = std::numeric_limits<RealType>::infinity();
BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(0, 1), inf), 0);
BOOST_CHECK_EQUAL(pdf(logistic_distribution<RealType>(0, 1), -inf), 0);
BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(0, 1), inf), 1);
BOOST_CHECK_EQUAL(cdf(logistic_distribution<RealType>(0, 1), -inf), 0);
BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(0, 1), inf)), 0);
BOOST_CHECK_EQUAL(cdf(complement(logistic_distribution<RealType>(0, 1), -inf)), 1);
}
// location/scale can't be infinity.
if(std::numeric_limits<RealType>::has_infinity)
{
#ifndef BOOST_NO_EXCEPTIONS
BOOST_MATH_CHECK_THROW(
logistic_distribution<RealType> dist(std::numeric_limits<RealType>::infinity(), 0.5),
std::domain_error);
BOOST_MATH_CHECK_THROW(
logistic_distribution<RealType> dist(0.5, std::numeric_limits<RealType>::infinity()),
std::domain_error);
#else
BOOST_MATH_CHECK_THROW(
logistic_distribution<RealType>(std::numeric_limits<RealType>::infinity(), 0.5),
std::domain_error);
BOOST_MATH_CHECK_THROW(
logistic_distribution<RealType>(0.5, std::numeric_limits<RealType>::infinity()),
std::domain_error);
#endif
}
// scale can't be negative or 0.
#ifndef BOOST_NO_EXCEPTIONS
BOOST_MATH_CHECK_THROW(
logistic_distribution<RealType> dist(0.5, -0.5),
std::domain_error);
BOOST_MATH_CHECK_THROW(
logistic_distribution<RealType> dist(0.5, 0),
std::domain_error);
#else
BOOST_MATH_CHECK_THROW(
logistic_distribution<RealType>(0.5, -0.5),
std::domain_error);
BOOST_MATH_CHECK_THROW(
logistic_distribution<RealType>(0.5, 0),
std::domain_error);
#endif
logistic_distribution<RealType> dist(0.5, 0.5);
// x can't be NaN, p can't be NaN.
if (std::numeric_limits<RealType>::has_quiet_NaN)
{
// No longer allow x to be NaN, then these tests should throw.
BOOST_MATH_CHECK_THROW(pdf(dist, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
BOOST_MATH_CHECK_THROW(cdf(dist, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // x = NaN
BOOST_MATH_CHECK_THROW(cdf(complement(dist, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // x = + infinity
BOOST_MATH_CHECK_THROW(quantile(dist, +std::numeric_limits<RealType>::quiet_NaN()), std::domain_error); // p = + infinity
BOOST_MATH_CHECK_THROW(quantile(complement(dist, +std::numeric_limits<RealType>::quiet_NaN())), std::domain_error); // p = + infinity
}
if (std::numeric_limits<RealType>::has_infinity)
{
// Added test for Trac https://svn.boost.org/trac/boost/ticket/9126#comment:1
logistic_distribution<RealType> dist(0., 0.5);
BOOST_CHECK_EQUAL(pdf(dist, +std::numeric_limits<RealType>::infinity()), static_cast<RealType>(0) ); // x = infinity
}
// p can't be outside (0,1).
BOOST_MATH_CHECK_THROW(quantile(dist, static_cast<RealType>(1.1)), std::domain_error);
BOOST_MATH_CHECK_THROW(quantile(dist, static_cast<RealType>(-0.1)), std::domain_error);
BOOST_MATH_CHECK_THROW(quantile(dist, static_cast<RealType>(1)), std::overflow_error);
BOOST_MATH_CHECK_THROW(quantile(dist, static_cast<RealType>(0)), std::overflow_error);
BOOST_MATH_CHECK_THROW(quantile(complement(dist, static_cast<RealType>(1.1))), std::domain_error);
BOOST_MATH_CHECK_THROW(quantile(complement(dist, static_cast<RealType>(-0.1))), std::domain_error);
BOOST_MATH_CHECK_THROW(quantile(complement(dist, static_cast<RealType>(1))), std::overflow_error);
BOOST_MATH_CHECK_THROW(quantile(complement(dist, static_cast<RealType>(0))), std::overflow_error);
// Tests for mean,mode,median,variance,skewness,kurtosis.
//mean
BOOST_CHECK_CLOSE(
::boost::math::mean(
logistic_distribution<RealType>(2,1)
),//x
static_cast<RealType>(2), // probability
tolerance); // %
//median
BOOST_CHECK_CLOSE(
::boost::math::median(
logistic_distribution<RealType>(2,1)
),//x
static_cast<RealType>(2), // probability
tolerance);
//mode
BOOST_CHECK_CLOSE(
::boost::math::mode(
logistic_distribution<RealType>(2,1)
),//x
static_cast<RealType>(2), // probability
tolerance);
//variance
BOOST_CHECK_CLOSE(
::boost::math::variance(
logistic_distribution<RealType>(2,1)
),//x
static_cast<RealType>(3.28986813369645287294483033329205L), // probability
tolerance);
//skewness
BOOST_CHECK_CLOSE(
::boost::math::skewness(
logistic_distribution<RealType>(2,1)
),//x
static_cast<RealType>(0), // probability
tolerance);
BOOST_CHECK_CLOSE(
::boost::math::kurtosis_excess(
logistic_distribution<RealType>(2,1)
),//x
static_cast<RealType>(1.2L), // probability
tolerance);
} // template <class RealType>void test_spots(RealType)
BOOST_AUTO_TEST_CASE( test_main )
{
// Check that can generate logistic distribution using the two convenience methods:
boost::math::logistic mycexp1(1.); // Using typedef
logistic_distribution<> myexp2(1.); // Using default RealType double.
// Basic sanity-check spot values.
// (Parameter value, arbitrarily zero, only communicates the floating point type).
test_spots(0.0F); // Test float. OK at decdigits = 0 tolerance = 0.0001 %
test_spots(0.0); // Test double. OK at decdigits 7, tolerance = 1e07 %
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
test_spots(0.0L); // Test long double.
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
#endif
#else
std::cout << "<note>The long double tests have been disabled on this platform "
"either because the long double overloads of the usual math functions are "
"not available at all, or because they are too inaccurate for these tests "
"to pass.</note>" << std::endl;
#endif
} // BOOST_AUTO_TEST_CASE( test_main )
|
<header>
<a id="go-back-home" href="{{ site.url }}"><img src="http://i.imgur.com/1I4y8Rr.jpg" alt="scribble" width="53" height="59"></a>
<p>{{ site.title }}</p>
</header>
|
const Homeassistant = require('./../index')
// Connect to home-assistant
let ha = new Homeassistant({
host: '192.168.1.166'
})
ha.connect()
.then(() => {
// subscribe to state changes
ha.on('state:media_player.spotify', data => {
console.log(data)
})
// access current state
console.log(ha.state('sun.sun'))
// call a service
return ha.call({
domain: 'light',
service: 'turn_on'
})
})
.catch(console.error)
ha.on('connection', info => {
console.log('connection changed', info)
})
|
# -*- coding: utf-8 -*-
# pylint: disable=not-context-manager,useless-object-inheritance
# NOTE: The pylint not-content-manager warning is disabled pending the fix of
# a bug in pylint https://github.com/PyCQA/pylint/issues/782
# NOTE: useless-object-inheritance needed for Python 2.x compatability
"""This module contains the classes underlying SoCo's caching system."""
from __future__ import unicode_literals
import threading
from time import time
from . import config
from .compat import dumps
class _BaseCache(object):
"""An abstract base class for the cache."""
# pylint: disable=no-self-use, unused-argument
def __init__(self, *args, **kwargs):
super().__init__()
self._cache = {}
#: `bool`: whether the cache is enabled
self.enabled = True
def put(self, item, *args, **kwargs):
"""Put an item into the cache."""
raise NotImplementedError
def get(self, *args, **kwargs):
"""Get an item from the cache."""
raise NotImplementedError
def delete(self, *args, **kwargs):
"""Delete an item from the cache."""
raise NotImplementedError
def clear(self):
"""Empty the whole cache."""
raise NotImplementedError
class NullCache(_BaseCache):
"""A cache which does nothing.
Useful for debugging.
"""
def put(self, item, *args, **kwargs):
"""Put an item into the cache."""
def get(self, *args, **kwargs):
"""Get an item from the cache."""
return None
def delete(self, *args, **kwargs):
"""Delete an item from the cache."""
def clear(self):
"""Empty the whole cache."""
class TimedCache(_BaseCache):
"""A simple thread-safe cache for caching method return values.
The cache key is generated by from the given ``*args`` and ``**kwargs``.
Items are expired from the cache after a given period of time.
Example:
>>> from time import sleep
>>> cache = TimedCache()
>>> cache.put("item", 'some', kw='args', timeout=3)
>>> # Fetch the item again, by providing the same args and kwargs.
>>> assert cache.get('some', kw='args') == "item"
>>> # Providing different args or kwargs will not return the item.
>>> assert not cache.get('some', 'otherargs') == "item"
>>> # Waiting for less than the provided timeout does not cause the
>>> # item to expire.
>>> sleep(2)
>>> assert cache.get('some', kw='args') == "item"
>>> # But waiting for longer does.
>>> sleep(2)
>>> assert not cache.get('some', kw='args') == "item"
Warning:
At present, the cache can theoretically grow and grow, since entries
are not automatically purged, though in practice this is unlikely
since there are not that many different combinations of arguments in
the places where it is used in SoCo, so not that many different
cache entries will be created. If this becomes a problem,
use a thread and timer to purge the cache, or rewrite this to use
LRU logic!
"""
def __init__(self, default_timeout=0):
"""
Args:
default_timeout (int): The default number of seconds after
which items will be expired.
"""
super().__init__()
#: `int`: The default caching expiry interval in seconds.
self.default_timeout = default_timeout
# A thread lock for the cache
self._cache_lock = threading.Lock()
def get(self, *args, **kwargs):
"""Get an item from the cache for this combination of args and kwargs.
Args:
*args: any arguments.
**kwargs: any keyword arguments.
Returns:
object: The object which has been found in the cache, or `None` if
no unexpired item is found. This means that there is no point
storing an item in the cache if it is `None`.
"""
if not self.enabled:
return None
# Look in the cache to see if there is an unexpired item. If there is
# we can just return the cached result.
cache_key = self.make_key(args, kwargs)
# Lock and load
with self._cache_lock:
if cache_key in self._cache:
expirytime, item = self._cache[cache_key]
if expirytime >= time():
return item
else:
# An expired item is present - delete it
del self._cache[cache_key]
# Nothing found
return None
def put(self, item, *args, **kwargs):
"""Put an item into the cache, for this combination of args and kwargs.
Args:
*args: any arguments.
**kwargs: any keyword arguments. If ``timeout`` is specified as one
of the keyword arguments, the item will remain available
for retrieval for ``timeout`` seconds. If ``timeout`` is
`None` or not specified, the ``default_timeout`` for this
cache will be used. Specify a ``timeout`` of 0 (or ensure that
the ``default_timeout`` for this cache is 0) if this item is
not to be cached.
"""
if not self.enabled:
return
# Check for a timeout keyword, store and remove it.
timeout = kwargs.pop("timeout", None)
if timeout is None:
timeout = self.default_timeout
cache_key = self.make_key(args, kwargs)
# Store the item, along with the time at which it will expire
with self._cache_lock:
self._cache[cache_key] = (time() + timeout, item)
def delete(self, *args, **kwargs):
"""Delete an item from the cache for this combination of args and
kwargs."""
cache_key = self.make_key(args, kwargs)
with self._cache_lock:
try:
del self._cache[cache_key]
except KeyError:
pass
def clear(self):
"""Empty the whole cache."""
with self._cache_lock:
self._cache.clear()
@staticmethod
def make_key(*args, **kwargs):
"""Generate a unique, hashable, representation of the args and kwargs.
Args:
*args: any arguments.
**kwargs: any keyword arguments.
Returns:
str: the key.
"""
# This is not entirely straightforward, since args and kwargs may
# contain mutable items and unicode. Possibilities include using
# __repr__, frozensets, and code from Py3's LRU cache. But pickle
# works, and although it is not as fast as some methods, it is good
# enough at the moment
cache_key = dumps((args, kwargs))
return cache_key
class Cache(NullCache):
"""A factory class which returns an instance of a cache subclass.
A `TimedCache` is returned, unless `config.CACHE_ENABLED` is `False`,
in which case a `NullCache` will be returned.
"""
def __new__(cls, *args, **kwargs):
if config.CACHE_ENABLED:
new_cls = TimedCache
else:
new_cls = NullCache
instance = super(Cache, cls).__new__(new_cls)
instance.__init__(*args, **kwargs)
return instance
|
<table class="wiki-content-table">
<tr>
<td>foo<br />
#<br />
# foo</td>
<td>foo<br />
<br />
foo</td>
</tr>
</table>
|
import { SkyColorpickerOutput } from './colorpicker-output';
/**
* Indicates the color that users apply when they select Apply in the colorpicker.
*/
export interface SkyColorpickerResult {
/**
* Describes the color that users select in the colorpicker.
*/
color: SkyColorpickerOutput;
}
|
package org.multiverse.stms.gamma.transactionalobjects.txnlong;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.multiverse.api.LockMode;
import org.multiverse.api.TxnFactory;
import org.multiverse.api.exceptions.*;
import org.multiverse.stms.gamma.GammaStm;
import org.multiverse.stms.gamma.transactionalobjects.GammaTxnLong;
import org.multiverse.stms.gamma.transactions.GammaTxn;
import org.multiverse.stms.gamma.transactions.GammaTxnFactory;
import org.multiverse.stms.gamma.transactions.fat.FatFixedLengthGammaTxnFactory;
import org.multiverse.stms.gamma.transactions.fat.FatMonoGammaTxnFactory;
import org.multiverse.stms.gamma.transactions.fat.FatVariableLengthGammaTxnFactory;
import java.util.Collection;
import static java.util.Arrays.asList;
import static org.junit.Assert.fail;
import static org.multiverse.TestUtils.*;
import static org.multiverse.api.TxnThreadLocal.clearThreadLocalTxn;
import static org.multiverse.api.TxnThreadLocal.setThreadLocalTxn;
import static org.multiverse.stms.gamma.GammaTestUtils.*;
@RunWith(Parameterized.class)
public class GammaTxnLong_increment1WithAmountTest {
private final GammaTxnFactory transactionFactory;
private final GammaStm stm;
public GammaTxnLong_increment1WithAmountTest(GammaTxnFactory transactionFactory) {
this.transactionFactory = transactionFactory;
this.stm = transactionFactory.getConfig().getStm();
}
@Before
public void setUp() {
clearThreadLocalTxn();
}
@Parameterized.Parameters
public static Collection<TxnFactory[]> configs() {
return asList(
new TxnFactory[]{new FatVariableLengthGammaTxnFactory(new GammaStm())},
new TxnFactory[]{new FatFixedLengthGammaTxnFactory(new GammaStm())},
new TxnFactory[]{new FatMonoGammaTxnFactory(new GammaStm())}
);
}
@Test
public void whenSuccess() {
long initialValue = 10;
GammaTxnLong ref = new GammaTxnLong(stm, initialValue);
long initialVersion = ref.getVersion();
GammaTxn tx = transactionFactory.newTxn();
setThreadLocalTxn(tx);
ref.increment(5);
tx.commit();
assertIsCommitted(tx);
assertVersionAndValue(ref, initialVersion + 1, initialValue + 5);
}
@Test
public void whenReadonlyTransaction_thenReadonlyException() {
long initialValue = 10;
GammaTxnLong ref = new GammaTxnLong(stm, initialValue);
long initialVersion = ref.getVersion();
GammaTxn tx = stm.newTxnFactoryBuilder()
.setReadonly(true)
.setSpeculative(false)
.newTransactionFactory()
.newTxn();
setThreadLocalTxn(tx);
try {
ref.increment(5);
fail();
} catch (ReadonlyException expected) {
}
assertIsAborted(tx);
assertVersionAndValue(ref, initialVersion, initialValue);
}
@Test
public void whenReadLockAcquiredByOther_thenIncrementSucceedsButCommitFails() {
long initialValue = 10;
GammaTxnLong ref = new GammaTxnLong(stm, initialValue);
long initialVersion = ref.getVersion();
GammaTxn otherTx = transactionFactory.newTxn();
ref.getLock().acquire(otherTx, LockMode.Read);
GammaTxn tx = transactionFactory.newTxn();
setThreadLocalTxn(tx);
ref.increment(5);
try {
tx.commit();
fail();
} catch (ReadWriteConflict expected) {
}
assertIsAborted(tx);
assertVersionAndValue(ref, initialVersion, initialValue);
assertRefHasReadLock(ref, otherTx);
assertReadLockCount(ref, 1);
}
@Test
public void whenWriteLockAcquiredByOther_thenIncrementSucceedsButCommitFails() {
long initialValue = 10;
GammaTxnLong ref = new GammaTxnLong(stm, initialValue);
long initialVersion = ref.getVersion();
GammaTxn otherTx = transactionFactory.newTxn();
ref.getLock().acquire(otherTx, LockMode.Write);
GammaTxn tx = transactionFactory.newTxn();
setThreadLocalTxn(tx);
ref.increment(5);
try {
tx.commit();
fail();
} catch (ReadWriteConflict expected) {
}
assertIsAborted(tx);
assertVersionAndValue(ref, initialVersion, initialValue);
assertRefHasWriteLock(ref, otherTx);
}
@Test
public void whenExclusiveLockAcquiredByOther_thenIncrementSucceedsButCommitFails() {
long initialValue = 10;
GammaTxnLong ref = new GammaTxnLong(stm, initialValue);
long initialVersion = ref.getVersion();
GammaTxn otherTx = transactionFactory.newTxn();
ref.getLock().acquire(otherTx, LockMode.Exclusive);
GammaTxn tx = transactionFactory.newTxn();
setThreadLocalTxn(tx);
ref.increment(5);
try {
tx.commit();
fail();
} catch (ReadWriteConflict expected) {
}
assertIsAborted(tx);
assertVersionAndValue(ref, initialVersion, initialValue);
assertRefHasExclusiveLock(ref, otherTx);
}
@Test
public void whenCommittedTransactionFound() {
long initialValue = 10;
GammaTxnLong ref = new GammaTxnLong(stm, initialValue);
long initialVersion = ref.getVersion();
GammaTxn tx = transactionFactory.newTxn();
setThreadLocalTxn(tx);
tx.commit();
try {
ref.increment(5);
fail();
} catch (DeadTxnException expected) {
}
assertIsCommitted(tx);
assertVersionAndValue(ref, initialVersion, initialValue);
}
@Test
public void whenAbortedTransactionFound_thenDeadTxnException() {
long initialValue = 10;
GammaTxnLong ref = new GammaTxnLong(stm, initialValue);
long initialVersion = ref.getVersion();
GammaTxn tx = transactionFactory.newTxn();
setThreadLocalTxn(tx);
tx.abort();
try {
ref.increment(5);
fail();
} catch (DeadTxnException expected) {
}
assertIsAborted(tx);
assertVersionAndValue(ref, initialVersion, initialValue);
}
@Test
public void whenPreparedTransactionFound_thenPreparedTxnException() {
long initialValue = 10;
GammaTxnLong ref = new GammaTxnLong(stm, initialValue);
long initialVersion = ref.getVersion();
GammaTxn tx = transactionFactory.newTxn();
setThreadLocalTxn(tx);
tx.prepare();
try {
ref.increment(5);
fail();
} catch (PreparedTxnException expected) {
}
assertIsAborted(tx);
assertVersionAndValue(ref, initialVersion, initialValue);
}
@Test
public void whenNoTransaction_thenTxnMandatoryException() {
long initialValue = 10;
GammaTxnLong ref = new GammaTxnLong(stm, initialValue);
long initialVersion = ref.getVersion();
try {
ref.increment(5);
fail();
} catch (TxnMandatoryException expected) {
}
assertVersionAndValue(ref, initialVersion, initialValue);
}
@Test
public void whenListenersAvailable() {
long initialValue = 10;
GammaTxnLong ref = new GammaTxnLong(stm, initialValue);
long initialVersion = ref.getVersion();
long amount = 4;
TxnLongAwaitThread thread = new TxnLongAwaitThread(ref, initialValue + amount);
thread.start();
sleepMs(500);
GammaTxn tx = transactionFactory.newTxn();
setThreadLocalTxn(tx);
ref.increment(amount);
tx.commit();
joinAll(thread);
assertVersionAndValue(ref, initialVersion + 1, initialValue + amount);
}
}
|
/**
* Created by whobird on 17/4/10.
*/
var winResizeDuration=null;
$(document).ready(function(){
if(!IsPC()){
window.location="./index.html";
return;
}
//project init
//start
$("img.lazy").lazyload({
event : "sporty",
effect : "fadeIn"
});
setPage();
$('#preloader').delay(350).fadeOut(function(){
$("img.lazy").trigger("sporty");
});
var slideCount=$(".section-wrapper").find(".section-slide").length;
var curIndex=0;
var curIndexProgress=0;
var lastProgress=0;
var checkPositionWorker=null;
function setPosition(){
console.log("timeout=============action=================");
console.log(curIndex);
mySwiper.slideTo(curIndex);
setTimeout(function(){
if(curIndex<0){curIndex=0;}
if(curIndex>=(slideCount-1)){
curIndex=slideCount-1;
//console.log(">=slide count -1===================")
//最后一张动画要反向;
//console.log("translate3d("+(-20*(curIndex-2))+"%, 0px, 0px)");
$(".section-wrapper").css({
"transform": "translate3d("+(-50*(curIndex-2))+"%, 0px, 0px)",
});
tweenAnim.setBox(curIndex,-1);
for(i=0;i<slideCount;i++) {
if (i == (curIndex - 1) || i == (curIndex - 2)) {
$("#section-" + i).removeClass("active").css("width", "20%");
} else if (i == curIndex) {
$("#section-" + curIndex).addClass("active").css("width", "50%");
} else {
$("#section-" + i).removeClass("active").css("width", "50%");
}
}
}else{
//console.log("curIndex:"+curIndex);
//console.log("translate3d("+(-20*curIndex)+"%, 0px, 0px)");
$(".section-wrapper").css({
"transform": "translate3d("+(-50*curIndex)+"%, 0px, 0px)",
});
tweenAnim.setBox(curIndex,0);
for(i=0;i<slideCount;i++){
if(i>curIndex){
$("#section-"+i).removeClass("active").css("width","20%");
}else if(i<curIndex){
$("#section-"+i).removeClass("active").css("width","50%");
}else{
$("#section-"+curIndex).addClass("active").css("width","50%");
}
}
}
},100);
clearTimeout(checkPositionWorker);
checkPositionWorker=null;
};
var mySwiper = new Swiper('.swiper-container', {
// slidesPerView: 3.2,
freeMode:true,
freeModeMomentum:false,
/* freeModeMomentumBounce : true,
freeModeMomentumBounceRatio:10,*/
slidesPerView: 'auto',
observer:true,
observerParents:true,
mousewheelControl:true,
mousewheelSensitivity :1.8,
watchSlidesProgress : true,
touchRatio:3.8,
//shortSwipes:false,
//threshold : 100,
/*freeModeSticky:true,
freeModeMomentumBounce : true,
freeModeMomentumBounceRatio:10,*/
grabCursor : true,
onProgress: function(swiper, progress){
//根据 progress 计算当前的index
var indexRate=100/(slideCount-1);
var index=Math.round(progress*100/indexRate)||0;
if(index<0){index=0;}
if(index>=(slideCount-1)){
index=slideCount-1;
//最后一张动画要反向;
var indexProgress=swiper.slides[index].progress;
$(".section-wrapper").css({
"transform": "translate3d("+((-50*(index-2))-(50*indexProgress) )+"%, 0px, 0px)",
});
}else if(index==(slideCount-2)){
var indexProgress=swiper.slides[index].progress;
//倒数第二张情况分两种
if(indexProgress>0){
//当前slide移走 时,最后一张进入,动画要反向
$(".section-wrapper").css({
"transform": "translate3d("+((-50*(index))+(50*indexProgress) )+"%, 0px, 0px)",
});
}else if(indexProgress<0){
//当前slide 移过来
$(".section-wrapper").css({
"transform": "translate3d("+((-50*(index))-(50*indexProgress) )+"%, 0px, 0px)",
});
}
}else{
var indexProgress=swiper.slides[index].progress;
$(".section-wrapper").css({
"transform": "translate3d("+((-50*(index))-(50*indexProgress) )+"%, 0px, 0px)",
});
}
curIndex=index;
if(index>0 && index<slideCount-1){
if(indexProgress>0){
//当前slide移走
var $targetSection=$("#section-"+(index+1));
$targetSection.css("width",(20+30*indexProgress)+"%");
tweenAnim.update(curIndex+1,indexProgress,1);
}else if(indexProgress<0){
//当前slide 移过来
var $curSection=$("#section-"+index);
$curSection.css("width",(50+30*indexProgress)+"%");
tweenAnim.update(curIndex,indexProgress,0);
}
}else if(index==0){
//index==0只处理slide移走情况
if(indexProgress>0){
var $targetSection=$("#section-"+(index+1));
$targetSection.css("width",(20+30*indexProgress)+"%");
tweenAnim.update(curIndex+1,indexProgress,1);
}
}else if(index==(slideCount-1)){
//最后一张考虑 slide 移过来
if(indexProgress<0){
//当前slide 移过来
var $curSection=$("#section-"+index);
var $prevSection=$("#section-"+(index-1));
var $prevSection2=$("#section-"+(index-2));
$curSection.css("width",(50+30*indexProgress)+"%");
$prevSection.css("width",(20-30*indexProgress)+"%");
$prevSection.css("width",(20-30*indexProgress)+"%");
tweenAnim.update(curIndex,indexProgress,0);
tweenAnim.update(curIndex-1,indexProgress,-2);
tweenAnim.update(curIndex-2,indexProgress,-3);
}
}
clearTimeout(checkPositionWorker);
checkPositionWorker=null;
if(!checkPositionWorker){
//console.log("timeout=============");
checkPositionWorker=setTimeout(setPosition,300);
}
},
onTransitionEnd: function(swiper){
console.log("transitionEnd======================");
}
});
$(".nav-btn").on("click",function(e){
$(".main").toggleClass("nav-active");
});
$(".swiper-slide > div.col-next").on("click",function(e){
e.preventDefault();
var index=$(this).data("index");
console.log("index============"+index);
var offset=parseInt($(".swiper-slide").css("width"))*(index-0.3);
console.log(offset);
mySwiper.setWrapperTranslate(-offset);
});
$(window).on("resize",function(e){
cancelAnimationFrame (winResizeDuration);
winResizeDuration=null;
if(!winResizeDuration){
winResizeDuration=requestAnimationFrame(setPage);
}
});
});
function setPage(){
setBottom();
setScale();
}
function setBottom(){
//计算底部比例,保证底部放大时正好触底
var w=parseFloat($(".section-slide.active").css("width"));
var h=parseFloat($("body").css("height"));
var imageRate=(1000/1980)//根据设计稿
var bottomPercent=(w-22)*imageRate/h;
$(".slide-content-set").css("height",bottomPercent*100+"%");
}
function setScale(){
var curW=parseFloat($(".section-slide.active").css("width"))*0.4;
var targetW=400;
var scaleRate=curW/targetW;
if(scaleRate>1){
scaleRate=1;
}
$(".slide-head").css({
"-webkit-transform":"scale("+scaleRate+")",
"transform":"scale("+scaleRate+")"
});
$(".slide-header-index").css({
"-webkit-transform":"scale("+scaleRate+")",
"transform":"scale("+scaleRate+")"
});
$(".slide-head-list").css({
"-webkit-transform":"scale("+scaleRate+")",
"transform":"scale("+scaleRate+")"
});
var fontScaleSize=14*scaleRate<10?(10/scaleRate):14;
$(".slide-head").find("p").css("font-size",(fontScaleSize)+"px");
$(".section-list-title").css("font-size",(fontScaleSize)+"px");
var contentScaleRate=fontScaleSize*scaleRate/12;
if(contentScaleRate>1){
contentScaleRate=1;
}
console.log("contentScaleRate============="+contentScaleRate);
var contentWidth=curW/contentScaleRate;
$(".content-main").css({
"min-width":contentWidth+"px",
"-webkit-transform":"scale("+contentScaleRate+")",
"transform":"scale("+contentScaleRate+")",
//"font-size":
});
$("#section-0 .slide-head").css({
"-webkit-transform":"scale("+contentScaleRate+")",
"transform":"scale("+contentScaleRate+")"
})
}
|
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-punch',
templateUrl: './punch.component.html',
styleUrls: ['./punch.component.css']
})
export class PunchComponent implements OnInit {
@Input()
value: string;
step: number = 0.1;
min: number = 0.0;
max: number = 23.99;
autocorrect: boolean = true;
decimals: number = 2;
format: string = "n2";
showbuttons: boolean = false;
constructor() { }
ngOnInit() {
}
}
|
/*
Title: NWERC 2015
Description: TUM goes to Sweden to participate in the Northwestern Europe Regional Contest of the ICPC.
Date: 2015/11/26
Template: news
*/
As every year in late November, the Northwestern European Regional Contest is upon us.
For nine students from TUM, this is the moment they have been training for - they will get to compete with top teams from all over Europe for one of the few much sought-after spots in the World Finals.
The NWERC is held annually at varying locations. This year, it takes place in Linköping, Sweden at Linköping University. More info about the contest can be found at http://www.nwerc.eu/.
But the NWERC is also a great opportunity for all of you that have to stay at home - you can have your own go at the problem set right from your living room. If you participate in our practical course, you can even earn bonus points to improve your grade.
So if you enjoy solving challenging problems, mark your calendars and join the fray.
## When
The online contest starts on Sunday, 29.11.2015 at 10:00 a.m. CET online at https://open.kattis.com/contests/nwerc15open and will last for 5 hours. You need to register a Kattis account to participate.
## Contact
Write a message to icpc@in.tum.de if you encounter any problems.
|
import config from './config';
describe('config', function(){
it('should exist', function(){
expect(config).to.be.an('object');
});
it('should contain the required keys', function(){
expect(config.ngxDirective).to.be.an('object');
expect(config.ngxDirective.name).to.be.a('string');
});
});
|
/**
* Created by tushar.mathur on 26/01/16.
*/
'use strict'
import test from 'ava'
import splitRange from '../src/splitRange'
test((t) => {
t.same(splitRange(100, 2), [[0, 49], [50, 100]])
t.same(splitRange(100, 3), [[0, 32], [33, 65], [66, 100]])
})
|
The MIT License (MIT)
Copyright (c) 2015 Hassan Althaf - Website: HassanAlthaf.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|
express-expeditious
===================
 [](https://badge.fury.io/js/express-expeditious) [](https://coveralls.io/github/evanshortiss/express-expeditious?branch=master)
[](https://github.com/ellerbrock/typescript-badges/) [](https://greenkeeper.io/)
An express middleware that simplifies caching responses for HTTP requests of any
type. It also handles many unique cases such as piping data, using sessions, and
ETags. This middleware is implemented at the socket level, so it is entirely
transparent to the response methods such as `res.json`, `res.end`, etc. and
stays out of your way as a result. TypeScript support is also included.
## How Does it Work?
Using the default settings it works by:
1. Generating a cache key for all incoming GET requests
2. Checking if that key already exists in a storage engine
3. Responding with the cached data if found, otherwise process the request using
the defined router logic and place the response in the cache if the status code
was a HTTP 200 (success).
## Features
* Support for TypeScript.
* Seamlessly caches responses without the need to modify route handler code.
* Caches all response functions and data types, e.g `res.json`, `res.sendFile`,
`res.pipe`, etc.
* Cache storage engines can be swapped easily. You're not limited to node.js
memory or redis (but there are adapters prebuilt for those two).
* Is `express-session` (`req.session`) aware. This ensures user data is not
accidentally shared when two users request the same URL.
* Retains ETag (HTTP 304) support from express 4.12.X and for all response types
including those piped or of file format.
* Support for custom cache key generation.
* Can override caching behaviours using a custom function.
* Cache times can be configured on a per status code basis.
* Cache inspection and invalidation using the underlying `expeditious` instance
* Support for `timestring` format for setting cache timeouts. For example you
can pass `'1 hour'` instead of `60 * 60 * 1000`.
* Responses contain an `x-expeditious-cache` header that states either `hit` or
`miss` so clients can determine if the data is a cached copy.
## Install
```
npm install express-expeditious --save
```
You can also install one of these to customise the cache storage location:
* expeditious-engine-redis
* expeditious-engine-memory (this is the default)
If you'd like to write an engine of your own for another storage system then take a look at the source
code for those modules - it's pretty easy and there's more information [here](https://github.com/evanshortiss/expeditious#custom-engines).
## Usage
These examples will cache any successful request - this is a request that you
send a 200 status code to the client.
### Using the Default In-Memory Cache
```js
const getExpeditiousCache = require('express-expeditious');
const express = require('express');
const cache = getExpeditiousCache({
// Namespace used to prevent cache conflicts, must be alphanumeric
namespace: 'expresscache',
// Store cache entries for 1 minute (can also pass milliseconds e.g 60000)
defaultTtl: '1 minute'
});
const app = express();
// the initial call to this will take 2 seconds, but any subsequent calls
// will receive a response instantly from cache for the next hour
app.get('/ping', cache.withTtl('1 hour'), (req, res) => {
setTimeout(() => {
res.end('pong');
}, 2000);
});
// Cache everything below this line for 1 minute (defaultTtl)
app.use(cache);
```
### Using the Default In-Memory Cache with TypeScript
Similar to the regular JavaScript example:
```ts
import * as expeditious from 'express-expeditious';
import * as express from 'express';
const cacheoptions: expeditious.ExpeditiousOptions = {
namespace: 'expresscache',
defaultTtl: '1 minute'
};
const cache = expeditious(cacheoptions);
const app = express();
// the initial call to this will take 2 seconds, but any subsequent calls
// will receive a response instantly from cache for the next hour
app.get('/ping', cache.withTtl('1 hour'), (req, res) => {
setTimeout(() => {
res.end('pong');
}, 2000);
});
```
There's also a TypeScript sample folder in this repo at `/example-ts`.
### Using Redis
Just like before, except we pass a redis engine:
```js
const getExpeditiousCache = require('express-expeditious');
const express = require('express');
const cache = getExpeditiousCache({
namespace: 'expresscache',
defaultTtl: '1 minute',
engine: require('expeditious-engine-redis')({
// options for the redis driver
host: 'redis.acme.com',
port: 6379
})
});
const app = express();
app.use(cache);
app.get('/ping', (req, res) => {
setTimeout(() => {
res.end('pong');
}, 2000);
});
```
### Cache Storage Format
Currently cached data is stored in the following format:
```js
{
headers: String
data: {
type: 'Buffer',
data: Uint8Array
}
}
```
For example, here's a cache entry that would be stored by the module:
```js
{
"headers": "HTTP/1.1 200 OK\r\nX-Powered-By: Express\r\nx-expeditious-cache: hit\r\nDate: Thu, 14 Jun 2018 16:16:33 GMT\r\nConnection: close\r\nTransfer-Encoding: chunked",
"data": {
"type": "Buffer",
"data": [
13,
10,
13,
10,
49,
13,
10,
111,
13,
10,
49,
13,
10,
107,
13,
10,
48,
13,
10,
13,
10
]
}
}
```
This format could be changed to improve the ability to query for specific
headers or data. The use of Buffers is to ensure binary/compressed data can be
cached, but PRs and ideas surrounding this are welcome. For example, we could
store non-binary data as strings to simplify the ability to query it.
### Using Modifers
You can modify cache behaviour for specific endpoint or routers easily like so:
```js
const app = require('express')();
const isEmpty = require('lodash.isempty');
const products = require('lib/products');
const cache = require('express-expeditious')({
namespace: 'expresscache',
defaultTtl: '1 minute'
});
/**
* Exposes a /products endpoint that can be queried for a list of products.
*
* If the client provides a querystring then the request will NOT be cached.
*
* The endpoint is also session independent meaning the data returned is the
* same regardless of the user that calls, so we set sessionAware to false since
* it will reduce resource usage.
*/
app.get(
'/products',
cache
.withSessionAwareness(false)
.withCondition((req) => { return isEmpty(req.query) }),
(req, res, next) => {
products.list(req.query)
.then((listOfProducts) => res.json(listOfProducts))
.catch(next)
}
);
/**
* Expose a /orders endpoint that caches all HTTP 200 responses for 5 minutes.
* It overrides the default behaviour and also caches 404 responses for a given
* request for 1 minute - by default only 200 responses are cached
*/
app.use(
'/orders',
cache
.withTtl('5 minutes')
.withTtlForStatus('1 minute', 404),
require('lib/routes/orders')
);
```
## Debugging
If you need to enable logging for this module, simply run your application in a
session with a DEBUG environment variable set to "express-expeditious" like so:
```
export DEBUG=express-expeditious
$ node your-app.js
```
This will have *express-expeditious* to enable the
[debug](https://www.npmjs.com/package/debug) logger module it uses.
## Benchmarks
Here's the performance increase seen in simple benchmarks using Apache Bench.
All of these tests use `expeditious-engine-memory` for storage meaning the
node.js process memory is used.
You can run the same tests using the following commands:
```
# after cloning the repo
cd express-expeditious/
npm install
npm run benchmark-server
```
You need to run MongoDB locally on its default port of 27017 also. These tests
were performed with MongoDB running inside docker using the following command:
```
docker run --name mongodb -p 27017:27017 -p 28017:28017 -d mongo
```
Now, to start the tests run the command below in another terminal:
```
ab -n 1000 -c 100 http://localhost:8080/$ENDPOINT_TO_TEST
```
Here are the requests per second averaged from 4 runs:

And here is the average time taken for each request averaged over 4 runs:

It's clear that with caching applied using *express-expeditious* latency is
reduced so your application will feel more responsive and the amount of requests
per second that can be served increases significantly.
## Full Example
See the example folder [here](https://github.com/evanshortiss/express-expeditious/tree/master/example).
You can hit HTTP endpoints on the example server using the following URLs:
* http://localhost:8080/ - Uses `res.render` to render a homepage
* http://localhost:8080/ping - Uses `res.end`
* http://localhost:8080/sendfile - Uses `res.sendFile`
* http://localhost:8080/pipe - Uses `res.pipe`
* http://localhost:8080/write - Uses `res.write`
All of these URLs respond after 2 seconds on the first call, but subsequent
calls will use *express-expeditious* to respond instantly using the cache.
## API
This module is a factory function (similar to express) that returns a
middleware function. A number of options are supported and are explained in the
following sections.
### module(opts)
Create a middleware `instance` using _opts_. Supported options are:
* [Optional] expeditious - The expeditious instance that will be used for caching response data for requests.
* [Optional] shouldCache - Function that will be called to determine if the response for a request should be cached.
* [Optional] genCacheKey - Function that will be called to generate a custom key for reading and writing a response
* [Optional] sessionAware - Determines if the default cache key generation will
include the session token in the key. Defaults to true since this is the safest
option to prevent data leaks between users. If `genCacheKey` is also supplied
then this option is ignored.
from the cache. By default _req.originalUrl_ is used as the key.
* [Optional] statusCodeExpires - Useful if you want different status code responses to be cached for different
durations.
* [Optional] cacheStatusHeader - Default responses use `x-expeditious-cache` as the header key. Set a new string value to
customize the header or `false` if you prefer not to write the expeditious response header.
* [Required/Optional] defaultTtl - This is required if the `expeditious` option is not passed. Represents time entries
will remain in the cache. Can be set to any value the `timestring` module accepts.
* [Required/Optional] namespace - This is required if the `expeditious` option is not passed. It's used as a namespace
to prevent cache conflicts.
* [Required/Optional] engine - This is required if the `expeditious` option is not passed. It is the storage engine for
caching.
These options are covered in greater detail in the behaviours section below.
### instance.withTtl(number)
Returns a new cache middleware that has a `defaultTtl` setting of `number`, but
inherits other values of the parent instance.
```js
const cache = require('express-expeditious')({
namespace: 'mycache',
defaultTtl: '30 minutes'
});
const userRoutes = require('./routes/users');
// Set cache time (defaultTtl) for /users to 15 minutes
app.use('/users', cache.withTtl('15 minutes'), userRoutes);
```
### instance.withNamespace(string)
Creates a new cache instance with the given namespace. All other settings are
inherited from the parent instance.
### instance.withTtlForStatus(ttl, statusCode)
Creates a new cache instance with the given ttl for a specific status code.
All other settings are inherited from the parent instance. Previously supplied
values for `statusCodeExpires` will be used, but the values you pass to this
function will override if a conflict in values is found.
### instance.withCondition(function)
Returns a new cache middleware that has a `shouldCache` setting of its parent
overwritten by the passed function. Passing nothing will create an instance
without a `shouldCache` entry. Other settings are inherited.
### instance.withCacheKey(function)
Returns a new cache middleware that has a `genCacheKey` setting of its parent
overwritten by the passed function. Passing nothing will create an instance
without a `genCacheKey` entry. Other settings are inherited.
### instance.withSessionAwareness([boolean])
Returns a new cache instance that either respects or ignores sessions. Pass
_true_ to create a clone of the original instance, but ignore sessions. Passing
_false_ will create an instance that will include session IDs in generated cache
keys. Passing no arguments is treated the same as passing _true_.
NOTE: If you supply a `genCacheKey` or `withCacheKey` option then this option
will not apply since you have chosen to generate cache keys manually.
### instance.flush([string, ]callback)
Deletes all cache entries associated with this middleware namespace and fires
the callback once complete. If you supply a _string_ for the first parameter
this will be passed to the flush function to target specific keys.
## Behaviours
### When to use the Cache (_shouldCache_ or _withCondition_)
#### Default
By default only HTTP GET requests with 200 responses are cached using the URL
as the primary unique identifier (key). The querystring is included in this
identifier meaning _GET /users?name=john_ and _GET /users?name=jane_ are both
cached separately and only if a 200 response is received.
#### Custom
If the default behaviour is undesirable that's fine, simply provide a
_shouldCache_ function in the options to *express-expeditious* and you can have
any logic you desire to determine if a request should be cached.
```js
const cache = expressExpeditious({
defaultTtl: 30000,
namespace: 'mycache',
shouldCache: function (req) {
// by default this middleware will cache all successful PUT requests
return 'put' === req.method.toLowerCase();
}
});
const cacheWhenNoSessionExists = cache.withCondition((req, res) => {
// if req.session is not found then the middleware will cache this request
return req.hasOwnProperty('session') === false;
});
```
You can also use the _statusCodeExpires_ (see Status Code Variations below)
to determine if you would like to cache a non 200 response.
### Cache Key Generation (_genCacheKey_ or _withCacheKey_)
#### Default
The default cache key is generated using:
* req.method
* req.session.id (if you are using `express-session`)
* req.originalUrl
Here's a sample cache key from an application or route that's using
`express-session`:
```
GET-fa0391d0a99ca3693bb8d658feabd28b-/cached
```
And here's one not using `express-session`:
```
GET-/cached
```
#### Custom
You can define custom a custom key for incoming requests by providing a
_genCacheKey_ option when creating _express-expeditious_ instances.
Here's an example for an API that has versioning based on a header:
```js
const cache = expressExpeditious({
defaultTtl: 30000,
namespace: 'mycache',
// cache key is based on a session id, api version, method, and url
genCacheKey: function (req, res) {
const sessionId = req.session.id;
const version = req.headers['x-api-version'];
const resource = req.originalUrl;
const method = req.method;
// Could also use res to access etag etc.
return `${method}-${resource}-${version}-${sessionId}`;
}
});
// this is similar to the default key generation in this middleware, but is
// simply provided for the sake of an example here - there's no need to do this
const versionlessCache = cache.withCacheKey((req, res) => {
const sessionId = req.session.id;
const resource = req.originalUrl;
const method = req.method;
return `${method}-${resource}-${sessionId}`;
});
```
### Hit/Miss Header (_cacheStatusHeader_)
#### Default
An `x-expeditious-cache` header is returned in each response with the value of
`hit` or `miss` to indicate if the request was served by the cache.
#### Custom
Passing the `cacheStatusHeader` option can change the name of the header from
`x-expeditious-cache` to a value of your choosing by passing a string. You can
also pass the boolean value `false` to disable the header entirely.
```js
const cache = expressExpeditious({
defaultTtl: '1 hour',
namespace: 'mycache',
// Disable sending the header
cacheStatusHeader: false
})
const cache = expressExpeditious({
defaultTtl: '1 minute',
namespace: 'my-other-cache',
// Change the header name
cacheStatusHeader: 'x-cache-status'
})
```
### Status Code Variations (_statusCodeExpires_ or _withTtlForStatus_)
#### Default
The default behaviour for _express-expeditious_ is to cache responses that have
a status code of 200. All other status codes will not be cached.
#### Custom
To cache non 200 responses and have different cache timeout (ttl) values for
different status codes, simply add the _statusCodeExpires_ option, and specify
the ttl value you would like to use for a particular status code in
milliseconds or as a `timestring` compatible value.
An example is provided below:
```js
const cache = expressExpeditious({
defaultTtl: '1 hour',
namespace: 'mycache',
// 500 errors will be cached for 60 seconds, and 404s will be cached for 5
// minutes. 200 responses are cached for 1 hour due to defaultTtl
statusCodeExpires: {
404: '5 minutes',
500: 60 * 1000 // 1 minute in milliseconds
}
});
app.get('/users', (req, res) => {
res.json({
message: `You want a list of all users? We should implement that feature... `
});
})
app.get('/users/:id', cache.withTtlForStatus('10 minutes', 400), (req, res) => {
if (req.params.id.match(/^[0-9]+$/)) {
// This response will be cached for an 10 minutes due to being a 400 status
res.status(400).json({
message: 'Hmm, that ID is invalid., IDs should have numbers only.'
})
} else {
// This will be cached for an hour since it's a 200 response
res.json({
message: `You wanted user with ID ${req.params.id}. We should implement that feature... `
});
}
})
```
## CHANGELOG
[Click here](https://github.com/evanshortiss/express-expeditious/blob/master/CHANGELOG.md) to see the CHANGELOG.md file.
## Contributing
Contributions are welcome and encouraged. Ensure you add or remove tests as
needed, and verify the build is passing for your Pull Request.
|
from logika import IGRALEC_R, IGRALEC_Y, PRAZNO, NEODLOCENO, NI_KONEC, MAKSIMALNO_STEVILO_POTEZ, nasprotnik
from five_logika import Five_logika
from powerup_logika import Powerup_logika, POWER_STOLPEC, POWER_ZETON, POWER_2X_NW, POWER_2X_W
from pop10_logika import Pop10_logika
from pop_logika import Pop_logika
import random
#######################
## ALGORITEM MINIMAX ##
#######################
class AlphaBeta:
# Algoritem alphabeta
def __init__(self, globina):
self.globina = globina # Kako globoko iščemo?
self.prekinitev = False # Želimo algoritem prekiniti?
self.igra = None # Objekt, ki predstavlja igro
self.jaz = None # Katerega igralca igramo?
self.poteza = None # Sem vpišemo potezo, ko jo najdemo
def prekini(self):
'''Metoda, ki jo pokliče GUI, če je treba nehati razmišljati, ker
je uporabnik zapr okno ali izbral novo igro.'''
self.prekinitev = True
def izracunaj_potezo(self, igra):
'''Izračunaj potezo za trenutno stanje dane igre.'''
# To metodo pokličemo iz vzporednega vlakna
self.igra = igra
self.jaz = self.igra.na_potezi
self.prekinitev = False # Glavno vlakno bo to nastavilo na True, če bomo morali prekiniti
self.poteza = None # Sem napišemo potezo, ko jo najdemo
# Poženemo alphabeta
(poteza, vrednost) = self.alphabeta(self.globina, -AlphaBeta.NESKONCNO, AlphaBeta.NESKONCNO, True)
self.jaz = None
self.igra = None
if not self.prekinitev:
# Nismo bili prekinjeni, torej potezo izvedemo
self.poteza = poteza
def uredi_poteze(self, poteze):
'''Vrne urejen seznam potez, ki ga nato uporabimo v alphabeta.'''
urejene_poteze = [] # Urejen seznam potez
if isinstance(self.igra, Five_logika):
# Imamo 5 v vrsto
zeljen_vrstni_red = [1,4,7] # Željen vrstni red, če so na voljo vse poteze
zeljen_vrstni_red = random.sample(zeljen_vrstni_red, 3)
for i in range(1,3):
dodajamo = [4-i,4+i] # Poteze, ki jih želimo dodati
dodajamo = random.sample(dodajamo, 2)
for j in dodajamo:
zeljen_vrstni_red.append(j)
elif isinstance(self.igra, Powerup_logika):
# Imamo Power Up igro
# Dodajmo dvojne poteze brez možnosti zmage
# Najprej dodamo te, ker če bi takšne z možnostjo zmage,
# bi jih (lahek) algoritem že na začetku porabil
zeljen_vrstni_red = [74]
for i in range(1,4):
zeljen_vrstni_red += random.sample([74+i, 74-i], 2)
# Dodajmo dvojne poteze z možno zmago
zeljen_vrstni_red.append(84)
for i in range(1,4):
zeljen_vrstni_red += random.sample([84+i, 84-i], 2)
# Dodajmo 'navadne' poteze
zeljen_vrstni_red.append(4)
for i in range(1,4):
zeljen_vrstni_red += random.sample([4+i, 4-i], 2)
# Dodajmo poteze, ki poteptajo stolpec pod sabo
zeljen_vrstni_red.append(14)
for i in range(1,4):
zeljen_vrstni_red += random.sample([14+i, 14-i], 2)
# Dodajmo poteze, ki odstranijo nasprotnikov žeton
zeljen_vrstni_red += random.sample([24+7*i for i in range(6)], 6)
for i in range(1,4):
dodajamo = [24+i+7*j for j in range(6)] + [24-i+7*j for j in range(6)]
zeljen_vrstni_red += random.sample(dodajamo, 12)
elif isinstance(self.igra, Pop10_logika):
# Imamo Pop 10 igro
if self.igra.faza == 1:
# Smo v fazi odstranjevanja žetonov
zeljen_vrstni_red = random.sample([18, 68, 25, 75], 4) # Središčni dve polji
dodajamo = [10, 11, 12, 17, 19, 24, 26, 31, 32, 33]
dodajamo += [50+i for i in dodajamo]
zeljen_vrstni_red += random.sample(dodajamo, len(dodajamo))
dodajamo = [i for i in range(2, 7)] + [i for i in range(37, 42)] + [9+7*i for i in range(4)] + [13+7*i for i in range(4)]
dodajamo += [50+i for i in dodajamo]
zeljen_vrstni_red += random.sample(dodajamo, len(dodajamo))
dodajamo = [1+7*i for i in range(6)] + [7+7*i for i in range(6)]
dodajamo += [50+i for i in dodajamo]
zeljen_vrstni_red += random.sample(dodajamo, len(dodajamo))
else:
# Smo v fazi dodajanja žetonov (lahko faza 0 ali 2)
zeljen_vrstni_red = [4]
for i in range(1,4):
zeljen_vrstni_red += random.sample([4+i, 4-i], 2)
else:
# Imamo 4 v vrsto ali Pop Out
zeljen_vrstni_red = [4,-4] # Željen vrstni red, če so na voljo vse poteze
for i in range(1,4):
dodajamo = [4-i,-4+i,4+i,-4-i] # Poteze, ki jih želimo dodati
dodajamo = random.sample(dodajamo, 4)
for j in dodajamo:
zeljen_vrstni_red.append(j)
for i in zeljen_vrstni_red:
if i in poteze:
# Poteza je na voljo, treba jo je dodati
urejene_poteze.append(i)
else:
# Poteza ni na voljo
continue
return urejene_poteze
# Vrednosti igre
ZMAGA = 10**5
NESKONCNO = ZMAGA + 1 # Več kot zmaga
def vrednost_pozicije(self):
'''Vrne oceno vrednosti polozaja.'''
vrednost = 0
if self.igra is None:
# Če bi se slučajno zgodilo, da ne bi bila izbrana nobena igra
return vrednost
elif self.igra.na_potezi is None:
# Igre je konec
# Sem ne bi smeli nikoli priti zaradi if stavkov v alphabeta
return vrednost
else:
delez = 0.8 # Faktor za katerega mu je izguba manj vredna kot dobiček
tocke = [0, 0] # Sem bomo shranili število točk igralcev [R,Y]
# Najprej preverimo kateri tip igre imamo
if isinstance(self.igra, Five_logika):
# Imamo 5 v vrsto, torej imamo zmagovalne štirke (robne)
# ter petke, pokličimo jih spodaj
stirke_R = self.igra.stirke_R
stirke_Y = self.igra.stirke_Y
petke = self.igra.petke
# Pojdimo skozi vse štirke & petke ter jih primerno ovrednotimo
# Štirke / petke, ki vsebujejo žetone obeh igralcev so vredne 0 točk
# Prazne petke so vredne 0.1 točke
# Štirke so vredne 0.2 + a/5 točke, kjer je a število žetonov v štirki,
# če je igralec pravilne barve za to štirko.
# Petke so vredne a/5 točke, kjer je a število žetonov v petki.
for s in stirke_R: # Štirke na voljo rdečemu
((i1,j1),(i2,j2),(i3,j3),(i4,j4)) = s
stirka = [self.igra.polozaj[i1][j1], self.igra.polozaj[i2][j2],
self.igra.polozaj[i3][j3], self.igra.polozaj[i4][j4]]
if IGRALEC_Y in stirka:
continue
else:
tocke[0] += 0.2 + stirka.count(IGRALEC_R) / 5
for s in stirke_Y: # Štirke na voljo rumenemu
((i1,j1),(i2,j2),(i3,j3),(i4,j4)) = s
stirka = [self.igra.polozaj[i1][j1], self.igra.polozaj[i2][j2],
self.igra.polozaj[i3][j3], self.igra.polozaj[i4][j4]]
if IGRALEC_R in stirka:
continue
else:
tocke[1] += 0.2 + stirka.count(IGRALEC_Y) / 5
for p in petke:
((i1,j1),(i2,j2),(i3,j3),(i4,j4),(i5,j5)) = p
petka = [self.igra.polozaj[i1][j1], self.igra.polozaj[i2][j2],
self.igra.polozaj[i3][j3], self.igra.polozaj[i4][j4],
self.igra.polozaj[i5][j5]]
barve = list(set(stirka))
if len(barve) == 2:
if PRAZNO in barve:
# V petki so žetoni samo 1 barve
b = list(set(barve) - set([PRAZNO]))[0]
if b == IGRALEC_R:
tocke[0] += petka.count(b) / 5
else:
tocke[1] += petka.count(b) / 5
else:
# V petki so rdeči in rumeni
continue
elif barve == [PRAZNO]:
# Petka je prazna
tocke[0] += 0.1
tocke[1] += 0.1
else:
# V petki so rumeni in rdeči žetoni
continue
elif isinstance(self.igra, Pop10_logika):
# Naš cilj tukaj je, da bi imeli čim več štirk in še pomembneje,
# da bi izločili čim več žetonov
vrednost_tocke = AlphaBeta.ZMAGA / 30 # Da ne bomo nikoli imeli > ZMAGA brez da smo zmagali. To je vbistvu vrednost zmagovalne štirke.
for s in self.igra.stirke:
((i1,j1),(i2,j2),(i3,j3),(i4,j4)) = s
stirka = [self.igra.polozaj[i1][j1], self.igra.polozaj[i2][j2],
self.igra.polozaj[i3][j3], self.igra.polozaj[i4][j4]]
tocke[0] += stirka.count(IGRALEC_R) / 4 / (10-self.igra.odstranjeni[0])
tocke[1] += stirka.count(IGRALEC_Y) / 4 / (10-self.igra.odstranjeni[1])
vrednost_razlike_ods = (self.igra.odstranjeni[0] - self.igra.odstranjeni[1]) * 3 # Vrednost razlike odstranjenih
if self.jaz == IGRALEC_R:
vrednost += (tocke[0] - delez*tocke[1] + vrednost_razlike_ods) * vrednost_tocke
elif self.jaz == IGRALEC_Y:
vrednost += (tocke[1] - delez*tocke[0] - vrednost_razlike_ods) * vrednost_tocke
vrednost *= 0.984**(max(self.igra.stevilo_potez - 42, 0)) / 10
return vrednost
else:
# Imamo normalno, popout ali powerup igro
# Pojdimo sedaj skozi vse možne zmagovalne štirke in jih
# primerno ovrednotimo
# Stirke, ki ze vsebujejo zetone obeh igralec so vredne 0 tock
# Prazne stirke so vredne 0.1 tocke
# Ostale so vredne a/4 tock, kjer je a stevilo zetonov znotraj stirke
for s in self.igra.stirke:
((i1,j1),(i2,j2),(i3,j3),(i4,j4)) = s
stirka = [self.igra.polozaj[i1][j1], self.igra.polozaj[i2][j2],
self.igra.polozaj[i3][j3], self.igra.polozaj[i4][j4]]
barve = list(set(stirka))
# barve bo dolžine 2 ali 3, če bi bilo dolžine 1,
# bi bilo igre že konec
if len(barve) == 2:
if PRAZNO in barve:
# V štirki so žetoni samo 1 barve
b = list(set(barve) - set([PRAZNO]))[0]
if b == IGRALEC_R:
tocke[0] += stirka.count(b) / 4
else:
tocke[1] += stirka.count(b) / 4
else:
continue
elif barve == [PRAZNO]:
# Štirka je prazna
tocke[0] += 0.1
tocke[1] += 0.1
else:
# V štirki so rumene in rdeče
continue
if self.jaz == IGRALEC_R:
vrednost += (tocke[0] - delez*tocke[1]) / 69 * 0.1 * AlphaBeta.ZMAGA
else:
vrednost += (tocke[1] - delez*tocke[0]) / 69 * 0.1 * AlphaBeta.ZMAGA
if isinstance(self.igra, Pop_logika):
k = 0.984**self.igra.stevilo_potez
elif isinstance(self.igra, Powerup_logika):
k = 1 - self.igra.stevilo_potez / (2*58)
else:
k = 1 - self.igra.stevilo_potez / (2*6*7)
vrednost *= k
return vrednost
def alphabeta(self, globina, alpha, beta, maksimiziramo):
'''Glavna metoda AlphaBeta.
Vrne zmagovalno potezo in njeno vrednost, če jo najde, sicer (None, 0).'''
if self.prekinitev:
# Sporočili so nam, da moramo prekiniti
return (None, 0)
(zmagovalec, stirka) = self.igra.stanje_igre()
if zmagovalec in (IGRALEC_R, IGRALEC_Y, NEODLOCENO):
if isinstance(self.igra, Pop10_logika):
k = 0.984**(max(self.igra.stevilo_potez - 42, 0))
elif isinstance(self.igra, Pop_logika):
k = 0.984**self.igra.stevilo_potez
elif isinstance(self.igra, Powerup_logika):
k = 1 - self.igra.stevilo_potez / (2*58) # Kjer je 58 max število potez v tej igri
else:
k = 1 - self.igra.stevilo_potez / (2*6*7)
# Igre je konec, vrnemo njeno vrednost
if zmagovalec == self.jaz:
return (None, AlphaBeta.ZMAGA * k)
elif zmagovalec == nasprotnik(self.jaz):
return (None, -AlphaBeta.ZMAGA * k)
else:
return (None, 0)
elif zmagovalec == NI_KONEC:
# Igre ni konec
if globina == 0:
return (None, self.vrednost_pozicije())
else:
# Naredimo en korak alphabeta metode
if maksimiziramo:
# Maksimiziramo
najboljsa_poteza = None
for p in self.uredi_poteze(self.igra.veljavne_poteze()):
self.igra.povleci_potezo(p, True)
if (p > 70 and isinstance(self.igra, Powerup_logika)) or (isinstance(self.igra, Pop10_logika) and self.igra.faza == 2):
# Imamo dvojno potezo
for p2 in self.uredi_poteze(self.igra.veljavne_poteze()):
self.igra.povleci_potezo(p2, True)
vrednost = self.alphabeta(max(globina-2, 0), alpha, beta, not maksimiziramo)[1]
self.igra.razveljavi()
if vrednost > alpha:
najboljsa_poteza = [p, p2]
alpha = vrednost
if najboljsa_poteza is None:
najboljsa_poteza = [p, p2]
if beta <= alpha:
break
self.igra.razveljavi()
if beta <= alpha:
break
else:
vrednost = self.alphabeta(globina-1, alpha, beta, not maksimiziramo)[1]
self.igra.razveljavi()
if vrednost > alpha:
najboljsa_poteza = p
alpha = vrednost
if najboljsa_poteza is None:
najboljsa_poteza = p
if beta <= alpha:
break
else:
# Minimiziramo
najboljsa_poteza = None
for p in self.uredi_poteze(self.igra.veljavne_poteze()):
self.igra.povleci_potezo(p, True)
if (p > 70 and isinstance(self.igra, Powerup_logika)) or (isinstance(self.igra, Pop10_logika) and self.igra.faza == 2):
# Imamo dvojno potezo
for p2 in self.uredi_poteze(self.igra.veljavne_poteze()):
self.igra.povleci_potezo(p2, True)
vrednost = self.alphabeta(max(globina-2, 0), alpha, beta, not maksimiziramo)[1]
self.igra.razveljavi()
if vrednost < beta:
najboljsa_poteza = [p, p2]
beta = vrednost
if najboljsa_poteza is None:
najboljsa_poteza = [p, p2]
if beta <= alpha:
break
self.igra.razveljavi()
if beta <= alpha:
break
else:
vrednost = self.alphabeta(globina-1, alpha, beta, not maksimiziramo)[1]
self.igra.razveljavi()
if vrednost < beta:
najboljsa_poteza = p
beta = vrednost
if najboljsa_poteza is None:
najboljsa_poteza = p
if beta <= alpha:
break
assert (najboljsa_poteza is not None), 'alphabeta: izračunana poteza je None, veljavne_poteze={0}, globina={1}'.format(self.igra.veljavne_poteze(), globina)
return (najboljsa_poteza, alpha if maksimiziramo else beta)
else:
assert False, 'alphabeta: nedefinirano stanje igre'
|
"use strict";
var Q = require("q");
var winston = require("winston");
var check = require('validator').check;
var Rule = function() {};
Rule.prototype.initializeFromJson = function(json) {
var self = this;
return Q.fcall(function() {
if(!json) throw new Error("JSON was not provided.");
if(!json.url) throw new Error("URL was not provided.");
check(json.url).isUrl();
if(!json.headers && !json.body) throw new Error("Either headers or a body must be present.");
self.rules = json;
winston.info("Set Rule: " + self.toString());
return self;
});
};
Rule.prototype.getUrl = function() {
return this.rules.url;
};
Rule.prototype.getHeaders = function() {
return this.rules.headers;
};
Rule.prototype.getBody = function() {
return this.rules.body;
};
Rule.prototype.getUrlReplacement = function() {
return this.rules.replaceUrls;
};
Rule.prototype.toString = function() {
return JSON.stringify(this.rules);
};
module.exports = Rule;
|
using System.Collections.Generic;
using System.Linq;
using System.Web.Hosting;
using RestSharp;
using Swagolicious.Models;
namespace Swagolicious.Service
{
public class Meetup
{
public List<Result> LoadFromMeetup()
{
return new InMemoryCache().Get("Meetup.Attendees", () =>
{
var api = new MeetupApiCall(Settings.MeetupApiKey);
//Get upcoming events
var request = new RestRequest { Resource = Settings.MeetupEventsUrl };
request.AddUrlSegment("groupname", Settings.MeetupGroupName);
var events = api.Execute<EventDto>(request);
var nextEvent = events.Results.First();
//Get RSVP list from first event
request = new RestRequest { Resource = Settings.MeetupRsvpUrl };
request.AddUrlSegment("eventid", nextEvent.Id);
var rsvpList = api.Execute<RsvpDto>(request);
//Do we have any guests?
var guestCount = nextEvent.YesRsvpCount - rsvpList.Results.Count;
//exclude coordinators
var results = rsvpList.Results
.Where(w => !Settings.AttendeesExcludeList.Contains(w.Member.Name))
.ToList();
BuildMemberModel(results, guestCount);
BuildSwagModel();
return results;
});
}
private void BuildSwagModel()
{
var result = new FileService().LoadSwagFromDisc();
if (result.Count == 0)
{
//Default swag
ApplicationData.Swag.Add(new Swag { Thing = "TShirt", Claimed = false });
ApplicationData.Swag.Add(new Swag { Thing = "TShirt", Claimed = false });
ApplicationData.Swag.Add(new Swag { Thing = "TShirt", Claimed = false });
}
else
{
foreach (var dto in result)
{
for (var i = 0; i < dto.Quantity; i++)
{
ApplicationData.Swag.Add(new Swag { Claimed = false, Thing = dto.Name });
}
}
}
ApplicationData.Swag.Shuffle();
}
private void BuildMemberModel(IEnumerable<Result> results, int guestCount)
{
ApplicationData.Initialise();
//lets fill the attendee and swag lists
foreach (var result in results)
{
ApplicationData.Attendees.Add(
new Attendee
{
Name = result.Member.Name.FirstNameAndSurnameInitial(),
Photo = result.MemberPhoto != null ?
result.MemberPhoto.PhotoLink : "http://img2.meetupstatic.com/img/2982428616572973604/noPhoto_80.gif",
WonSwag = false,
SwagThing = "?",
MemberId = result.Member.MemberId
});
}
for (var i = 1; i <= guestCount; i++)
{
ApplicationData.Attendees.Add(
new Attendee
{
Name = "Guest " + i,
Photo = "http://img2.meetupstatic.com/img/2982428616572973604/noPhoto_80.gif",
WonSwag = false,
SwagThing = "?",
MemberId = -i
});
}
ApplicationData.Attendees.Shuffle();
}
public void Reload()
{
new InMemoryCache().Remove("Meetup.Attendees");
LoadFromMeetup();
}
}
} |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>JsDoc Reference - Index</title>
<meta name="generator" content="JsDoc Toolkit" />
<style type="text/css">
/* default.css */
body
{
font: 12px "Lucida Grande", Tahoma, Arial, Helvetica, sans-serif;
width: 800px;
}
.header
{
clear: both;
background-color: #ccc;
padding: 8px;
}
h1
{
font-size: 150%;
font-weight: bold;
padding: 0;
margin: 1em 0 0 .3em;
}
hr
{
border: none 0;
border-top: 1px solid #7F8FB1;
height: 1px;
}
pre.code
{
display: block;
padding: 8px;
border: 1px dashed #ccc;
}
#index
{
margin-top: 24px;
float: left;
width: 160px;
position: absolute;
left: 8px;
background-color: #F3F3F3;
padding: 8px;
}
#content
{
margin-left: 190px;
width: 600px;
}
.classList
{
list-style-type: none;
padding: 0;
margin: 0 0 0 8px;
font-family: arial, sans-serif;
font-size: 1em;
overflow: auto;
}
.classList li
{
padding: 0;
margin: 0 0 8px 0;
}
.summaryTable { width: 100%; }
h1.classTitle
{
font-size:170%;
line-height:130%;
}
h2 { font-size: 110%; }
caption, div.sectionTitle
{
background-color: #7F8FB1;
color: #fff;
font-size:130%;
text-align: left;
padding: 2px 6px 2px 6px;
border: 1px #7F8FB1 solid;
}
div.sectionTitle { margin-bottom: 8px; }
.summaryTable thead { display: none; }
.summaryTable td
{
vertical-align: top;
padding: 4px;
border-bottom: 1px #7F8FB1 solid;
border-right: 1px #7F8FB1 solid;
}
/*col#summaryAttributes {}*/
.summaryTable td.attributes
{
border-left: 1px #7F8FB1 solid;
width: 140px;
text-align: right;
}
td.attributes, .fixedFont
{
line-height: 15px;
color: #002EBE;
font-family: "Courier New",Courier,monospace;
font-size: 13px;
}
.summaryTable td.nameDescription
{
text-align: left;
font-size: 13px;
line-height: 15px;
}
.summaryTable td.nameDescription, .description
{
line-height: 15px;
padding: 4px;
padding-left: 4px;
}
.summaryTable { margin-bottom: 8px; }
ul.inheritsList
{
list-style: square;
margin-left: 20px;
padding-left: 0;
}
.detailList {
margin-left: 20px;
line-height: 15px;
}
.detailList dt { margin-left: 20px; }
.detailList .heading
{
font-weight: bold;
padding-bottom: 6px;
margin-left: 0;
}
.light, td.attributes, .light a:link, .light a:visited
{
color: #777;
font-style: italic;
}
.fineprint
{
text-align: right;
font-size: 10px;
}
</style>
</head>
<body>
<div id="header">
</div>
<div id="index">
<div align="center"><a href="index.html">Class Index</a>
| <a href="files.html">File Index</a></div>
<hr />
<h2>Classes</h2>
<ul class="classList">
<li><i><a href="symbols/_global_.html">_global_</a></i></li>
<li><a href="symbols/app.html">app</a></li>
<li><a href="symbols/Foundation.html">Foundation</a></li>
<li><a href="symbols/Foundation.PersistentStorage.html">Foundation.PersistentStorage</a></li>
<li><a href="symbols/Foundation.Request.html">Foundation.Request</a></li>
<li><a href="symbols/Foundation.Storage.html">Foundation.Storage</a></li>
<li><a href="symbols/Foundation.UI.html">Foundation.UI</a></li>
</ul>
<hr />
</div>
<div id="content">
<h1 class="classTitle">Class Index</h1>
<div>
<h2><a href="symbols/_global_.html">_global_</a></h2>
</div>
<hr />
<div>
<h2><a href="symbols/app.html">app</a></h2>
Your app's namespace.
</div>
<hr />
<div>
<h2><a href="symbols/Foundation.html">Foundation</a></h2>
</div>
<hr />
<div>
<h2><a href="symbols/Foundation.PersistentStorage.html">Foundation.PersistentStorage</a></h2>
</div>
<hr />
<div>
<h2><a href="symbols/Foundation.Request.html">Foundation.Request</a></h2>
</div>
<hr />
<div>
<h2><a href="symbols/Foundation.Storage.html">Foundation.Storage</a></h2>
</div>
<hr />
<div>
<h2><a href="symbols/Foundation.UI.html">Foundation.UI</a></h2>
</div>
<hr />
</div>
<div class="fineprint" style="clear:both">
Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Fri Nov 19 2010 11:02:54 GMT-0000 (GMT)
</div>
</body>
</html> |
<?php
namespace Hvanoch\Component\DateIntervalParser;
class DateIntervalParser
{
/** @var array */
protected $aliases = array(
'y' => 'y,yr,yrs,year,years',
'm' => 'm,mo,mon,mos,mons,month,months',
'w' => 'w,we,wk,week,weeks',
'd' => 'd,dy,dys,day,days',
'h' => 'h,hr,hrs,hour,hours',
'i' => 'i,min,mins,minute,minutes',
's' => 's,sec,secs,second,seconds'
);
/** @var array */
protected $tokens = array();
/** @var \DateInterval */
private $dateTimeInterval;
/**
* @param array $additionalAliases
*/
public function __construct($additionalAliases = array())
{
$this->mergeAdditionalAliases($additionalAliases);
$tokens = array();
foreach ($this->aliases as $key => $aliasConcat) {
$aliasList = explode(',', $aliasConcat);
foreach ($aliasList as $alias) {
$tokens[$alias] = $key;
}
}
$this->tokens = $tokens;
}
/**
* @param $additionalAliases
* @throws DateIntervalParseException
*/
private function mergeAdditionalAliases($additionalAliases)
{
$aliasKeys = array_keys($this->aliases);
foreach ($additionalAliases as $key => $alias) {
if (!in_array($key, $aliasKeys)) {
throw new DateIntervalParseException(sprintf('Key "%" for aliases "%" is not valid', $key, $alias));
}
$this->aliases[$key] .= ',' . str_replace(' ', '', $alias);
}
}
/**
* @param $input
* @return \DateInterval
*/
public function parse($input)
{
$this->dateTimeInterval = new \DateInterval('P0D');
$this->process($input);
return $this->dateTimeInterval;
}
/**
* @param string $input
*/
private function cleanupString(&$input)
{
$input = trim($input);
}
/**
* @param string $input
* @throws DateIntervalParseException
*/
private function process($input)
{
$this->cleanupString($input);
$this->checkInvert($input);
$matches = preg_split("/[\s]+/", $input);
foreach ($matches as $match) {
$this->processTerm($match);
}
}
/**
* @param $input
*/
private function checkInvert(&$input)
{
if (substr($input, 0, 1) == '-') {
$this->dateTimeInterval->invert = 1;
$input = substr($input, 1);
}
}
/**
* @param $input
* @throws \Exception
*/
private function processTerm($input)
{
if (!preg_match('/(\d+)\s*([a-z]+)/i', $input, $matches)) {
throw new DateIntervalParseException(sprintf('Unable to parse "%s"', $input));
}
$tokenAliased = $matches[2];
if (!array_key_exists($tokenAliased, $this->tokens)) {
throw new DateIntervalParseException(sprintf('No token found for "%s"', $tokenAliased));
}
$token = $this->tokens[$tokenAliased];
$number = (int)$matches[1];
/** Convert weeks to days */
if ($token == 'w') {
$token = 'd';
$number = $number * 7;
}
$this->dateTimeInterval->{$token} += $number;
}
} |
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Tevent_1 = require("../../../events/Tevent");
class TagentEvent extends Tevent_1.Tevent {
constructor(type, eventData = null, cancelable = true) {
super(type, eventData, cancelable);
}
}
TagentEvent.FAILURE = "FAILURE";
exports.TagentEvent = TagentEvent;
//# sourceMappingURL=TagentEvent.js.map |
package com.accela.ObjectStreams;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import com.accela.ObjectStreams.support.ObjectOutputStreamSupport;
/**
*
* Ò»¡¢HP¶ÔÏóÊä³öÁ÷(ÎÒÆðµÄÃû×Ö)¡£Õâ¸ö¶ÔÏóÊä³öÁ÷ÓÉ·´Éäд³É¡£
* ¿ÉÒÔ¶ÁÈ¡»òÊä³ö£º
* 1¡¢¶ÁȡӵÓпÉÒÔͨ¹ý·´ÉäÀûÓù¹Ô캯ÊýÀ´´´½¨µÄ¶ÔÏó¡£¹¹Ô캯Êý¿ÉÒÔ
* ÊÇ˽Óеģ¬×îºÃÊÇÎ޲ι¹Ô캯Êý£¬µ«ÊÇÓвÎÊýµÄ¹¹Ô캯ÊýÒ²¿ÉÒÔ£¬
* Ö»ÊÇËٶȸüÂý¡£
* 2¡¢Êý×éÀàÐÍ£¬ÎÞÂÛÊý×éÔªËØÊÇ»ù±¾ÀàÐÍ»¹ÊǶÔÏóÀàÐÍ¡£
* null¡£
* 3¡¢Ã¶¾Ù±äÁ¿
* 4¡¢Äܹ»Ê¶±ðÉùÃ÷ΪtransientµÄ¶ÔÏóÀàÐ͵Ä×ֶΣ¬ÔÚÊä³öµÄʱºò»á×Ô¶¯
* дΪnull
* 5¡¢Äܹ»Ê¶±ðʵÏÖÁËCollection»òMap½Ó¿ÚµÄ¶ÔÏó£¬ÓÃÓÅ»¯µÄ·½Ê½Êä³ö¡£
* µ«ÊǶÔÓÚËüÃÇ»áºöÂÔÈ¥ÖеÄtransient×ֶΣ¬µ±×÷ûÓÐÉùÃ÷transient
* µÄ×Ö¶ÎÊä³ö
* 6¡¢Äܹ»Êä³öºÍ¶ÁÈ¡´æÔÚÑ»·ÒýÓõĶÔÏó
*
* ¶þ¡¢Óëjava.io.ObjectInputStreamºÍjava.io.ObjectOutputStreamµÄÇø±ð£º
* 1¡¢Èç¹ûÔÚÎļþÖÐдÈëÒ»¸ö¶ÔÏó£¬ÓÃjava.io.ObjectInputStream¶ÁÈ¡ÎÞÂÛ
* ¶àÉٴΣ¬¶¼Ö»»áÉú³ÉÒ»¸öʵÀý¡£ÕâÔÚÍøÂçÖз¢ËͶÔÏóµÄʱºò»áµ¼Ö·¢ËͶÔÏó
* ·½·¢ËÍÒ»¸ö¶ÔÏóºó£¬¸ü¸Ä¸Ã¶ÔÏó£¬ÔÙ·¢ËÍ£¬¶ø½ÓÊÕ¶ÔÏó·½Ö»ÄܽÓÊÕÒ»´Î£¬ºó
* ÐøµÄ½ÓÊÕ·µ»ØµÄ¶¼ÊǵÚÒ»´Î½ÓÊյĶÔÏó¡£
* 2¡¢ÓëObjectPoolÅäºÏ£¬ÓÅ»¯ÁËн¨¶ÔÏóʱµÄÄÚ´æ·ÖÅä¡£µ±·¢ËÍͬÀàÐ͵ĶÔ
* ÏóµÄʱºò£¬Èç¹ûÿ10ms¿Ë¡һ¸±±¾²¢·¢ËÍÒ»´Î(Èç¹û²»¿Ë¡£¬java.io.ObjectInputStream£¬
* ¾ÍÖ»ÄܽÓÊÕµÚÒ»´Î·¢Ë͵ĶÔÏó)£¬Ê¹ÓÃjava.io.ObjectInputStream½ÓÊÕ¶ÔÏó
* µÄʱºò»áн¨´óÁ¿¶ÔÏóʵÀý£¬¼´Ê¹ÊÍ·ÅÒ²ÄÑÒÔ±»Á¢¼´»ØÊÕ¡£¶øÊ¹ÓÃHPObjectInputStream
* Ôò¿ÉÒÔÓë¶ÔÏó³ØÅäºÏ£¬ÀûÓÃÊͷŵôµÄ¶ÔÏ󣬱ÜÃâÖØ¸´Ð½¨ÊµÀý¡£
*
* Èý¡¢ÐèҪעÒâµÄµØ·½£º
* 1¡¢HPObjectOutputStreamºÍHPObjectInputStreamÓëjava.io.ObjectInputStream
* ºÍjava.io.ObjectOutputStream²¢²»ÄܼæÈÝ¡£ÓÃÒ»ÖÖÊä³öÁ÷дµÄ¶ÔÏó£¬ÁíÒ»ÖÖÊäÈëÁ÷
* ²»ÄܶÁÈ¡¡£
* 2¡¢HPObjectOutputStreamºÍHPObjectInputStreamʹÓ÷´Éäд³É£¬·´ÉäÊÇÆäÐÔÄܵį¿
* ¾±£¬¾¡¹Ü¶ÔÏó³Ø¿ÉÒÔ´ó´óµØÓÅ»¯ÆäЧÂÊ¡£HPObjectInputStreamʹÓ÷´Éä¹¹Ô캯ÊýÀ´ÐÂ
* ½¨¶ÔϵÄǸö£¬Èç¹ûûÓÐÎ޲ι¹Ô캯Êý£¬HPObjectInputStream¾Í»áÓÃÊÔ̽²ÎÊý²âÊÔÆäËûµÄ
* Óвι¹Ô캯Êý£¬À´ÊÔͼн¨¶ÔÏóʵÀý¡£Õâ»ØÔì³ÉÐÔÄÜÀË·Ñ£¬½¨ÒéÔÚ²»±ãʹÓÃÓвι¹Ô캯Êý
* µÄÇé¿öÏ£¬¸øÐèÒªÊä³öµÄÀàдһ¸ö˽ÓеÄÎ޲ι¹Ô캯Êý¡£
* 3¡¢HPObjectOutputStreamºÍHPObjectInputStreamʹÓ÷´ÉäÀ´·ÃÎʶÔÏóµÄ¹¹Ô캯ÊýºÍ×Ö
* ¶Î£¬µ«ÊÇÈç¹û¶ÔÏóÊÇÓÃÁËSecurityManagerÀ´½ûÖ¹£¬ÄÄÅÂʹÓÃsetAccessible(true)·½·¨£¬
* Ò²ÎÞ·¨·ÃÎʵϰ£¬HPObjectOutputStreamºÍHPObjectInputStream¾Í»áÅ׳öÒì³£¡£
*
* ËÄ¡¢Î´½â¾öµÄBUG
* 1¡¢ÔÚʹÓÃÖз¢ÏÖ£¬µ±Ê¹ÓÃHPObjectOutputStreamºÍHPObjectInputStreamʱ£¬¼«ÉÙÇé¿öÏ£¬
* »áËæ»úµÄ·¢ÉúConcurrentModificationException¡£ÔÒò²»Ã÷£¬¿ÉÄܺͶÔд¼¯ºÏÀàÓйء£
*
*
*/
public class HPObjectOutputStream extends DataOutputStream
{
private ObjectOutputStreamSupport support = new ObjectOutputStreamSupport();
public HPObjectOutputStream(OutputStream out)
{
super(out);
}
public void writeObject(Object object) throws IOException
{
support.writeObject(object, this);
}
}
|
<!DOCTYPE html>
<html>
{% include header.html %}
{% include google_analytics.html %}
<body>
{{ content }}
</body>
</html>
|
PHP-DBChecker
=============
A simple Database consistency check tool fully customizable written in PHP.
Out of the plethora of automated database consistency checker I've made my own one. With Blackjack and Hookers.
|
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gzip
import (
"bufio"
"errors"
"fmt"
"io"
"net"
"net/http"
"regexp"
"strconv"
"strings"
"sync"
"gitea.com/macaron/macaron"
"github.com/klauspost/compress/gzip"
)
const (
acceptEncodingHeader = "Accept-Encoding"
contentEncodingHeader = "Content-Encoding"
contentLengthHeader = "Content-Length"
contentTypeHeader = "Content-Type"
rangeHeader = "Range"
varyHeader = "Vary"
)
const (
// MinSize is the minimum size of content we will compress
MinSize = 1400
)
// noopClosers are io.Writers with a shim to prevent early closure
type noopCloser struct {
io.Writer
}
func (noopCloser) Close() error { return nil }
// WriterPool is a gzip writer pool to reduce workload on creation of
// gzip writers
type WriterPool struct {
pool sync.Pool
compressionLevel int
}
// NewWriterPool creates a new pool
func NewWriterPool(compressionLevel int) *WriterPool {
return &WriterPool{pool: sync.Pool{
// New will return nil, we'll manage the creation of new
// writers in the middleware
New: func() interface{} { return nil },
},
compressionLevel: compressionLevel}
}
// Get a writer from the pool - or create one if not available
func (wp *WriterPool) Get(rw macaron.ResponseWriter) *gzip.Writer {
ret := wp.pool.Get()
if ret == nil {
ret, _ = gzip.NewWriterLevel(rw, wp.compressionLevel)
} else {
ret.(*gzip.Writer).Reset(rw)
}
return ret.(*gzip.Writer)
}
// Put returns a writer to the pool
func (wp *WriterPool) Put(w *gzip.Writer) {
wp.pool.Put(w)
}
var writerPool WriterPool
// Options represents the configuration for the gzip middleware
type Options struct {
CompressionLevel int
}
func validateCompressionLevel(level int) bool {
return level == gzip.DefaultCompression ||
level == gzip.ConstantCompression ||
(level >= gzip.BestSpeed && level <= gzip.BestCompression)
}
func validate(options []Options) Options {
// Default to level 4 compression (Best results seem to be between 4 and 6)
opt := Options{CompressionLevel: 4}
if len(options) > 0 {
opt = options[0]
}
if !validateCompressionLevel(opt.CompressionLevel) {
opt.CompressionLevel = 4
}
return opt
}
// Middleware creates a macaron.Handler to proxy the response
func Middleware(options ...Options) macaron.Handler {
opt := validate(options)
writerPool = *NewWriterPool(opt.CompressionLevel)
regex := regexp.MustCompile(`bytes=(\d+)\-.*`)
return func(ctx *macaron.Context) {
// If the client won't accept gzip or x-gzip don't compress
if !strings.Contains(ctx.Req.Header.Get(acceptEncodingHeader), "gzip") &&
!strings.Contains(ctx.Req.Header.Get(acceptEncodingHeader), "x-gzip") {
return
}
// If the client is asking for a specific range of bytes - don't compress
if rangeHdr := ctx.Req.Header.Get(rangeHeader); rangeHdr != "" {
match := regex.FindStringSubmatch(rangeHdr)
if len(match) > 1 {
return
}
}
// OK we should proxy the response writer
// We are still not necessarily going to compress...
proxyWriter := &ProxyResponseWriter{
internal: ctx.Resp,
}
defer proxyWriter.Close()
ctx.Resp = proxyWriter
ctx.MapTo(proxyWriter, (*http.ResponseWriter)(nil))
// Check if render middleware has been registered,
// if yes, we need to modify ResponseWriter for it as well.
if _, ok := ctx.Render.(*macaron.DummyRender); !ok {
ctx.Render.SetResponseWriter(proxyWriter)
}
ctx.Next()
ctx.Resp = proxyWriter.internal
}
}
// ProxyResponseWriter is a wrapped macaron ResponseWriter that may compress its contents
type ProxyResponseWriter struct {
writer io.WriteCloser
internal macaron.ResponseWriter
stopped bool
code int
buf []byte
}
// Header returns the header map
func (proxy *ProxyResponseWriter) Header() http.Header {
return proxy.internal.Header()
}
// Status returns the status code of the response or 0 if the response has not been written.
func (proxy *ProxyResponseWriter) Status() int {
if proxy.code != 0 {
return proxy.code
}
return proxy.internal.Status()
}
// Written returns whether or not the ResponseWriter has been written.
func (proxy *ProxyResponseWriter) Written() bool {
if proxy.code != 0 {
return true
}
return proxy.internal.Written()
}
// Size returns the size of the response body.
func (proxy *ProxyResponseWriter) Size() int {
return proxy.internal.Size()
}
// Before allows for a function to be called before the ResponseWriter has been written to. This is
// useful for setting headers or any other operations that must happen before a response has been written.
func (proxy *ProxyResponseWriter) Before(before macaron.BeforeFunc) {
proxy.internal.Before(before)
}
// Write appends data to the proxied gzip writer.
func (proxy *ProxyResponseWriter) Write(b []byte) (int, error) {
// if writer is initialized, use the writer
if proxy.writer != nil {
return proxy.writer.Write(b)
}
proxy.buf = append(proxy.buf, b...)
var (
contentLength, _ = strconv.Atoi(proxy.Header().Get(contentLengthHeader))
contentType = proxy.Header().Get(contentTypeHeader)
contentEncoding = proxy.Header().Get(contentEncodingHeader)
)
// OK if an encoding hasn't been chosen, and content length > 1400
// and content type isn't a compressed type
if contentEncoding == "" &&
(contentLength == 0 || contentLength >= MinSize) &&
(contentType == "" || !compressedContentType(contentType)) {
// If current buffer is less than the min size and a Content-Length isn't set, then wait
if len(proxy.buf) < MinSize && contentLength == 0 {
return len(b), nil
}
// If the Content-Length is larger than minSize or the current buffer is larger than minSize, then continue.
if contentLength >= MinSize || len(proxy.buf) >= MinSize {
// if we don't know the content type, infer it
if contentType == "" {
contentType = http.DetectContentType(proxy.buf)
proxy.Header().Set(contentTypeHeader, contentType)
}
// If the Content-Type is not compressed - Compress!
if !compressedContentType(contentType) {
if err := proxy.startGzip(); err != nil {
return 0, err
}
return len(b), nil
}
}
}
// If we got here, we should not GZIP this response.
if err := proxy.startPlain(); err != nil {
return 0, err
}
return len(b), nil
}
func (proxy *ProxyResponseWriter) startGzip() error {
// Set the content-encoding and vary headers.
proxy.Header().Set(contentEncodingHeader, "gzip")
proxy.Header().Set(varyHeader, acceptEncodingHeader)
// if the Content-Length is already set, then calls to Write on gzip
// will fail to set the Content-Length header since its already set
// See: https://github.com/golang/go/issues/14975.
proxy.Header().Del(contentLengthHeader)
// Write the header to gzip response.
if proxy.code != 0 {
proxy.internal.WriteHeader(proxy.code)
// Ensure that no other WriteHeader's happen
proxy.code = 0
}
// Initialize and flush the buffer into the gzip response if there are any bytes.
// If there aren't any, we shouldn't initialize it yet because on Close it will
// write the gzip header even if nothing was ever written.
if len(proxy.buf) > 0 {
// Initialize the GZIP response.
proxy.writer = writerPool.Get(proxy.internal)
return proxy.writeBuf()
}
return nil
}
func (proxy *ProxyResponseWriter) startPlain() error {
if proxy.code != 0 {
proxy.internal.WriteHeader(proxy.code)
proxy.code = 0
}
proxy.stopped = true
proxy.writer = noopCloser{proxy.internal}
return proxy.writeBuf()
}
func (proxy *ProxyResponseWriter) writeBuf() error {
if proxy.buf == nil {
return nil
}
n, err := proxy.writer.Write(proxy.buf)
// This should never happen (per io.Writer docs), but if the write didn't
// accept the entire buffer but returned no specific error, we have no clue
// what's going on, so abort just to be safe.
if err == nil && n < len(proxy.buf) {
err = io.ErrShortWrite
}
proxy.buf = nil
return err
}
// WriteHeader will ensure that we have setup the writer before we write the header
func (proxy *ProxyResponseWriter) WriteHeader(code int) {
if proxy.code == 0 {
proxy.code = code
}
}
// Close the writer
func (proxy *ProxyResponseWriter) Close() error {
if proxy.stopped {
return nil
}
if proxy.writer == nil {
err := proxy.startPlain()
if err != nil {
return fmt.Errorf("GzipMiddleware: write to regular responseWriter at close gets error: %q", err.Error())
}
}
err := proxy.writer.Close()
if poolWriter, ok := proxy.writer.(*gzip.Writer); ok {
writerPool.Put(poolWriter)
}
proxy.writer = nil
proxy.stopped = true
return err
}
// Flush the writer
func (proxy *ProxyResponseWriter) Flush() {
if proxy.writer == nil {
return
}
if gw, ok := proxy.writer.(*gzip.Writer); ok {
gw.Flush()
}
proxy.internal.Flush()
}
// Push implements http.Pusher for HTTP/2 Push purposes
func (proxy *ProxyResponseWriter) Push(target string, opts *http.PushOptions) error {
pusher, ok := proxy.internal.(http.Pusher)
if !ok {
return errors.New("the ResponseWriter doesn't support the Pusher interface")
}
return pusher.Push(target, opts)
}
// Hijack implements http.Hijacker. If the underlying ResponseWriter is a
// Hijacker, its Hijack method is returned. Otherwise an error is returned.
func (proxy *ProxyResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
hijacker, ok := proxy.internal.(http.Hijacker)
if !ok {
return nil, nil, fmt.Errorf("the ResponseWriter doesn't support the Hijacker interface")
}
return hijacker.Hijack()
}
// verify Hijacker interface implementation
var _ http.Hijacker = &ProxyResponseWriter{}
func compressedContentType(contentType string) bool {
switch contentType {
case "application/zip":
return true
case "application/x-gzip":
return true
case "application/gzip":
return true
default:
return false
}
}
|
using System;
using System.IO;
using AM.IO;
using AM.Json;
using AM.Runtime;
using AM.Text;
using AM.Xml;
using JetBrains.Annotations;
using ManagedIrbis;
using ManagedIrbis.Client;
using ManagedIrbis.Ibf;
using ManagedIrbis.Ibf.Infrastructure;
using ManagedIrbis.Ibf.Infrastructure.Ast;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTests.ManagedIrbis.Ibf.Infrastructure.Ast
{
[TestClass]
public class IbfSilenceTest
: CommonIbfAstTest
{
[NotNull]
private IbfSilence _GetNode()
{
return new IbfSilence();
}
[TestMethod]
[Description("Создание объекта")]
public void IbfSilence_Construction_1()
{
IbfSilence node = new IbfSilence();
Assert.IsNotNull(node);
}
[TestMethod]
[Description("Исполнение")]
public void IbfSilence_Execute_1()
{
using (IrbisProvider provider = GetProvider())
{
IbfContext context = new IbfContext(provider);
IbfSilence node = new IbfSilence();
node.Execute(context);
}
}
private void _TestSerialization
(
[NotNull] IbfSilence first
)
{
byte[] bytes = first.SaveToMemory();
IbfSilence second = bytes.RestoreObjectFromMemory<IbfSilence>();
Assert.IsNull(second.UserData);
}
[TestMethod]
[Description("Сериализация")]
public void IbfSilence_Serialization_1()
{
IbfSilence node = new IbfSilence();
_TestSerialization(node);
node = _GetNode();
_TestSerialization(node);
}
[TestMethod]
[Description("Верификация")]
public void IbfSilence_Verify_1()
{
IbfSilence node = new IbfSilence();
Assert.IsTrue(node.Verify(false));
}
[TestMethod]
public void IbfSilence_ToXml_1()
{
IbfSilence node = new IbfSilence();
Assert.AreEqual("<IbfSilence />", XmlUtility.SerializeShort(node));
}
[TestMethod]
public void IbfSilence_ToJson_1()
{
IbfSilence node = new IbfSilence();
Assert.AreEqual("{}", JsonUtility.SerializeShort(node));
}
[TestMethod]
public void IbfSilence_ToString_1()
{
IbfSilence node = new IbfSilence();
Assert.AreEqual("Silence", node.ToString());
}
}
}
|
body {
padding: 30px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
a {
color: #00B7FF;
}
div.main {
border: 1px solid #e1e4e8;
}
input[type="button"] {
color: #FFF;
background-color: #5cb85c;
cursor: pointer;
border: none;
margin: 1em, 0.25em, 0, 0;
padding: 6px;
font-weight: 700;
text-align: center;
border-radius: 0.3rem;
box-shadow: 0 0 0 1px transparent inset, 0 0 0 0 rgba(34, 36, 38, .15) inset;
}
|
var http = require("http");
var server = http.createServer(function(request, response) {
response.writeHead(200, { "Grip-Hold": "response",
"Grip-Channel": "mychannel",
"Grip-Timeout": "60"});
response.write('<b>Hello {{name}}</b>!');
response.end();
});
server.listen(8080);
console.log("Server is listening");
|
<!doctype html public "embarassment">
<title>Markdown Example</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
.markdown-group {
overflow: hidden;
border: 1px solid #CCC;
border-radius: 4px;
}
.markdown-field {
border: none;
border-radius: 0;
border-right: 1px solid #CCC;
font-color: #333;
}
.markdown-field-group {
position: relative;
}
.markdown-field-group .buttons {
position: absolute;
bottom: 5px;
right: 5px;
}
.markdown-field-group .buttons button {
margin-left: 5px;
}
.markdown-preview {
padding: 6px 12px;
overflow-wrap: break-word;
}
.form-horizontal .form-group.textarea-nested-field {
margin-left: 0;
margin-right: 0;
}
.input-group-btn {
vertical-align: top;
}
</style>
<body>
<div id="example"/>
<script src="/markdown.js"></script> |
/*
* Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.1 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _IOKIT_IOCFPLUGIN_H_
#define _IOKIT_IOCFPLUGIN_H_
/* IOCFPlugIn.h
*/
#include <sys/cdefs.h>
__BEGIN_DECLS
#include <CoreFoundation/CFPlugIn.h>
#if COREFOUNDATION_CFPLUGINCOM_SEPARATE
#include <CoreFoundation/CFPlugInCOM.h>
#endif
#include <IOKit/IOKitLib.h>
/* C244E858-109C-11D4-91D4-0050E4C6426F */
#define kIOCFPlugInInterfaceID CFUUIDGetConstantUUIDWithBytes(NULL, \
0xC2, 0x44, 0xE8, 0x58, 0x10, 0x9C, 0x11, 0xD4, \
0x91, 0xD4, 0x00, 0x50, 0xE4, 0xC6, 0x42, 0x6F)
#define IOCFPLUGINBASE \
UInt16 version; \
UInt16 revision; \
IOReturn (*Probe)(void *thisPointer, CFDictionaryRef propertyTable, \
io_service_t service, SInt32 * order); \
IOReturn (*Start)(void *thisPointer, CFDictionaryRef propertyTable, \
io_service_t service); \
IOReturn (*Stop)(void *thisPointer)
typedef struct IOCFPlugInInterfaceStruct {
IUNKNOWN_C_GUTS;
IOCFPLUGINBASE;
} IOCFPlugInInterface;
kern_return_t
IOCreatePlugInInterfaceForService(io_service_t service,
CFUUIDRef pluginType, CFUUIDRef interfaceType,
IOCFPlugInInterface *** theInterface, SInt32 * theScore);
kern_return_t
IODestroyPlugInInterface(IOCFPlugInInterface ** interface);
__END_DECLS
#endif /* !_IOKIT_IOCFPLUGIN_H_ */
|
//
// This source file is part of appleseed.
// Visit https://appleseedhq.net/ for additional information and resources.
//
// This software is released under the MIT license.
//
// Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited
// Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// appleseed.foundation headers.
#include "foundation/core/concepts/noncopyable.h"
#include "foundation/math/aabb.h"
#include "foundation/math/bsp.h"
#include "foundation/math/intersection/rayaabb.h"
#include "foundation/math/ray.h"
#include "foundation/math/split.h"
#include "foundation/math/vector.h"
#include "foundation/utility/test.h"
// Standard headers.
#include <algorithm>
#include <cstddef>
#include <limits>
#include <memory>
#include <utility>
#include <vector>
using namespace foundation;
using namespace std;
TEST_SUITE(Foundation_Math_BSP_Node)
{
typedef bsp::Node<double> NodeType;
TEST_CASE(TestLeafNode)
{
NodeType node;
node.make_leaf();
EXPECT_TRUE(node.is_leaf());
node.set_leaf_index(42);
EXPECT_TRUE(node.is_leaf());
EXPECT_EQ(42, node.get_leaf_index());
const size_t LeafIndex = (size_t(1) << 31) - 1;
node.set_leaf_index(LeafIndex);
EXPECT_TRUE(node.is_leaf());
EXPECT_EQ(LeafIndex, node.get_leaf_index());
node.set_leaf_size(33);
EXPECT_TRUE(node.is_leaf());
EXPECT_EQ(LeafIndex, node.get_leaf_index());
}
TEST_CASE(TestInteriorNode)
{
NodeType node;
node.make_interior();
EXPECT_TRUE(node.is_interior());
node.set_child_node_index(42);
EXPECT_TRUE(node.is_interior());
EXPECT_EQ(42, node.get_child_node_index());
const size_t ChildIndex = (size_t(1) << 29) - 1;
node.set_child_node_index(ChildIndex);
EXPECT_TRUE(node.is_interior());
EXPECT_EQ(ChildIndex, node.get_child_node_index());
node.set_split_dim(1);
EXPECT_TRUE(node.is_interior());
EXPECT_EQ(ChildIndex, node.get_child_node_index());
EXPECT_EQ(1, node.get_split_dim());
node.set_split_abs(66.0);
EXPECT_TRUE(node.is_interior());
EXPECT_EQ(ChildIndex, node.get_child_node_index());
EXPECT_EQ(1, node.get_split_dim());
EXPECT_EQ(66.0, node.get_split_abs());
}
}
TEST_SUITE(Foundation_Math_BSP_Intersector)
{
class Leaf
: public NonCopyable
{
public:
void clear()
{
m_boxes.clear();
}
size_t get_size() const
{
return m_boxes.size();
}
void insert(const AABB3d& box)
{
m_boxes.push_back(box);
}
const AABB3d& get_box(const size_t i) const
{
return m_boxes[i];
}
AABB3d get_bbox() const
{
AABB3d bbox;
bbox.invalidate();
for (size_t i = 0; i < m_boxes.size(); ++i)
bbox.insert(m_boxes[i]);
return bbox;
}
size_t get_memory_size() const
{
return 0;
}
private:
vector<AABB3d> m_boxes;
};
struct LeafFactory
: public NonCopyable
{
Leaf* create_leaf()
{
return new Leaf();
}
};
struct LeafSplitter
: public NonCopyable
{
typedef bsp::LeafInfo<double, 3> LeafInfoType;
typedef Split<double> SplitType;
bool m_first_leaf;
LeafSplitter()
: m_first_leaf(true)
{
}
double get_priority(
const Leaf& leaf,
const LeafInfoType& leaf_info)
{
const double priority = m_first_leaf ? 1.0 : 0.0;
m_first_leaf = false;
return priority;
}
bool split(
const Leaf& leaf,
const LeafInfoType& leaf_info,
SplitType& split)
{
split.m_dimension = 0;
split.m_abscissa = 0.0;
return true;
}
void sort(
const Leaf& leaf,
const LeafInfoType& leaf_info,
const SplitType& split,
Leaf& left_leaf,
const LeafInfoType& left_leaf_info,
Leaf& right_leaf,
const LeafInfoType& right_leaf_info)
{
for (size_t i = 0; i < leaf.get_size(); ++i)
{
const AABB3d& box = leaf.get_box(i);
if (box.max[split.m_dimension] <= split.m_abscissa)
{
left_leaf.insert(box);
}
else if (box.min[split.m_dimension] >= split.m_abscissa)
{
right_leaf.insert(box);
}
else
{
left_leaf.insert(box);
right_leaf.insert(box);
}
}
}
};
class LeafVisitor
: public NonCopyable
{
public:
LeafVisitor()
: m_visited_leaf_count(0)
, m_closest_hit(numeric_limits<double>::max())
{
}
double visit(
const Leaf* leaf, // todo: why not a reference?
const Ray3d& ray,
const RayInfo3d& ray_info)
{
++m_visited_leaf_count;
for (size_t i = 0; i < leaf->get_size(); ++i)
{
const AABB3d& box = leaf->get_box(i);
double distance;
if (intersect(ray, ray_info, box, distance))
m_closest_hit = min(m_closest_hit, distance);
}
return m_closest_hit;
}
size_t get_visited_leaf_count() const
{
return m_visited_leaf_count;
}
double get_closest_hit() const
{
return m_closest_hit;
}
private:
size_t m_visited_leaf_count;
double m_closest_hit;
};
struct Fixture
{
typedef bsp::Tree<double, 3, Leaf> Tree;
typedef bsp::Intersector<double, Tree, LeafVisitor, Ray3d> Intersector;
Tree m_tree;
LeafVisitor m_leaf_visitor; // todo: Visitor or LeafVisitor?
Intersector m_intersector;
bsp::TraversalStatistics m_traversal_stats;
Fixture()
{
unique_ptr<Leaf> root_leaf(new Leaf());
root_leaf->insert(AABB3d(Vector3d(-1.0, -0.5, -0.2), Vector3d(0.0, 0.5, 0.2)));
root_leaf->insert(AABB3d(Vector3d(0.0, -0.5, -0.7), Vector3d(1.0, 0.5, 0.7)));
bsp::Builder<Tree, LeafFactory, LeafSplitter> builder;
LeafFactory leaf_factory;
LeafSplitter leaf_splitter;
builder.build(m_tree, move(root_leaf), leaf_factory, leaf_splitter);
}
};
#ifdef FOUNDATION_BSP_ENABLE_TRAVERSAL_STATS
#define TRAVERSAL_STATISTICS , m_traversal_stats
#else
#define TRAVERSAL_STATISTICS
#endif
#pragma warning (push)
#pragma warning (disable : 4723) // potential division by 0
TEST_CASE_F(Intersect_GivenRayEmbeddedInSplitPlane_VisitsBothLeaves, Fixture)
{
Ray3d ray(Vector3d(0.0, 0.0, 1.0), Vector3d(0.0, 0.0, -1.0));
m_intersector.intersect(m_tree, ray, RayInfo3d(ray), m_leaf_visitor TRAVERSAL_STATISTICS);
EXPECT_EQ(2, m_leaf_visitor.get_visited_leaf_count());
EXPECT_FEQ(1.0 - 0.7, m_leaf_visitor.get_closest_hit());
}
TEST_CASE_F(Intersect_GivenRayPiercingLeftNode_VisitsLeftNode, Fixture)
{
Ray3d ray(Vector3d(-0.5, 0.0, 1.0), Vector3d(0.0, 0.0, -1.0));
m_intersector.intersect(m_tree, ray, RayInfo3d(ray), m_leaf_visitor TRAVERSAL_STATISTICS);
EXPECT_EQ(1, m_leaf_visitor.get_visited_leaf_count());
EXPECT_FEQ(1.0 - 0.2, m_leaf_visitor.get_closest_hit());
}
TEST_CASE_F(Intersect_GivenRayPiercingRightNode_VisitsRightNode, Fixture)
{
Ray3d ray(Vector3d(0.5, 0.0, 1.0), Vector3d(0.0, 0.0, -1.0));
m_intersector.intersect(m_tree, ray, RayInfo3d(ray), m_leaf_visitor TRAVERSAL_STATISTICS);
EXPECT_EQ(1, m_leaf_visitor.get_visited_leaf_count());
EXPECT_FEQ(1.0 - 0.7, m_leaf_visitor.get_closest_hit());
}
#pragma warning (pop)
#undef TRAVERSAL_STATISTICS
}
|
/*
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <string.h>
#include "ec_lcl.h"
#include BOSS_OPENSSL_V_openssl__sha_h //original-code:<openssl/sha.h>
#if defined(X25519_ASM) && (defined(__x86_64) || defined(__x86_64__) || \
defined(_M_AMD64) || defined(_M_X64))
# define BASE_2_64_IMPLEMENTED
typedef uint64_t fe64[4];
int x25519_fe64_eligible(void);
/*
* Following subroutines perform corresponding operations modulo
* 2^256-38, i.e. double the curve modulus. However, inputs and
* outputs are permitted to be partially reduced, i.e. to remain
* in [0..2^256) range. It's all tied up in final fe64_tobytes
* that performs full reduction modulo 2^255-19.
*
* There are no reference C implementations for these.
*/
void x25519_fe64_mul(fe64 h, const fe64 f, const fe64 g);
void x25519_fe64_sqr(fe64 h, const fe64 f);
void x25519_fe64_mul121666(fe64 h, fe64 f);
void x25519_fe64_add(fe64 h, const fe64 f, const fe64 g);
void x25519_fe64_sub(fe64 h, const fe64 f, const fe64 g);
void x25519_fe64_tobytes(uint8_t *s, const fe64 f);
# define fe64_mul x25519_fe64_mul
# define fe64_sqr x25519_fe64_sqr
# define fe64_mul121666 x25519_fe64_mul121666
# define fe64_add x25519_fe64_add
# define fe64_sub x25519_fe64_sub
# define fe64_tobytes x25519_fe64_tobytes
static uint64_t load_8(const uint8_t *in)
{
uint64_t result;
result = in[0];
result |= ((uint64_t)in[1]) << 8;
result |= ((uint64_t)in[2]) << 16;
result |= ((uint64_t)in[3]) << 24;
result |= ((uint64_t)in[4]) << 32;
result |= ((uint64_t)in[5]) << 40;
result |= ((uint64_t)in[6]) << 48;
result |= ((uint64_t)in[7]) << 56;
return result;
}
static void fe64_frombytes(fe64 h, const uint8_t *s)
{
h[0] = load_8(s);
h[1] = load_8(s + 8);
h[2] = load_8(s + 16);
h[3] = load_8(s + 24) & 0x7fffffffffffffff;
}
static void fe64_0(fe64 h)
{
h[0] = 0;
h[1] = 0;
h[2] = 0;
h[3] = 0;
}
static void fe64_1(fe64 h)
{
h[0] = 1;
h[1] = 0;
h[2] = 0;
h[3] = 0;
}
static void fe64_copy(fe64 h, const fe64 f)
{
h[0] = f[0];
h[1] = f[1];
h[2] = f[2];
h[3] = f[3];
}
static void fe64_cswap(fe64 f, fe64 g, unsigned int b)
{
int i;
uint64_t mask = 0 - (uint64_t)b;
for (i = 0; i < 4; i++) {
uint64_t x = f[i] ^ g[i];
x &= mask;
f[i] ^= x;
g[i] ^= x;
}
}
static void fe64_invert(fe64 out, const fe64 z)
{
fe64 t0;
fe64 t1;
fe64 t2;
fe64 t3;
int i;
/*
* Compute z ** -1 = z ** (2 ** 255 - 19 - 2) with the exponent as
* 2 ** 255 - 21 = (2 ** 5) * (2 ** 250 - 1) + 11.
*/
/* t0 = z ** 2 */
fe64_sqr(t0, z);
/* t1 = t0 ** (2 ** 2) = z ** 8 */
fe64_sqr(t1, t0);
fe64_sqr(t1, t1);
/* t1 = z * t1 = z ** 9 */
fe64_mul(t1, z, t1);
/* t0 = t0 * t1 = z ** 11 -- stash t0 away for the end. */
fe64_mul(t0, t0, t1);
/* t2 = t0 ** 2 = z ** 22 */
fe64_sqr(t2, t0);
/* t1 = t1 * t2 = z ** (2 ** 5 - 1) */
fe64_mul(t1, t1, t2);
/* t2 = t1 ** (2 ** 5) = z ** ((2 ** 5) * (2 ** 5 - 1)) */
fe64_sqr(t2, t1);
for (i = 1; i < 5; ++i)
fe64_sqr(t2, t2);
/* t1 = t1 * t2 = z ** ((2 ** 5 + 1) * (2 ** 5 - 1)) = z ** (2 ** 10 - 1) */
fe64_mul(t1, t2, t1);
/* Continuing similarly... */
/* t2 = z ** (2 ** 20 - 1) */
fe64_sqr(t2, t1);
for (i = 1; i < 10; ++i)
fe64_sqr(t2, t2);
fe64_mul(t2, t2, t1);
/* t2 = z ** (2 ** 40 - 1) */
fe64_sqr(t3, t2);
for (i = 1; i < 20; ++i)
fe64_sqr(t3, t3);
fe64_mul(t2, t3, t2);
/* t2 = z ** (2 ** 10) * (2 ** 40 - 1) */
for (i = 0; i < 10; ++i)
fe64_sqr(t2, t2);
/* t1 = z ** (2 ** 50 - 1) */
fe64_mul(t1, t2, t1);
/* t2 = z ** (2 ** 100 - 1) */
fe64_sqr(t2, t1);
for (i = 1; i < 50; ++i)
fe64_sqr(t2, t2);
fe64_mul(t2, t2, t1);
/* t2 = z ** (2 ** 200 - 1) */
fe64_sqr(t3, t2);
for (i = 1; i < 100; ++i)
fe64_sqr(t3, t3);
fe64_mul(t2, t3, t2);
/* t2 = z ** ((2 ** 50) * (2 ** 200 - 1) */
for (i = 0; i < 50; ++i)
fe64_sqr(t2, t2);
/* t1 = z ** (2 ** 250 - 1) */
fe64_mul(t1, t2, t1);
/* t1 = z ** ((2 ** 5) * (2 ** 250 - 1)) */
for (i = 0; i < 5; ++i)
fe64_sqr(t1, t1);
/* Recall t0 = z ** 11; out = z ** (2 ** 255 - 21) */
fe64_mul(out, t1, t0);
}
/*
* Duplicate of original x25519_scalar_mult_generic, but using
* fe64_* subroutines.
*/
static void x25519_scalar_mulx(uint8_t out[32], const uint8_t scalar[32],
const uint8_t point[32])
{
fe64 x1, x2, z2, x3, z3, tmp0, tmp1;
uint8_t e[32];
unsigned swap = 0;
int pos;
memcpy(e, scalar, 32);
e[0] &= 0xf8;
e[31] &= 0x7f;
e[31] |= 0x40;
fe64_frombytes(x1, point);
fe64_1(x2);
fe64_0(z2);
fe64_copy(x3, x1);
fe64_1(z3);
for (pos = 254; pos >= 0; --pos) {
unsigned int b = 1 & (e[pos / 8] >> (pos & 7));
swap ^= b;
fe64_cswap(x2, x3, swap);
fe64_cswap(z2, z3, swap);
swap = b;
fe64_sub(tmp0, x3, z3);
fe64_sub(tmp1, x2, z2);
fe64_add(x2, x2, z2);
fe64_add(z2, x3, z3);
fe64_mul(z3, x2, tmp0);
fe64_mul(z2, z2, tmp1);
fe64_sqr(tmp0, tmp1);
fe64_sqr(tmp1, x2);
fe64_add(x3, z3, z2);
fe64_sub(z2, z3, z2);
fe64_mul(x2, tmp1, tmp0);
fe64_sub(tmp1, tmp1, tmp0);
fe64_sqr(z2, z2);
fe64_mul121666(z3, tmp1);
fe64_sqr(x3, x3);
fe64_add(tmp0, tmp0, z3);
fe64_mul(z3, x1, z2);
fe64_mul(z2, tmp1, tmp0);
}
fe64_invert(z2, z2);
fe64_mul(x2, x2, z2);
fe64_tobytes(out, x2);
OPENSSL_cleanse(e, sizeof(e));
}
#endif
#if defined(X25519_ASM) \
|| ( (defined(__SIZEOF_INT128__) && __SIZEOF_INT128__ == 16) \
&& !defined(__sparc__) \
&& !(defined(__ANDROID__) && !defined(__clang__)) )
/*
* Base 2^51 implementation. It's virtually no different from reference
* base 2^25.5 implementation in respect to lax boundary conditions for
* intermediate values and even individual limbs. So that whatever you
* know about the reference, applies even here...
*/
# define BASE_2_51_IMPLEMENTED
typedef uint64_t fe51[5];
static const uint64_t MASK51 = 0x7ffffffffffff;
static uint64_t load_7(const uint8_t *in)
{
uint64_t result;
result = in[0];
result |= ((uint64_t)in[1]) << 8;
result |= ((uint64_t)in[2]) << 16;
result |= ((uint64_t)in[3]) << 24;
result |= ((uint64_t)in[4]) << 32;
result |= ((uint64_t)in[5]) << 40;
result |= ((uint64_t)in[6]) << 48;
return result;
}
static uint64_t load_6(const uint8_t *in)
{
uint64_t result;
result = in[0];
result |= ((uint64_t)in[1]) << 8;
result |= ((uint64_t)in[2]) << 16;
result |= ((uint64_t)in[3]) << 24;
result |= ((uint64_t)in[4]) << 32;
result |= ((uint64_t)in[5]) << 40;
return result;
}
static void fe51_frombytes(fe51 h, const uint8_t *s)
{
uint64_t h0 = load_7(s); /* 56 bits */
uint64_t h1 = load_6(s + 7) << 5; /* 53 bits */
uint64_t h2 = load_7(s + 13) << 2; /* 58 bits */
uint64_t h3 = load_6(s + 20) << 7; /* 55 bits */
uint64_t h4 = (load_6(s + 26) & 0x7fffffffffff) << 4; /* 51 bits */
h1 |= h0 >> 51; h0 &= MASK51;
h2 |= h1 >> 51; h1 &= MASK51;
h3 |= h2 >> 51; h2 &= MASK51;
h4 |= h3 >> 51; h3 &= MASK51;
h[0] = h0;
h[1] = h1;
h[2] = h2;
h[3] = h3;
h[4] = h4;
}
static void fe51_tobytes(uint8_t *s, const fe51 h)
{
uint64_t h0 = h[0];
uint64_t h1 = h[1];
uint64_t h2 = h[2];
uint64_t h3 = h[3];
uint64_t h4 = h[4];
uint64_t q;
/* compare to modulus */
q = (h0 + 19) >> 51;
q = (h1 + q) >> 51;
q = (h2 + q) >> 51;
q = (h3 + q) >> 51;
q = (h4 + q) >> 51;
/* full reduce */
h0 += 19 * q;
h1 += h0 >> 51; h0 &= MASK51;
h2 += h1 >> 51; h1 &= MASK51;
h3 += h2 >> 51; h2 &= MASK51;
h4 += h3 >> 51; h3 &= MASK51;
h4 &= MASK51;
/* smash */
s[0] = (uint8_t)(h0 >> 0);
s[1] = (uint8_t)(h0 >> 8);
s[2] = (uint8_t)(h0 >> 16);
s[3] = (uint8_t)(h0 >> 24);
s[4] = (uint8_t)(h0 >> 32);
s[5] = (uint8_t)(h0 >> 40);
s[6] = (uint8_t)((h0 >> 48) | ((uint32_t)h1 << 3));
s[7] = (uint8_t)(h1 >> 5);
s[8] = (uint8_t)(h1 >> 13);
s[9] = (uint8_t)(h1 >> 21);
s[10] = (uint8_t)(h1 >> 29);
s[11] = (uint8_t)(h1 >> 37);
s[12] = (uint8_t)((h1 >> 45) | ((uint32_t)h2 << 6));
s[13] = (uint8_t)(h2 >> 2);
s[14] = (uint8_t)(h2 >> 10);
s[15] = (uint8_t)(h2 >> 18);
s[16] = (uint8_t)(h2 >> 26);
s[17] = (uint8_t)(h2 >> 34);
s[18] = (uint8_t)(h2 >> 42);
s[19] = (uint8_t)((h2 >> 50) | ((uint32_t)h3 << 1));
s[20] = (uint8_t)(h3 >> 7);
s[21] = (uint8_t)(h3 >> 15);
s[22] = (uint8_t)(h3 >> 23);
s[23] = (uint8_t)(h3 >> 31);
s[24] = (uint8_t)(h3 >> 39);
s[25] = (uint8_t)((h3 >> 47) | ((uint32_t)h4 << 4));
s[26] = (uint8_t)(h4 >> 4);
s[27] = (uint8_t)(h4 >> 12);
s[28] = (uint8_t)(h4 >> 20);
s[29] = (uint8_t)(h4 >> 28);
s[30] = (uint8_t)(h4 >> 36);
s[31] = (uint8_t)(h4 >> 44);
}
# if defined(X25519_ASM)
void x25519_fe51_mul(fe51 h, const fe51 f, const fe51 g);
void x25519_fe51_sqr(fe51 h, const fe51 f);
void x25519_fe51_mul121666(fe51 h, fe51 f);
# define fe51_mul x25519_fe51_mul
# define fe51_sq x25519_fe51_sqr
# define fe51_mul121666 x25519_fe51_mul121666
# else
typedef __uint128_t u128;
static void fe51_mul(fe51 h, const fe51 f, const fe51 g)
{
u128 h0, h1, h2, h3, h4;
uint64_t f_i, g0, g1, g2, g3, g4;
f_i = f[0];
h0 = (u128)f_i * (g0 = g[0]);
h1 = (u128)f_i * (g1 = g[1]);
h2 = (u128)f_i * (g2 = g[2]);
h3 = (u128)f_i * (g3 = g[3]);
h4 = (u128)f_i * (g4 = g[4]);
f_i = f[1];
h0 += (u128)f_i * (g4 *= 19);
h1 += (u128)f_i * g0;
h2 += (u128)f_i * g1;
h3 += (u128)f_i * g2;
h4 += (u128)f_i * g3;
f_i = f[2];
h0 += (u128)f_i * (g3 *= 19);
h1 += (u128)f_i * g4;
h2 += (u128)f_i * g0;
h3 += (u128)f_i * g1;
h4 += (u128)f_i * g2;
f_i = f[3];
h0 += (u128)f_i * (g2 *= 19);
h1 += (u128)f_i * g3;
h2 += (u128)f_i * g4;
h3 += (u128)f_i * g0;
h4 += (u128)f_i * g1;
f_i = f[4];
h0 += (u128)f_i * (g1 *= 19);
h1 += (u128)f_i * g2;
h2 += (u128)f_i * g3;
h3 += (u128)f_i * g4;
h4 += (u128)f_i * g0;
/* partial [lazy] reduction */
h3 += (uint64_t)(h2 >> 51); g2 = (uint64_t)h2 & MASK51;
h1 += (uint64_t)(h0 >> 51); g0 = (uint64_t)h0 & MASK51;
h4 += (uint64_t)(h3 >> 51); g3 = (uint64_t)h3 & MASK51;
g2 += (uint64_t)(h1 >> 51); g1 = (uint64_t)h1 & MASK51;
g0 += (uint64_t)(h4 >> 51) * 19; g4 = (uint64_t)h4 & MASK51;
g3 += g2 >> 51; g2 &= MASK51;
g1 += g0 >> 51; g0 &= MASK51;
h[0] = g0;
h[1] = g1;
h[2] = g2;
h[3] = g3;
h[4] = g4;
}
static void fe51_sq(fe51 h, const fe51 f)
{
# if defined(OPENSSL_SMALL_FOOTPRINT)
fe51_mul(h, f, f);
# else
/* dedicated squaring gives 16-25% overall improvement */
uint64_t g0 = f[0];
uint64_t g1 = f[1];
uint64_t g2 = f[2];
uint64_t g3 = f[3];
uint64_t g4 = f[4];
u128 h0, h1, h2, h3, h4;
h0 = (u128)g0 * g0; g0 *= 2;
h1 = (u128)g0 * g1;
h2 = (u128)g0 * g2;
h3 = (u128)g0 * g3;
h4 = (u128)g0 * g4;
g0 = g4; /* borrow g0 */
h3 += (u128)g0 * (g4 *= 19);
h2 += (u128)g1 * g1; g1 *= 2;
h3 += (u128)g1 * g2;
h4 += (u128)g1 * g3;
h0 += (u128)g1 * g4;
g0 = g3; /* borrow g0 */
h1 += (u128)g0 * (g3 *= 19);
h2 += (u128)(g0 * 2) * g4;
h4 += (u128)g2 * g2; g2 *= 2;
h0 += (u128)g2 * g3;
h1 += (u128)g2 * g4;
/* partial [lazy] reduction */
h3 += (uint64_t)(h2 >> 51); g2 = (uint64_t)h2 & MASK51;
h1 += (uint64_t)(h0 >> 51); g0 = (uint64_t)h0 & MASK51;
h4 += (uint64_t)(h3 >> 51); g3 = (uint64_t)h3 & MASK51;
g2 += (uint64_t)(h1 >> 51); g1 = (uint64_t)h1 & MASK51;
g0 += (uint64_t)(h4 >> 51) * 19; g4 = (uint64_t)h4 & MASK51;
g3 += g2 >> 51; g2 &= MASK51;
g1 += g0 >> 51; g0 &= MASK51;
h[0] = g0;
h[1] = g1;
h[2] = g2;
h[3] = g3;
h[4] = g4;
# endif
}
static void fe51_mul121666(fe51 h, fe51 f)
{
u128 h0 = f[0] * (u128)121666;
u128 h1 = f[1] * (u128)121666;
u128 h2 = f[2] * (u128)121666;
u128 h3 = f[3] * (u128)121666;
u128 h4 = f[4] * (u128)121666;
uint64_t g0, g1, g2, g3, g4;
h3 += (uint64_t)(h2 >> 51); g2 = (uint64_t)h2 & MASK51;
h1 += (uint64_t)(h0 >> 51); g0 = (uint64_t)h0 & MASK51;
h4 += (uint64_t)(h3 >> 51); g3 = (uint64_t)h3 & MASK51;
g2 += (uint64_t)(h1 >> 51); g1 = (uint64_t)h1 & MASK51;
g0 += (uint64_t)(h4 >> 51) * 19; g4 = (uint64_t)h4 & MASK51;
g3 += g2 >> 51; g2 &= MASK51;
g1 += g0 >> 51; g0 &= MASK51;
h[0] = g0;
h[1] = g1;
h[2] = g2;
h[3] = g3;
h[4] = g4;
}
# endif
static void fe51_add(fe51 h, const fe51 f, const fe51 g)
{
h[0] = f[0] + g[0];
h[1] = f[1] + g[1];
h[2] = f[2] + g[2];
h[3] = f[3] + g[3];
h[4] = f[4] + g[4];
}
static void fe51_sub(fe51 h, const fe51 f, const fe51 g)
{
/*
* Add 2*modulus to ensure that result remains positive
* even if subtrahend is partially reduced.
*/
h[0] = (f[0] + 0xfffffffffffda) - g[0];
h[1] = (f[1] + 0xffffffffffffe) - g[1];
h[2] = (f[2] + 0xffffffffffffe) - g[2];
h[3] = (f[3] + 0xffffffffffffe) - g[3];
h[4] = (f[4] + 0xffffffffffffe) - g[4];
}
static void fe51_0(fe51 h)
{
h[0] = 0;
h[1] = 0;
h[2] = 0;
h[3] = 0;
h[4] = 0;
}
static void fe51_1(fe51 h)
{
h[0] = 1;
h[1] = 0;
h[2] = 0;
h[3] = 0;
h[4] = 0;
}
static void fe51_copy(fe51 h, const fe51 f)
{
h[0] = f[0];
h[1] = f[1];
h[2] = f[2];
h[3] = f[3];
h[4] = f[4];
}
static void fe51_cswap(fe51 f, fe51 g, unsigned int b)
{
int i;
uint64_t mask = 0 - (uint64_t)b;
for (i = 0; i < 5; i++) {
int64_t x = f[i] ^ g[i];
x &= mask;
f[i] ^= x;
g[i] ^= x;
}
}
static void fe51_invert(fe51 out, const fe51 z)
{
fe51 t0;
fe51 t1;
fe51 t2;
fe51 t3;
int i;
/*
* Compute z ** -1 = z ** (2 ** 255 - 19 - 2) with the exponent as
* 2 ** 255 - 21 = (2 ** 5) * (2 ** 250 - 1) + 11.
*/
/* t0 = z ** 2 */
fe51_sq(t0, z);
/* t1 = t0 ** (2 ** 2) = z ** 8 */
fe51_sq(t1, t0);
fe51_sq(t1, t1);
/* t1 = z * t1 = z ** 9 */
fe51_mul(t1, z, t1);
/* t0 = t0 * t1 = z ** 11 -- stash t0 away for the end. */
fe51_mul(t0, t0, t1);
/* t2 = t0 ** 2 = z ** 22 */
fe51_sq(t2, t0);
/* t1 = t1 * t2 = z ** (2 ** 5 - 1) */
fe51_mul(t1, t1, t2);
/* t2 = t1 ** (2 ** 5) = z ** ((2 ** 5) * (2 ** 5 - 1)) */
fe51_sq(t2, t1);
for (i = 1; i < 5; ++i)
fe51_sq(t2, t2);
/* t1 = t1 * t2 = z ** ((2 ** 5 + 1) * (2 ** 5 - 1)) = z ** (2 ** 10 - 1) */
fe51_mul(t1, t2, t1);
/* Continuing similarly... */
/* t2 = z ** (2 ** 20 - 1) */
fe51_sq(t2, t1);
for (i = 1; i < 10; ++i)
fe51_sq(t2, t2);
fe51_mul(t2, t2, t1);
/* t2 = z ** (2 ** 40 - 1) */
fe51_sq(t3, t2);
for (i = 1; i < 20; ++i)
fe51_sq(t3, t3);
fe51_mul(t2, t3, t2);
/* t2 = z ** (2 ** 10) * (2 ** 40 - 1) */
for (i = 0; i < 10; ++i)
fe51_sq(t2, t2);
/* t1 = z ** (2 ** 50 - 1) */
fe51_mul(t1, t2, t1);
/* t2 = z ** (2 ** 100 - 1) */
fe51_sq(t2, t1);
for (i = 1; i < 50; ++i)
fe51_sq(t2, t2);
fe51_mul(t2, t2, t1);
/* t2 = z ** (2 ** 200 - 1) */
fe51_sq(t3, t2);
for (i = 1; i < 100; ++i)
fe51_sq(t3, t3);
fe51_mul(t2, t3, t2);
/* t2 = z ** ((2 ** 50) * (2 ** 200 - 1) */
for (i = 0; i < 50; ++i)
fe51_sq(t2, t2);
/* t1 = z ** (2 ** 250 - 1) */
fe51_mul(t1, t2, t1);
/* t1 = z ** ((2 ** 5) * (2 ** 250 - 1)) */
for (i = 0; i < 5; ++i)
fe51_sq(t1, t1);
/* Recall t0 = z ** 11; out = z ** (2 ** 255 - 21) */
fe51_mul(out, t1, t0);
}
/*
* Duplicate of original x25519_scalar_mult_generic, but using
* fe51_* subroutines.
*/
static void x25519_scalar_mult(uint8_t out[32], const uint8_t scalar[32],
const uint8_t point[32])
{
fe51 x1, x2, z2, x3, z3, tmp0, tmp1;
uint8_t e[32];
unsigned swap = 0;
int pos;
# ifdef BASE_2_64_IMPLEMENTED
if (x25519_fe64_eligible()) {
x25519_scalar_mulx(out, scalar, point);
return;
}
# endif
memcpy(e, scalar, 32);
e[0] &= 0xf8;
e[31] &= 0x7f;
e[31] |= 0x40;
fe51_frombytes(x1, point);
fe51_1(x2);
fe51_0(z2);
fe51_copy(x3, x1);
fe51_1(z3);
for (pos = 254; pos >= 0; --pos) {
unsigned int b = 1 & (e[pos / 8] >> (pos & 7));
swap ^= b;
fe51_cswap(x2, x3, swap);
fe51_cswap(z2, z3, swap);
swap = b;
fe51_sub(tmp0, x3, z3);
fe51_sub(tmp1, x2, z2);
fe51_add(x2, x2, z2);
fe51_add(z2, x3, z3);
fe51_mul(z3, tmp0, x2);
fe51_mul(z2, z2, tmp1);
fe51_sq(tmp0, tmp1);
fe51_sq(tmp1, x2);
fe51_add(x3, z3, z2);
fe51_sub(z2, z3, z2);
fe51_mul(x2, tmp1, tmp0);
fe51_sub(tmp1, tmp1, tmp0);
fe51_sq(z2, z2);
fe51_mul121666(z3, tmp1);
fe51_sq(x3, x3);
fe51_add(tmp0, tmp0, z3);
fe51_mul(z3, x1, z2);
fe51_mul(z2, tmp1, tmp0);
}
fe51_invert(z2, z2);
fe51_mul(x2, x2, z2);
fe51_tobytes(out, x2);
OPENSSL_cleanse(e, sizeof(e));
}
#endif
/*
* Reference base 2^25.5 implementation.
*/
/*
* This code is mostly taken from the ref10 version of Ed25519 in SUPERCOP
* 20141124 (http://bench.cr.yp.to/supercop.html).
*
* The field functions are shared by Ed25519 and X25519 where possible.
*/
/* fe means field element. Here the field is \Z/(2^255-19). An element t,
* entries t[0]...t[9], represents the integer t[0]+2^26 t[1]+2^51 t[2]+2^77
* t[3]+2^102 t[4]+...+2^230 t[9]. Bounds on each t[i] vary depending on
* context. */
typedef int32_t fe[10];
static const int64_t kBottom25Bits = 0x1ffffffLL;
static const int64_t kBottom26Bits = 0x3ffffffLL;
static const int64_t kTop39Bits = 0xfffffffffe000000LL;
static const int64_t kTop38Bits = 0xfffffffffc000000LL;
static uint64_t load_3(const uint8_t *in) {
uint64_t result;
result = (uint64_t)in[0];
result |= ((uint64_t)in[1]) << 8;
result |= ((uint64_t)in[2]) << 16;
return result;
}
static uint64_t load_4(const uint8_t *in) {
uint64_t result;
result = (uint64_t)in[0];
result |= ((uint64_t)in[1]) << 8;
result |= ((uint64_t)in[2]) << 16;
result |= ((uint64_t)in[3]) << 24;
return result;
}
static void fe_frombytes(fe h, const uint8_t *s) {
/* Ignores top bit of h. */
int64_t h0 = load_4(s);
int64_t h1 = load_3(s + 4) << 6;
int64_t h2 = load_3(s + 7) << 5;
int64_t h3 = load_3(s + 10) << 3;
int64_t h4 = load_3(s + 13) << 2;
int64_t h5 = load_4(s + 16);
int64_t h6 = load_3(s + 20) << 7;
int64_t h7 = load_3(s + 23) << 5;
int64_t h8 = load_3(s + 26) << 4;
int64_t h9 = (load_3(s + 29) & 8388607) << 2;
int64_t carry0;
int64_t carry1;
int64_t carry2;
int64_t carry3;
int64_t carry4;
int64_t carry5;
int64_t carry6;
int64_t carry7;
int64_t carry8;
int64_t carry9;
carry9 = h9 + (1 << 24); h0 += (carry9 >> 25) * 19; h9 -= carry9 & kTop39Bits;
carry1 = h1 + (1 << 24); h2 += carry1 >> 25; h1 -= carry1 & kTop39Bits;
carry3 = h3 + (1 << 24); h4 += carry3 >> 25; h3 -= carry3 & kTop39Bits;
carry5 = h5 + (1 << 24); h6 += carry5 >> 25; h5 -= carry5 & kTop39Bits;
carry7 = h7 + (1 << 24); h8 += carry7 >> 25; h7 -= carry7 & kTop39Bits;
carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
carry2 = h2 + (1 << 25); h3 += carry2 >> 26; h2 -= carry2 & kTop38Bits;
carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
carry6 = h6 + (1 << 25); h7 += carry6 >> 26; h6 -= carry6 & kTop38Bits;
carry8 = h8 + (1 << 25); h9 += carry8 >> 26; h8 -= carry8 & kTop38Bits;
h[0] = (int32_t)h0;
h[1] = (int32_t)h1;
h[2] = (int32_t)h2;
h[3] = (int32_t)h3;
h[4] = (int32_t)h4;
h[5] = (int32_t)h5;
h[6] = (int32_t)h6;
h[7] = (int32_t)h7;
h[8] = (int32_t)h8;
h[9] = (int32_t)h9;
}
/* Preconditions:
* |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
*
* Write p=2^255-19; q=floor(h/p).
* Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))).
*
* Proof:
* Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4.
* Also have |h-2^230 h9|<2^231 so |19 2^(-255)(h-2^230 h9)|<1/4.
*
* Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9).
* Then 0<y<1.
*
* Write r=h-pq.
* Have 0<=r<=p-1=2^255-20.
* Thus 0<=r+19(2^-255)r<r+19(2^-255)2^255<=2^255-1.
*
* Write x=r+19(2^-255)r+y.
* Then 0<x<2^255 so floor(2^(-255)x) = 0 so floor(q+2^(-255)x) = q.
*
* Have q+2^(-255)x = 2^(-255)(h + 19 2^(-25) h9 + 2^(-1))
* so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q. */
static void fe_tobytes(uint8_t *s, const fe h) {
int32_t h0 = h[0];
int32_t h1 = h[1];
int32_t h2 = h[2];
int32_t h3 = h[3];
int32_t h4 = h[4];
int32_t h5 = h[5];
int32_t h6 = h[6];
int32_t h7 = h[7];
int32_t h8 = h[8];
int32_t h9 = h[9];
int32_t q;
q = (19 * h9 + (((int32_t) 1) << 24)) >> 25;
q = (h0 + q) >> 26;
q = (h1 + q) >> 25;
q = (h2 + q) >> 26;
q = (h3 + q) >> 25;
q = (h4 + q) >> 26;
q = (h5 + q) >> 25;
q = (h6 + q) >> 26;
q = (h7 + q) >> 25;
q = (h8 + q) >> 26;
q = (h9 + q) >> 25;
/* Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. */
h0 += 19 * q;
/* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */
h1 += h0 >> 26; h0 &= kBottom26Bits;
h2 += h1 >> 25; h1 &= kBottom25Bits;
h3 += h2 >> 26; h2 &= kBottom26Bits;
h4 += h3 >> 25; h3 &= kBottom25Bits;
h5 += h4 >> 26; h4 &= kBottom26Bits;
h6 += h5 >> 25; h5 &= kBottom25Bits;
h7 += h6 >> 26; h6 &= kBottom26Bits;
h8 += h7 >> 25; h7 &= kBottom25Bits;
h9 += h8 >> 26; h8 &= kBottom26Bits;
h9 &= kBottom25Bits;
/* h10 = carry9 */
/* Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20.
* Have h0+...+2^230 h9 between 0 and 2^255-1;
* evidently 2^255 h10-2^255 q = 0.
* Goal: Output h0+...+2^230 h9. */
s[0] = (uint8_t)(h0 >> 0);
s[1] = (uint8_t)(h0 >> 8);
s[2] = (uint8_t)(h0 >> 16);
s[3] = (uint8_t)((h0 >> 24) | ((uint32_t)(h1) << 2));
s[4] = (uint8_t)(h1 >> 6);
s[5] = (uint8_t)(h1 >> 14);
s[6] = (uint8_t)((h1 >> 22) | ((uint32_t)(h2) << 3));
s[7] = (uint8_t)(h2 >> 5);
s[8] = (uint8_t)(h2 >> 13);
s[9] = (uint8_t)((h2 >> 21) | ((uint32_t)(h3) << 5));
s[10] = (uint8_t)(h3 >> 3);
s[11] = (uint8_t)(h3 >> 11);
s[12] = (uint8_t)((h3 >> 19) | ((uint32_t)(h4) << 6));
s[13] = (uint8_t)(h4 >> 2);
s[14] = (uint8_t)(h4 >> 10);
s[15] = (uint8_t)(h4 >> 18);
s[16] = (uint8_t)(h5 >> 0);
s[17] = (uint8_t)(h5 >> 8);
s[18] = (uint8_t)(h5 >> 16);
s[19] = (uint8_t)((h5 >> 24) | ((uint32_t)(h6) << 1));
s[20] = (uint8_t)(h6 >> 7);
s[21] = (uint8_t)(h6 >> 15);
s[22] = (uint8_t)((h6 >> 23) | ((uint32_t)(h7) << 3));
s[23] = (uint8_t)(h7 >> 5);
s[24] = (uint8_t)(h7 >> 13);
s[25] = (uint8_t)((h7 >> 21) | ((uint32_t)(h8) << 4));
s[26] = (uint8_t)(h8 >> 4);
s[27] = (uint8_t)(h8 >> 12);
s[28] = (uint8_t)((h8 >> 20) | ((uint32_t)(h9) << 6));
s[29] = (uint8_t)(h9 >> 2);
s[30] = (uint8_t)(h9 >> 10);
s[31] = (uint8_t)(h9 >> 18);
}
/* h = f */
static void fe_copy(fe h, const fe f) {
memmove(h, f, sizeof(int32_t) * 10);
}
/* h = 0 */
static void fe_0(fe h) { memset(h, 0, sizeof(int32_t) * 10); }
/* h = 1 */
static void fe_1(fe h) {
memset(h, 0, sizeof(int32_t) * 10);
h[0] = 1;
}
/* h = f + g
* Can overlap h with f or g.
*
* Preconditions:
* |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
* |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
*
* Postconditions:
* |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. */
static void fe_add(fe h, const fe f, const fe g) {
unsigned i;
for (i = 0; i < 10; i++) {
h[i] = f[i] + g[i];
}
}
/* h = f - g
* Can overlap h with f or g.
*
* Preconditions:
* |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
* |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
*
* Postconditions:
* |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. */
static void fe_sub(fe h, const fe f, const fe g) {
unsigned i;
for (i = 0; i < 10; i++) {
h[i] = f[i] - g[i];
}
}
/* h = f * g
* Can overlap h with f or g.
*
* Preconditions:
* |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
* |g| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
*
* Postconditions:
* |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
*
* Notes on implementation strategy:
*
* Using schoolbook multiplication.
* Karatsuba would save a little in some cost models.
*
* Most multiplications by 2 and 19 are 32-bit precomputations;
* cheaper than 64-bit postcomputations.
*
* There is one remaining multiplication by 19 in the carry chain;
* one *19 precomputation can be merged into this,
* but the resulting data flow is considerably less clean.
*
* There are 12 carries below.
* 10 of them are 2-way parallelizable and vectorizable.
* Can get away with 11 carries, but then data flow is much deeper.
*
* With tighter constraints on inputs can squeeze carries into int32. */
static void fe_mul(fe h, const fe f, const fe g) {
int32_t f0 = f[0];
int32_t f1 = f[1];
int32_t f2 = f[2];
int32_t f3 = f[3];
int32_t f4 = f[4];
int32_t f5 = f[5];
int32_t f6 = f[6];
int32_t f7 = f[7];
int32_t f8 = f[8];
int32_t f9 = f[9];
int32_t g0 = g[0];
int32_t g1 = g[1];
int32_t g2 = g[2];
int32_t g3 = g[3];
int32_t g4 = g[4];
int32_t g5 = g[5];
int32_t g6 = g[6];
int32_t g7 = g[7];
int32_t g8 = g[8];
int32_t g9 = g[9];
int32_t g1_19 = 19 * g1; /* 1.959375*2^29 */
int32_t g2_19 = 19 * g2; /* 1.959375*2^30; still ok */
int32_t g3_19 = 19 * g3;
int32_t g4_19 = 19 * g4;
int32_t g5_19 = 19 * g5;
int32_t g6_19 = 19 * g6;
int32_t g7_19 = 19 * g7;
int32_t g8_19 = 19 * g8;
int32_t g9_19 = 19 * g9;
int32_t f1_2 = 2 * f1;
int32_t f3_2 = 2 * f3;
int32_t f5_2 = 2 * f5;
int32_t f7_2 = 2 * f7;
int32_t f9_2 = 2 * f9;
int64_t f0g0 = f0 * (int64_t) g0;
int64_t f0g1 = f0 * (int64_t) g1;
int64_t f0g2 = f0 * (int64_t) g2;
int64_t f0g3 = f0 * (int64_t) g3;
int64_t f0g4 = f0 * (int64_t) g4;
int64_t f0g5 = f0 * (int64_t) g5;
int64_t f0g6 = f0 * (int64_t) g6;
int64_t f0g7 = f0 * (int64_t) g7;
int64_t f0g8 = f0 * (int64_t) g8;
int64_t f0g9 = f0 * (int64_t) g9;
int64_t f1g0 = f1 * (int64_t) g0;
int64_t f1g1_2 = f1_2 * (int64_t) g1;
int64_t f1g2 = f1 * (int64_t) g2;
int64_t f1g3_2 = f1_2 * (int64_t) g3;
int64_t f1g4 = f1 * (int64_t) g4;
int64_t f1g5_2 = f1_2 * (int64_t) g5;
int64_t f1g6 = f1 * (int64_t) g6;
int64_t f1g7_2 = f1_2 * (int64_t) g7;
int64_t f1g8 = f1 * (int64_t) g8;
int64_t f1g9_38 = f1_2 * (int64_t) g9_19;
int64_t f2g0 = f2 * (int64_t) g0;
int64_t f2g1 = f2 * (int64_t) g1;
int64_t f2g2 = f2 * (int64_t) g2;
int64_t f2g3 = f2 * (int64_t) g3;
int64_t f2g4 = f2 * (int64_t) g4;
int64_t f2g5 = f2 * (int64_t) g5;
int64_t f2g6 = f2 * (int64_t) g6;
int64_t f2g7 = f2 * (int64_t) g7;
int64_t f2g8_19 = f2 * (int64_t) g8_19;
int64_t f2g9_19 = f2 * (int64_t) g9_19;
int64_t f3g0 = f3 * (int64_t) g0;
int64_t f3g1_2 = f3_2 * (int64_t) g1;
int64_t f3g2 = f3 * (int64_t) g2;
int64_t f3g3_2 = f3_2 * (int64_t) g3;
int64_t f3g4 = f3 * (int64_t) g4;
int64_t f3g5_2 = f3_2 * (int64_t) g5;
int64_t f3g6 = f3 * (int64_t) g6;
int64_t f3g7_38 = f3_2 * (int64_t) g7_19;
int64_t f3g8_19 = f3 * (int64_t) g8_19;
int64_t f3g9_38 = f3_2 * (int64_t) g9_19;
int64_t f4g0 = f4 * (int64_t) g0;
int64_t f4g1 = f4 * (int64_t) g1;
int64_t f4g2 = f4 * (int64_t) g2;
int64_t f4g3 = f4 * (int64_t) g3;
int64_t f4g4 = f4 * (int64_t) g4;
int64_t f4g5 = f4 * (int64_t) g5;
int64_t f4g6_19 = f4 * (int64_t) g6_19;
int64_t f4g7_19 = f4 * (int64_t) g7_19;
int64_t f4g8_19 = f4 * (int64_t) g8_19;
int64_t f4g9_19 = f4 * (int64_t) g9_19;
int64_t f5g0 = f5 * (int64_t) g0;
int64_t f5g1_2 = f5_2 * (int64_t) g1;
int64_t f5g2 = f5 * (int64_t) g2;
int64_t f5g3_2 = f5_2 * (int64_t) g3;
int64_t f5g4 = f5 * (int64_t) g4;
int64_t f5g5_38 = f5_2 * (int64_t) g5_19;
int64_t f5g6_19 = f5 * (int64_t) g6_19;
int64_t f5g7_38 = f5_2 * (int64_t) g7_19;
int64_t f5g8_19 = f5 * (int64_t) g8_19;
int64_t f5g9_38 = f5_2 * (int64_t) g9_19;
int64_t f6g0 = f6 * (int64_t) g0;
int64_t f6g1 = f6 * (int64_t) g1;
int64_t f6g2 = f6 * (int64_t) g2;
int64_t f6g3 = f6 * (int64_t) g3;
int64_t f6g4_19 = f6 * (int64_t) g4_19;
int64_t f6g5_19 = f6 * (int64_t) g5_19;
int64_t f6g6_19 = f6 * (int64_t) g6_19;
int64_t f6g7_19 = f6 * (int64_t) g7_19;
int64_t f6g8_19 = f6 * (int64_t) g8_19;
int64_t f6g9_19 = f6 * (int64_t) g9_19;
int64_t f7g0 = f7 * (int64_t) g0;
int64_t f7g1_2 = f7_2 * (int64_t) g1;
int64_t f7g2 = f7 * (int64_t) g2;
int64_t f7g3_38 = f7_2 * (int64_t) g3_19;
int64_t f7g4_19 = f7 * (int64_t) g4_19;
int64_t f7g5_38 = f7_2 * (int64_t) g5_19;
int64_t f7g6_19 = f7 * (int64_t) g6_19;
int64_t f7g7_38 = f7_2 * (int64_t) g7_19;
int64_t f7g8_19 = f7 * (int64_t) g8_19;
int64_t f7g9_38 = f7_2 * (int64_t) g9_19;
int64_t f8g0 = f8 * (int64_t) g0;
int64_t f8g1 = f8 * (int64_t) g1;
int64_t f8g2_19 = f8 * (int64_t) g2_19;
int64_t f8g3_19 = f8 * (int64_t) g3_19;
int64_t f8g4_19 = f8 * (int64_t) g4_19;
int64_t f8g5_19 = f8 * (int64_t) g5_19;
int64_t f8g6_19 = f8 * (int64_t) g6_19;
int64_t f8g7_19 = f8 * (int64_t) g7_19;
int64_t f8g8_19 = f8 * (int64_t) g8_19;
int64_t f8g9_19 = f8 * (int64_t) g9_19;
int64_t f9g0 = f9 * (int64_t) g0;
int64_t f9g1_38 = f9_2 * (int64_t) g1_19;
int64_t f9g2_19 = f9 * (int64_t) g2_19;
int64_t f9g3_38 = f9_2 * (int64_t) g3_19;
int64_t f9g4_19 = f9 * (int64_t) g4_19;
int64_t f9g5_38 = f9_2 * (int64_t) g5_19;
int64_t f9g6_19 = f9 * (int64_t) g6_19;
int64_t f9g7_38 = f9_2 * (int64_t) g7_19;
int64_t f9g8_19 = f9 * (int64_t) g8_19;
int64_t f9g9_38 = f9_2 * (int64_t) g9_19;
int64_t h0 = f0g0+f1g9_38+f2g8_19+f3g7_38+f4g6_19+f5g5_38+f6g4_19+f7g3_38+f8g2_19+f9g1_38;
int64_t h1 = f0g1+f1g0 +f2g9_19+f3g8_19+f4g7_19+f5g6_19+f6g5_19+f7g4_19+f8g3_19+f9g2_19;
int64_t h2 = f0g2+f1g1_2 +f2g0 +f3g9_38+f4g8_19+f5g7_38+f6g6_19+f7g5_38+f8g4_19+f9g3_38;
int64_t h3 = f0g3+f1g2 +f2g1 +f3g0 +f4g9_19+f5g8_19+f6g7_19+f7g6_19+f8g5_19+f9g4_19;
int64_t h4 = f0g4+f1g3_2 +f2g2 +f3g1_2 +f4g0 +f5g9_38+f6g8_19+f7g7_38+f8g6_19+f9g5_38;
int64_t h5 = f0g5+f1g4 +f2g3 +f3g2 +f4g1 +f5g0 +f6g9_19+f7g8_19+f8g7_19+f9g6_19;
int64_t h6 = f0g6+f1g5_2 +f2g4 +f3g3_2 +f4g2 +f5g1_2 +f6g0 +f7g9_38+f8g8_19+f9g7_38;
int64_t h7 = f0g7+f1g6 +f2g5 +f3g4 +f4g3 +f5g2 +f6g1 +f7g0 +f8g9_19+f9g8_19;
int64_t h8 = f0g8+f1g7_2 +f2g6 +f3g5_2 +f4g4 +f5g3_2 +f6g2 +f7g1_2 +f8g0 +f9g9_38;
int64_t h9 = f0g9+f1g8 +f2g7 +f3g6 +f4g5 +f5g4 +f6g3 +f7g2 +f8g1 +f9g0 ;
int64_t carry0;
int64_t carry1;
int64_t carry2;
int64_t carry3;
int64_t carry4;
int64_t carry5;
int64_t carry6;
int64_t carry7;
int64_t carry8;
int64_t carry9;
/* |h0| <= (1.65*1.65*2^52*(1+19+19+19+19)+1.65*1.65*2^50*(38+38+38+38+38))
* i.e. |h0| <= 1.4*2^60; narrower ranges for h2, h4, h6, h8
* |h1| <= (1.65*1.65*2^51*(1+1+19+19+19+19+19+19+19+19))
* i.e. |h1| <= 1.7*2^59; narrower ranges for h3, h5, h7, h9 */
carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
/* |h0| <= 2^25 */
/* |h4| <= 2^25 */
/* |h1| <= 1.71*2^59 */
/* |h5| <= 1.71*2^59 */
carry1 = h1 + (1 << 24); h2 += carry1 >> 25; h1 -= carry1 & kTop39Bits;
carry5 = h5 + (1 << 24); h6 += carry5 >> 25; h5 -= carry5 & kTop39Bits;
/* |h1| <= 2^24; from now on fits into int32 */
/* |h5| <= 2^24; from now on fits into int32 */
/* |h2| <= 1.41*2^60 */
/* |h6| <= 1.41*2^60 */
carry2 = h2 + (1 << 25); h3 += carry2 >> 26; h2 -= carry2 & kTop38Bits;
carry6 = h6 + (1 << 25); h7 += carry6 >> 26; h6 -= carry6 & kTop38Bits;
/* |h2| <= 2^25; from now on fits into int32 unchanged */
/* |h6| <= 2^25; from now on fits into int32 unchanged */
/* |h3| <= 1.71*2^59 */
/* |h7| <= 1.71*2^59 */
carry3 = h3 + (1 << 24); h4 += carry3 >> 25; h3 -= carry3 & kTop39Bits;
carry7 = h7 + (1 << 24); h8 += carry7 >> 25; h7 -= carry7 & kTop39Bits;
/* |h3| <= 2^24; from now on fits into int32 unchanged */
/* |h7| <= 2^24; from now on fits into int32 unchanged */
/* |h4| <= 1.72*2^34 */
/* |h8| <= 1.41*2^60 */
carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
carry8 = h8 + (1 << 25); h9 += carry8 >> 26; h8 -= carry8 & kTop38Bits;
/* |h4| <= 2^25; from now on fits into int32 unchanged */
/* |h8| <= 2^25; from now on fits into int32 unchanged */
/* |h5| <= 1.01*2^24 */
/* |h9| <= 1.71*2^59 */
carry9 = h9 + (1 << 24); h0 += (carry9 >> 25) * 19; h9 -= carry9 & kTop39Bits;
/* |h9| <= 2^24; from now on fits into int32 unchanged */
/* |h0| <= 1.1*2^39 */
carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
/* |h0| <= 2^25; from now on fits into int32 unchanged */
/* |h1| <= 1.01*2^24 */
h[0] = (int32_t)h0;
h[1] = (int32_t)h1;
h[2] = (int32_t)h2;
h[3] = (int32_t)h3;
h[4] = (int32_t)h4;
h[5] = (int32_t)h5;
h[6] = (int32_t)h6;
h[7] = (int32_t)h7;
h[8] = (int32_t)h8;
h[9] = (int32_t)h9;
}
/* h = f * f
* Can overlap h with f.
*
* Preconditions:
* |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
*
* Postconditions:
* |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
*
* See fe_mul.c for discussion of implementation strategy. */
static void fe_sq(fe h, const fe f) {
int32_t f0 = f[0];
int32_t f1 = f[1];
int32_t f2 = f[2];
int32_t f3 = f[3];
int32_t f4 = f[4];
int32_t f5 = f[5];
int32_t f6 = f[6];
int32_t f7 = f[7];
int32_t f8 = f[8];
int32_t f9 = f[9];
int32_t f0_2 = 2 * f0;
int32_t f1_2 = 2 * f1;
int32_t f2_2 = 2 * f2;
int32_t f3_2 = 2 * f3;
int32_t f4_2 = 2 * f4;
int32_t f5_2 = 2 * f5;
int32_t f6_2 = 2 * f6;
int32_t f7_2 = 2 * f7;
int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */
int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */
int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */
int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */
int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */
int64_t f0f0 = f0 * (int64_t) f0;
int64_t f0f1_2 = f0_2 * (int64_t) f1;
int64_t f0f2_2 = f0_2 * (int64_t) f2;
int64_t f0f3_2 = f0_2 * (int64_t) f3;
int64_t f0f4_2 = f0_2 * (int64_t) f4;
int64_t f0f5_2 = f0_2 * (int64_t) f5;
int64_t f0f6_2 = f0_2 * (int64_t) f6;
int64_t f0f7_2 = f0_2 * (int64_t) f7;
int64_t f0f8_2 = f0_2 * (int64_t) f8;
int64_t f0f9_2 = f0_2 * (int64_t) f9;
int64_t f1f1_2 = f1_2 * (int64_t) f1;
int64_t f1f2_2 = f1_2 * (int64_t) f2;
int64_t f1f3_4 = f1_2 * (int64_t) f3_2;
int64_t f1f4_2 = f1_2 * (int64_t) f4;
int64_t f1f5_4 = f1_2 * (int64_t) f5_2;
int64_t f1f6_2 = f1_2 * (int64_t) f6;
int64_t f1f7_4 = f1_2 * (int64_t) f7_2;
int64_t f1f8_2 = f1_2 * (int64_t) f8;
int64_t f1f9_76 = f1_2 * (int64_t) f9_38;
int64_t f2f2 = f2 * (int64_t) f2;
int64_t f2f3_2 = f2_2 * (int64_t) f3;
int64_t f2f4_2 = f2_2 * (int64_t) f4;
int64_t f2f5_2 = f2_2 * (int64_t) f5;
int64_t f2f6_2 = f2_2 * (int64_t) f6;
int64_t f2f7_2 = f2_2 * (int64_t) f7;
int64_t f2f8_38 = f2_2 * (int64_t) f8_19;
int64_t f2f9_38 = f2 * (int64_t) f9_38;
int64_t f3f3_2 = f3_2 * (int64_t) f3;
int64_t f3f4_2 = f3_2 * (int64_t) f4;
int64_t f3f5_4 = f3_2 * (int64_t) f5_2;
int64_t f3f6_2 = f3_2 * (int64_t) f6;
int64_t f3f7_76 = f3_2 * (int64_t) f7_38;
int64_t f3f8_38 = f3_2 * (int64_t) f8_19;
int64_t f3f9_76 = f3_2 * (int64_t) f9_38;
int64_t f4f4 = f4 * (int64_t) f4;
int64_t f4f5_2 = f4_2 * (int64_t) f5;
int64_t f4f6_38 = f4_2 * (int64_t) f6_19;
int64_t f4f7_38 = f4 * (int64_t) f7_38;
int64_t f4f8_38 = f4_2 * (int64_t) f8_19;
int64_t f4f9_38 = f4 * (int64_t) f9_38;
int64_t f5f5_38 = f5 * (int64_t) f5_38;
int64_t f5f6_38 = f5_2 * (int64_t) f6_19;
int64_t f5f7_76 = f5_2 * (int64_t) f7_38;
int64_t f5f8_38 = f5_2 * (int64_t) f8_19;
int64_t f5f9_76 = f5_2 * (int64_t) f9_38;
int64_t f6f6_19 = f6 * (int64_t) f6_19;
int64_t f6f7_38 = f6 * (int64_t) f7_38;
int64_t f6f8_38 = f6_2 * (int64_t) f8_19;
int64_t f6f9_38 = f6 * (int64_t) f9_38;
int64_t f7f7_38 = f7 * (int64_t) f7_38;
int64_t f7f8_38 = f7_2 * (int64_t) f8_19;
int64_t f7f9_76 = f7_2 * (int64_t) f9_38;
int64_t f8f8_19 = f8 * (int64_t) f8_19;
int64_t f8f9_38 = f8 * (int64_t) f9_38;
int64_t f9f9_38 = f9 * (int64_t) f9_38;
int64_t h0 = f0f0 +f1f9_76+f2f8_38+f3f7_76+f4f6_38+f5f5_38;
int64_t h1 = f0f1_2+f2f9_38+f3f8_38+f4f7_38+f5f6_38;
int64_t h2 = f0f2_2+f1f1_2 +f3f9_76+f4f8_38+f5f7_76+f6f6_19;
int64_t h3 = f0f3_2+f1f2_2 +f4f9_38+f5f8_38+f6f7_38;
int64_t h4 = f0f4_2+f1f3_4 +f2f2 +f5f9_76+f6f8_38+f7f7_38;
int64_t h5 = f0f5_2+f1f4_2 +f2f3_2 +f6f9_38+f7f8_38;
int64_t h6 = f0f6_2+f1f5_4 +f2f4_2 +f3f3_2 +f7f9_76+f8f8_19;
int64_t h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38;
int64_t h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4 +f9f9_38;
int64_t h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2;
int64_t carry0;
int64_t carry1;
int64_t carry2;
int64_t carry3;
int64_t carry4;
int64_t carry5;
int64_t carry6;
int64_t carry7;
int64_t carry8;
int64_t carry9;
carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
carry1 = h1 + (1 << 24); h2 += carry1 >> 25; h1 -= carry1 & kTop39Bits;
carry5 = h5 + (1 << 24); h6 += carry5 >> 25; h5 -= carry5 & kTop39Bits;
carry2 = h2 + (1 << 25); h3 += carry2 >> 26; h2 -= carry2 & kTop38Bits;
carry6 = h6 + (1 << 25); h7 += carry6 >> 26; h6 -= carry6 & kTop38Bits;
carry3 = h3 + (1 << 24); h4 += carry3 >> 25; h3 -= carry3 & kTop39Bits;
carry7 = h7 + (1 << 24); h8 += carry7 >> 25; h7 -= carry7 & kTop39Bits;
carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
carry8 = h8 + (1 << 25); h9 += carry8 >> 26; h8 -= carry8 & kTop38Bits;
carry9 = h9 + (1 << 24); h0 += (carry9 >> 25) * 19; h9 -= carry9 & kTop39Bits;
carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
h[0] = (int32_t)h0;
h[1] = (int32_t)h1;
h[2] = (int32_t)h2;
h[3] = (int32_t)h3;
h[4] = (int32_t)h4;
h[5] = (int32_t)h5;
h[6] = (int32_t)h6;
h[7] = (int32_t)h7;
h[8] = (int32_t)h8;
h[9] = (int32_t)h9;
}
static void fe_invert(fe out, const fe z) {
fe t0;
fe t1;
fe t2;
fe t3;
int i;
/*
* Compute z ** -1 = z ** (2 ** 255 - 19 - 2) with the exponent as
* 2 ** 255 - 21 = (2 ** 5) * (2 ** 250 - 1) + 11.
*/
/* t0 = z ** 2 */
fe_sq(t0, z);
/* t1 = t0 ** (2 ** 2) = z ** 8 */
fe_sq(t1, t0);
fe_sq(t1, t1);
/* t1 = z * t1 = z ** 9 */
fe_mul(t1, z, t1);
/* t0 = t0 * t1 = z ** 11 -- stash t0 away for the end. */
fe_mul(t0, t0, t1);
/* t2 = t0 ** 2 = z ** 22 */
fe_sq(t2, t0);
/* t1 = t1 * t2 = z ** (2 ** 5 - 1) */
fe_mul(t1, t1, t2);
/* t2 = t1 ** (2 ** 5) = z ** ((2 ** 5) * (2 ** 5 - 1)) */
fe_sq(t2, t1);
for (i = 1; i < 5; ++i) {
fe_sq(t2, t2);
}
/* t1 = t1 * t2 = z ** ((2 ** 5 + 1) * (2 ** 5 - 1)) = z ** (2 ** 10 - 1) */
fe_mul(t1, t2, t1);
/* Continuing similarly... */
/* t2 = z ** (2 ** 20 - 1) */
fe_sq(t2, t1);
for (i = 1; i < 10; ++i) {
fe_sq(t2, t2);
}
fe_mul(t2, t2, t1);
/* t2 = z ** (2 ** 40 - 1) */
fe_sq(t3, t2);
for (i = 1; i < 20; ++i) {
fe_sq(t3, t3);
}
fe_mul(t2, t3, t2);
/* t2 = z ** (2 ** 10) * (2 ** 40 - 1) */
for (i = 0; i < 10; ++i) {
fe_sq(t2, t2);
}
/* t1 = z ** (2 ** 50 - 1) */
fe_mul(t1, t2, t1);
/* t2 = z ** (2 ** 100 - 1) */
fe_sq(t2, t1);
for (i = 1; i < 50; ++i) {
fe_sq(t2, t2);
}
fe_mul(t2, t2, t1);
/* t2 = z ** (2 ** 200 - 1) */
fe_sq(t3, t2);
for (i = 1; i < 100; ++i) {
fe_sq(t3, t3);
}
fe_mul(t2, t3, t2);
/* t2 = z ** ((2 ** 50) * (2 ** 200 - 1) */
fe_sq(t2, t2);
for (i = 1; i < 50; ++i) {
fe_sq(t2, t2);
}
/* t1 = z ** (2 ** 250 - 1) */
fe_mul(t1, t2, t1);
/* t1 = z ** ((2 ** 5) * (2 ** 250 - 1)) */
fe_sq(t1, t1);
for (i = 1; i < 5; ++i) {
fe_sq(t1, t1);
}
/* Recall t0 = z ** 11; out = z ** (2 ** 255 - 21) */
fe_mul(out, t1, t0);
}
/* h = -f
*
* Preconditions:
* |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
*
* Postconditions:
* |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. */
static void fe_neg(fe h, const fe f) {
unsigned i;
for (i = 0; i < 10; i++) {
h[i] = -f[i];
}
}
/* Replace (f,g) with (g,g) if b == 1;
* replace (f,g) with (f,g) if b == 0.
*
* Preconditions: b in {0,1}. */
static void fe_cmov(fe f, const fe g, unsigned b) {
size_t i;
b = 0-b;
for (i = 0; i < 10; i++) {
int32_t x = f[i] ^ g[i];
x &= b;
f[i] ^= x;
}
}
/* return 0 if f == 0
* return 1 if f != 0
*
* Preconditions:
* |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. */
static int fe_isnonzero(const fe f) {
uint8_t s[32];
static const uint8_t zero[32] = {0};
fe_tobytes(s, f);
return CRYPTO_memcmp(s, zero, sizeof(zero)) != 0;
}
/* return 1 if f is in {1,3,5,...,q-2}
* return 0 if f is in {0,2,4,...,q-1}
*
* Preconditions:
* |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. */
static int fe_isnegative(const fe f) {
uint8_t s[32];
fe_tobytes(s, f);
return s[0] & 1;
}
/* h = 2 * f * f
* Can overlap h with f.
*
* Preconditions:
* |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
*
* Postconditions:
* |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
*
* See fe_mul.c for discussion of implementation strategy. */
static void fe_sq2(fe h, const fe f) {
int32_t f0 = f[0];
int32_t f1 = f[1];
int32_t f2 = f[2];
int32_t f3 = f[3];
int32_t f4 = f[4];
int32_t f5 = f[5];
int32_t f6 = f[6];
int32_t f7 = f[7];
int32_t f8 = f[8];
int32_t f9 = f[9];
int32_t f0_2 = 2 * f0;
int32_t f1_2 = 2 * f1;
int32_t f2_2 = 2 * f2;
int32_t f3_2 = 2 * f3;
int32_t f4_2 = 2 * f4;
int32_t f5_2 = 2 * f5;
int32_t f6_2 = 2 * f6;
int32_t f7_2 = 2 * f7;
int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */
int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */
int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */
int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */
int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */
int64_t f0f0 = f0 * (int64_t) f0;
int64_t f0f1_2 = f0_2 * (int64_t) f1;
int64_t f0f2_2 = f0_2 * (int64_t) f2;
int64_t f0f3_2 = f0_2 * (int64_t) f3;
int64_t f0f4_2 = f0_2 * (int64_t) f4;
int64_t f0f5_2 = f0_2 * (int64_t) f5;
int64_t f0f6_2 = f0_2 * (int64_t) f6;
int64_t f0f7_2 = f0_2 * (int64_t) f7;
int64_t f0f8_2 = f0_2 * (int64_t) f8;
int64_t f0f9_2 = f0_2 * (int64_t) f9;
int64_t f1f1_2 = f1_2 * (int64_t) f1;
int64_t f1f2_2 = f1_2 * (int64_t) f2;
int64_t f1f3_4 = f1_2 * (int64_t) f3_2;
int64_t f1f4_2 = f1_2 * (int64_t) f4;
int64_t f1f5_4 = f1_2 * (int64_t) f5_2;
int64_t f1f6_2 = f1_2 * (int64_t) f6;
int64_t f1f7_4 = f1_2 * (int64_t) f7_2;
int64_t f1f8_2 = f1_2 * (int64_t) f8;
int64_t f1f9_76 = f1_2 * (int64_t) f9_38;
int64_t f2f2 = f2 * (int64_t) f2;
int64_t f2f3_2 = f2_2 * (int64_t) f3;
int64_t f2f4_2 = f2_2 * (int64_t) f4;
int64_t f2f5_2 = f2_2 * (int64_t) f5;
int64_t f2f6_2 = f2_2 * (int64_t) f6;
int64_t f2f7_2 = f2_2 * (int64_t) f7;
int64_t f2f8_38 = f2_2 * (int64_t) f8_19;
int64_t f2f9_38 = f2 * (int64_t) f9_38;
int64_t f3f3_2 = f3_2 * (int64_t) f3;
int64_t f3f4_2 = f3_2 * (int64_t) f4;
int64_t f3f5_4 = f3_2 * (int64_t) f5_2;
int64_t f3f6_2 = f3_2 * (int64_t) f6;
int64_t f3f7_76 = f3_2 * (int64_t) f7_38;
int64_t f3f8_38 = f3_2 * (int64_t) f8_19;
int64_t f3f9_76 = f3_2 * (int64_t) f9_38;
int64_t f4f4 = f4 * (int64_t) f4;
int64_t f4f5_2 = f4_2 * (int64_t) f5;
int64_t f4f6_38 = f4_2 * (int64_t) f6_19;
int64_t f4f7_38 = f4 * (int64_t) f7_38;
int64_t f4f8_38 = f4_2 * (int64_t) f8_19;
int64_t f4f9_38 = f4 * (int64_t) f9_38;
int64_t f5f5_38 = f5 * (int64_t) f5_38;
int64_t f5f6_38 = f5_2 * (int64_t) f6_19;
int64_t f5f7_76 = f5_2 * (int64_t) f7_38;
int64_t f5f8_38 = f5_2 * (int64_t) f8_19;
int64_t f5f9_76 = f5_2 * (int64_t) f9_38;
int64_t f6f6_19 = f6 * (int64_t) f6_19;
int64_t f6f7_38 = f6 * (int64_t) f7_38;
int64_t f6f8_38 = f6_2 * (int64_t) f8_19;
int64_t f6f9_38 = f6 * (int64_t) f9_38;
int64_t f7f7_38 = f7 * (int64_t) f7_38;
int64_t f7f8_38 = f7_2 * (int64_t) f8_19;
int64_t f7f9_76 = f7_2 * (int64_t) f9_38;
int64_t f8f8_19 = f8 * (int64_t) f8_19;
int64_t f8f9_38 = f8 * (int64_t) f9_38;
int64_t f9f9_38 = f9 * (int64_t) f9_38;
int64_t h0 = f0f0 +f1f9_76+f2f8_38+f3f7_76+f4f6_38+f5f5_38;
int64_t h1 = f0f1_2+f2f9_38+f3f8_38+f4f7_38+f5f6_38;
int64_t h2 = f0f2_2+f1f1_2 +f3f9_76+f4f8_38+f5f7_76+f6f6_19;
int64_t h3 = f0f3_2+f1f2_2 +f4f9_38+f5f8_38+f6f7_38;
int64_t h4 = f0f4_2+f1f3_4 +f2f2 +f5f9_76+f6f8_38+f7f7_38;
int64_t h5 = f0f5_2+f1f4_2 +f2f3_2 +f6f9_38+f7f8_38;
int64_t h6 = f0f6_2+f1f5_4 +f2f4_2 +f3f3_2 +f7f9_76+f8f8_19;
int64_t h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38;
int64_t h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4 +f9f9_38;
int64_t h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2;
int64_t carry0;
int64_t carry1;
int64_t carry2;
int64_t carry3;
int64_t carry4;
int64_t carry5;
int64_t carry6;
int64_t carry7;
int64_t carry8;
int64_t carry9;
h0 += h0;
h1 += h1;
h2 += h2;
h3 += h3;
h4 += h4;
h5 += h5;
h6 += h6;
h7 += h7;
h8 += h8;
h9 += h9;
carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
carry1 = h1 + (1 << 24); h2 += carry1 >> 25; h1 -= carry1 & kTop39Bits;
carry5 = h5 + (1 << 24); h6 += carry5 >> 25; h5 -= carry5 & kTop39Bits;
carry2 = h2 + (1 << 25); h3 += carry2 >> 26; h2 -= carry2 & kTop38Bits;
carry6 = h6 + (1 << 25); h7 += carry6 >> 26; h6 -= carry6 & kTop38Bits;
carry3 = h3 + (1 << 24); h4 += carry3 >> 25; h3 -= carry3 & kTop39Bits;
carry7 = h7 + (1 << 24); h8 += carry7 >> 25; h7 -= carry7 & kTop39Bits;
carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
carry8 = h8 + (1 << 25); h9 += carry8 >> 26; h8 -= carry8 & kTop38Bits;
carry9 = h9 + (1 << 24); h0 += (carry9 >> 25) * 19; h9 -= carry9 & kTop39Bits;
carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
h[0] = (int32_t)h0;
h[1] = (int32_t)h1;
h[2] = (int32_t)h2;
h[3] = (int32_t)h3;
h[4] = (int32_t)h4;
h[5] = (int32_t)h5;
h[6] = (int32_t)h6;
h[7] = (int32_t)h7;
h[8] = (int32_t)h8;
h[9] = (int32_t)h9;
}
static void fe_pow22523(fe out, const fe z) {
fe t0;
fe t1;
fe t2;
int i;
fe_sq(t0, z);
fe_sq(t1, t0);
for (i = 1; i < 2; ++i) {
fe_sq(t1, t1);
}
fe_mul(t1, z, t1);
fe_mul(t0, t0, t1);
fe_sq(t0, t0);
fe_mul(t0, t1, t0);
fe_sq(t1, t0);
for (i = 1; i < 5; ++i) {
fe_sq(t1, t1);
}
fe_mul(t0, t1, t0);
fe_sq(t1, t0);
for (i = 1; i < 10; ++i) {
fe_sq(t1, t1);
}
fe_mul(t1, t1, t0);
fe_sq(t2, t1);
for (i = 1; i < 20; ++i) {
fe_sq(t2, t2);
}
fe_mul(t1, t2, t1);
fe_sq(t1, t1);
for (i = 1; i < 10; ++i) {
fe_sq(t1, t1);
}
fe_mul(t0, t1, t0);
fe_sq(t1, t0);
for (i = 1; i < 50; ++i) {
fe_sq(t1, t1);
}
fe_mul(t1, t1, t0);
fe_sq(t2, t1);
for (i = 1; i < 100; ++i) {
fe_sq(t2, t2);
}
fe_mul(t1, t2, t1);
fe_sq(t1, t1);
for (i = 1; i < 50; ++i) {
fe_sq(t1, t1);
}
fe_mul(t0, t1, t0);
fe_sq(t0, t0);
for (i = 1; i < 2; ++i) {
fe_sq(t0, t0);
}
fe_mul(out, t0, z);
}
/* ge means group element.
* Here the group is the set of pairs (x,y) of field elements (see fe.h)
* satisfying -x^2 + y^2 = 1 + d x^2y^2
* where d = -121665/121666.
*
* Representations:
* ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
* ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
* ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
* ge_precomp (Duif): (y+x,y-x,2dxy) */
typedef struct {
fe X;
fe Y;
fe Z;
} ge_p2;
typedef struct {
fe X;
fe Y;
fe Z;
fe T;
} ge_p3;
typedef struct {
fe X;
fe Y;
fe Z;
fe T;
} ge_p1p1;
typedef struct {
fe yplusx;
fe yminusx;
fe xy2d;
} ge_precomp;
typedef struct {
fe YplusX;
fe YminusX;
fe Z;
fe T2d;
} ge_cached;
static void ge_tobytes(uint8_t *s, const ge_p2 *h) {
fe recip;
fe x;
fe y;
fe_invert(recip, h->Z);
fe_mul(x, h->X, recip);
fe_mul(y, h->Y, recip);
fe_tobytes(s, y);
s[31] ^= fe_isnegative(x) << 7;
}
static void ge_p3_tobytes(uint8_t *s, const ge_p3 *h) {
fe recip;
fe x;
fe y;
fe_invert(recip, h->Z);
fe_mul(x, h->X, recip);
fe_mul(y, h->Y, recip);
fe_tobytes(s, y);
s[31] ^= fe_isnegative(x) << 7;
}
static const fe d = {-10913610, 13857413, -15372611, 6949391, 114729,
-8787816, -6275908, -3247719, -18696448, -12055116};
static const fe sqrtm1 = {-32595792, -7943725, 9377950, 3500415, 12389472,
-272473, -25146209, -2005654, 326686, 11406482};
static int ge_frombytes_vartime(ge_p3 *h, const uint8_t *s) {
fe u;
fe v;
fe v3;
fe vxx;
fe check;
fe_frombytes(h->Y, s);
fe_1(h->Z);
fe_sq(u, h->Y);
fe_mul(v, u, d);
fe_sub(u, u, h->Z); /* u = y^2-1 */
fe_add(v, v, h->Z); /* v = dy^2+1 */
fe_sq(v3, v);
fe_mul(v3, v3, v); /* v3 = v^3 */
fe_sq(h->X, v3);
fe_mul(h->X, h->X, v);
fe_mul(h->X, h->X, u); /* x = uv^7 */
fe_pow22523(h->X, h->X); /* x = (uv^7)^((q-5)/8) */
fe_mul(h->X, h->X, v3);
fe_mul(h->X, h->X, u); /* x = uv^3(uv^7)^((q-5)/8) */
fe_sq(vxx, h->X);
fe_mul(vxx, vxx, v);
fe_sub(check, vxx, u); /* vx^2-u */
if (fe_isnonzero(check)) {
fe_add(check, vxx, u); /* vx^2+u */
if (fe_isnonzero(check)) {
return -1;
}
fe_mul(h->X, h->X, sqrtm1);
}
if (fe_isnegative(h->X) != (s[31] >> 7)) {
fe_neg(h->X, h->X);
}
fe_mul(h->T, h->X, h->Y);
return 0;
}
static void ge_p2_0(ge_p2 *h) {
fe_0(h->X);
fe_1(h->Y);
fe_1(h->Z);
}
static void ge_p3_0(ge_p3 *h) {
fe_0(h->X);
fe_1(h->Y);
fe_1(h->Z);
fe_0(h->T);
}
static void ge_precomp_0(ge_precomp *h) {
fe_1(h->yplusx);
fe_1(h->yminusx);
fe_0(h->xy2d);
}
/* r = p */
static void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p) {
fe_copy(r->X, p->X);
fe_copy(r->Y, p->Y);
fe_copy(r->Z, p->Z);
}
static const fe d2 = {-21827239, -5839606, -30745221, 13898782, 229458,
15978800, -12551817, -6495438, 29715968, 9444199};
/* r = p */
static void ge_p3_to_cached(ge_cached *r, const ge_p3 *p) {
fe_add(r->YplusX, p->Y, p->X);
fe_sub(r->YminusX, p->Y, p->X);
fe_copy(r->Z, p->Z);
fe_mul(r->T2d, p->T, d2);
}
/* r = p */
static void ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p) {
fe_mul(r->X, p->X, p->T);
fe_mul(r->Y, p->Y, p->Z);
fe_mul(r->Z, p->Z, p->T);
}
/* r = p */
static void ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p) {
fe_mul(r->X, p->X, p->T);
fe_mul(r->Y, p->Y, p->Z);
fe_mul(r->Z, p->Z, p->T);
fe_mul(r->T, p->X, p->Y);
}
/* r = 2 * p */
static void ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p) {
fe t0;
fe_sq(r->X, p->X);
fe_sq(r->Z, p->Y);
fe_sq2(r->T, p->Z);
fe_add(r->Y, p->X, p->Y);
fe_sq(t0, r->Y);
fe_add(r->Y, r->Z, r->X);
fe_sub(r->Z, r->Z, r->X);
fe_sub(r->X, t0, r->Y);
fe_sub(r->T, r->T, r->Z);
}
/* r = 2 * p */
static void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p) {
ge_p2 q;
ge_p3_to_p2(&q, p);
ge_p2_dbl(r, &q);
}
/* r = p + q */
static void ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) {
fe t0;
fe_add(r->X, p->Y, p->X);
fe_sub(r->Y, p->Y, p->X);
fe_mul(r->Z, r->X, q->yplusx);
fe_mul(r->Y, r->Y, q->yminusx);
fe_mul(r->T, q->xy2d, p->T);
fe_add(t0, p->Z, p->Z);
fe_sub(r->X, r->Z, r->Y);
fe_add(r->Y, r->Z, r->Y);
fe_add(r->Z, t0, r->T);
fe_sub(r->T, t0, r->T);
}
/* r = p - q */
static void ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) {
fe t0;
fe_add(r->X, p->Y, p->X);
fe_sub(r->Y, p->Y, p->X);
fe_mul(r->Z, r->X, q->yminusx);
fe_mul(r->Y, r->Y, q->yplusx);
fe_mul(r->T, q->xy2d, p->T);
fe_add(t0, p->Z, p->Z);
fe_sub(r->X, r->Z, r->Y);
fe_add(r->Y, r->Z, r->Y);
fe_sub(r->Z, t0, r->T);
fe_add(r->T, t0, r->T);
}
/* r = p + q */
static void ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
fe t0;
fe_add(r->X, p->Y, p->X);
fe_sub(r->Y, p->Y, p->X);
fe_mul(r->Z, r->X, q->YplusX);
fe_mul(r->Y, r->Y, q->YminusX);
fe_mul(r->T, q->T2d, p->T);
fe_mul(r->X, p->Z, q->Z);
fe_add(t0, r->X, r->X);
fe_sub(r->X, r->Z, r->Y);
fe_add(r->Y, r->Z, r->Y);
fe_add(r->Z, t0, r->T);
fe_sub(r->T, t0, r->T);
}
/* r = p - q */
static void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
fe t0;
fe_add(r->X, p->Y, p->X);
fe_sub(r->Y, p->Y, p->X);
fe_mul(r->Z, r->X, q->YminusX);
fe_mul(r->Y, r->Y, q->YplusX);
fe_mul(r->T, q->T2d, p->T);
fe_mul(r->X, p->Z, q->Z);
fe_add(t0, r->X, r->X);
fe_sub(r->X, r->Z, r->Y);
fe_add(r->Y, r->Z, r->Y);
fe_sub(r->Z, t0, r->T);
fe_add(r->T, t0, r->T);
}
static uint8_t equal(signed char b, signed char c) {
uint8_t ub = b;
uint8_t uc = c;
uint8_t x = ub ^ uc; /* 0: yes; 1..255: no */
uint32_t y = x; /* 0: yes; 1..255: no */
y -= 1; /* 4294967295: yes; 0..254: no */
y >>= 31; /* 1: yes; 0: no */
return y;
}
static void cmov(ge_precomp *t, const ge_precomp *u, uint8_t b) {
fe_cmov(t->yplusx, u->yplusx, b);
fe_cmov(t->yminusx, u->yminusx, b);
fe_cmov(t->xy2d, u->xy2d, b);
}
/* k25519Precomp[i][j] = (j+1)*256^i*B */
static const ge_precomp k25519Precomp[32][8] = {
{
{
{25967493, -14356035, 29566456, 3660896, -12694345, 4014787,
27544626, -11754271, -6079156, 2047605},
{-12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692,
5043384, 19500929, -15469378},
{-8738181, 4489570, 9688441, -14785194, 10184609, -12363380,
29287919, 11864899, -24514362, -4438546},
},
{
{-12815894, -12976347, -21581243, 11784320, -25355658, -2750717,
-11717903, -3814571, -358445, -10211303},
{-21703237, 6903825, 27185491, 6451973, -29577724, -9554005,
-15616551, 11189268, -26829678, -5319081},
{26966642, 11152617, 32442495, 15396054, 14353839, -12752335,
-3128826, -9541118, -15472047, -4166697},
},
{
{15636291, -9688557, 24204773, -7912398, 616977, -16685262,
27787600, -14772189, 28944400, -1550024},
{16568933, 4717097, -11556148, -1102322, 15682896, -11807043,
16354577, -11775962, 7689662, 11199574},
{30464156, -5976125, -11779434, -15670865, 23220365, 15915852,
7512774, 10017326, -17749093, -9920357},
},
{
{-17036878, 13921892, 10945806, -6033431, 27105052, -16084379,
-28926210, 15006023, 3284568, -6276540},
{23599295, -8306047, -11193664, -7687416, 13236774, 10506355,
7464579, 9656445, 13059162, 10374397},
{7798556, 16710257, 3033922, 2874086, 28997861, 2835604, 32406664,
-3839045, -641708, -101325},
},
{
{10861363, 11473154, 27284546, 1981175, -30064349, 12577861,
32867885, 14515107, -15438304, 10819380},
{4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668,
12483688, -12668491, 5581306},
{19563160, 16186464, -29386857, 4097519, 10237984, -4348115,
28542350, 13850243, -23678021, -15815942},
},
{
{-15371964, -12862754, 32573250, 4720197, -26436522, 5875511,
-19188627, -15224819, -9818940, -12085777},
{-8549212, 109983, 15149363, 2178705, 22900618, 4543417, 3044240,
-15689887, 1762328, 14866737},
{-18199695, -15951423, -10473290, 1707278, -17185920, 3916101,
-28236412, 3959421, 27914454, 4383652},
},
{
{5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852,
5230134, -23952439, -15175766},
{-30269007, -3463509, 7665486, 10083793, 28475525, 1649722,
20654025, 16520125, 30598449, 7715701},
{28881845, 14381568, 9657904, 3680757, -20181635, 7843316,
-31400660, 1370708, 29794553, -1409300},
},
{
{14499471, -2729599, -33191113, -4254652, 28494862, 14271267,
30290735, 10876454, -33154098, 2381726},
{-7195431, -2655363, -14730155, 462251, -27724326, 3941372,
-6236617, 3696005, -32300832, 15351955},
{27431194, 8222322, 16448760, -3907995, -18707002, 11938355,
-32961401, -2970515, 29551813, 10109425},
},
},
{
{
{-13657040, -13155431, -31283750, 11777098, 21447386, 6519384,
-2378284, -1627556, 10092783, -4764171},
{27939166, 14210322, 4677035, 16277044, -22964462, -12398139,
-32508754, 12005538, -17810127, 12803510},
{17228999, -15661624, -1233527, 300140, -1224870, -11714777,
30364213, -9038194, 18016357, 4397660},
},
{
{-10958843, -7690207, 4776341, -14954238, 27850028, -15602212,
-26619106, 14544525, -17477504, 982639},
{29253598, 15796703, -2863982, -9908884, 10057023, 3163536, 7332899,
-4120128, -21047696, 9934963},
{5793303, 16271923, -24131614, -10116404, 29188560, 1206517,
-14747930, 4559895, -30123922, -10897950},
},
{
{-27643952, -11493006, 16282657, -11036493, 28414021, -15012264,
24191034, 4541697, -13338309, 5500568},
{12650548, -1497113, 9052871, 11355358, -17680037, -8400164,
-17430592, 12264343, 10874051, 13524335},
{25556948, -3045990, 714651, 2510400, 23394682, -10415330, 33119038,
5080568, -22528059, 5376628},
},
{
{-26088264, -4011052, -17013699, -3537628, -6726793, 1920897,
-22321305, -9447443, 4535768, 1569007},
{-2255422, 14606630, -21692440, -8039818, 28430649, 8775819,
-30494562, 3044290, 31848280, 12543772},
{-22028579, 2943893, -31857513, 6777306, 13784462, -4292203,
-27377195, -2062731, 7718482, 14474653},
},
{
{2385315, 2454213, -22631320, 46603, -4437935, -15680415, 656965,
-7236665, 24316168, -5253567},
{13741529, 10911568, -33233417, -8603737, -20177830, -1033297,
33040651, -13424532, -20729456, 8321686},
{21060490, -2212744, 15712757, -4336099, 1639040, 10656336,
23845965, -11874838, -9984458, 608372},
},
{
{-13672732, -15087586, -10889693, -7557059, -6036909, 11305547,
1123968, -6780577, 27229399, 23887},
{-23244140, -294205, -11744728, 14712571, -29465699, -2029617,
12797024, -6440308, -1633405, 16678954},
{-29500620, 4770662, -16054387, 14001338, 7830047, 9564805,
-1508144, -4795045, -17169265, 4904953},
},
{
{24059557, 14617003, 19037157, -15039908, 19766093, -14906429,
5169211, 16191880, 2128236, -4326833},
{-16981152, 4124966, -8540610, -10653797, 30336522, -14105247,
-29806336, 916033, -6882542, -2986532},
{-22630907, 12419372, -7134229, -7473371, -16478904, 16739175,
285431, 2763829, 15736322, 4143876},
},
{
{2379352, 11839345, -4110402, -5988665, 11274298, 794957, 212801,
-14594663, 23527084, -16458268},
{33431127, -11130478, -17838966, -15626900, 8909499, 8376530,
-32625340, 4087881, -15188911, -14416214},
{1767683, 7197987, -13205226, -2022635, -13091350, 448826, 5799055,
4357868, -4774191, -16323038},
},
},
{
{
{6721966, 13833823, -23523388, -1551314, 26354293, -11863321,
23365147, -3949732, 7390890, 2759800},
{4409041, 2052381, 23373853, 10530217, 7676779, -12885954, 21302353,
-4264057, 1244380, -12919645},
{-4421239, 7169619, 4982368, -2957590, 30256825, -2777540, 14086413,
9208236, 15886429, 16489664},
},
{
{1996075, 10375649, 14346367, 13311202, -6874135, -16438411,
-13693198, 398369, -30606455, -712933},
{-25307465, 9795880, -2777414, 14878809, -33531835, 14780363,
13348553, 12076947, -30836462, 5113182},
{-17770784, 11797796, 31950843, 13929123, -25888302, 12288344,
-30341101, -7336386, 13847711, 5387222},
},
{
{-18582163, -3416217, 17824843, -2340966, 22744343, -10442611,
8763061, 3617786, -19600662, 10370991},
{20246567, -14369378, 22358229, -543712, 18507283, -10413996,
14554437, -8746092, 32232924, 16763880},
{9648505, 10094563, 26416693, 14745928, -30374318, -6472621,
11094161, 15689506, 3140038, -16510092},
},
{
{-16160072, 5472695, 31895588, 4744994, 8823515, 10365685,
-27224800, 9448613, -28774454, 366295},
{19153450, 11523972, -11096490, -6503142, -24647631, 5420647,
28344573, 8041113, 719605, 11671788},
{8678025, 2694440, -6808014, 2517372, 4964326, 11152271, -15432916,
-15266516, 27000813, -10195553},
},
{
{-15157904, 7134312, 8639287, -2814877, -7235688, 10421742, 564065,
5336097, 6750977, -14521026},
{11836410, -3979488, 26297894, 16080799, 23455045, 15735944,
1695823, -8819122, 8169720, 16220347},
{-18115838, 8653647, 17578566, -6092619, -8025777, -16012763,
-11144307, -2627664, -5990708, -14166033},
},
{
{-23308498, -10968312, 15213228, -10081214, -30853605, -11050004,
27884329, 2847284, 2655861, 1738395},
{-27537433, -14253021, -25336301, -8002780, -9370762, 8129821,
21651608, -3239336, -19087449, -11005278},
{1533110, 3437855, 23735889, 459276, 29970501, 11335377, 26030092,
5821408, 10478196, 8544890},
},
{
{32173121, -16129311, 24896207, 3921497, 22579056, -3410854,
19270449, 12217473, 17789017, -3395995},
{-30552961, -2228401, -15578829, -10147201, 13243889, 517024,
15479401, -3853233, 30460520, 1052596},
{-11614875, 13323618, 32618793, 8175907, -15230173, 12596687,
27491595, -4612359, 3179268, -9478891},
},
{
{31947069, -14366651, -4640583, -15339921, -15125977, -6039709,
-14756777, -16411740, 19072640, -9511060},
{11685058, 11822410, 3158003, -13952594, 33402194, -4165066,
5977896, -5215017, 473099, 5040608},
{-20290863, 8198642, -27410132, 11602123, 1290375, -2799760,
28326862, 1721092, -19558642, -3131606},
},
},
{
{
{7881532, 10687937, 7578723, 7738378, -18951012, -2553952, 21820786,
8076149, -27868496, 11538389},
{-19935666, 3899861, 18283497, -6801568, -15728660, -11249211,
8754525, 7446702, -5676054, 5797016},
{-11295600, -3793569, -15782110, -7964573, 12708869, -8456199,
2014099, -9050574, -2369172, -5877341},
},
{
{-22472376, -11568741, -27682020, 1146375, 18956691, 16640559,
1192730, -3714199, 15123619, 10811505},
{14352098, -3419715, -18942044, 10822655, 32750596, 4699007, -70363,
15776356, -28886779, -11974553},
{-28241164, -8072475, -4978962, -5315317, 29416931, 1847569,
-20654173, -16484855, 4714547, -9600655},
},
{
{15200332, 8368572, 19679101, 15970074, -31872674, 1959451,
24611599, -4543832, -11745876, 12340220},
{12876937, -10480056, 33134381, 6590940, -6307776, 14872440,
9613953, 8241152, 15370987, 9608631},
{-4143277, -12014408, 8446281, -391603, 4407738, 13629032, -7724868,
15866074, -28210621, -8814099},
},
{
{26660628, -15677655, 8393734, 358047, -7401291, 992988, -23904233,
858697, 20571223, 8420556},
{14620715, 13067227, -15447274, 8264467, 14106269, 15080814,
33531827, 12516406, -21574435, -12476749},
{236881, 10476226, 57258, -14677024, 6472998, 2466984, 17258519,
7256740, 8791136, 15069930},
},
{
{1276410, -9371918, 22949635, -16322807, -23493039, -5702186,
14711875, 4874229, -30663140, -2331391},
{5855666, 4990204, -13711848, 7294284, -7804282, 1924647, -1423175,
-7912378, -33069337, 9234253},
{20590503, -9018988, 31529744, -7352666, -2706834, 10650548,
31559055, -11609587, 18979186, 13396066},
},
{
{24474287, 4968103, 22267082, 4407354, 24063882, -8325180,
-18816887, 13594782, 33514650, 7021958},
{-11566906, -6565505, -21365085, 15928892, -26158305, 4315421,
-25948728, -3916677, -21480480, 12868082},
{-28635013, 13504661, 19988037, -2132761, 21078225, 6443208,
-21446107, 2244500, -12455797, -8089383},
},
{
{-30595528, 13793479, -5852820, 319136, -25723172, -6263899,
33086546, 8957937, -15233648, 5540521},
{-11630176, -11503902, -8119500, -7643073, 2620056, 1022908,
-23710744, -1568984, -16128528, -14962807},
{23152971, 775386, 27395463, 14006635, -9701118, 4649512, 1689819,
892185, -11513277, -15205948},
},
{
{9770129, 9586738, 26496094, 4324120, 1556511, -3550024, 27453819,
4763127, -19179614, 5867134},
{-32765025, 1927590, 31726409, -4753295, 23962434, -16019500,
27846559, 5931263, -29749703, -16108455},
{27461885, -2977536, 22380810, 1815854, -23033753, -3031938,
7283490, -15148073, -19526700, 7734629},
},
},
{
{
{-8010264, -9590817, -11120403, 6196038, 29344158, -13430885,
7585295, -3176626, 18549497, 15302069},
{-32658337, -6171222, -7672793, -11051681, 6258878, 13504381,
10458790, -6418461, -8872242, 8424746},
{24687205, 8613276, -30667046, -3233545, 1863892, -1830544,
19206234, 7134917, -11284482, -828919},
},
{
{11334899, -9218022, 8025293, 12707519, 17523892, -10476071,
10243738, -14685461, -5066034, 16498837},
{8911542, 6887158, -9584260, -6958590, 11145641, -9543680, 17303925,
-14124238, 6536641, 10543906},
{-28946384, 15479763, -17466835, 568876, -1497683, 11223454,
-2669190, -16625574, -27235709, 8876771},
},
{
{-25742899, -12566864, -15649966, -846607, -33026686, -796288,
-33481822, 15824474, -604426, -9039817},
{10330056, 70051, 7957388, -9002667, 9764902, 15609756, 27698697,
-4890037, 1657394, 3084098},
{10477963, -7470260, 12119566, -13250805, 29016247, -5365589,
31280319, 14396151, -30233575, 15272409},
},
{
{-12288309, 3169463, 28813183, 16658753, 25116432, -5630466,
-25173957, -12636138, -25014757, 1950504},
{-26180358, 9489187, 11053416, -14746161, -31053720, 5825630,
-8384306, -8767532, 15341279, 8373727},
{28685821, 7759505, -14378516, -12002860, -31971820, 4079242,
298136, -10232602, -2878207, 15190420},
},
{
{-32932876, 13806336, -14337485, -15794431, -24004620, 10940928,
8669718, 2742393, -26033313, -6875003},
{-1580388, -11729417, -25979658, -11445023, -17411874, -10912854,
9291594, -16247779, -12154742, 6048605},
{-30305315, 14843444, 1539301, 11864366, 20201677, 1900163,
13934231, 5128323, 11213262, 9168384},
},
{
{-26280513, 11007847, 19408960, -940758, -18592965, -4328580,
-5088060, -11105150, 20470157, -16398701},
{-23136053, 9282192, 14855179, -15390078, -7362815, -14408560,
-22783952, 14461608, 14042978, 5230683},
{29969567, -2741594, -16711867, -8552442, 9175486, -2468974,
21556951, 3506042, -5933891, -12449708},
},
{
{-3144746, 8744661, 19704003, 4581278, -20430686, 6830683,
-21284170, 8971513, -28539189, 15326563},
{-19464629, 10110288, -17262528, -3503892, -23500387, 1355669,
-15523050, 15300988, -20514118, 9168260},
{-5353335, 4488613, -23803248, 16314347, 7780487, -15638939,
-28948358, 9601605, 33087103, -9011387},
},
{
{-19443170, -15512900, -20797467, -12445323, -29824447, 10229461,
-27444329, -15000531, -5996870, 15664672},
{23294591, -16632613, -22650781, -8470978, 27844204, 11461195,
13099750, -2460356, 18151676, 13417686},
{-24722913, -4176517, -31150679, 5988919, -26858785, 6685065,
1661597, -12551441, 15271676, -15452665},
},
},
{
{
{11433042, -13228665, 8239631, -5279517, -1985436, -725718,
-18698764, 2167544, -6921301, -13440182},
{-31436171, 15575146, 30436815, 12192228, -22463353, 9395379,
-9917708, -8638997, 12215110, 12028277},
{14098400, 6555944, 23007258, 5757252, -15427832, -12950502,
30123440, 4617780, -16900089, -655628},
},
{
{-4026201, -15240835, 11893168, 13718664, -14809462, 1847385,
-15819999, 10154009, 23973261, -12684474},
{-26531820, -3695990, -1908898, 2534301, -31870557, -16550355,
18341390, -11419951, 32013174, -10103539},
{-25479301, 10876443, -11771086, -14625140, -12369567, 1838104,
21911214, 6354752, 4425632, -837822},
},
{
{-10433389, -14612966, 22229858, -3091047, -13191166, 776729,
-17415375, -12020462, 4725005, 14044970},
{19268650, -7304421, 1555349, 8692754, -21474059, -9910664, 6347390,
-1411784, -19522291, -16109756},
{-24864089, 12986008, -10898878, -5558584, -11312371, -148526,
19541418, 8180106, 9282262, 10282508},
},
{
{-26205082, 4428547, -8661196, -13194263, 4098402, -14165257,
15522535, 8372215, 5542595, -10702683},
{-10562541, 14895633, 26814552, -16673850, -17480754, -2489360,
-2781891, 6993761, -18093885, 10114655},
{-20107055, -929418, 31422704, 10427861, -7110749, 6150669,
-29091755, -11529146, 25953725, -106158},
},
{
{-4234397, -8039292, -9119125, 3046000, 2101609, -12607294,
19390020, 6094296, -3315279, 12831125},
{-15998678, 7578152, 5310217, 14408357, -33548620, -224739,
31575954, 6326196, 7381791, -2421839},
{-20902779, 3296811, 24736065, -16328389, 18374254, 7318640,
6295303, 8082724, -15362489, 12339664},
},
{
{27724736, 2291157, 6088201, -14184798, 1792727, 5857634, 13848414,
15768922, 25091167, 14856294},
{-18866652, 8331043, 24373479, 8541013, -701998, -9269457, 12927300,
-12695493, -22182473, -9012899},
{-11423429, -5421590, 11632845, 3405020, 30536730, -11674039,
-27260765, 13866390, 30146206, 9142070},
},
{
{3924129, -15307516, -13817122, -10054960, 12291820, -668366,
-27702774, 9326384, -8237858, 4171294},
{-15921940, 16037937, 6713787, 16606682, -21612135, 2790944,
26396185, 3731949, 345228, -5462949},
{-21327538, 13448259, 25284571, 1143661, 20614966, -8849387,
2031539, -12391231, -16253183, -13582083},
},
{
{31016211, -16722429, 26371392, -14451233, -5027349, 14854137,
17477601, 3842657, 28012650, -16405420},
{-5075835, 9368966, -8562079, -4600902, -15249953, 6970560,
-9189873, 16292057, -8867157, 3507940},
{29439664, 3537914, 23333589, 6997794, -17555561, -11018068,
-15209202, -15051267, -9164929, 6580396},
},
},
{
{
{-12185861, -7679788, 16438269, 10826160, -8696817, -6235611,
17860444, -9273846, -2095802, 9304567},
{20714564, -4336911, 29088195, 7406487, 11426967, -5095705,
14792667, -14608617, 5289421, -477127},
{-16665533, -10650790, -6160345, -13305760, 9192020, -1802462,
17271490, 12349094, 26939669, -3752294},
},
{
{-12889898, 9373458, 31595848, 16374215, 21471720, 13221525,
-27283495, -12348559, -3698806, 117887},
{22263325, -6560050, 3984570, -11174646, -15114008, -566785,
28311253, 5358056, -23319780, 541964},
{16259219, 3261970, 2309254, -15534474, -16885711, -4581916,
24134070, -16705829, -13337066, -13552195},
},
{
{9378160, -13140186, -22845982, -12745264, 28198281, -7244098,
-2399684, -717351, 690426, 14876244},
{24977353, -314384, -8223969, -13465086, 28432343, -1176353,
-13068804, -12297348, -22380984, 6618999},
{-1538174, 11685646, 12944378, 13682314, -24389511, -14413193,
8044829, -13817328, 32239829, -5652762},
},
{
{-18603066, 4762990, -926250, 8885304, -28412480, -3187315, 9781647,
-10350059, 32779359, 5095274},
{-33008130, -5214506, -32264887, -3685216, 9460461, -9327423,
-24601656, 14506724, 21639561, -2630236},
{-16400943, -13112215, 25239338, 15531969, 3987758, -4499318,
-1289502, -6863535, 17874574, 558605},
},
{
{-13600129, 10240081, 9171883, 16131053, -20869254, 9599700,
33499487, 5080151, 2085892, 5119761},
{-22205145, -2519528, -16381601, 414691, -25019550, 2170430,
30634760, -8363614, -31999993, -5759884},
{-6845704, 15791202, 8550074, -1312654, 29928809, -12092256,
27534430, -7192145, -22351378, 12961482},
},
{
{-24492060, -9570771, 10368194, 11582341, -23397293, -2245287,
16533930, 8206996, -30194652, -5159638},
{-11121496, -3382234, 2307366, 6362031, -135455, 8868177, -16835630,
7031275, 7589640, 8945490},
{-32152748, 8917967, 6661220, -11677616, -1192060, -15793393,
7251489, -11182180, 24099109, -14456170},
},
{
{5019558, -7907470, 4244127, -14714356, -26933272, 6453165,
-19118182, -13289025, -6231896, -10280736},
{10853594, 10721687, 26480089, 5861829, -22995819, 1972175,
-1866647, -10557898, -3363451, -6441124},
{-17002408, 5906790, 221599, -6563147, 7828208, -13248918, 24362661,
-2008168, -13866408, 7421392},
},
{
{8139927, -6546497, 32257646, -5890546, 30375719, 1886181,
-21175108, 15441252, 28826358, -4123029},
{6267086, 9695052, 7709135, -16603597, -32869068, -1886135,
14795160, -7840124, 13746021, -1742048},
{28584902, 7787108, -6732942, -15050729, 22846041, -7571236,
-3181936, -363524, 4771362, -8419958},
},
},
{
{
{24949256, 6376279, -27466481, -8174608, -18646154, -9930606,
33543569, -12141695, 3569627, 11342593},
{26514989, 4740088, 27912651, 3697550, 19331575, -11472339, 6809886,
4608608, 7325975, -14801071},
{-11618399, -14554430, -24321212, 7655128, -1369274, 5214312,
-27400540, 10258390, -17646694, -8186692},
},
{
{11431204, 15823007, 26570245, 14329124, 18029990, 4796082,
-31446179, 15580664, 9280358, -3973687},
{-160783, -10326257, -22855316, -4304997, -20861367, -13621002,
-32810901, -11181622, -15545091, 4387441},
{-20799378, 12194512, 3937617, -5805892, -27154820, 9340370,
-24513992, 8548137, 20617071, -7482001},
},
{
{-938825, -3930586, -8714311, 16124718, 24603125, -6225393,
-13775352, -11875822, 24345683, 10325460},
{-19855277, -1568885, -22202708, 8714034, 14007766, 6928528,
16318175, -1010689, 4766743, 3552007},
{-21751364, -16730916, 1351763, -803421, -4009670, 3950935, 3217514,
14481909, 10988822, -3994762},
},
{
{15564307, -14311570, 3101243, 5684148, 30446780, -8051356,
12677127, -6505343, -8295852, 13296005},
{-9442290, 6624296, -30298964, -11913677, -4670981, -2057379,
31521204, 9614054, -30000824, 12074674},
{4771191, -135239, 14290749, -13089852, 27992298, 14998318,
-1413936, -1556716, 29832613, -16391035},
},
{
{7064884, -7541174, -19161962, -5067537, -18891269, -2912736,
25825242, 5293297, -27122660, 13101590},
{-2298563, 2439670, -7466610, 1719965, -27267541, -16328445,
32512469, -5317593, -30356070, -4190957},
{-30006540, 10162316, -33180176, 3981723, -16482138, -13070044,
14413974, 9515896, 19568978, 9628812},
},
{
{33053803, 199357, 15894591, 1583059, 27380243, -4580435, -17838894,
-6106839, -6291786, 3437740},
{-18978877, 3884493, 19469877, 12726490, 15913552, 13614290,
-22961733, 70104, 7463304, 4176122},
{-27124001, 10659917, 11482427, -16070381, 12771467, -6635117,
-32719404, -5322751, 24216882, 5944158},
},
{
{8894125, 7450974, -2664149, -9765752, -28080517, -12389115,
19345746, 14680796, 11632993, 5847885},
{26942781, -2315317, 9129564, -4906607, 26024105, 11769399,
-11518837, 6367194, -9727230, 4782140},
{19916461, -4828410, -22910704, -11414391, 25606324, -5972441,
33253853, 8220911, 6358847, -1873857},
},
{
{801428, -2081702, 16569428, 11065167, 29875704, 96627, 7908388,
-4480480, -13538503, 1387155},
{19646058, 5720633, -11416706, 12814209, 11607948, 12749789,
14147075, 15156355, -21866831, 11835260},
{19299512, 1155910, 28703737, 14890794, 2925026, 7269399, 26121523,
15467869, -26560550, 5052483},
},
},
{
{
{-3017432, 10058206, 1980837, 3964243, 22160966, 12322533, -6431123,
-12618185, 12228557, -7003677},
{32944382, 14922211, -22844894, 5188528, 21913450, -8719943,
4001465, 13238564, -6114803, 8653815},
{22865569, -4652735, 27603668, -12545395, 14348958, 8234005,
24808405, 5719875, 28483275, 2841751},
},
{
{-16420968, -1113305, -327719, -12107856, 21886282, -15552774,
-1887966, -315658, 19932058, -12739203},
{-11656086, 10087521, -8864888, -5536143, -19278573, -3055912,
3999228, 13239134, -4777469, -13910208},
{1382174, -11694719, 17266790, 9194690, -13324356, 9720081,
20403944, 11284705, -14013818, 3093230},
},
{
{16650921, -11037932, -1064178, 1570629, -8329746, 7352753, -302424,
16271225, -24049421, -6691850},
{-21911077, -5927941, -4611316, -5560156, -31744103, -10785293,
24123614, 15193618, -21652117, -16739389},
{-9935934, -4289447, -25279823, 4372842, 2087473, 10399484,
31870908, 14690798, 17361620, 11864968},
},
{
{-11307610, 6210372, 13206574, 5806320, -29017692, -13967200,
-12331205, -7486601, -25578460, -16240689},
{14668462, -12270235, 26039039, 15305210, 25515617, 4542480,
10453892, 6577524, 9145645, -6443880},
{5974874, 3053895, -9433049, -10385191, -31865124, 3225009,
-7972642, 3936128, -5652273, -3050304},
},
{
{30625386, -4729400, -25555961, -12792866, -20484575, 7695099,
17097188, -16303496, -27999779, 1803632},
{-3553091, 9865099, -5228566, 4272701, -5673832, -16689700,
14911344, 12196514, -21405489, 7047412},
{20093277, 9920966, -11138194, -5343857, 13161587, 12044805,
-32856851, 4124601, -32343828, -10257566},
},
{
{-20788824, 14084654, -13531713, 7842147, 19119038, -13822605,
4752377, -8714640, -21679658, 2288038},
{-26819236, -3283715, 29965059, 3039786, -14473765, 2540457,
29457502, 14625692, -24819617, 12570232},
{-1063558, -11551823, 16920318, 12494842, 1278292, -5869109,
-21159943, -3498680, -11974704, 4724943},
},
{
{17960970, -11775534, -4140968, -9702530, -8876562, -1410617,
-12907383, -8659932, -29576300, 1903856},
{23134274, -14279132, -10681997, -1611936, 20684485, 15770816,
-12989750, 3190296, 26955097, 14109738},
{15308788, 5320727, -30113809, -14318877, 22902008, 7767164,
29425325, -11277562, 31960942, 11934971},
},
{
{-27395711, 8435796, 4109644, 12222639, -24627868, 14818669,
20638173, 4875028, 10491392, 1379718},
{-13159415, 9197841, 3875503, -8936108, -1383712, -5879801,
33518459, 16176658, 21432314, 12180697},
{-11787308, 11500838, 13787581, -13832590, -22430679, 10140205,
1465425, 12689540, -10301319, -13872883},
},
},
{
{
{5414091, -15386041, -21007664, 9643570, 12834970, 1186149,
-2622916, -1342231, 26128231, 6032912},
{-26337395, -13766162, 32496025, -13653919, 17847801, -12669156,
3604025, 8316894, -25875034, -10437358},
{3296484, 6223048, 24680646, -12246460, -23052020, 5903205,
-8862297, -4639164, 12376617, 3188849},
},
{
{29190488, -14659046, 27549113, -1183516, 3520066, -10697301,
32049515, -7309113, -16109234, -9852307},
{-14744486, -9309156, 735818, -598978, -20407687, -5057904,
25246078, -15795669, 18640741, -960977},
{-6928835, -16430795, 10361374, 5642961, 4910474, 12345252,
-31638386, -494430, 10530747, 1053335},
},
{
{-29265967, -14186805, -13538216, -12117373, -19457059, -10655384,
-31462369, -2948985, 24018831, 15026644},
{-22592535, -3145277, -2289276, 5953843, -13440189, 9425631,
25310643, 13003497, -2314791, -15145616},
{-27419985, -603321, -8043984, -1669117, -26092265, 13987819,
-27297622, 187899, -23166419, -2531735},
},
{
{-21744398, -13810475, 1844840, 5021428, -10434399, -15911473,
9716667, 16266922, -5070217, 726099},
{29370922, -6053998, 7334071, -15342259, 9385287, 2247707,
-13661962, -4839461, 30007388, -15823341},
{-936379, 16086691, 23751945, -543318, -1167538, -5189036, 9137109,
730663, 9835848, 4555336},
},
{
{-23376435, 1410446, -22253753, -12899614, 30867635, 15826977,
17693930, 544696, -11985298, 12422646},
{31117226, -12215734, -13502838, 6561947, -9876867, -12757670,
-5118685, -4096706, 29120153, 13924425},
{-17400879, -14233209, 19675799, -2734756, -11006962, -5858820,
-9383939, -11317700, 7240931, -237388},
},
{
{-31361739, -11346780, -15007447, -5856218, -22453340, -12152771,
1222336, 4389483, 3293637, -15551743},
{-16684801, -14444245, 11038544, 11054958, -13801175, -3338533,
-24319580, 7733547, 12796905, -6335822},
{-8759414, -10817836, -25418864, 10783769, -30615557, -9746811,
-28253339, 3647836, 3222231, -11160462},
},
{
{18606113, 1693100, -25448386, -15170272, 4112353, 10045021,
23603893, -2048234, -7550776, 2484985},
{9255317, -3131197, -12156162, -1004256, 13098013, -9214866,
16377220, -2102812, -19802075, -3034702},
{-22729289, 7496160, -5742199, 11329249, 19991973, -3347502,
-31718148, 9936966, -30097688, -10618797},
},
{
{21878590, -5001297, 4338336, 13643897, -3036865, 13160960,
19708896, 5415497, -7360503, -4109293},
{27736861, 10103576, 12500508, 8502413, -3413016, -9633558,
10436918, -1550276, -23659143, -8132100},
{19492550, -12104365, -29681976, -852630, -3208171, 12403437,
30066266, 8367329, 13243957, 8709688},
},
},
{
{
{12015105, 2801261, 28198131, 10151021, 24818120, -4743133,
-11194191, -5645734, 5150968, 7274186},
{2831366, -12492146, 1478975, 6122054, 23825128, -12733586,
31097299, 6083058, 31021603, -9793610},
{-2529932, -2229646, 445613, 10720828, -13849527, -11505937,
-23507731, 16354465, 15067285, -14147707},
},
{
{7840942, 14037873, -33364863, 15934016, -728213, -3642706,
21403988, 1057586, -19379462, -12403220},
{915865, -16469274, 15608285, -8789130, -24357026, 6060030,
-17371319, 8410997, -7220461, 16527025},
{32922597, -556987, 20336074, -16184568, 10903705, -5384487,
16957574, 52992, 23834301, 6588044},
},
{
{32752030, 11232950, 3381995, -8714866, 22652988, -10744103,
17159699, 16689107, -20314580, -1305992},
{-4689649, 9166776, -25710296, -10847306, 11576752, 12733943,
7924251, -2752281, 1976123, -7249027},
{21251222, 16309901, -2983015, -6783122, 30810597, 12967303, 156041,
-3371252, 12331345, -8237197},
},
{
{8651614, -4477032, -16085636, -4996994, 13002507, 2950805,
29054427, -5106970, 10008136, -4667901},
{31486080, 15114593, -14261250, 12951354, 14369431, -7387845,
16347321, -13662089, 8684155, -10532952},
{19443825, 11385320, 24468943, -9659068, -23919258, 2187569,
-26263207, -6086921, 31316348, 14219878},
},
{
{-28594490, 1193785, 32245219, 11392485, 31092169, 15722801,
27146014, 6992409, 29126555, 9207390},
{32382935, 1110093, 18477781, 11028262, -27411763, -7548111,
-4980517, 10843782, -7957600, -14435730},
{2814918, 7836403, 27519878, -7868156, -20894015, -11553689,
-21494559, 8550130, 28346258, 1994730},
},
{
{-19578299, 8085545, -14000519, -3948622, 2785838, -16231307,
-19516951, 7174894, 22628102, 8115180},
{-30405132, 955511, -11133838, -15078069, -32447087, -13278079,
-25651578, 3317160, -9943017, 930272},
{-15303681, -6833769, 28856490, 1357446, 23421993, 1057177,
24091212, -1388970, -22765376, -10650715},
},
{
{-22751231, -5303997, -12907607, -12768866, -15811511, -7797053,
-14839018, -16554220, -1867018, 8398970},
{-31969310, 2106403, -4736360, 1362501, 12813763, 16200670,
22981545, -6291273, 18009408, -15772772},
{-17220923, -9545221, -27784654, 14166835, 29815394, 7444469,
29551787, -3727419, 19288549, 1325865},
},
{
{15100157, -15835752, -23923978, -1005098, -26450192, 15509408,
12376730, -3479146, 33166107, -8042750},
{20909231, 13023121, -9209752, 16251778, -5778415, -8094914,
12412151, 10018715, 2213263, -13878373},
{32529814, -11074689, 30361439, -16689753, -9135940, 1513226,
22922121, 6382134, -5766928, 8371348},
},
},
{
{
{9923462, 11271500, 12616794, 3544722, -29998368, -1721626,
12891687, -8193132, -26442943, 10486144},
{-22597207, -7012665, 8587003, -8257861, 4084309, -12970062, 361726,
2610596, -23921530, -11455195},
{5408411, -1136691, -4969122, 10561668, 24145918, 14240566,
31319731, -4235541, 19985175, -3436086},
},
{
{-13994457, 16616821, 14549246, 3341099, 32155958, 13648976,
-17577068, 8849297, 65030, 8370684},
{-8320926, -12049626, 31204563, 5839400, -20627288, -1057277,
-19442942, 6922164, 12743482, -9800518},
{-2361371, 12678785, 28815050, 4759974, -23893047, 4884717,
23783145, 11038569, 18800704, 255233},
},
{
{-5269658, -1773886, 13957886, 7990715, 23132995, 728773, 13393847,
9066957, 19258688, -14753793},
{-2936654, -10827535, -10432089, 14516793, -3640786, 4372541,
-31934921, 2209390, -1524053, 2055794},
{580882, 16705327, 5468415, -2683018, -30926419, -14696000,
-7203346, -8994389, -30021019, 7394435},
},
{
{23838809, 1822728, -15738443, 15242727, 8318092, -3733104,
-21672180, -3492205, -4821741, 14799921},
{13345610, 9759151, 3371034, -16137791, 16353039, 8577942, 31129804,
13496856, -9056018, 7402518},
{2286874, -4435931, -20042458, -2008336, -13696227, 5038122,
11006906, -15760352, 8205061, 1607563},
},
{
{14414086, -8002132, 3331830, -3208217, 22249151, -5594188,
18364661, -2906958, 30019587, -9029278},
{-27688051, 1585953, -10775053, 931069, -29120221, -11002319,
-14410829, 12029093, 9944378, 8024},
{4368715, -3709630, 29874200, -15022983, -20230386, -11410704,
-16114594, -999085, -8142388, 5640030},
},
{
{10299610, 13746483, 11661824, 16234854, 7630238, 5998374, 9809887,
-16694564, 15219798, -14327783},
{27425505, -5719081, 3055006, 10660664, 23458024, 595578, -15398605,
-1173195, -18342183, 9742717},
{6744077, 2427284, 26042789, 2720740, -847906, 1118974, 32324614,
7406442, 12420155, 1994844},
},
{
{14012521, -5024720, -18384453, -9578469, -26485342, -3936439,
-13033478, -10909803, 24319929, -6446333},
{16412690, -4507367, 10772641, 15929391, -17068788, -4658621,
10555945, -10484049, -30102368, -4739048},
{22397382, -7767684, -9293161, -12792868, 17166287, -9755136,
-27333065, 6199366, 21880021, -12250760},
},
{
{-4283307, 5368523, -31117018, 8163389, -30323063, 3209128,
16557151, 8890729, 8840445, 4957760},
{-15447727, 709327, -6919446, -10870178, -29777922, 6522332,
-21720181, 12130072, -14796503, 5005757},
{-2114751, -14308128, 23019042, 15765735, -25269683, 6002752,
10183197, -13239326, -16395286, -2176112},
},
},
{
{
{-19025756, 1632005, 13466291, -7995100, -23640451, 16573537,
-32013908, -3057104, 22208662, 2000468},
{3065073, -1412761, -25598674, -361432, -17683065, -5703415,
-8164212, 11248527, -3691214, -7414184},
{10379208, -6045554, 8877319, 1473647, -29291284, -12507580,
16690915, 2553332, -3132688, 16400289},
},
{
{15716668, 1254266, -18472690, 7446274, -8448918, 6344164,
-22097271, -7285580, 26894937, 9132066},
{24158887, 12938817, 11085297, -8177598, -28063478, -4457083,
-30576463, 64452, -6817084, -2692882},
{13488534, 7794716, 22236231, 5989356, 25426474, -12578208, 2350710,
-3418511, -4688006, 2364226},
},
{
{16335052, 9132434, 25640582, 6678888, 1725628, 8517937, -11807024,
-11697457, 15445875, -7798101},
{29004207, -7867081, 28661402, -640412, -12794003, -7943086,
31863255, -4135540, -278050, -15759279},
{-6122061, -14866665, -28614905, 14569919, -10857999, -3591829,
10343412, -6976290, -29828287, -10815811},
},
{
{27081650, 3463984, 14099042, -4517604, 1616303, -6205604, 29542636,
15372179, 17293797, 960709},
{20263915, 11434237, -5765435, 11236810, 13505955, -10857102,
-16111345, 6493122, -19384511, 7639714},
{-2830798, -14839232, 25403038, -8215196, -8317012, -16173699,
18006287, -16043750, 29994677, -15808121},
},
{
{9769828, 5202651, -24157398, -13631392, -28051003, -11561624,
-24613141, -13860782, -31184575, 709464},
{12286395, 13076066, -21775189, -1176622, -25003198, 4057652,
-32018128, -8890874, 16102007, 13205847},
{13733362, 5599946, 10557076, 3195751, -5557991, 8536970, -25540170,
8525972, 10151379, 10394400},
},
{
{4024660, -16137551, 22436262, 12276534, -9099015, -2686099,
19698229, 11743039, -33302334, 8934414},
{-15879800, -4525240, -8580747, -2934061, 14634845, -698278,
-9449077, 3137094, -11536886, 11721158},
{17555939, -5013938, 8268606, 2331751, -22738815, 9761013, 9319229,
8835153, -9205489, -1280045},
},
{
{-461409, -7830014, 20614118, 16688288, -7514766, -4807119,
22300304, 505429, 6108462, -6183415},
{-5070281, 12367917, -30663534, 3234473, 32617080, -8422642,
29880583, -13483331, -26898490, -7867459},
{-31975283, 5726539, 26934134, 10237677, -3173717, -605053,
24199304, 3795095, 7592688, -14992079},
},
{
{21594432, -14964228, 17466408, -4077222, 32537084, 2739898,
6407723, 12018833, -28256052, 4298412},
{-20650503, -11961496, -27236275, 570498, 3767144, -1717540,
13891942, -1569194, 13717174, 10805743},
{-14676630, -15644296, 15287174, 11927123, 24177847, -8175568,
-796431, 14860609, -26938930, -5863836},
},
},
{
{
{12962541, 5311799, -10060768, 11658280, 18855286, -7954201,
13286263, -12808704, -4381056, 9882022},
{18512079, 11319350, -20123124, 15090309, 18818594, 5271736,
-22727904, 3666879, -23967430, -3299429},
{-6789020, -3146043, 16192429, 13241070, 15898607, -14206114,
-10084880, -6661110, -2403099, 5276065},
},
{
{30169808, -5317648, 26306206, -11750859, 27814964, 7069267,
7152851, 3684982, 1449224, 13082861},
{10342826, 3098505, 2119311, 193222, 25702612, 12233820, 23697382,
15056736, -21016438, -8202000},
{-33150110, 3261608, 22745853, 7948688, 19370557, -15177665,
-26171976, 6482814, -10300080, -11060101},
},
{
{32869458, -5408545, 25609743, 15678670, -10687769, -15471071,
26112421, 2521008, -22664288, 6904815},
{29506923, 4457497, 3377935, -9796444, -30510046, 12935080, 1561737,
3841096, -29003639, -6657642},
{10340844, -6630377, -18656632, -2278430, 12621151, -13339055,
30878497, -11824370, -25584551, 5181966},
},
{
{25940115, -12658025, 17324188, -10307374, -8671468, 15029094,
24396252, -16450922, -2322852, -12388574},
{-21765684, 9916823, -1300409, 4079498, -1028346, 11909559, 1782390,
12641087, 20603771, -6561742},
{-18882287, -11673380, 24849422, 11501709, 13161720, -4768874,
1925523, 11914390, 4662781, 7820689},
},
{
{12241050, -425982, 8132691, 9393934, 32846760, -1599620, 29749456,
12172924, 16136752, 15264020},
{-10349955, -14680563, -8211979, 2330220, -17662549, -14545780,
10658213, 6671822, 19012087, 3772772},
{3753511, -3421066, 10617074, 2028709, 14841030, -6721664, 28718732,
-15762884, 20527771, 12988982},
},
{
{-14822485, -5797269, -3707987, 12689773, -898983, -10914866,
-24183046, -10564943, 3299665, -12424953},
{-16777703, -15253301, -9642417, 4978983, 3308785, 8755439, 6943197,
6461331, -25583147, 8991218},
{-17226263, 1816362, -1673288, -6086439, 31783888, -8175991,
-32948145, 7417950, -30242287, 1507265},
},
{
{29692663, 6829891, -10498800, 4334896, 20945975, -11906496,
-28887608, 8209391, 14606362, -10647073},
{-3481570, 8707081, 32188102, 5672294, 22096700, 1711240, -33020695,
9761487, 4170404, -2085325},
{-11587470, 14855945, -4127778, -1531857, -26649089, 15084046,
22186522, 16002000, -14276837, -8400798},
},
{
{-4811456, 13761029, -31703877, -2483919, -3312471, 7869047,
-7113572, -9620092, 13240845, 10965870},
{-7742563, -8256762, -14768334, -13656260, -23232383, 12387166,
4498947, 14147411, 29514390, 4302863},
{-13413405, -12407859, 20757302, -13801832, 14785143, 8976368,
-5061276, -2144373, 17846988, -13971927},
},
},
{
{
{-2244452, -754728, -4597030, -1066309, -6247172, 1455299,
-21647728, -9214789, -5222701, 12650267},
{-9906797, -16070310, 21134160, 12198166, -27064575, 708126, 387813,
13770293, -19134326, 10958663},
{22470984, 12369526, 23446014, -5441109, -21520802, -9698723,
-11772496, -11574455, -25083830, 4271862},
},
{
{-25169565, -10053642, -19909332, 15361595, -5984358, 2159192,
75375, -4278529, -32526221, 8469673},
{15854970, 4148314, -8893890, 7259002, 11666551, 13824734,
-30531198, 2697372, 24154791, -9460943},
{15446137, -15806644, 29759747, 14019369, 30811221, -9610191,
-31582008, 12840104, 24913809, 9815020},
},
{
{-4709286, -5614269, -31841498, -12288893, -14443537, 10799414,
-9103676, 13438769, 18735128, 9466238},
{11933045, 9281483, 5081055, -5183824, -2628162, -4905629, -7727821,
-10896103, -22728655, 16199064},
{14576810, 379472, -26786533, -8317236, -29426508, -10812974,
-102766, 1876699, 30801119, 2164795},
},
{
{15995086, 3199873, 13672555, 13712240, -19378835, -4647646,
-13081610, -15496269, -13492807, 1268052},
{-10290614, -3659039, -3286592, 10948818, 23037027, 3794475,
-3470338, -12600221, -17055369, 3565904},
{29210088, -9419337, -5919792, -4952785, 10834811, -13327726,
-16512102, -10820713, -27162222, -14030531},
},
{
{-13161890, 15508588, 16663704, -8156150, -28349942, 9019123,
-29183421, -3769423, 2244111, -14001979},
{-5152875, -3800936, -9306475, -6071583, 16243069, 14684434,
-25673088, -16180800, 13491506, 4641841},
{10813417, 643330, -19188515, -728916, 30292062, -16600078,
27548447, -7721242, 14476989, -12767431},
},
{
{10292079, 9984945, 6481436, 8279905, -7251514, 7032743, 27282937,
-1644259, -27912810, 12651324},
{-31185513, -813383, 22271204, 11835308, 10201545, 15351028,
17099662, 3988035, 21721536, -3148940},
{10202177, -6545839, -31373232, -9574638, -32150642, -8119683,
-12906320, 3852694, 13216206, 14842320},
},
{
{-15815640, -10601066, -6538952, -7258995, -6984659, -6581778,
-31500847, 13765824, -27434397, 9900184},
{14465505, -13833331, -32133984, -14738873, -27443187, 12990492,
33046193, 15796406, -7051866, -8040114},
{30924417, -8279620, 6359016, -12816335, 16508377, 9071735,
-25488601, 15413635, 9524356, -7018878},
},
{
{12274201, -13175547, 32627641, -1785326, 6736625, 13267305,
5237659, -5109483, 15663516, 4035784},
{-2951309, 8903985, 17349946, 601635, -16432815, -4612556,
-13732739, -15889334, -22258478, 4659091},
{-16916263, -4952973, -30393711, -15158821, 20774812, 15897498,
5736189, 15026997, -2178256, -13455585},
},
},
{
{
{-8858980, -2219056, 28571666, -10155518, -474467, -10105698,
-3801496, 278095, 23440562, -290208},
{10226241, -5928702, 15139956, 120818, -14867693, 5218603, 32937275,
11551483, -16571960, -7442864},
{17932739, -12437276, -24039557, 10749060, 11316803, 7535897,
22503767, 5561594, -3646624, 3898661},
},
{
{7749907, -969567, -16339731, -16464, -25018111, 15122143, -1573531,
7152530, 21831162, 1245233},
{26958459, -14658026, 4314586, 8346991, -5677764, 11960072,
-32589295, -620035, -30402091, -16716212},
{-12165896, 9166947, 33491384, 13673479, 29787085, 13096535,
6280834, 14587357, -22338025, 13987525},
},
{
{-24349909, 7778775, 21116000, 15572597, -4833266, -5357778,
-4300898, -5124639, -7469781, -2858068},
{9681908, -6737123, -31951644, 13591838, -6883821, 386950, 31622781,
6439245, -14581012, 4091397},
{-8426427, 1470727, -28109679, -1596990, 3978627, -5123623,
-19622683, 12092163, 29077877, -14741988},
},
{
{5269168, -6859726, -13230211, -8020715, 25932563, 1763552,
-5606110, -5505881, -20017847, 2357889},
{32264008, -15407652, -5387735, -1160093, -2091322, -3946900,
23104804, -12869908, 5727338, 189038},
{14609123, -8954470, -6000566, -16622781, -14577387, -7743898,
-26745169, 10942115, -25888931, -14884697},
},
{
{20513500, 5557931, -15604613, 7829531, 26413943, -2019404,
-21378968, 7471781, 13913677, -5137875},
{-25574376, 11967826, 29233242, 12948236, -6754465, 4713227,
-8940970, 14059180, 12878652, 8511905},
{-25656801, 3393631, -2955415, -7075526, -2250709, 9366908,
-30223418, 6812974, 5568676, -3127656},
},
{
{11630004, 12144454, 2116339, 13606037, 27378885, 15676917,
-17408753, -13504373, -14395196, 8070818},
{27117696, -10007378, -31282771, -5570088, 1127282, 12772488,
-29845906, 10483306, -11552749, -1028714},
{10637467, -5688064, 5674781, 1072708, -26343588, -6982302,
-1683975, 9177853, -27493162, 15431203},
},
{
{20525145, 10892566, -12742472, 12779443, -29493034, 16150075,
-28240519, 14943142, -15056790, -7935931},
{-30024462, 5626926, -551567, -9981087, 753598, 11981191, 25244767,
-3239766, -3356550, 9594024},
{-23752644, 2636870, -5163910, -10103818, 585134, 7877383, 11345683,
-6492290, 13352335, -10977084},
},
{
{-1931799, -5407458, 3304649, -12884869, 17015806, -4877091,
-29783850, -7752482, -13215537, -319204},
{20239939, 6607058, 6203985, 3483793, -18386976, -779229, -20723742,
15077870, -22750759, 14523817},
{27406042, -6041657, 27423596, -4497394, 4996214, 10002360,
-28842031, -4545494, -30172742, -4805667},
},
},
{
{
{11374242, 12660715, 17861383, -12540833, 10935568, 1099227,
-13886076, -9091740, -27727044, 11358504},
{-12730809, 10311867, 1510375, 10778093, -2119455, -9145702,
32676003, 11149336, -26123651, 4985768},
{-19096303, 341147, -6197485, -239033, 15756973, -8796662, -983043,
13794114, -19414307, -15621255},
},
{
{6490081, 11940286, 25495923, -7726360, 8668373, -8751316, 3367603,
6970005, -1691065, -9004790},
{1656497, 13457317, 15370807, 6364910, 13605745, 8362338, -19174622,
-5475723, -16796596, -5031438},
{-22273315, -13524424, -64685, -4334223, -18605636, -10921968,
-20571065, -7007978, -99853, -10237333},
},
{
{17747465, 10039260, 19368299, -4050591, -20630635, -16041286,
31992683, -15857976, -29260363, -5511971},
{31932027, -4986141, -19612382, 16366580, 22023614, 88450, 11371999,
-3744247, 4882242, -10626905},
{29796507, 37186, 19818052, 10115756, -11829032, 3352736, 18551198,
3272828, -5190932, -4162409},
},
{
{12501286, 4044383, -8612957, -13392385, -32430052, 5136599,
-19230378, -3529697, 330070, -3659409},
{6384877, 2899513, 17807477, 7663917, -2358888, 12363165, 25366522,
-8573892, -271295, 12071499},
{-8365515, -4042521, 25133448, -4517355, -6211027, 2265927,
-32769618, 1936675, -5159697, 3829363},
},
{
{28425966, -5835433, -577090, -4697198, -14217555, 6870930, 7921550,
-6567787, 26333140, 14267664},
{-11067219, 11871231, 27385719, -10559544, -4585914, -11189312,
10004786, -8709488, -21761224, 8930324},
{-21197785, -16396035, 25654216, -1725397, 12282012, 11008919,
1541940, 4757911, -26491501, -16408940},
},
{
{13537262, -7759490, -20604840, 10961927, -5922820, -13218065,
-13156584, 6217254, -15943699, 13814990},
{-17422573, 15157790, 18705543, 29619, 24409717, -260476, 27361681,
9257833, -1956526, -1776914},
{-25045300, -10191966, 15366585, 15166509, -13105086, 8423556,
-29171540, 12361135, -18685978, 4578290},
},
{
{24579768, 3711570, 1342322, -11180126, -27005135, 14124956,
-22544529, 14074919, 21964432, 8235257},
{-6528613, -2411497, 9442966, -5925588, 12025640, -1487420,
-2981514, -1669206, 13006806, 2355433},
{-16304899, -13605259, -6632427, -5142349, 16974359, -10911083,
27202044, 1719366, 1141648, -12796236},
},
{
{-12863944, -13219986, -8318266, -11018091, -6810145, -4843894,
13475066, -3133972, 32674895, 13715045},
{11423335, -5468059, 32344216, 8962751, 24989809, 9241752,
-13265253, 16086212, -28740881, -15642093},
{-1409668, 12530728, -6368726, 10847387, 19531186, -14132160,
-11709148, 7791794, -27245943, 4383347},
},
},
{
{
{-28970898, 5271447, -1266009, -9736989, -12455236, 16732599,
-4862407, -4906449, 27193557, 6245191},
{-15193956, 5362278, -1783893, 2695834, 4960227, 12840725, 23061898,
3260492, 22510453, 8577507},
{-12632451, 11257346, -32692994, 13548177, -721004, 10879011,
31168030, 13952092, -29571492, -3635906},
},
{
{3877321, -9572739, 32416692, 5405324, -11004407, -13656635,
3759769, 11935320, 5611860, 8164018},
{-16275802, 14667797, 15906460, 12155291, -22111149, -9039718,
32003002, -8832289, 5773085, -8422109},
{-23788118, -8254300, 1950875, 8937633, 18686727, 16459170, -905725,
12376320, 31632953, 190926},
},
{
{-24593607, -16138885, -8423991, 13378746, 14162407, 6901328,
-8288749, 4508564, -25341555, -3627528},
{8884438, -5884009, 6023974, 10104341, -6881569, -4941533, 18722941,
-14786005, -1672488, 827625},
{-32720583, -16289296, -32503547, 7101210, 13354605, 2659080,
-1800575, -14108036, -24878478, 1541286},
},
{
{2901347, -1117687, 3880376, -10059388, -17620940, -3612781,
-21802117, -3567481, 20456845, -1885033},
{27019610, 12299467, -13658288, -1603234, -12861660, -4861471,
-19540150, -5016058, 29439641, 15138866},
{21536104, -6626420, -32447818, -10690208, -22408077, 5175814,
-5420040, -16361163, 7779328, 109896},
},
{
{30279744, 14648750, -8044871, 6425558, 13639621, -743509, 28698390,
12180118, 23177719, -554075},
{26572847, 3405927, -31701700, 12890905, -19265668, 5335866,
-6493768, 2378492, 4439158, -13279347},
{-22716706, 3489070, -9225266, -332753, 18875722, -1140095,
14819434, -12731527, -17717757, -5461437},
},
{
{-5056483, 16566551, 15953661, 3767752, -10436499, 15627060,
-820954, 2177225, 8550082, -15114165},
{-18473302, 16596775, -381660, 15663611, 22860960, 15585581,
-27844109, -3582739, -23260460, -8428588},
{-32480551, 15707275, -8205912, -5652081, 29464558, 2713815,
-22725137, 15860482, -21902570, 1494193},
},
{
{-19562091, -14087393, -25583872, -9299552, 13127842, 759709,
21923482, 16529112, 8742704, 12967017},
{-28464899, 1553205, 32536856, -10473729, -24691605, -406174,
-8914625, -2933896, -29903758, 15553883},
{21877909, 3230008, 9881174, 10539357, -4797115, 2841332, 11543572,
14513274, 19375923, -12647961},
},
{
{8832269, -14495485, 13253511, 5137575, 5037871, 4078777, 24880818,
-6222716, 2862653, 9455043},
{29306751, 5123106, 20245049, -14149889, 9592566, 8447059, -2077124,
-2990080, 15511449, 4789663},
{-20679756, 7004547, 8824831, -9434977, -4045704, -3750736,
-5754762, 108893, 23513200, 16652362},
},
},
{
{
{-33256173, 4144782, -4476029, -6579123, 10770039, -7155542,
-6650416, -12936300, -18319198, 10212860},
{2756081, 8598110, 7383731, -6859892, 22312759, -1105012, 21179801,
2600940, -9988298, -12506466},
{-24645692, 13317462, -30449259, -15653928, 21365574, -10869657,
11344424, 864440, -2499677, -16710063},
},
{
{-26432803, 6148329, -17184412, -14474154, 18782929, -275997,
-22561534, 211300, 2719757, 4940997},
{-1323882, 3911313, -6948744, 14759765, -30027150, 7851207,
21690126, 8518463, 26699843, 5276295},
{-13149873, -6429067, 9396249, 365013, 24703301, -10488939, 1321586,
149635, -15452774, 7159369},
},
{
{9987780, -3404759, 17507962, 9505530, 9731535, -2165514, 22356009,
8312176, 22477218, -8403385},
{18155857, -16504990, 19744716, 9006923, 15154154, -10538976,
24256460, -4864995, -22548173, 9334109},
{2986088, -4911893, 10776628, -3473844, 10620590, -7083203,
-21413845, 14253545, -22587149, 536906},
},
{
{4377756, 8115836, 24567078, 15495314, 11625074, 13064599, 7390551,
10589625, 10838060, -15420424},
{-19342404, 867880, 9277171, -3218459, -14431572, -1986443,
19295826, -15796950, 6378260, 699185},
{7895026, 4057113, -7081772, -13077756, -17886831, -323126, -716039,
15693155, -5045064, -13373962},
},
{
{-7737563, -5869402, -14566319, -7406919, 11385654, 13201616,
31730678, -10962840, -3918636, -9669325},
{10188286, -15770834, -7336361, 13427543, 22223443, 14896287,
30743455, 7116568, -21786507, 5427593},
{696102, 13206899, 27047647, -10632082, 15285305, -9853179,
10798490, -4578720, 19236243, 12477404},
},
{
{-11229439, 11243796, -17054270, -8040865, -788228, -8167967,
-3897669, 11180504, -23169516, 7733644},
{17800790, -14036179, -27000429, -11766671, 23887827, 3149671,
23466177, -10538171, 10322027, 15313801},
{26246234, 11968874, 32263343, -5468728, 6830755, -13323031,
-15794704, -101982, -24449242, 10890804},
},
{
{-31365647, 10271363, -12660625, -6267268, 16690207, -13062544,
-14982212, 16484931, 25180797, -5334884},
{-586574, 10376444, -32586414, -11286356, 19801893, 10997610,
2276632, 9482883, 316878, 13820577},
{-9882808, -4510367, -2115506, 16457136, -11100081, 11674996,
30756178, -7515054, 30696930, -3712849},
},
{
{32988917, -9603412, 12499366, 7910787, -10617257, -11931514,
-7342816, -9985397, -32349517, 7392473},
{-8855661, 15927861, 9866406, -3649411, -2396914, -16655781,
-30409476, -9134995, 25112947, -2926644},
{-2504044, -436966, 25621774, -5678772, 15085042, -5479877,
-24884878, -13526194, 5537438, -13914319},
},
},
{
{
{-11225584, 2320285, -9584280, 10149187, -33444663, 5808648,
-14876251, -1729667, 31234590, 6090599},
{-9633316, 116426, 26083934, 2897444, -6364437, -2688086, 609721,
15878753, -6970405, -9034768},
{-27757857, 247744, -15194774, -9002551, 23288161, -10011936,
-23869595, 6503646, 20650474, 1804084},
},
{
{-27589786, 15456424, 8972517, 8469608, 15640622, 4439847, 3121995,
-10329713, 27842616, -202328},
{-15306973, 2839644, 22530074, 10026331, 4602058, 5048462, 28248656,
5031932, -11375082, 12714369},
{20807691, -7270825, 29286141, 11421711, -27876523, -13868230,
-21227475, 1035546, -19733229, 12796920},
},
{
{12076899, -14301286, -8785001, -11848922, -25012791, 16400684,
-17591495, -12899438, 3480665, -15182815},
{-32361549, 5457597, 28548107, 7833186, 7303070, -11953545,
-24363064, -15921875, -33374054, 2771025},
{-21389266, 421932, 26597266, 6860826, 22486084, -6737172,
-17137485, -4210226, -24552282, 15673397},
},
{
{-20184622, 2338216, 19788685, -9620956, -4001265, -8740893,
-20271184, 4733254, 3727144, -12934448},
{6120119, 814863, -11794402, -622716, 6812205, -15747771, 2019594,
7975683, 31123697, -10958981},
{30069250, -11435332, 30434654, 2958439, 18399564, -976289,
12296869, 9204260, -16432438, 9648165},
},
{
{32705432, -1550977, 30705658, 7451065, -11805606, 9631813, 3305266,
5248604, -26008332, -11377501},
{17219865, 2375039, -31570947, -5575615, -19459679, 9219903, 294711,
15298639, 2662509, -16297073},
{-1172927, -7558695, -4366770, -4287744, -21346413, -8434326,
32087529, -1222777, 32247248, -14389861},
},
{
{14312628, 1221556, 17395390, -8700143, -4945741, -8684635,
-28197744, -9637817, -16027623, -13378845},
{-1428825, -9678990, -9235681, 6549687, -7383069, -468664, 23046502,
9803137, 17597934, 2346211},
{18510800, 15337574, 26171504, 981392, -22241552, 7827556,
-23491134, -11323352, 3059833, -11782870},
},
{
{10141598, 6082907, 17829293, -1947643, 9830092, 13613136,
-25556636, -5544586, -33502212, 3592096},
{33114168, -15889352, -26525686, -13343397, 33076705, 8716171,
1151462, 1521897, -982665, -6837803},
{-32939165, -4255815, 23947181, -324178, -33072974, -12305637,
-16637686, 3891704, 26353178, 693168},
},
{
{30374239, 1595580, -16884039, 13186931, 4600344, 406904, 9585294,
-400668, 31375464, 14369965},
{-14370654, -7772529, 1510301, 6434173, -18784789, -6262728,
32732230, -13108839, 17901441, 16011505},
{18171223, -11934626, -12500402, 15197122, -11038147, -15230035,
-19172240, -16046376, 8764035, 12309598},
},
},
{
{
{5975908, -5243188, -19459362, -9681747, -11541277, 14015782,
-23665757, 1228319, 17544096, -10593782},
{5811932, -1715293, 3442887, -2269310, -18367348, -8359541,
-18044043, -15410127, -5565381, 12348900},
{-31399660, 11407555, 25755363, 6891399, -3256938, 14872274,
-24849353, 8141295, -10632534, -585479},
},
{
{-12675304, 694026, -5076145, 13300344, 14015258, -14451394,
-9698672, -11329050, 30944593, 1130208},
{8247766, -6710942, -26562381, -7709309, -14401939, -14648910,
4652152, 2488540, 23550156, -271232},
{17294316, -3788438, 7026748, 15626851, 22990044, 113481, 2267737,
-5908146, -408818, -137719},
},
{
{16091085, -16253926, 18599252, 7340678, 2137637, -1221657,
-3364161, 14550936, 3260525, -7166271},
{-4910104, -13332887, 18550887, 10864893, -16459325, -7291596,
-23028869, -13204905, -12748722, 2701326},
{-8574695, 16099415, 4629974, -16340524, -20786213, -6005432,
-10018363, 9276971, 11329923, 1862132},
},
{
{14763076, -15903608, -30918270, 3689867, 3511892, 10313526,
-21951088, 12219231, -9037963, -940300},
{8894987, -3446094, 6150753, 3013931, 301220, 15693451, -31981216,
-2909717, -15438168, 11595570},
{15214962, 3537601, -26238722, -14058872, 4418657, -15230761,
13947276, 10730794, -13489462, -4363670},
},
{
{-2538306, 7682793, 32759013, 263109, -29984731, -7955452,
-22332124, -10188635, 977108, 699994},
{-12466472, 4195084, -9211532, 550904, -15565337, 12917920,
19118110, -439841, -30534533, -14337913},
{31788461, -14507657, 4799989, 7372237, 8808585, -14747943, 9408237,
-10051775, 12493932, -5409317},
},
{
{-25680606, 5260744, -19235809, -6284470, -3695942, 16566087,
27218280, 2607121, 29375955, 6024730},
{842132, -2794693, -4763381, -8722815, 26332018, -12405641,
11831880, 6985184, -9940361, 2854096},
{-4847262, -7969331, 2516242, -5847713, 9695691, -7221186, 16512645,
960770, 12121869, 16648078},
},
{
{-15218652, 14667096, -13336229, 2013717, 30598287, -464137,
-31504922, -7882064, 20237806, 2838411},
{-19288047, 4453152, 15298546, -16178388, 22115043, -15972604,
12544294, -13470457, 1068881, -12499905},
{-9558883, -16518835, 33238498, 13506958, 30505848, -1114596,
-8486907, -2630053, 12521378, 4845654},
},
{
{-28198521, 10744108, -2958380, 10199664, 7759311, -13088600,
3409348, -873400, -6482306, -12885870},
{-23561822, 6230156, -20382013, 10655314, -24040585, -11621172,
10477734, -1240216, -3113227, 13974498},
{12966261, 15550616, -32038948, -1615346, 21025980, -629444,
5642325, 7188737, 18895762, 12629579},
},
},
{
{
{14741879, -14946887, 22177208, -11721237, 1279741, 8058600,
11758140, 789443, 32195181, 3895677},
{10758205, 15755439, -4509950, 9243698, -4879422, 6879879, -2204575,
-3566119, -8982069, 4429647},
{-2453894, 15725973, -20436342, -10410672, -5803908, -11040220,
-7135870, -11642895, 18047436, -15281743},
},
{
{-25173001, -11307165, 29759956, 11776784, -22262383, -15820455,
10993114, -12850837, -17620701, -9408468},
{21987233, 700364, -24505048, 14972008, -7774265, -5718395,
32155026, 2581431, -29958985, 8773375},
{-25568350, 454463, -13211935, 16126715, 25240068, 8594567,
20656846, 12017935, -7874389, -13920155},
},
{
{6028182, 6263078, -31011806, -11301710, -818919, 2461772,
-31841174, -5468042, -1721788, -2776725},
{-12278994, 16624277, 987579, -5922598, 32908203, 1248608, 7719845,
-4166698, 28408820, 6816612},
{-10358094, -8237829, 19549651, -12169222, 22082623, 16147817,
20613181, 13982702, -10339570, 5067943},
},
{
{-30505967, -3821767, 12074681, 13582412, -19877972, 2443951,
-19719286, 12746132, 5331210, -10105944},
{30528811, 3601899, -1957090, 4619785, -27361822, -15436388,
24180793, -12570394, 27679908, -1648928},
{9402404, -13957065, 32834043, 10838634, -26580150, -13237195,
26653274, -8685565, 22611444, -12715406},
},
{
{22190590, 1118029, 22736441, 15130463, -30460692, -5991321,
19189625, -4648942, 4854859, 6622139},
{-8310738, -2953450, -8262579, -3388049, -10401731, -271929,
13424426, -3567227, 26404409, 13001963},
{-31241838, -15415700, -2994250, 8939346, 11562230, -12840670,
-26064365, -11621720, -15405155, 11020693},
},
{
{1866042, -7949489, -7898649, -10301010, 12483315, 13477547,
3175636, -12424163, 28761762, 1406734},
{-448555, -1777666, 13018551, 3194501, -9580420, -11161737,
24760585, -4347088, 25577411, -13378680},
{-24290378, 4759345, -690653, -1852816, 2066747, 10693769,
-29595790, 9884936, -9368926, 4745410},
},
{
{-9141284, 6049714, -19531061, -4341411, -31260798, 9944276,
-15462008, -11311852, 10931924, -11931931},
{-16561513, 14112680, -8012645, 4817318, -8040464, -11414606,
-22853429, 10856641, -20470770, 13434654},
{22759489, -10073434, -16766264, -1871422, 13637442, -10168091,
1765144, -12654326, 28445307, -5364710},
},
{
{29875063, 12493613, 2795536, -3786330, 1710620, 15181182,
-10195717, -8788675, 9074234, 1167180},
{-26205683, 11014233, -9842651, -2635485, -26908120, 7532294,
-18716888, -9535498, 3843903, 9367684},
{-10969595, -6403711, 9591134, 9582310, 11349256, 108879, 16235123,
8601684, -139197, 4242895},
},
},
{
{
{22092954, -13191123, -2042793, -11968512, 32186753, -11517388,
-6574341, 2470660, -27417366, 16625501},
{-11057722, 3042016, 13770083, -9257922, 584236, -544855, -7770857,
2602725, -27351616, 14247413},
{6314175, -10264892, -32772502, 15957557, -10157730, 168750,
-8618807, 14290061, 27108877, -1180880},
},
{
{-8586597, -7170966, 13241782, 10960156, -32991015, -13794596,
33547976, -11058889, -27148451, 981874},
{22833440, 9293594, -32649448, -13618667, -9136966, 14756819,
-22928859, -13970780, -10479804, -16197962},
{-7768587, 3326786, -28111797, 10783824, 19178761, 14905060,
22680049, 13906969, -15933690, 3797899},
},
{
{21721356, -4212746, -12206123, 9310182, -3882239, -13653110,
23740224, -2709232, 20491983, -8042152},
{9209270, -15135055, -13256557, -6167798, -731016, 15289673,
25947805, 15286587, 30997318, -6703063},
{7392032, 16618386, 23946583, -8039892, -13265164, -1533858,
-14197445, -2321576, 17649998, -250080},
},
{
{-9301088, -14193827, 30609526, -3049543, -25175069, -1283752,
-15241566, -9525724, -2233253, 7662146},
{-17558673, 1763594, -33114336, 15908610, -30040870, -12174295,
7335080, -8472199, -3174674, 3440183},
{-19889700, -5977008, -24111293, -9688870, 10799743, -16571957,
40450, -4431835, 4862400, 1133},
},
{
{-32856209, -7873957, -5422389, 14860950, -16319031, 7956142,
7258061, 311861, -30594991, -7379421},
{-3773428, -1565936, 28985340, 7499440, 24445838, 9325937, 29727763,
16527196, 18278453, 15405622},
{-4381906, 8508652, -19898366, -3674424, -5984453, 15149970,
-13313598, 843523, -21875062, 13626197},
},
{
{2281448, -13487055, -10915418, -2609910, 1879358, 16164207,
-10783882, 3953792, 13340839, 15928663},
{31727126, -7179855, -18437503, -8283652, 2875793, -16390330,
-25269894, -7014826, -23452306, 5964753},
{4100420, -5959452, -17179337, 6017714, -18705837, 12227141,
-26684835, 11344144, 2538215, -7570755},
},
{
{-9433605, 6123113, 11159803, -2156608, 30016280, 14966241,
-20474983, 1485421, -629256, -15958862},
{-26804558, 4260919, 11851389, 9658551, -32017107, 16367492,
-20205425, -13191288, 11659922, -11115118},
{26180396, 10015009, -30844224, -8581293, 5418197, 9480663, 2231568,
-10170080, 33100372, -1306171},
},
{
{15121113, -5201871, -10389905, 15427821, -27509937, -15992507,
21670947, 4486675, -5931810, -14466380},
{16166486, -9483733, -11104130, 6023908, -31926798, -1364923,
2340060, -16254968, -10735770, -10039824},
{28042865, -3557089, -12126526, 12259706, -3717498, -6945899,
6766453, -8689599, 18036436, 5803270},
},
},
{
{
{-817581, 6763912, 11803561, 1585585, 10958447, -2671165, 23855391,
4598332, -6159431, -14117438},
{-31031306, -14256194, 17332029, -2383520, 31312682, -5967183,
696309, 50292, -20095739, 11763584},
{-594563, -2514283, -32234153, 12643980, 12650761, 14811489, 665117,
-12613632, -19773211, -10713562},
},
{
{30464590, -11262872, -4127476, -12734478, 19835327, -7105613,
-24396175, 2075773, -17020157, 992471},
{18357185, -6994433, 7766382, 16342475, -29324918, 411174, 14578841,
8080033, -11574335, -10601610},
{19598397, 10334610, 12555054, 2555664, 18821899, -10339780,
21873263, 16014234, 26224780, 16452269},
},
{
{-30223925, 5145196, 5944548, 16385966, 3976735, 2009897, -11377804,
-7618186, -20533829, 3698650},
{14187449, 3448569, -10636236, -10810935, -22663880, -3433596,
7268410, -10890444, 27394301, 12015369},
{19695761, 16087646, 28032085, 12999827, 6817792, 11427614,
20244189, -1312777, -13259127, -3402461},
},
{
{30860103, 12735208, -1888245, -4699734, -16974906, 2256940,
-8166013, 12298312, -8550524, -10393462},
{-5719826, -11245325, -1910649, 15569035, 26642876, -7587760,
-5789354, -15118654, -4976164, 12651793},
{-2848395, 9953421, 11531313, -5282879, 26895123, -12697089,
-13118820, -16517902, 9768698, -2533218},
},
{
{-24719459, 1894651, -287698, -4704085, 15348719, -8156530,
32767513, 12765450, 4940095, 10678226},
{18860224, 15980149, -18987240, -1562570, -26233012, -11071856,
-7843882, 13944024, -24372348, 16582019},
{-15504260, 4970268, -29893044, 4175593, -20993212, -2199756,
-11704054, 15444560, -11003761, 7989037},
},
{
{31490452, 5568061, -2412803, 2182383, -32336847, 4531686,
-32078269, 6200206, -19686113, -14800171},
{-17308668, -15879940, -31522777, -2831, -32887382, 16375549,
8680158, -16371713, 28550068, -6857132},
{-28126887, -5688091, 16837845, -1820458, -6850681, 12700016,
-30039981, 4364038, 1155602, 5988841},
},
{
{21890435, -13272907, -12624011, 12154349, -7831873, 15300496,
23148983, -4470481, 24618407, 8283181},
{-33136107, -10512751, 9975416, 6841041, -31559793, 16356536,
3070187, -7025928, 1466169, 10740210},
{-1509399, -15488185, -13503385, -10655916, 32799044, 909394,
-13938903, -5779719, -32164649, -15327040},
},
{
{3960823, -14267803, -28026090, -15918051, -19404858, 13146868,
15567327, 951507, -3260321, -573935},
{24740841, 5052253, -30094131, 8961361, 25877428, 6165135,
-24368180, 14397372, -7380369, -6144105},
{-28888365, 3510803, -28103278, -1158478, -11238128, -10631454,
-15441463, -14453128, -1625486, -6494814},
},
},
{
{
{793299, -9230478, 8836302, -6235707, -27360908, -2369593, 33152843,
-4885251, -9906200, -621852},
{5666233, 525582, 20782575, -8038419, -24538499, 14657740, 16099374,
1468826, -6171428, -15186581},
{-4859255, -3779343, -2917758, -6748019, 7778750, 11688288,
-30404353, -9871238, -1558923, -9863646},
},
{
{10896332, -7719704, 824275, 472601, -19460308, 3009587, 25248958,
14783338, -30581476, -15757844},
{10566929, 12612572, -31944212, 11118703, -12633376, 12362879,
21752402, 8822496, 24003793, 14264025},
{27713862, -7355973, -11008240, 9227530, 27050101, 2504721,
23886875, -13117525, 13958495, -5732453},
},
{
{-23481610, 4867226, -27247128, 3900521, 29838369, -8212291,
-31889399, -10041781, 7340521, -15410068},
{4646514, -8011124, -22766023, -11532654, 23184553, 8566613,
31366726, -1381061, -15066784, -10375192},
{-17270517, 12723032, -16993061, 14878794, 21619651, -6197576,
27584817, 3093888, -8843694, 3849921},
},
{
{-9064912, 2103172, 25561640, -15125738, -5239824, 9582958,
32477045, -9017955, 5002294, -15550259},
{-12057553, -11177906, 21115585, -13365155, 8808712, -12030708,
16489530, 13378448, -25845716, 12741426},
{-5946367, 10645103, -30911586, 15390284, -3286982, -7118677,
24306472, 15852464, 28834118, -7646072},
},
{
{-17335748, -9107057, -24531279, 9434953, -8472084, -583362,
-13090771, 455841, 20461858, 5491305},
{13669248, -16095482, -12481974, -10203039, -14569770, -11893198,
-24995986, 11293807, -28588204, -9421832},
{28497928, 6272777, -33022994, 14470570, 8906179, -1225630,
18504674, -14165166, 29867745, -8795943},
},
{
{-16207023, 13517196, -27799630, -13697798, 24009064, -6373891,
-6367600, -13175392, 22853429, -4012011},
{24191378, 16712145, -13931797, 15217831, 14542237, 1646131,
18603514, -11037887, 12876623, -2112447},
{17902668, 4518229, -411702, -2829247, 26878217, 5258055, -12860753,
608397, 16031844, 3723494},
},
{
{-28632773, 12763728, -20446446, 7577504, 33001348, -13017745,
17558842, -7872890, 23896954, -4314245},
{-20005381, -12011952, 31520464, 605201, 2543521, 5991821, -2945064,
7229064, -9919646, -8826859},
{28816045, 298879, -28165016, -15920938, 19000928, -1665890,
-12680833, -2949325, -18051778, -2082915},
},
{
{16000882, -344896, 3493092, -11447198, -29504595, -13159789,
12577740, 16041268, -19715240, 7847707},
{10151868, 10572098, 27312476, 7922682, 14825339, 4723128,
-32855931, -6519018, -10020567, 3852848},
{-11430470, 15697596, -21121557, -4420647, 5386314, 15063598,
16514493, -15932110, 29330899, -15076224},
},
},
{
{
{-25499735, -4378794, -15222908, -6901211, 16615731, 2051784,
3303702, 15490, -27548796, 12314391},
{15683520, -6003043, 18109120, -9980648, 15337968, -5997823,
-16717435, 15921866, 16103996, -3731215},
{-23169824, -10781249, 13588192, -1628807, -3798557, -1074929,
-19273607, 5402699, -29815713, -9841101},
},
{
{23190676, 2384583, -32714340, 3462154, -29903655, -1529132,
-11266856, 8911517, -25205859, 2739713},
{21374101, -3554250, -33524649, 9874411, 15377179, 11831242,
-33529904, 6134907, 4931255, 11987849},
{-7732, -2978858, -16223486, 7277597, 105524, -322051, -31480539,
13861388, -30076310, 10117930},
},
{
{-29501170, -10744872, -26163768, 13051539, -25625564, 5089643,
-6325503, 6704079, 12890019, 15728940},
{-21972360, -11771379, -951059, -4418840, 14704840, 2695116, 903376,
-10428139, 12885167, 8311031},
{-17516482, 5352194, 10384213, -13811658, 7506451, 13453191,
26423267, 4384730, 1888765, -5435404},
},
{
{-25817338, -3107312, -13494599, -3182506, 30896459, -13921729,
-32251644, -12707869, -19464434, -3340243},
{-23607977, -2665774, -526091, 4651136, 5765089, 4618330, 6092245,
14845197, 17151279, -9854116},
{-24830458, -12733720, -15165978, 10367250, -29530908, -265356,
22825805, -7087279, -16866484, 16176525},
},
{
{-23583256, 6564961, 20063689, 3798228, -4740178, 7359225, 2006182,
-10363426, -28746253, -10197509},
{-10626600, -4486402, -13320562, -5125317, 3432136, -6393229,
23632037, -1940610, 32808310, 1099883},
{15030977, 5768825, -27451236, -2887299, -6427378, -15361371,
-15277896, -6809350, 2051441, -15225865},
},
{
{-3362323, -7239372, 7517890, 9824992, 23555850, 295369, 5148398,
-14154188, -22686354, 16633660},
{4577086, -16752288, 13249841, -15304328, 19958763, -14537274,
18559670, -10759549, 8402478, -9864273},
{-28406330, -1051581, -26790155, -907698, -17212414, -11030789,
9453451, -14980072, 17983010, 9967138},
},
{
{-25762494, 6524722, 26585488, 9969270, 24709298, 1220360, -1677990,
7806337, 17507396, 3651560},
{-10420457, -4118111, 14584639, 15971087, -15768321, 8861010,
26556809, -5574557, -18553322, -11357135},
{2839101, 14284142, 4029895, 3472686, 14402957, 12689363, -26642121,
8459447, -5605463, -7621941},
},
{
{-4839289, -3535444, 9744961, 2871048, 25113978, 3187018, -25110813,
-849066, 17258084, -7977739},
{18164541, -10595176, -17154882, -1542417, 19237078, -9745295,
23357533, -15217008, 26908270, 12150756},
{-30264870, -7647865, 5112249, -7036672, -1499807, -6974257, 43168,
-5537701, -32302074, 16215819},
},
},
{
{
{-6898905, 9824394, -12304779, -4401089, -31397141, -6276835,
32574489, 12532905, -7503072, -8675347},
{-27343522, -16515468, -27151524, -10722951, 946346, 16291093,
254968, 7168080, 21676107, -1943028},
{21260961, -8424752, -16831886, -11920822, -23677961, 3968121,
-3651949, -6215466, -3556191, -7913075},
},
{
{16544754, 13250366, -16804428, 15546242, -4583003, 12757258,
-2462308, -8680336, -18907032, -9662799},
{-2415239, -15577728, 18312303, 4964443, -15272530, -12653564,
26820651, 16690659, 25459437, -4564609},
{-25144690, 11425020, 28423002, -11020557, -6144921, -15826224,
9142795, -2391602, -6432418, -1644817},
},
{
{-23104652, 6253476, 16964147, -3768872, -25113972, -12296437,
-27457225, -16344658, 6335692, 7249989},
{-30333227, 13979675, 7503222, -12368314, -11956721, -4621693,
-30272269, 2682242, 25993170, -12478523},
{4364628, 5930691, 32304656, -10044554, -8054781, 15091131,
22857016, -10598955, 31820368, 15075278},
},
{
{31879134, -8918693, 17258761, 90626, -8041836, -4917709, 24162788,
-9650886, -17970238, 12833045},
{19073683, 14851414, -24403169, -11860168, 7625278, 11091125,
-19619190, 2074449, -9413939, 14905377},
{24483667, -11935567, -2518866, -11547418, -1553130, 15355506,
-25282080, 9253129, 27628530, -7555480},
},
{
{17597607, 8340603, 19355617, 552187, 26198470, -3176583, 4593324,
-9157582, -14110875, 15297016},
{510886, 14337390, -31785257, 16638632, 6328095, 2713355, -20217417,
-11864220, 8683221, 2921426},
{18606791, 11874196, 27155355, -5281482, -24031742, 6265446,
-25178240, -1278924, 4674690, 13890525},
},
{
{13609624, 13069022, -27372361, -13055908, 24360586, 9592974,
14977157, 9835105, 4389687, 288396},
{9922506, -519394, 13613107, 5883594, -18758345, -434263, -12304062,
8317628, 23388070, 16052080},
{12720016, 11937594, -31970060, -5028689, 26900120, 8561328,
-20155687, -11632979, -14754271, -10812892},
},
{
{15961858, 14150409, 26716931, -665832, -22794328, 13603569,
11829573, 7467844, -28822128, 929275},
{11038231, -11582396, -27310482, -7316562, -10498527, -16307831,
-23479533, -9371869, -21393143, 2465074},
{20017163, -4323226, 27915242, 1529148, 12396362, 15675764,
13817261, -9658066, 2463391, -4622140},
},
{
{-16358878, -12663911, -12065183, 4996454, -1256422, 1073572,
9583558, 12851107, 4003896, 12673717},
{-1731589, -15155870, -3262930, 16143082, 19294135, 13385325,
14741514, -9103726, 7903886, 2348101},
{24536016, -16515207, 12715592, -3862155, 1511293, 10047386,
-3842346, -7129159, -28377538, 10048127},
},
},
{
{
{-12622226, -6204820, 30718825, 2591312, -10617028, 12192840,
18873298, -7297090, -32297756, 15221632},
{-26478122, -11103864, 11546244, -1852483, 9180880, 7656409,
-21343950, 2095755, 29769758, 6593415},
{-31994208, -2907461, 4176912, 3264766, 12538965, -868111, 26312345,
-6118678, 30958054, 8292160},
},
{
{31429822, -13959116, 29173532, 15632448, 12174511, -2760094,
32808831, 3977186, 26143136, -3148876},
{22648901, 1402143, -22799984, 13746059, 7936347, 365344, -8668633,
-1674433, -3758243, -2304625},
{-15491917, 8012313, -2514730, -12702462, -23965846, -10254029,
-1612713, -1535569, -16664475, 8194478},
},
{
{27338066, -7507420, -7414224, 10140405, -19026427, -6589889,
27277191, 8855376, 28572286, 3005164},
{26287124, 4821776, 25476601, -4145903, -3764513, -15788984,
-18008582, 1182479, -26094821, -13079595},
{-7171154, 3178080, 23970071, 6201893, -17195577, -4489192,
-21876275, -13982627, 32208683, -1198248},
},
{
{-16657702, 2817643, -10286362, 14811298, 6024667, 13349505,
-27315504, -10497842, -27672585, -11539858},
{15941029, -9405932, -21367050, 8062055, 31876073, -238629,
-15278393, -1444429, 15397331, -4130193},
{8934485, -13485467, -23286397, -13423241, -32446090, 14047986,
31170398, -1441021, -27505566, 15087184},
},
{
{-18357243, -2156491, 24524913, -16677868, 15520427, -6360776,
-15502406, 11461896, 16788528, -5868942},
{-1947386, 16013773, 21750665, 3714552, -17401782, -16055433,
-3770287, -10323320, 31322514, -11615635},
{21426655, -5650218, -13648287, -5347537, -28812189, -4920970,
-18275391, -14621414, 13040862, -12112948},
},
{
{11293895, 12478086, -27136401, 15083750, -29307421, 14748872,
14555558, -13417103, 1613711, 4896935},
{-25894883, 15323294, -8489791, -8057900, 25967126, -13425460,
2825960, -4897045, -23971776, -11267415},
{-15924766, -5229880, -17443532, 6410664, 3622847, 10243618,
20615400, 12405433, -23753030, -8436416},
},
{
{-7091295, 12556208, -20191352, 9025187, -17072479, 4333801,
4378436, 2432030, 23097949, -566018},
{4565804, -16025654, 20084412, -7842817, 1724999, 189254, 24767264,
10103221, -18512313, 2424778},
{366633, -11976806, 8173090, -6890119, 30788634, 5745705, -7168678,
1344109, -3642553, 12412659},
},
{
{-24001791, 7690286, 14929416, -168257, -32210835, -13412986,
24162697, -15326504, -3141501, 11179385},
{18289522, -14724954, 8056945, 16430056, -21729724, 7842514,
-6001441, -1486897, -18684645, -11443503},
{476239, 6601091, -6152790, -9723375, 17503545, -4863900, 27672959,
13403813, 11052904, 5219329},
},
},
{
{
{20678546, -8375738, -32671898, 8849123, -5009758, 14574752,
31186971, -3973730, 9014762, -8579056},
{-13644050, -10350239, -15962508, 5075808, -1514661, -11534600,
-33102500, 9160280, 8473550, -3256838},
{24900749, 14435722, 17209120, -15292541, -22592275, 9878983,
-7689309, -16335821, -24568481, 11788948},
},
{
{-3118155, -11395194, -13802089, 14797441, 9652448, -6845904,
-20037437, 10410733, -24568470, -1458691},
{-15659161, 16736706, -22467150, 10215878, -9097177, 7563911,
11871841, -12505194, -18513325, 8464118},
{-23400612, 8348507, -14585951, -861714, -3950205, -6373419,
14325289, 8628612, 33313881, -8370517},
},
{
{-20186973, -4967935, 22367356, 5271547, -1097117, -4788838,
-24805667, -10236854, -8940735, -5818269},
{-6948785, -1795212, -32625683, -16021179, 32635414, -7374245,
15989197, -12838188, 28358192, -4253904},
{-23561781, -2799059, -32351682, -1661963, -9147719, 10429267,
-16637684, 4072016, -5351664, 5596589},
},
{
{-28236598, -3390048, 12312896, 6213178, 3117142, 16078565,
29266239, 2557221, 1768301, 15373193},
{-7243358, -3246960, -4593467, -7553353, -127927, -912245, -1090902,
-4504991, -24660491, 3442910},
{-30210571, 5124043, 14181784, 8197961, 18964734, -11939093,
22597931, 7176455, -18585478, 13365930},
},
{
{-7877390, -1499958, 8324673, 4690079, 6261860, 890446, 24538107,
-8570186, -9689599, -3031667},
{25008904, -10771599, -4305031, -9638010, 16265036, 15721635,
683793, -11823784, 15723479, -15163481},
{-9660625, 12374379, -27006999, -7026148, -7724114, -12314514,
11879682, 5400171, 519526, -1235876},
},
{
{22258397, -16332233, -7869817, 14613016, -22520255, -2950923,
-20353881, 7315967, 16648397, 7605640},
{-8081308, -8464597, -8223311, 9719710, 19259459, -15348212,
23994942, -5281555, -9468848, 4763278},
{-21699244, 9220969, -15730624, 1084137, -25476107, -2852390,
31088447, -7764523, -11356529, 728112},
},
{
{26047220, -11751471, -6900323, -16521798, 24092068, 9158119,
-4273545, -12555558, -29365436, -5498272},
{17510331, -322857, 5854289, 8403524, 17133918, -3112612, -28111007,
12327945, 10750447, 10014012},
{-10312768, 3936952, 9156313, -8897683, 16498692, -994647,
-27481051, -666732, 3424691, 7540221},
},
{
{30322361, -6964110, 11361005, -4143317, 7433304, 4989748, -7071422,
-16317219, -9244265, 15258046},
{13054562, -2779497, 19155474, 469045, -12482797, 4566042, 5631406,
2711395, 1062915, -5136345},
{-19240248, -11254599, -29509029, -7499965, -5835763, 13005411,
-6066489, 12194497, 32960380, 1459310},
},
},
{
{
{19852034, 7027924, 23669353, 10020366, 8586503, -6657907, 394197,
-6101885, 18638003, -11174937},
{31395534, 15098109, 26581030, 8030562, -16527914, -5007134,
9012486, -7584354, -6643087, -5442636},
{-9192165, -2347377, -1997099, 4529534, 25766844, 607986, -13222,
9677543, -32294889, -6456008},
},
{
{-2444496, -149937, 29348902, 8186665, 1873760, 12489863, -30934579,
-7839692, -7852844, -8138429},
{-15236356, -15433509, 7766470, 746860, 26346930, -10221762,
-27333451, 10754588, -9431476, 5203576},
{31834314, 14135496, -770007, 5159118, 20917671, -16768096,
-7467973, -7337524, 31809243, 7347066},
},
{
{-9606723, -11874240, 20414459, 13033986, 13716524, -11691881,
19797970, -12211255, 15192876, -2087490},
{-12663563, -2181719, 1168162, -3804809, 26747877, -14138091,
10609330, 12694420, 33473243, -13382104},
{33184999, 11180355, 15832085, -11385430, -1633671, 225884,
15089336, -11023903, -6135662, 14480053},
},
{
{31308717, -5619998, 31030840, -1897099, 15674547, -6582883,
5496208, 13685227, 27595050, 8737275},
{-20318852, -15150239, 10933843, -16178022, 8335352, -7546022,
-31008351, -12610604, 26498114, 66511},
{22644454, -8761729, -16671776, 4884562, -3105614, -13559366,
30540766, -4286747, -13327787, -7515095},
},
{
{-28017847, 9834845, 18617207, -2681312, -3401956, -13307506,
8205540, 13585437, -17127465, 15115439},
{23711543, -672915, 31206561, -8362711, 6164647, -9709987,
-33535882, -1426096, 8236921, 16492939},
{-23910559, -13515526, -26299483, -4503841, 25005590, -7687270,
19574902, 10071562, 6708380, -6222424},
},
{
{2101391, -4930054, 19702731, 2367575, -15427167, 1047675, 5301017,
9328700, 29955601, -11678310},
{3096359, 9271816, -21620864, -15521844, -14847996, -7592937,
-25892142, -12635595, -9917575, 6216608},
{-32615849, 338663, -25195611, 2510422, -29213566, -13820213,
24822830, -6146567, -26767480, 7525079},
},
{
{-23066649, -13985623, 16133487, -7896178, -3389565, 778788,
-910336, -2782495, -19386633, 11994101},
{21691500, -13624626, -641331, -14367021, 3285881, -3483596,
-25064666, 9718258, -7477437, 13381418},
{18445390, -4202236, 14979846, 11622458, -1727110, -3582980,
23111648, -6375247, 28535282, 15779576},
},
{
{30098053, 3089662, -9234387, 16662135, -21306940, 11308411,
-14068454, 12021730, 9955285, -16303356},
{9734894, -14576830, -7473633, -9138735, 2060392, 11313496,
-18426029, 9924399, 20194861, 13380996},
{-26378102, -7965207, -22167821, 15789297, -18055342, -6168792,
-1984914, 15707771, 26342023, 10146099},
},
},
{
{
{-26016874, -219943, 21339191, -41388, 19745256, -2878700,
-29637280, 2227040, 21612326, -545728},
{-13077387, 1184228, 23562814, -5970442, -20351244, -6348714,
25764461, 12243797, -20856566, 11649658},
{-10031494, 11262626, 27384172, 2271902, 26947504, -15997771, 39944,
6114064, 33514190, 2333242},
},
{
{-21433588, -12421821, 8119782, 7219913, -21830522, -9016134,
-6679750, -12670638, 24350578, -13450001},
{-4116307, -11271533, -23886186, 4843615, -30088339, 690623,
-31536088, -10406836, 8317860, 12352766},
{18200138, -14475911, -33087759, -2696619, -23702521, -9102511,
-23552096, -2287550, 20712163, 6719373},
},
{
{26656208, 6075253, -7858556, 1886072, -28344043, 4262326, 11117530,
-3763210, 26224235, -3297458},
{-17168938, -14854097, -3395676, -16369877, -19954045, 14050420,
21728352, 9493610, 18620611, -16428628},
{-13323321, 13325349, 11432106, 5964811, 18609221, 6062965,
-5269471, -9725556, -30701573, -16479657},
},
{
{-23860538, -11233159, 26961357, 1640861, -32413112, -16737940,
12248509, -5240639, 13735342, 1934062},
{25089769, 6742589, 17081145, -13406266, 21909293, -16067981,
-15136294, -3765346, -21277997, 5473616},
{31883677, -7961101, 1083432, -11572403, 22828471, 13290673,
-7125085, 12469656, 29111212, -5451014},
},
{
{24244947, -15050407, -26262976, 2791540, -14997599, 16666678,
24367466, 6388839, -10295587, 452383},
{-25640782, -3417841, 5217916, 16224624, 19987036, -4082269,
-24236251, -5915248, 15766062, 8407814},
{-20406999, 13990231, 15495425, 16395525, 5377168, 15166495,
-8917023, -4388953, -8067909, 2276718},
},
{
{30157918, 12924066, -17712050, 9245753, 19895028, 3368142,
-23827587, 5096219, 22740376, -7303417},
{2041139, -14256350, 7783687, 13876377, -25946985, -13352459,
24051124, 13742383, -15637599, 13295222},
{33338237, -8505733, 12532113, 7977527, 9106186, -1715251,
-17720195, -4612972, -4451357, -14669444},
},
{
{-20045281, 5454097, -14346548, 6447146, 28862071, 1883651,
-2469266, -4141880, 7770569, 9620597},
{23208068, 7979712, 33071466, 8149229, 1758231, -10834995, 30945528,
-1694323, -33502340, -14767970},
{1439958, -16270480, -1079989, -793782, 4625402, 10647766, -5043801,
1220118, 30494170, -11440799},
},
{
{-5037580, -13028295, -2970559, -3061767, 15640974, -6701666,
-26739026, 926050, -1684339, -13333647},
{13908495, -3549272, 30919928, -6273825, -21521863, 7989039,
9021034, 9078865, 3353509, 4033511},
{-29663431, -15113610, 32259991, -344482, 24295849, -12912123,
23161163, 8839127, 27485041, 7356032},
},
},
{
{
{9661027, 705443, 11980065, -5370154, -1628543, 14661173, -6346142,
2625015, 28431036, -16771834},
{-23839233, -8311415, -25945511, 7480958, -17681669, -8354183,
-22545972, 14150565, 15970762, 4099461},
{29262576, 16756590, 26350592, -8793563, 8529671, -11208050,
13617293, -9937143, 11465739, 8317062},
},
{
{-25493081, -6962928, 32500200, -9419051, -23038724, -2302222,
14898637, 3848455, 20969334, -5157516},
{-20384450, -14347713, -18336405, 13884722, -33039454, 2842114,
-21610826, -3649888, 11177095, 14989547},
{-24496721, -11716016, 16959896, 2278463, 12066309, 10137771,
13515641, 2581286, -28487508, 9930240},
},
{
{-17751622, -2097826, 16544300, -13009300, -15914807, -14949081,
18345767, -13403753, 16291481, -5314038},
{-33229194, 2553288, 32678213, 9875984, 8534129, 6889387, -9676774,
6957617, 4368891, 9788741},
{16660756, 7281060, -10830758, 12911820, 20108584, -8101676,
-21722536, -8613148, 16250552, -11111103},
},
{
{-19765507, 2390526, -16551031, 14161980, 1905286, 6414907, 4689584,
10604807, -30190403, 4782747},
{-1354539, 14736941, -7367442, -13292886, 7710542, -14155590,
-9981571, 4383045, 22546403, 437323},
{31665577, -12180464, -16186830, 1491339, -18368625, 3294682,
27343084, 2786261, -30633590, -14097016},
},
{
{-14467279, -683715, -33374107, 7448552, 19294360, 14334329,
-19690631, 2355319, -19284671, -6114373},
{15121312, -15796162, 6377020, -6031361, -10798111, -12957845,
18952177, 15496498, -29380133, 11754228},
{-2637277, -13483075, 8488727, -14303896, 12728761, -1622493,
7141596, 11724556, 22761615, -10134141},
},
{
{16918416, 11729663, -18083579, 3022987, -31015732, -13339659,
-28741185, -12227393, 32851222, 11717399},
{11166634, 7338049, -6722523, 4531520, -29468672, -7302055,
31474879, 3483633, -1193175, -4030831},
{-185635, 9921305, 31456609, -13536438, -12013818, 13348923,
33142652, 6546660, -19985279, -3948376},
},
{
{-32460596, 11266712, -11197107, -7899103, 31703694, 3855903,
-8537131, -12833048, -30772034, -15486313},
{-18006477, 12709068, 3991746, -6479188, -21491523, -10550425,
-31135347, -16049879, 10928917, 3011958},
{-6957757, -15594337, 31696059, 334240, 29576716, 14796075,
-30831056, -12805180, 18008031, 10258577},
},
{
{-22448644, 15655569, 7018479, -4410003, -30314266, -1201591,
-1853465, 1367120, 25127874, 6671743},
{29701166, -14373934, -10878120, 9279288, -17568, 13127210,
21382910, 11042292, 25838796, 4642684},
{-20430234, 14955537, -24126347, 8124619, -5369288, -5990470,
30468147, -13900640, 18423289, 4177476},
},
},
};
static uint8_t negative(signed char b) {
uint32_t x = b;
x >>= 31; /* 1: yes; 0: no */
return x;
}
static void table_select(ge_precomp *t, int pos, signed char b) {
ge_precomp minust;
uint8_t bnegative = negative(b);
uint8_t babs = b - ((uint8_t)((-bnegative) & b) << 1);
ge_precomp_0(t);
cmov(t, &k25519Precomp[pos][0], equal(babs, 1));
cmov(t, &k25519Precomp[pos][1], equal(babs, 2));
cmov(t, &k25519Precomp[pos][2], equal(babs, 3));
cmov(t, &k25519Precomp[pos][3], equal(babs, 4));
cmov(t, &k25519Precomp[pos][4], equal(babs, 5));
cmov(t, &k25519Precomp[pos][5], equal(babs, 6));
cmov(t, &k25519Precomp[pos][6], equal(babs, 7));
cmov(t, &k25519Precomp[pos][7], equal(babs, 8));
fe_copy(minust.yplusx, t->yminusx);
fe_copy(minust.yminusx, t->yplusx);
fe_neg(minust.xy2d, t->xy2d);
cmov(t, &minust, bnegative);
}
/* h = a * B
* where a = a[0]+256*a[1]+...+256^31 a[31]
* B is the Ed25519 base point (x,4/5) with x positive.
*
* Preconditions:
* a[31] <= 127 */
static void ge_scalarmult_base(ge_p3 *h, const uint8_t *a) {
signed char e[64];
signed char carry;
ge_p1p1 r;
ge_p2 s;
ge_precomp t;
int i;
for (i = 0; i < 32; ++i) {
e[2 * i + 0] = (a[i] >> 0) & 15;
e[2 * i + 1] = (a[i] >> 4) & 15;
}
/* each e[i] is between 0 and 15 */
/* e[63] is between 0 and 7 */
carry = 0;
for (i = 0; i < 63; ++i) {
e[i] += carry;
carry = e[i] + 8;
carry >>= 4;
e[i] -= carry << 4;
}
e[63] += carry;
/* each e[i] is between -8 and 8 */
ge_p3_0(h);
for (i = 1; i < 64; i += 2) {
table_select(&t, i / 2, e[i]);
ge_madd(&r, h, &t);
ge_p1p1_to_p3(h, &r);
}
ge_p3_dbl(&r, h);
ge_p1p1_to_p2(&s, &r);
ge_p2_dbl(&r, &s);
ge_p1p1_to_p2(&s, &r);
ge_p2_dbl(&r, &s);
ge_p1p1_to_p2(&s, &r);
ge_p2_dbl(&r, &s);
ge_p1p1_to_p3(h, &r);
for (i = 0; i < 64; i += 2) {
table_select(&t, i / 2, e[i]);
ge_madd(&r, h, &t);
ge_p1p1_to_p3(h, &r);
}
OPENSSL_cleanse(e, sizeof(e));
}
#if !defined(BASE_2_51_IMPLEMENTED)
/* Replace (f,g) with (g,f) if b == 1;
* replace (f,g) with (f,g) if b == 0.
*
* Preconditions: b in {0,1}. */
static void fe_cswap(fe f, fe g, unsigned int b) {
size_t i;
b = 0-b;
for (i = 0; i < 10; i++) {
int32_t x = f[i] ^ g[i];
x &= b;
f[i] ^= x;
g[i] ^= x;
}
}
/* h = f * 121666
* Can overlap h with f.
*
* Preconditions:
* |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
*
* Postconditions:
* |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. */
static void fe_mul121666(fe h, fe f) {
int32_t f0 = f[0];
int32_t f1 = f[1];
int32_t f2 = f[2];
int32_t f3 = f[3];
int32_t f4 = f[4];
int32_t f5 = f[5];
int32_t f6 = f[6];
int32_t f7 = f[7];
int32_t f8 = f[8];
int32_t f9 = f[9];
int64_t h0 = f0 * (int64_t) 121666;
int64_t h1 = f1 * (int64_t) 121666;
int64_t h2 = f2 * (int64_t) 121666;
int64_t h3 = f3 * (int64_t) 121666;
int64_t h4 = f4 * (int64_t) 121666;
int64_t h5 = f5 * (int64_t) 121666;
int64_t h6 = f6 * (int64_t) 121666;
int64_t h7 = f7 * (int64_t) 121666;
int64_t h8 = f8 * (int64_t) 121666;
int64_t h9 = f9 * (int64_t) 121666;
int64_t carry0;
int64_t carry1;
int64_t carry2;
int64_t carry3;
int64_t carry4;
int64_t carry5;
int64_t carry6;
int64_t carry7;
int64_t carry8;
int64_t carry9;
carry9 = h9 + (1 << 24); h0 += (carry9 >> 25) * 19; h9 -= carry9 & kTop39Bits;
carry1 = h1 + (1 << 24); h2 += carry1 >> 25; h1 -= carry1 & kTop39Bits;
carry3 = h3 + (1 << 24); h4 += carry3 >> 25; h3 -= carry3 & kTop39Bits;
carry5 = h5 + (1 << 24); h6 += carry5 >> 25; h5 -= carry5 & kTop39Bits;
carry7 = h7 + (1 << 24); h8 += carry7 >> 25; h7 -= carry7 & kTop39Bits;
carry0 = h0 + (1 << 25); h1 += carry0 >> 26; h0 -= carry0 & kTop38Bits;
carry2 = h2 + (1 << 25); h3 += carry2 >> 26; h2 -= carry2 & kTop38Bits;
carry4 = h4 + (1 << 25); h5 += carry4 >> 26; h4 -= carry4 & kTop38Bits;
carry6 = h6 + (1 << 25); h7 += carry6 >> 26; h6 -= carry6 & kTop38Bits;
carry8 = h8 + (1 << 25); h9 += carry8 >> 26; h8 -= carry8 & kTop38Bits;
h[0] = (int32_t)h0;
h[1] = (int32_t)h1;
h[2] = (int32_t)h2;
h[3] = (int32_t)h3;
h[4] = (int32_t)h4;
h[5] = (int32_t)h5;
h[6] = (int32_t)h6;
h[7] = (int32_t)h7;
h[8] = (int32_t)h8;
h[9] = (int32_t)h9;
}
static void x25519_scalar_mult_generic(uint8_t out[32],
const uint8_t scalar[32],
const uint8_t point[32]) {
fe x1, x2, z2, x3, z3, tmp0, tmp1;
uint8_t e[32];
unsigned swap = 0;
int pos;
memcpy(e, scalar, 32);
e[0] &= 248;
e[31] &= 127;
e[31] |= 64;
fe_frombytes(x1, point);
fe_1(x2);
fe_0(z2);
fe_copy(x3, x1);
fe_1(z3);
for (pos = 254; pos >= 0; --pos) {
unsigned b = 1 & (e[pos / 8] >> (pos & 7));
swap ^= b;
fe_cswap(x2, x3, swap);
fe_cswap(z2, z3, swap);
swap = b;
fe_sub(tmp0, x3, z3);
fe_sub(tmp1, x2, z2);
fe_add(x2, x2, z2);
fe_add(z2, x3, z3);
fe_mul(z3, tmp0, x2);
fe_mul(z2, z2, tmp1);
fe_sq(tmp0, tmp1);
fe_sq(tmp1, x2);
fe_add(x3, z3, z2);
fe_sub(z2, z3, z2);
fe_mul(x2, tmp1, tmp0);
fe_sub(tmp1, tmp1, tmp0);
fe_sq(z2, z2);
fe_mul121666(z3, tmp1);
fe_sq(x3, x3);
fe_add(tmp0, tmp0, z3);
fe_mul(z3, x1, z2);
fe_mul(z2, tmp1, tmp0);
}
fe_invert(z2, z2);
fe_mul(x2, x2, z2);
fe_tobytes(out, x2);
OPENSSL_cleanse(e, sizeof(e));
}
static void x25519_scalar_mult(uint8_t out[32], const uint8_t scalar[32],
const uint8_t point[32]) {
x25519_scalar_mult_generic(out, scalar, point);
}
#endif
static void slide(signed char *r, const uint8_t *a) {
int i;
int b;
int k;
for (i = 0; i < 256; ++i) {
r[i] = 1 & (a[i >> 3] >> (i & 7));
}
for (i = 0; i < 256; ++i) {
if (r[i]) {
for (b = 1; b <= 6 && i + b < 256; ++b) {
if (r[i + b]) {
if (r[i] + (r[i + b] << b) <= 15) {
r[i] += r[i + b] << b;
r[i + b] = 0;
} else if (r[i] - (r[i + b] << b) >= -15) {
r[i] -= r[i + b] << b;
for (k = i + b; k < 256; ++k) {
if (!r[k]) {
r[k] = 1;
break;
}
r[k] = 0;
}
} else {
break;
}
}
}
}
}
}
static const ge_precomp Bi[8] = {
{
{25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626,
-11754271, -6079156, 2047605},
{-12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692,
5043384, 19500929, -15469378},
{-8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919,
11864899, -24514362, -4438546},
},
{
{15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600,
-14772189, 28944400, -1550024},
{16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577,
-11775962, 7689662, 11199574},
{30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774,
10017326, -17749093, -9920357},
},
{
{10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885,
14515107, -15438304, 10819380},
{4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668,
12483688, -12668491, 5581306},
{19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350,
13850243, -23678021, -15815942},
},
{
{5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852,
5230134, -23952439, -15175766},
{-30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025,
16520125, 30598449, 7715701},
{28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660,
1370708, 29794553, -1409300},
},
{
{-22518993, -6692182, 14201702, -8745502, -23510406, 8844726, 18474211,
-1361450, -13062696, 13821877},
{-6455177, -7839871, 3374702, -4740862, -27098617, -10571707, 31655028,
-7212327, 18853322, -14220951},
{4566830, -12963868, -28974889, -12240689, -7602672, -2830569, -8514358,
-10431137, 2207753, -3209784},
},
{
{-25154831, -4185821, 29681144, 7868801, -6854661, -9423865, -12437364,
-663000, -31111463, -16132436},
{25576264, -2703214, 7349804, -11814844, 16472782, 9300885, 3844789,
15725684, 171356, 6466918},
{23103977, 13316479, 9739013, -16149481, 817875, -15038942, 8965339,
-14088058, -30714912, 16193877},
},
{
{-33521811, 3180713, -2394130, 14003687, -16903474, -16270840, 17238398,
4729455, -18074513, 9256800},
{-25182317, -4174131, 32336398, 5036987, -21236817, 11360617, 22616405,
9761698, -19827198, 630305},
{-13720693, 2639453, -24237460, -7406481, 9494427, -5774029, -6554551,
-15960994, -2449256, -14291300},
},
{
{-3151181, -5046075, 9282714, 6866145, -31907062, -863023, -18940575,
15033784, 25105118, -7894876},
{-24326370, 15950226, -31801215, -14592823, -11662737, -5090925,
1573892, -2625887, 2198790, -15804619},
{-3099351, 10324967, -2241613, 7453183, -5446979, -2735503, -13812022,
-16236442, -32461234, -12290683},
},
};
/* r = a * A + b * B
* where a = a[0]+256*a[1]+...+256^31 a[31].
* and b = b[0]+256*b[1]+...+256^31 b[31].
* B is the Ed25519 base point (x,4/5) with x positive. */
static void ge_double_scalarmult_vartime(ge_p2 *r, const uint8_t *a,
const ge_p3 *A, const uint8_t *b) {
signed char aslide[256];
signed char bslide[256];
ge_cached Ai[8]; /* A,3A,5A,7A,9A,11A,13A,15A */
ge_p1p1 t;
ge_p3 u;
ge_p3 A2;
int i;
slide(aslide, a);
slide(bslide, b);
ge_p3_to_cached(&Ai[0], A);
ge_p3_dbl(&t, A);
ge_p1p1_to_p3(&A2, &t);
ge_add(&t, &A2, &Ai[0]);
ge_p1p1_to_p3(&u, &t);
ge_p3_to_cached(&Ai[1], &u);
ge_add(&t, &A2, &Ai[1]);
ge_p1p1_to_p3(&u, &t);
ge_p3_to_cached(&Ai[2], &u);
ge_add(&t, &A2, &Ai[2]);
ge_p1p1_to_p3(&u, &t);
ge_p3_to_cached(&Ai[3], &u);
ge_add(&t, &A2, &Ai[3]);
ge_p1p1_to_p3(&u, &t);
ge_p3_to_cached(&Ai[4], &u);
ge_add(&t, &A2, &Ai[4]);
ge_p1p1_to_p3(&u, &t);
ge_p3_to_cached(&Ai[5], &u);
ge_add(&t, &A2, &Ai[5]);
ge_p1p1_to_p3(&u, &t);
ge_p3_to_cached(&Ai[6], &u);
ge_add(&t, &A2, &Ai[6]);
ge_p1p1_to_p3(&u, &t);
ge_p3_to_cached(&Ai[7], &u);
ge_p2_0(r);
for (i = 255; i >= 0; --i) {
if (aslide[i] || bslide[i]) {
break;
}
}
for (; i >= 0; --i) {
ge_p2_dbl(&t, r);
if (aslide[i] > 0) {
ge_p1p1_to_p3(&u, &t);
ge_add(&t, &u, &Ai[aslide[i] / 2]);
} else if (aslide[i] < 0) {
ge_p1p1_to_p3(&u, &t);
ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]);
}
if (bslide[i] > 0) {
ge_p1p1_to_p3(&u, &t);
ge_madd(&t, &u, &Bi[bslide[i] / 2]);
} else if (bslide[i] < 0) {
ge_p1p1_to_p3(&u, &t);
ge_msub(&t, &u, &Bi[(-bslide[i]) / 2]);
}
ge_p1p1_to_p2(r, &t);
}
}
/* The set of scalars is \Z/l
* where l = 2^252 + 27742317777372353535851937790883648493. */
/* Input:
* s[0]+256*s[1]+...+256^63*s[63] = s
*
* Output:
* s[0]+256*s[1]+...+256^31*s[31] = s mod l
* where l = 2^252 + 27742317777372353535851937790883648493.
* Overwrites s in place. */
static void x25519_sc_reduce(uint8_t *s) {
int64_t s0 = 2097151 & load_3(s);
int64_t s1 = 2097151 & (load_4(s + 2) >> 5);
int64_t s2 = 2097151 & (load_3(s + 5) >> 2);
int64_t s3 = 2097151 & (load_4(s + 7) >> 7);
int64_t s4 = 2097151 & (load_4(s + 10) >> 4);
int64_t s5 = 2097151 & (load_3(s + 13) >> 1);
int64_t s6 = 2097151 & (load_4(s + 15) >> 6);
int64_t s7 = 2097151 & (load_3(s + 18) >> 3);
int64_t s8 = 2097151 & load_3(s + 21);
int64_t s9 = 2097151 & (load_4(s + 23) >> 5);
int64_t s10 = 2097151 & (load_3(s + 26) >> 2);
int64_t s11 = 2097151 & (load_4(s + 28) >> 7);
int64_t s12 = 2097151 & (load_4(s + 31) >> 4);
int64_t s13 = 2097151 & (load_3(s + 34) >> 1);
int64_t s14 = 2097151 & (load_4(s + 36) >> 6);
int64_t s15 = 2097151 & (load_3(s + 39) >> 3);
int64_t s16 = 2097151 & load_3(s + 42);
int64_t s17 = 2097151 & (load_4(s + 44) >> 5);
int64_t s18 = 2097151 & (load_3(s + 47) >> 2);
int64_t s19 = 2097151 & (load_4(s + 49) >> 7);
int64_t s20 = 2097151 & (load_4(s + 52) >> 4);
int64_t s21 = 2097151 & (load_3(s + 55) >> 1);
int64_t s22 = 2097151 & (load_4(s + 57) >> 6);
int64_t s23 = (load_4(s + 60) >> 3);
int64_t carry0;
int64_t carry1;
int64_t carry2;
int64_t carry3;
int64_t carry4;
int64_t carry5;
int64_t carry6;
int64_t carry7;
int64_t carry8;
int64_t carry9;
int64_t carry10;
int64_t carry11;
int64_t carry12;
int64_t carry13;
int64_t carry14;
int64_t carry15;
int64_t carry16;
s11 += s23 * 666643;
s12 += s23 * 470296;
s13 += s23 * 654183;
s14 -= s23 * 997805;
s15 += s23 * 136657;
s16 -= s23 * 683901;
s23 = 0;
s10 += s22 * 666643;
s11 += s22 * 470296;
s12 += s22 * 654183;
s13 -= s22 * 997805;
s14 += s22 * 136657;
s15 -= s22 * 683901;
s22 = 0;
s9 += s21 * 666643;
s10 += s21 * 470296;
s11 += s21 * 654183;
s12 -= s21 * 997805;
s13 += s21 * 136657;
s14 -= s21 * 683901;
s21 = 0;
s8 += s20 * 666643;
s9 += s20 * 470296;
s10 += s20 * 654183;
s11 -= s20 * 997805;
s12 += s20 * 136657;
s13 -= s20 * 683901;
s20 = 0;
s7 += s19 * 666643;
s8 += s19 * 470296;
s9 += s19 * 654183;
s10 -= s19 * 997805;
s11 += s19 * 136657;
s12 -= s19 * 683901;
s19 = 0;
s6 += s18 * 666643;
s7 += s18 * 470296;
s8 += s18 * 654183;
s9 -= s18 * 997805;
s10 += s18 * 136657;
s11 -= s18 * 683901;
s18 = 0;
carry6 = (s6 + (1 << 20)) >> 21;
s7 += carry6;
s6 -= carry6 * (1 << 21);
carry8 = (s8 + (1 << 20)) >> 21;
s9 += carry8;
s8 -= carry8 * (1 << 21);
carry10 = (s10 + (1 << 20)) >> 21;
s11 += carry10;
s10 -= carry10 * (1 << 21);
carry12 = (s12 + (1 << 20)) >> 21;
s13 += carry12;
s12 -= carry12 * (1 << 21);
carry14 = (s14 + (1 << 20)) >> 21;
s15 += carry14;
s14 -= carry14 * (1 << 21);
carry16 = (s16 + (1 << 20)) >> 21;
s17 += carry16;
s16 -= carry16 * (1 << 21);
carry7 = (s7 + (1 << 20)) >> 21;
s8 += carry7;
s7 -= carry7 * (1 << 21);
carry9 = (s9 + (1 << 20)) >> 21;
s10 += carry9;
s9 -= carry9 * (1 << 21);
carry11 = (s11 + (1 << 20)) >> 21;
s12 += carry11;
s11 -= carry11 * (1 << 21);
carry13 = (s13 + (1 << 20)) >> 21;
s14 += carry13;
s13 -= carry13 * (1 << 21);
carry15 = (s15 + (1 << 20)) >> 21;
s16 += carry15;
s15 -= carry15 * (1 << 21);
s5 += s17 * 666643;
s6 += s17 * 470296;
s7 += s17 * 654183;
s8 -= s17 * 997805;
s9 += s17 * 136657;
s10 -= s17 * 683901;
s17 = 0;
s4 += s16 * 666643;
s5 += s16 * 470296;
s6 += s16 * 654183;
s7 -= s16 * 997805;
s8 += s16 * 136657;
s9 -= s16 * 683901;
s16 = 0;
s3 += s15 * 666643;
s4 += s15 * 470296;
s5 += s15 * 654183;
s6 -= s15 * 997805;
s7 += s15 * 136657;
s8 -= s15 * 683901;
s15 = 0;
s2 += s14 * 666643;
s3 += s14 * 470296;
s4 += s14 * 654183;
s5 -= s14 * 997805;
s6 += s14 * 136657;
s7 -= s14 * 683901;
s14 = 0;
s1 += s13 * 666643;
s2 += s13 * 470296;
s3 += s13 * 654183;
s4 -= s13 * 997805;
s5 += s13 * 136657;
s6 -= s13 * 683901;
s13 = 0;
s0 += s12 * 666643;
s1 += s12 * 470296;
s2 += s12 * 654183;
s3 -= s12 * 997805;
s4 += s12 * 136657;
s5 -= s12 * 683901;
s12 = 0;
carry0 = (s0 + (1 << 20)) >> 21;
s1 += carry0;
s0 -= carry0 * (1 << 21);
carry2 = (s2 + (1 << 20)) >> 21;
s3 += carry2;
s2 -= carry2 * (1 << 21);
carry4 = (s4 + (1 << 20)) >> 21;
s5 += carry4;
s4 -= carry4 * (1 << 21);
carry6 = (s6 + (1 << 20)) >> 21;
s7 += carry6;
s6 -= carry6 * (1 << 21);
carry8 = (s8 + (1 << 20)) >> 21;
s9 += carry8;
s8 -= carry8 * (1 << 21);
carry10 = (s10 + (1 << 20)) >> 21;
s11 += carry10;
s10 -= carry10 * (1 << 21);
carry1 = (s1 + (1 << 20)) >> 21;
s2 += carry1;
s1 -= carry1 * (1 << 21);
carry3 = (s3 + (1 << 20)) >> 21;
s4 += carry3;
s3 -= carry3 * (1 << 21);
carry5 = (s5 + (1 << 20)) >> 21;
s6 += carry5;
s5 -= carry5 * (1 << 21);
carry7 = (s7 + (1 << 20)) >> 21;
s8 += carry7;
s7 -= carry7 * (1 << 21);
carry9 = (s9 + (1 << 20)) >> 21;
s10 += carry9;
s9 -= carry9 * (1 << 21);
carry11 = (s11 + (1 << 20)) >> 21;
s12 += carry11;
s11 -= carry11 * (1 << 21);
s0 += s12 * 666643;
s1 += s12 * 470296;
s2 += s12 * 654183;
s3 -= s12 * 997805;
s4 += s12 * 136657;
s5 -= s12 * 683901;
s12 = 0;
carry0 = s0 >> 21;
s1 += carry0;
s0 -= carry0 * (1 << 21);
carry1 = s1 >> 21;
s2 += carry1;
s1 -= carry1 * (1 << 21);
carry2 = s2 >> 21;
s3 += carry2;
s2 -= carry2 * (1 << 21);
carry3 = s3 >> 21;
s4 += carry3;
s3 -= carry3 * (1 << 21);
carry4 = s4 >> 21;
s5 += carry4;
s4 -= carry4 * (1 << 21);
carry5 = s5 >> 21;
s6 += carry5;
s5 -= carry5 * (1 << 21);
carry6 = s6 >> 21;
s7 += carry6;
s6 -= carry6 * (1 << 21);
carry7 = s7 >> 21;
s8 += carry7;
s7 -= carry7 * (1 << 21);
carry8 = s8 >> 21;
s9 += carry8;
s8 -= carry8 * (1 << 21);
carry9 = s9 >> 21;
s10 += carry9;
s9 -= carry9 * (1 << 21);
carry10 = s10 >> 21;
s11 += carry10;
s10 -= carry10 * (1 << 21);
carry11 = s11 >> 21;
s12 += carry11;
s11 -= carry11 * (1 << 21);
s0 += s12 * 666643;
s1 += s12 * 470296;
s2 += s12 * 654183;
s3 -= s12 * 997805;
s4 += s12 * 136657;
s5 -= s12 * 683901;
s12 = 0;
carry0 = s0 >> 21;
s1 += carry0;
s0 -= carry0 * (1 << 21);
carry1 = s1 >> 21;
s2 += carry1;
s1 -= carry1 * (1 << 21);
carry2 = s2 >> 21;
s3 += carry2;
s2 -= carry2 * (1 << 21);
carry3 = s3 >> 21;
s4 += carry3;
s3 -= carry3 * (1 << 21);
carry4 = s4 >> 21;
s5 += carry4;
s4 -= carry4 * (1 << 21);
carry5 = s5 >> 21;
s6 += carry5;
s5 -= carry5 * (1 << 21);
carry6 = s6 >> 21;
s7 += carry6;
s6 -= carry6 * (1 << 21);
carry7 = s7 >> 21;
s8 += carry7;
s7 -= carry7 * (1 << 21);
carry8 = s8 >> 21;
s9 += carry8;
s8 -= carry8 * (1 << 21);
carry9 = s9 >> 21;
s10 += carry9;
s9 -= carry9 * (1 << 21);
carry10 = s10 >> 21;
s11 += carry10;
s10 -= carry10 * (1 << 21);
s[0] = (uint8_t)(s0 >> 0);
s[1] = (uint8_t)(s0 >> 8);
s[2] = (uint8_t)((s0 >> 16) | (s1 << 5));
s[3] = (uint8_t)(s1 >> 3);
s[4] = (uint8_t)(s1 >> 11);
s[5] = (uint8_t)((s1 >> 19) | (s2 << 2));
s[6] = (uint8_t)(s2 >> 6);
s[7] = (uint8_t)((s2 >> 14) | (s3 << 7));
s[8] = (uint8_t)(s3 >> 1);
s[9] = (uint8_t)(s3 >> 9);
s[10] = (uint8_t)((s3 >> 17) | (s4 << 4));
s[11] = (uint8_t)(s4 >> 4);
s[12] = (uint8_t)(s4 >> 12);
s[13] = (uint8_t)((s4 >> 20) | (s5 << 1));
s[14] = (uint8_t)(s5 >> 7);
s[15] = (uint8_t)((s5 >> 15) | (s6 << 6));
s[16] = (uint8_t)(s6 >> 2);
s[17] = (uint8_t)(s6 >> 10);
s[18] = (uint8_t)((s6 >> 18) | (s7 << 3));
s[19] = (uint8_t)(s7 >> 5);
s[20] = (uint8_t)(s7 >> 13);
s[21] = (uint8_t)(s8 >> 0);
s[22] = (uint8_t)(s8 >> 8);
s[23] = (uint8_t)((s8 >> 16) | (s9 << 5));
s[24] = (uint8_t)(s9 >> 3);
s[25] = (uint8_t)(s9 >> 11);
s[26] = (uint8_t)((s9 >> 19) | (s10 << 2));
s[27] = (uint8_t)(s10 >> 6);
s[28] = (uint8_t)((s10 >> 14) | (s11 << 7));
s[29] = (uint8_t)(s11 >> 1);
s[30] = (uint8_t)(s11 >> 9);
s[31] = (uint8_t)(s11 >> 17);
}
/* Input:
* a[0]+256*a[1]+...+256^31*a[31] = a
* b[0]+256*b[1]+...+256^31*b[31] = b
* c[0]+256*c[1]+...+256^31*c[31] = c
*
* Output:
* s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l
* where l = 2^252 + 27742317777372353535851937790883648493. */
static void sc_muladd(uint8_t *s, const uint8_t *a, const uint8_t *b,
const uint8_t *c) {
int64_t a0 = 2097151 & load_3(a);
int64_t a1 = 2097151 & (load_4(a + 2) >> 5);
int64_t a2 = 2097151 & (load_3(a + 5) >> 2);
int64_t a3 = 2097151 & (load_4(a + 7) >> 7);
int64_t a4 = 2097151 & (load_4(a + 10) >> 4);
int64_t a5 = 2097151 & (load_3(a + 13) >> 1);
int64_t a6 = 2097151 & (load_4(a + 15) >> 6);
int64_t a7 = 2097151 & (load_3(a + 18) >> 3);
int64_t a8 = 2097151 & load_3(a + 21);
int64_t a9 = 2097151 & (load_4(a + 23) >> 5);
int64_t a10 = 2097151 & (load_3(a + 26) >> 2);
int64_t a11 = (load_4(a + 28) >> 7);
int64_t b0 = 2097151 & load_3(b);
int64_t b1 = 2097151 & (load_4(b + 2) >> 5);
int64_t b2 = 2097151 & (load_3(b + 5) >> 2);
int64_t b3 = 2097151 & (load_4(b + 7) >> 7);
int64_t b4 = 2097151 & (load_4(b + 10) >> 4);
int64_t b5 = 2097151 & (load_3(b + 13) >> 1);
int64_t b6 = 2097151 & (load_4(b + 15) >> 6);
int64_t b7 = 2097151 & (load_3(b + 18) >> 3);
int64_t b8 = 2097151 & load_3(b + 21);
int64_t b9 = 2097151 & (load_4(b + 23) >> 5);
int64_t b10 = 2097151 & (load_3(b + 26) >> 2);
int64_t b11 = (load_4(b + 28) >> 7);
int64_t c0 = 2097151 & load_3(c);
int64_t c1 = 2097151 & (load_4(c + 2) >> 5);
int64_t c2 = 2097151 & (load_3(c + 5) >> 2);
int64_t c3 = 2097151 & (load_4(c + 7) >> 7);
int64_t c4 = 2097151 & (load_4(c + 10) >> 4);
int64_t c5 = 2097151 & (load_3(c + 13) >> 1);
int64_t c6 = 2097151 & (load_4(c + 15) >> 6);
int64_t c7 = 2097151 & (load_3(c + 18) >> 3);
int64_t c8 = 2097151 & load_3(c + 21);
int64_t c9 = 2097151 & (load_4(c + 23) >> 5);
int64_t c10 = 2097151 & (load_3(c + 26) >> 2);
int64_t c11 = (load_4(c + 28) >> 7);
int64_t s0;
int64_t s1;
int64_t s2;
int64_t s3;
int64_t s4;
int64_t s5;
int64_t s6;
int64_t s7;
int64_t s8;
int64_t s9;
int64_t s10;
int64_t s11;
int64_t s12;
int64_t s13;
int64_t s14;
int64_t s15;
int64_t s16;
int64_t s17;
int64_t s18;
int64_t s19;
int64_t s20;
int64_t s21;
int64_t s22;
int64_t s23;
int64_t carry0;
int64_t carry1;
int64_t carry2;
int64_t carry3;
int64_t carry4;
int64_t carry5;
int64_t carry6;
int64_t carry7;
int64_t carry8;
int64_t carry9;
int64_t carry10;
int64_t carry11;
int64_t carry12;
int64_t carry13;
int64_t carry14;
int64_t carry15;
int64_t carry16;
int64_t carry17;
int64_t carry18;
int64_t carry19;
int64_t carry20;
int64_t carry21;
int64_t carry22;
s0 = c0 + a0 * b0;
s1 = c1 + a0 * b1 + a1 * b0;
s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0;
s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0;
s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0;
s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0;
s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0;
s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 +
a6 * b1 + a7 * b0;
s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 +
a6 * b2 + a7 * b1 + a8 * b0;
s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 +
a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0;
s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 +
a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0;
s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 +
a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0;
s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 + a7 * b5 +
a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1;
s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 + a8 * b5 +
a9 * b4 + a10 * b3 + a11 * b2;
s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 + a9 * b5 +
a10 * b4 + a11 * b3;
s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 + a10 * b5 +
a11 * b4;
s16 = a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5;
s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6;
s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7;
s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8;
s20 = a9 * b11 + a10 * b10 + a11 * b9;
s21 = a10 * b11 + a11 * b10;
s22 = a11 * b11;
s23 = 0;
carry0 = (s0 + (1 << 20)) >> 21;
s1 += carry0;
s0 -= carry0 * (1 << 21);
carry2 = (s2 + (1 << 20)) >> 21;
s3 += carry2;
s2 -= carry2 * (1 << 21);
carry4 = (s4 + (1 << 20)) >> 21;
s5 += carry4;
s4 -= carry4 * (1 << 21);
carry6 = (s6 + (1 << 20)) >> 21;
s7 += carry6;
s6 -= carry6 * (1 << 21);
carry8 = (s8 + (1 << 20)) >> 21;
s9 += carry8;
s8 -= carry8 * (1 << 21);
carry10 = (s10 + (1 << 20)) >> 21;
s11 += carry10;
s10 -= carry10 * (1 << 21);
carry12 = (s12 + (1 << 20)) >> 21;
s13 += carry12;
s12 -= carry12 * (1 << 21);
carry14 = (s14 + (1 << 20)) >> 21;
s15 += carry14;
s14 -= carry14 * (1 << 21);
carry16 = (s16 + (1 << 20)) >> 21;
s17 += carry16;
s16 -= carry16 * (1 << 21);
carry18 = (s18 + (1 << 20)) >> 21;
s19 += carry18;
s18 -= carry18 * (1 << 21);
carry20 = (s20 + (1 << 20)) >> 21;
s21 += carry20;
s20 -= carry20 * (1 << 21);
carry22 = (s22 + (1 << 20)) >> 21;
s23 += carry22;
s22 -= carry22 * (1 << 21);
carry1 = (s1 + (1 << 20)) >> 21;
s2 += carry1;
s1 -= carry1 * (1 << 21);
carry3 = (s3 + (1 << 20)) >> 21;
s4 += carry3;
s3 -= carry3 * (1 << 21);
carry5 = (s5 + (1 << 20)) >> 21;
s6 += carry5;
s5 -= carry5 * (1 << 21);
carry7 = (s7 + (1 << 20)) >> 21;
s8 += carry7;
s7 -= carry7 * (1 << 21);
carry9 = (s9 + (1 << 20)) >> 21;
s10 += carry9;
s9 -= carry9 * (1 << 21);
carry11 = (s11 + (1 << 20)) >> 21;
s12 += carry11;
s11 -= carry11 * (1 << 21);
carry13 = (s13 + (1 << 20)) >> 21;
s14 += carry13;
s13 -= carry13 * (1 << 21);
carry15 = (s15 + (1 << 20)) >> 21;
s16 += carry15;
s15 -= carry15 * (1 << 21);
carry17 = (s17 + (1 << 20)) >> 21;
s18 += carry17;
s17 -= carry17 * (1 << 21);
carry19 = (s19 + (1 << 20)) >> 21;
s20 += carry19;
s19 -= carry19 * (1 << 21);
carry21 = (s21 + (1 << 20)) >> 21;
s22 += carry21;
s21 -= carry21 * (1 << 21);
s11 += s23 * 666643;
s12 += s23 * 470296;
s13 += s23 * 654183;
s14 -= s23 * 997805;
s15 += s23 * 136657;
s16 -= s23 * 683901;
s23 = 0;
s10 += s22 * 666643;
s11 += s22 * 470296;
s12 += s22 * 654183;
s13 -= s22 * 997805;
s14 += s22 * 136657;
s15 -= s22 * 683901;
s22 = 0;
s9 += s21 * 666643;
s10 += s21 * 470296;
s11 += s21 * 654183;
s12 -= s21 * 997805;
s13 += s21 * 136657;
s14 -= s21 * 683901;
s21 = 0;
s8 += s20 * 666643;
s9 += s20 * 470296;
s10 += s20 * 654183;
s11 -= s20 * 997805;
s12 += s20 * 136657;
s13 -= s20 * 683901;
s20 = 0;
s7 += s19 * 666643;
s8 += s19 * 470296;
s9 += s19 * 654183;
s10 -= s19 * 997805;
s11 += s19 * 136657;
s12 -= s19 * 683901;
s19 = 0;
s6 += s18 * 666643;
s7 += s18 * 470296;
s8 += s18 * 654183;
s9 -= s18 * 997805;
s10 += s18 * 136657;
s11 -= s18 * 683901;
s18 = 0;
carry6 = (s6 + (1 << 20)) >> 21;
s7 += carry6;
s6 -= carry6 * (1 << 21);
carry8 = (s8 + (1 << 20)) >> 21;
s9 += carry8;
s8 -= carry8 * (1 << 21);
carry10 = (s10 + (1 << 20)) >> 21;
s11 += carry10;
s10 -= carry10 * (1 << 21);
carry12 = (s12 + (1 << 20)) >> 21;
s13 += carry12;
s12 -= carry12 * (1 << 21);
carry14 = (s14 + (1 << 20)) >> 21;
s15 += carry14;
s14 -= carry14 * (1 << 21);
carry16 = (s16 + (1 << 20)) >> 21;
s17 += carry16;
s16 -= carry16 * (1 << 21);
carry7 = (s7 + (1 << 20)) >> 21;
s8 += carry7;
s7 -= carry7 * (1 << 21);
carry9 = (s9 + (1 << 20)) >> 21;
s10 += carry9;
s9 -= carry9 * (1 << 21);
carry11 = (s11 + (1 << 20)) >> 21;
s12 += carry11;
s11 -= carry11 * (1 << 21);
carry13 = (s13 + (1 << 20)) >> 21;
s14 += carry13;
s13 -= carry13 * (1 << 21);
carry15 = (s15 + (1 << 20)) >> 21;
s16 += carry15;
s15 -= carry15 * (1 << 21);
s5 += s17 * 666643;
s6 += s17 * 470296;
s7 += s17 * 654183;
s8 -= s17 * 997805;
s9 += s17 * 136657;
s10 -= s17 * 683901;
s17 = 0;
s4 += s16 * 666643;
s5 += s16 * 470296;
s6 += s16 * 654183;
s7 -= s16 * 997805;
s8 += s16 * 136657;
s9 -= s16 * 683901;
s16 = 0;
s3 += s15 * 666643;
s4 += s15 * 470296;
s5 += s15 * 654183;
s6 -= s15 * 997805;
s7 += s15 * 136657;
s8 -= s15 * 683901;
s15 = 0;
s2 += s14 * 666643;
s3 += s14 * 470296;
s4 += s14 * 654183;
s5 -= s14 * 997805;
s6 += s14 * 136657;
s7 -= s14 * 683901;
s14 = 0;
s1 += s13 * 666643;
s2 += s13 * 470296;
s3 += s13 * 654183;
s4 -= s13 * 997805;
s5 += s13 * 136657;
s6 -= s13 * 683901;
s13 = 0;
s0 += s12 * 666643;
s1 += s12 * 470296;
s2 += s12 * 654183;
s3 -= s12 * 997805;
s4 += s12 * 136657;
s5 -= s12 * 683901;
s12 = 0;
carry0 = (s0 + (1 << 20)) >> 21;
s1 += carry0;
s0 -= carry0 * (1 << 21);
carry2 = (s2 + (1 << 20)) >> 21;
s3 += carry2;
s2 -= carry2 * (1 << 21);
carry4 = (s4 + (1 << 20)) >> 21;
s5 += carry4;
s4 -= carry4 * (1 << 21);
carry6 = (s6 + (1 << 20)) >> 21;
s7 += carry6;
s6 -= carry6 * (1 << 21);
carry8 = (s8 + (1 << 20)) >> 21;
s9 += carry8;
s8 -= carry8 * (1 << 21);
carry10 = (s10 + (1 << 20)) >> 21;
s11 += carry10;
s10 -= carry10 * (1 << 21);
carry1 = (s1 + (1 << 20)) >> 21;
s2 += carry1;
s1 -= carry1 * (1 << 21);
carry3 = (s3 + (1 << 20)) >> 21;
s4 += carry3;
s3 -= carry3 * (1 << 21);
carry5 = (s5 + (1 << 20)) >> 21;
s6 += carry5;
s5 -= carry5 * (1 << 21);
carry7 = (s7 + (1 << 20)) >> 21;
s8 += carry7;
s7 -= carry7 * (1 << 21);
carry9 = (s9 + (1 << 20)) >> 21;
s10 += carry9;
s9 -= carry9 * (1 << 21);
carry11 = (s11 + (1 << 20)) >> 21;
s12 += carry11;
s11 -= carry11 * (1 << 21);
s0 += s12 * 666643;
s1 += s12 * 470296;
s2 += s12 * 654183;
s3 -= s12 * 997805;
s4 += s12 * 136657;
s5 -= s12 * 683901;
s12 = 0;
carry0 = s0 >> 21;
s1 += carry0;
s0 -= carry0 * (1 << 21);
carry1 = s1 >> 21;
s2 += carry1;
s1 -= carry1 * (1 << 21);
carry2 = s2 >> 21;
s3 += carry2;
s2 -= carry2 * (1 << 21);
carry3 = s3 >> 21;
s4 += carry3;
s3 -= carry3 * (1 << 21);
carry4 = s4 >> 21;
s5 += carry4;
s4 -= carry4 * (1 << 21);
carry5 = s5 >> 21;
s6 += carry5;
s5 -= carry5 * (1 << 21);
carry6 = s6 >> 21;
s7 += carry6;
s6 -= carry6 * (1 << 21);
carry7 = s7 >> 21;
s8 += carry7;
s7 -= carry7 * (1 << 21);
carry8 = s8 >> 21;
s9 += carry8;
s8 -= carry8 * (1 << 21);
carry9 = s9 >> 21;
s10 += carry9;
s9 -= carry9 * (1 << 21);
carry10 = s10 >> 21;
s11 += carry10;
s10 -= carry10 * (1 << 21);
carry11 = s11 >> 21;
s12 += carry11;
s11 -= carry11 * (1 << 21);
s0 += s12 * 666643;
s1 += s12 * 470296;
s2 += s12 * 654183;
s3 -= s12 * 997805;
s4 += s12 * 136657;
s5 -= s12 * 683901;
s12 = 0;
carry0 = s0 >> 21;
s1 += carry0;
s0 -= carry0 * (1 << 21);
carry1 = s1 >> 21;
s2 += carry1;
s1 -= carry1 * (1 << 21);
carry2 = s2 >> 21;
s3 += carry2;
s2 -= carry2 * (1 << 21);
carry3 = s3 >> 21;
s4 += carry3;
s3 -= carry3 * (1 << 21);
carry4 = s4 >> 21;
s5 += carry4;
s4 -= carry4 * (1 << 21);
carry5 = s5 >> 21;
s6 += carry5;
s5 -= carry5 * (1 << 21);
carry6 = s6 >> 21;
s7 += carry6;
s6 -= carry6 * (1 << 21);
carry7 = s7 >> 21;
s8 += carry7;
s7 -= carry7 * (1 << 21);
carry8 = s8 >> 21;
s9 += carry8;
s8 -= carry8 * (1 << 21);
carry9 = s9 >> 21;
s10 += carry9;
s9 -= carry9 * (1 << 21);
carry10 = s10 >> 21;
s11 += carry10;
s10 -= carry10 * (1 << 21);
s[0] = (uint8_t)(s0 >> 0);
s[1] = (uint8_t)(s0 >> 8);
s[2] = (uint8_t)((s0 >> 16) | (s1 << 5));
s[3] = (uint8_t)(s1 >> 3);
s[4] = (uint8_t)(s1 >> 11);
s[5] = (uint8_t)((s1 >> 19) | (s2 << 2));
s[6] = (uint8_t)(s2 >> 6);
s[7] = (uint8_t)((s2 >> 14) | (s3 << 7));
s[8] = (uint8_t)(s3 >> 1);
s[9] = (uint8_t)(s3 >> 9);
s[10] = (uint8_t)((s3 >> 17) | (s4 << 4));
s[11] = (uint8_t)(s4 >> 4);
s[12] = (uint8_t)(s4 >> 12);
s[13] = (uint8_t)((s4 >> 20) | (s5 << 1));
s[14] = (uint8_t)(s5 >> 7);
s[15] = (uint8_t)((s5 >> 15) | (s6 << 6));
s[16] = (uint8_t)(s6 >> 2);
s[17] = (uint8_t)(s6 >> 10);
s[18] = (uint8_t)((s6 >> 18) | (s7 << 3));
s[19] = (uint8_t)(s7 >> 5);
s[20] = (uint8_t)(s7 >> 13);
s[21] = (uint8_t)(s8 >> 0);
s[22] = (uint8_t)(s8 >> 8);
s[23] = (uint8_t)((s8 >> 16) | (s9 << 5));
s[24] = (uint8_t)(s9 >> 3);
s[25] = (uint8_t)(s9 >> 11);
s[26] = (uint8_t)((s9 >> 19) | (s10 << 2));
s[27] = (uint8_t)(s10 >> 6);
s[28] = (uint8_t)((s10 >> 14) | (s11 << 7));
s[29] = (uint8_t)(s11 >> 1);
s[30] = (uint8_t)(s11 >> 9);
s[31] = (uint8_t)(s11 >> 17);
}
int ED25519_sign(uint8_t *out_sig, const uint8_t *message, size_t message_len,
const uint8_t public_key[32], const uint8_t private_key[32]) {
uint8_t az[SHA512_DIGEST_LENGTH];
uint8_t nonce[SHA512_DIGEST_LENGTH];
ge_p3 R;
uint8_t hram[SHA512_DIGEST_LENGTH];
SHA512_CTX hash_ctx;
SHA512_Init(&hash_ctx);
SHA512_Update(&hash_ctx, private_key, 32);
SHA512_Final(az, &hash_ctx);
az[0] &= 248;
az[31] &= 63;
az[31] |= 64;
SHA512_Init(&hash_ctx);
SHA512_Update(&hash_ctx, az + 32, 32);
SHA512_Update(&hash_ctx, message, message_len);
SHA512_Final(nonce, &hash_ctx);
x25519_sc_reduce(nonce);
ge_scalarmult_base(&R, nonce);
ge_p3_tobytes(out_sig, &R);
SHA512_Init(&hash_ctx);
SHA512_Update(&hash_ctx, out_sig, 32);
SHA512_Update(&hash_ctx, public_key, 32);
SHA512_Update(&hash_ctx, message, message_len);
SHA512_Final(hram, &hash_ctx);
x25519_sc_reduce(hram);
sc_muladd(out_sig + 32, hram, az, nonce);
OPENSSL_cleanse(&hash_ctx, sizeof(hash_ctx));
OPENSSL_cleanse(nonce, sizeof(nonce));
OPENSSL_cleanse(az, sizeof(az));
return 1;
}
int ED25519_verify(const uint8_t *message, size_t message_len,
const uint8_t signature[64], const uint8_t public_key[32]) {
ge_p3 A;
uint8_t rcopy[32];
uint8_t scopy[32];
SHA512_CTX hash_ctx;
ge_p2 R;
uint8_t rcheck[32];
uint8_t h[SHA512_DIGEST_LENGTH];
if ((signature[63] & 224) != 0 ||
ge_frombytes_vartime(&A, public_key) != 0) {
return 0;
}
fe_neg(A.X, A.X);
fe_neg(A.T, A.T);
memcpy(rcopy, signature, 32);
memcpy(scopy, signature + 32, 32);
SHA512_Init(&hash_ctx);
SHA512_Update(&hash_ctx, signature, 32);
SHA512_Update(&hash_ctx, public_key, 32);
SHA512_Update(&hash_ctx, message, message_len);
SHA512_Final(h, &hash_ctx);
x25519_sc_reduce(h);
ge_double_scalarmult_vartime(&R, h, &A, scopy);
ge_tobytes(rcheck, &R);
return CRYPTO_memcmp(rcheck, rcopy, sizeof(rcheck)) == 0;
}
void ED25519_public_from_private(uint8_t out_public_key[32],
const uint8_t private_key[32]) {
uint8_t az[SHA512_DIGEST_LENGTH];
ge_p3 A;
SHA512(private_key, 32, az);
az[0] &= 248;
az[31] &= 63;
az[31] |= 64;
ge_scalarmult_base(&A, az);
ge_p3_tobytes(out_public_key, &A);
OPENSSL_cleanse(az, sizeof(az));
}
int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
const uint8_t peer_public_value[32]) {
static const uint8_t kZeros[32] = {0};
x25519_scalar_mult(out_shared_key, private_key, peer_public_value);
/* The all-zero output results when the input is a point of small order. */
return CRYPTO_memcmp(kZeros, out_shared_key, 32) != 0;
}
void X25519_public_from_private(uint8_t out_public_value[32],
const uint8_t private_key[32]) {
uint8_t e[32];
ge_p3 A;
fe zplusy, zminusy, zminusy_inv;
memcpy(e, private_key, 32);
e[0] &= 248;
e[31] &= 127;
e[31] |= 64;
ge_scalarmult_base(&A, e);
/* We only need the u-coordinate of the curve25519 point. The map is
* u=(y+1)/(1-y). Since y=Y/Z, this gives u=(Z+Y)/(Z-Y). */
fe_add(zplusy, A.Z, A.Y);
fe_sub(zminusy, A.Z, A.Y);
fe_invert(zminusy_inv, zminusy);
fe_mul(zplusy, zplusy, zminusy_inv);
fe_tobytes(out_public_value, zplusy);
OPENSSL_cleanse(e, sizeof(e));
}
|
## 描述
实现 Flatten Arrays 的功能:将数组(可以包含数字,或数组,数组的数组。。。)展开为一层
## 例子
Input: var input = [2, 1, [3, [4, 5], 6], 7, [8]];
Output: [2, 1, 3, 4, 5, 6, 7, 8]
## 代码
```go
package main
import (
"reflect"
"fmt"
)
func listFlatten(inputList []interface{}, intList *[]int) {
for _, value := range inputList {
if reflect.TypeOf(value).Kind() == reflect.Int {
value, _ := value.(int)
*intList = append(*intList, value)
} else {
if value2, ok := value.([]interface{}); ok {
listFlatten(value2, intList)
} else if value2, ok := value.([]int); ok {
*intList = append(*intList, value2...)
}
}
}
}
func main() {
a := []int{}
inputList := []interface{}{2, 1, []interface{}{3, []int{4, 5}, 6}, 7, []int{8}}
listFlatten(inputList, &a)
fmt.Printf("last intList is %v\n", a)
// last intList is [2 1 3 4 5 6 7 8]
}
```
## 其他
使用递归函数处理数据
定义一个变量存储结果,关键是这个变量在递归的过程中需要全局访问
所以可以:
定义全局变量
在递归函数中使用指针(Go),如果是python,可以使用列表(因为其是引用,不是值传递)
|
<?php
/**
* This file is part of the GraphAware Neo4j Client package.
*
* (c) GraphAware Limited <http://graphaware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace GraphAware\Neo4j\Client\HttpDriver;
use GraphAware\Common\Transaction\TransactionInterface;
use GraphAware\Neo4j\Client\Exception\Neo4jException;
use GraphAware\Neo4j\Client\HttpDriver\Session;
use GraphAware\Common\Cypher\Statement;
class Transaction implements TransactionInterface
{
const OPENED = 'OPEN';
const COMMITED = 'COMMITED';
const ROLLED_BACK = 'ROLLED_BACK';
protected $state;
protected $session;
protected $closed = false;
protected $transactionId;
protected $expires;
public function __construct(Session $session)
{
$this->session = $session;
$this->session->transaction = $this;
}
public function isOpen()
{
return $this->state === self::OPENED;
}
public function isCommited()
{
return $this->state === self::COMMITED;
}
public function isRolledBack()
{
return $this->state === self::ROLLED_BACK;
}
public function getStatus()
{
return $this->state;
}
public function begin()
{
$this->assertNotStarted();
$response = $this->session->begin();
$body = json_decode($response->getBody(), true);
$parts = explode('/', $body['commit']);
$this->transactionId = (int) $parts[count($parts)-2];
$this->state = self::OPENED;
$this->session->transaction = $this;
}
public function run(Statement $statement)
{
$this->assertStarted();
try {
return $this->session->pushToTransaction($this->transactionId, array($statement));
} catch (Neo4jException $e) {
if ($e->effect() === Neo4jException::EFFECT_ROLLBACK) {
$this->closed = true;
$this->state = self::ROLLED_BACK;
}
throw $e;
}
}
public function runMultiple(array $statements)
{
try {
return $this->session->pushToTransaction($this->transactionId, $statements);
} catch (Neo4jException $e) {
if ($e->effect() === Neo4jException::EFFECT_ROLLBACK) {
$this->closed = true;
$this->state = self::ROLLED_BACK;
throw $e;
}
}
}
public function success()
{
$this->assertNotClosed();
$this->assertStarted();
$this->session->commitTransaction($this->transactionId);
$this->state = self::COMMITED;
$this->closed = true;
$this->session->transaction = null;
}
public function rollback()
{
$this->assertNotClosed();
$this->assertStarted();
$this->session->rollbackTransaction($this->transactionId);
$this->closed = true;
$this->state = self::ROLLED_BACK;
$this->session->transaction = null;
}
private function assertStarted()
{
if ($this->state !== self::OPENED) {
throw new \RuntimeException('This transaction has not been started');
}
}
private function assertNotStarted()
{
if (null !== $this->state) {
throw new \RuntimeException(sprintf('Can not begin transaction, Transaction State is "%s"', $this->state));
}
}
private function assertNotClosed()
{
if (false !== $this->closed) {
throw new \RuntimeException('This Transaction is closed');
}
}
public function status()
{
return $this->state;
}
public function commit()
{
$this->success();
}
public function push($query, array $parameters = array(), $tag = null)
{
//
}
public function getSession()
{
return $this->session;
}
} |
require 'php_ruby/io/functions'
Object.send :include, PhpRuby::Io::Functions
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.