text:
static NSString *const kConsumerKey    = @"pxVUnHa52dzSXmkgZZ9kjPCfL";
static NSString *const kConsumerSecret = @"nhOETEJHhtyhIV0mRQ9qs5esZIBceoAOp1K3kbaqCJecCHfp8v";
static NSString *const kUrlScheme      = @"TwitterAuthDemo://";

@interface NSString (Testing)

- (NSString *)URLEncodedString_ch;

@end

@interface TwitterSafariViewControllerAuth (Testing)

@property (nonatomic, strong) NSString *consumerSecret;

@property (nonatomic, strong) NSString *consumerKey;

@property (nonatomic, strong) NSString *redirectUri;

- (NSString *)createOAuthHeaderWithToken:(NSString *)tokenString tokenSecret:(NSString *)tokenSecretString verifier:(NSString *)verifierString urlString:(NSString *)urlString consumerKey:(NSString *)consumerKey nonce:(NSString *)nonce timestamp:(NSString *)timestamp;

- (void)getAuthUrlWithCompletion:(void (^)(NSURL *))completion;

- (NSString *)UUID;

@end

@interface UnitTests : XCTestCase

@end

@implementation UnitTests

- (void)setUp {
    [super setUp];

    [[TwitterSafariViewControllerAuth sharedInstance] configureConsumerKey:kConsumerKey consumerSecret:kConsumerSecret urlScheme:kUrlScheme];
}

- (void)testConfigure {
    XCTAssertEqual([TwitterSafariViewControllerAuth sharedInstance].consumerKey, kConsumerKey);
    XCTAssertEqual([TwitterSafariViewControllerAuth sharedInstance].consumerSecret, kConsumerSecret);
    XCTAssertEqual([TwitterSafariViewControllerAuth sharedInstance].redirectUri, kUrlScheme);
}

- (void)testGetAuthUrl {
    XCTestExpectation *expectation = [self expectationWithDescription:@"Auth URL"];

    [[TwitterSafariViewControllerAuth sharedInstance] getAuthUrlWithCompletion:^(NSURL *authUrl) {
        XCTAssertNotNil(authUrl);
        [expectation fulfill];
    }];

    [self waitForExpectationsWithTimeout:10 handler:^(NSError *error) {
        if (error != nil) {
            NSLog(@"Error: %@", error.localizedDescription);
        }
    }];
}

- (void)testHandleOpenUrlDeny {
    NSString *urlString = @"twitterauthdemo://?denied=HupSXgAAAAAAt5yJAAABUzgfLc0";
    NSURL *url = [NSURL URLWithString:urlString];
    [[TwitterSafariViewControllerAuth sharedInstance] handleOpenUrl:url options:nil success:nil failure:^(NSError *error) {
        XCTAssertNotNil(error);
    }];
}

- (void)testUrlEncodedString {
    [self helperForUrlEncodedString:@"https://api.twitter.com/oauth/request_token" expect:@"https%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token"];
    [self helperForUrlEncodedString:@"oauth_callback" expect:@"oauth_callback"];
    [self helperForUrlEncodedString:@"TwitterAuthDemo://" expect:@"TwitterAuthDemo%3A%2F%2F"];
    [self helperForUrlEncodedString:@"oauth_signature_method" expect:@"oauth_signature_method"];
    [self helperForUrlEncodedString:@"HMAC-SHA1" expect:@"HMAC-SHA1"];
    [self helperForUrlEncodedString:@"oauth_nonce" expect:@"oauth_nonce"];
    [self helperForUrlEncodedString:@"943FB130-BBCB-4CE7-8072-F2234AC0C5E6" expect:@"943FB130-BBCB-4CE7-8072-F2234AC0C5E6"];
    [self helperForUrlEncodedString:@"oauth_consumer_key" expect:@"oauth_consumer_key"];
    [self helperForUrlEncodedString:@"pxVUnHa52dzSXmkgZZ9kjPCfL" expect:@"pxVUnHa52dzSXmkgZZ9kjPCfL"];
    [self helperForUrlEncodedString:@"oauth_timestamp" expect:@"oauth_timestamp"];
    [self helperForUrlEncodedString:@"1456936623" expect:@"1456936623"];
    [self helperForUrlEncodedString:@"oauth_version" expect:@"oauth_version"];
    [self helperForUrlEncodedString:@"1.0" expect:@"1.0"];
    [self helperForUrlEncodedString:@"oauth_callback=TwitterAuthDemo%3A%2F%2F&oauth_consumer_key=pxVUnHa52dzSXmkgZZ9kjPCfL&oauth_nonce=943FB130-BBCB-4CE7-8072-F2234AC0C5E6&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1456936623&oauth_version=1.0" expect:@"oauth_callback%3DTwitterAuthDemo%253A%252F%252F%26oauth_consumer_key%3DpxVUnHa52dzSXmkgZZ9kjPCfL%26oauth_nonce%3D943FB130-BBCB-4CE7-8072-F2234AC0C5E6%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1456936623%26oauth_version%3D1.0"];
    [self helperForUrlEncodedString:@"nhOETEJHhtyhIV0mRQ9qs5esZIBceoAOp1K3kbaqCJecCHfp8v" expect:@"nhOETEJHhtyhIV0mRQ9qs5esZIBceoAOp1K3kbaqCJecCHfp8v"];
    [self helperForUrlEncodedString:@"6rqypovjfJm9iDdQLphF4q7qLbc=" expect:@"6rqypovjfJm9iDdQLphF4q7qLbc%3D"];
}

- (void)helperForUrlEncodedString:(NSString *)string expect:(NSString *)expect {
NSString *value = string.URLEncodedString_ch;
    XCTAssertEqualObjects(value, expect);
}

- (void)testUuid {
    NSString *first = [TwitterSafariViewControllerAuth sharedInstance].UUID;
    NSString *second = [TwitterSafariViewControllerAuth sharedInstance].UUID;
    XCTAssertNotEqualObjects(first, second);
}

- (void)testCreateOAuthHeader {
    NSString *urlString = @"https://api.twitter.com/oauth/request_token";
    NSString *nonce = @"F465B10F-F3AE-4DCB-8612-3F97B792255E";
    NSString *timestamp = @"1456944863";
    NSString *header = [[TwitterSafariViewControllerAuth sharedInstance] createOAuthHeaderWithToken:nil tokenSecret:nil verifier:nil urlString:urlString consumerKey:kConsumerKey nonce:nonce timestamp:timestamp];

    NSString *expect = @"OAuth oauth_consumer_key=\"pxVUnHa52dzSXmkgZZ9kjPCfL\", oauth_callback=\"TwitterAuthDemo%3A%2F%2F\", oauth_signature_method=\"HMAC-SHA1\", oauth_signature=\"eZR5mRysjftRcozmKHHQY3FHzWQ%3D\", oauth_timestamp=\"1456944863\", oauth_nonce=\"F465B10F-F3AE-4DCB-8612-3F97B792255E\", oauth_version=\"1.0\"";

    XCTAssertEqualObjects(header, expect);
}

@end


text:
import React, {PropTypes} from 'react';
import '../../styles/bmc.scss';

// Destrucuring props for brevity below.
const BMCForm = ({appState}) => {
  return (
    <div id="bmc-form" style="display:none">
      <form className="pure-form">
        <fieldset className="pure-group">
          <input type="text" className="pure-input-1-2" placeholder="Username"/>
            <input type="text" className="pure-input-1-2" placeholder="Password"/>
              <input type="email" className="pure-input-1-2" placeholder="Email"/>
        </fieldset>

        <fieldset className="pure-group">
          <input type="text" className="pure-input-1-2" placeholder="A title"/>
            <textarea className="pure-input-1-2" placeholder="Textareas work too"/>
        </fieldset>

        <button type="submit" className="pure-button pure-input-1-2 pure-button-primary">Sign in</button>
      </form>
    </div>
  );
};

BMCForm.propTypes = {
  appState: PropTypes.object.isRequired
};

export default BMCForm;

redpajama_set_name: RedPajamaGithub


text:
/* Chipset interface APIs */

#include "ap_power/ap_power_interface.h"
#include "chipset_state_check.h"
#include "common.h"

int chipset_in_state(int state_mask)
{
	return ap_power_in_state(state_mask);
}

int chipset_in_or_transitioning_to_state(int state_mask)
{
	return ap_power_in_or_transitioning_to_state(state_mask);
}

void chipset_exit_hard_off(void)
{
	ap_power_exit_hardoff();
}

void chipset_force_shutdown(enum chipset_shutdown_reason reason)
{
	ap_power_force_shutdown((enum ap_power_shutdown_reason)reason);
}

void chipset_reset(enum chipset_shutdown_reason reason)
{
	ap_power_reset((enum ap_power_shutdown_reason)reason);
}

/* TODO: b/214509787
 * To be added later when this functionality is implemented in ap_pwrseq.
 */
void chipset_throttle_cpu(int throttle)
{
}

void init_reset_log(void)
{
	ap_power_init_reset_log();
}


text:
package api;

public class StorageUnit {
    private String productRefNo;
    private long amount;

    public StorageUnit() {
    }

    public String getProductRefNo() {
        return this.productRefNo;
    }

    public long getAmount() {
        return this.amount;
    }

    public void setProductRefNo(String productRefNo) {
        this.productRefNo = productRefNo;
    }

    public void setAmount(long amount) {
        this.amount = amount;
    }

    public boolean equals(Object o) {
        if (o == this) return true;
        if (!(o instanceof StorageUnit)) return false;
        final StorageUnit other = (StorageUnit) o;
        if (!other.canEqual((Object) this)) return false;
        final Object this$productRefNo = this.getProductRefNo();
        final Object other$productRefNo = other.getProductRefNo();
        if (this$productRefNo == null ? other$productRefNo != null : !this$productRefNo.equals(other$productRefNo))
            return false;
        if (this.getAmount() != other.getAmount()) return false;
        return true;
    }

    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        final Object $productRefNo = this.getProductRefNo();
        result = result * PRIME + ($productRefNo == null ? 43 : $productRefNo.hashCode());
        final long $amount = this.getAmount();
        result = result * PRIME + (int) ($amount >>> 32 ^ $amount);
        return result;
    }

    protected boolean canEqual(Object other) {
        return other instanceof StorageUnit;
    }

    public String toString() {
        return "api.StorageUnit(productRefNo=" + this.getProductRefNo() + ", amount=" + this.getAmount() + ")";
    }
}


text:
<component name="ProjectRunConfigurationManager">
  <configuration default="false" name="Debug Server Tests" type="NodeJSConfigurationType" factoryName="Node.js" path-to-node="node" path-to-js-file="node_modules/jasmine/bin/jasmine.js" working-dir="$PROJECT_DIR$">
    <method v="2">
      <option name="NpmBeforeRunTask" enabled="true">
        <package-json value="$PROJECT_DIR$/package.json" />
        <command value="run" />
        <scripts>
          <script value="test" />
        </scripts>
        <arguments value="webstorm-debug" />
        <node-interpreter value="node" />
        <package-manager value="npm" />
        <envs />
      </option>
    </method>
  </configuration>
</component>


text:
.. image:: pyeco.png
    :height: 20
    :alt: Economie
    :target: http://www.xavierdupre.fr/app/ensae_teaching_cs/helpsphinx/td_2a_notions.html#pour-un-profil-plutot-economiste

.. image:: pystat.png
    :height: 20
    :alt: Statistique
    :target: http://www.xavierdupre.fr/app/ensae_teaching_cs/helpsphinx/td_2a_notions.html#pour-un-profil-plutot-data-scientist

.. _l-imbalanced-classification:

Imbalanced classification
+++++++++++++++++++++++++

.. index:: imbalanced, mal-balancé

Imbalanced, mal balancé, skewed, ce type de problème de données
est très fréquent. Il signifie qu'une classe dans un problème de classification
est sous-représentée par rapport aux autres et que le modèle de machine
learning n'est pas suffisamment pénalisé s'il n'en tient pas compte.
Le cas classique est un problème à deux classes, une majoritaire à 99%,
une minoritaire à 1%. Un modèle qui répond toujours la majorité est correct
99% du temps mais il n'a rien appris puisque sa réponse est constante.
Comment le forcer à apprendre quelque chose ? Il existe trois types approches
et la réponse est souvent un mélange des trois :

* *boosting* : le modèle pondère davantage les exemples sur lesquels il fait
  des erreurs, a fortiori, les exemples de la classe minoritaire
* *over sampling* : on multiplie les exemples de la classe minoritaire
  de façon à lui donner plus de poids
* *under sampling* : on réduit le nombre d'exemples de la classe majoritaire
  sans altérer la capacité du modèle à trouver une bonne solution, cela consiste
  à enlever des exemples loin de la frontière de classification.

*Notebooks*

.. toctree::
    :maxdepth: 2

    ../notebooks/ml_b_imbalanced

*Lectures*

* `Classification of Imbalanced Data with a Geometric Digraph Family
  <http://www.jmlr.org/papers/volume17/15-604/15-604.pdf>`_
* `RUSBoost: A Hybrid Approach to Alleviating Class Imbalance
  <http://citeseerx.ist.psu.edu/viewdoc/
  download;jsessionid=9260A5C92AC5F8FA3B8590A53A06248D?
  doi=10.1.1.309.2305&rep=rep1&type=pdf>`_
* `RAMOBoost: Ranked Minority Oversampling in Boosting
  <https://ai2-s2-pdfs.s3.amazonaws.com/9640/1540d5d8c4d5d956ae5fa487590dd8682507.pdf>`_
* `ND DIAL: Imbalanced Algorithms <https://github.com/dialnd/imbalanced-algorithms>`_
* `rusboost.py <https://github.com/harusametime/RUSBoost>`_ (plutôt un bout de code)
* `xgboost <https://xgboost.readthedocs.io/en/latest/>`_
* `Boosting and AdaBoost for Machine Learning
  <https://machinelearningmastery.com/boosting-and-adaboost-for-machine-learning/>`_,
  `A Gentle Introduction to the Gradient Boosting Algorithm for Machine Learning
  <https://machinelearningmastery.com/
  gentle-introduction-gradient-boosting-algorithm-machine-learning/>`_,
  `Thoughts on Hypothesis Boosting
  <https://www.cis.upenn.edu/~mkearns/papers/boostnote.pdf>`_,
  `Predictions Games and Arcing Algorithms
  <https://www.stat.berkeley.edu/~breiman/games.pdf>`_
* `Focal Loss for Dense Object Detection
  <https://arxiv.org/pdf/1708.02002.pdf>`_

*Lectures - subsampling*

* `Data Subsampling (Edward)
  <http://edwardlib.org/api/inference-data-subsampling>`_
* `5601 Notes: The Subsampling Bootstrap
  <http://www.stat.umn.edu/geyer/5601/notes/sub.pdf>`_
* `Bootstrapping and Subsampling: Part I
  <https://normaldeviate.wordpress.com/2013/01/19/bootstrapping-and-subsampling-part-i/>`_
* `Subsampling versus bootstrapping in resampling-based model
  selection for multivariable regression
  <https://epub.ub.uni-muenchen.de/21724/1/technRep_171.pdf>`_
* `Subsampling vs Bootstrap
  <https://web.stanford.edu/~doubleh/lecturenotes/lecture13.pdf>`_

*Modules*

* `imbalanced-learn <https://github.com/scikit-learn-contrib/imbalanced-learn>`_
  (la `documentation <https://imbalanced-learn.readthedocs.io/en/stable/api.html>`_
  est intéressante)


text:
'use strict';

require('mocha');
var assert = require('assert');
var each = require('./');

describe('each', function() {
  it('should return when the first arg is null', function() {
    var arr;
    each('', function(ele) {
      arr = [ele];
    });
    assert.equal(arr, undefined);
  });

  it('should loop over each item in an array and call the given function on every element:', function() {
    var res = [];
    each(['a', 'b', 'c'], function(ele) {
      res.push(ele + ele);
    });
    assert.deepEqual(res, ['aa', 'bb', 'cc']);
  });

  it('should "break" when `false` is returned:', function() {
    var res = [];
    each(['a', 'b', 'c'], function(ele, i) {
      if (ele === 'b') {
        return false;
      }
      res.push(ele + ele);
    });
    assert.deepEqual(res, ['aa']);
  });

  it('should expose the index as the second parameter:', function() {
    var res = [];
    each(['a', 'b', 'c'], function(ele, i) {
      res.push(i);
    });
    assert.deepEqual(res, [0, 1, 2]);
  });
});


text:
Will bootstrap your App.

## Installation

1. Include gem to the `Gemfile`
```ruby
gem 'foundationstone'
```
2. Mount it like Rails engine
```ruby
mount Foundationstone::Engine => '/'
```
3. Install engine
```
rails g foundationstone:install
```


text:
package com.google.security.zynamics.binnavi.Gui.InsertViewDialog;

import java.awt.Window;
import java.util.List;

import javax.swing.tree.DefaultTreeModel;

import com.google.common.base.Preconditions;
import com.google.security.zynamics.binnavi.disassembly.INaviAddressSpace;
import com.google.security.zynamics.binnavi.disassembly.INaviModule;
import com.google.security.zynamics.binnavi.disassembly.views.IViewContainer;
import com.google.security.zynamics.zylib.gui.jtree.IconNode;

/**
 * Class of root nodes of the view selection tree.
 */
public final class CRootNode extends IconNode implements IViewSelectionTreeNode
{
	// TODO: Dispose nodes

	/**
	 * Used for serialization.
	 */
	private static final long serialVersionUID = 896018082290216639L;

	/**
	 * Creates a new view selection root node.
	 *
	 * @param dialog Parent window used for dialogs.
	 * @param container The container that provides the views to select from.
	 * @param model Tree model of the tree the node belongs to.
	 */
	public CRootNode(final Window dialog, final IViewContainer container, final DefaultTreeModel model)
	{
		Preconditions.checkNotNull(container, "IE01822: Container argument can not be null");

		final List<INaviAddressSpace> addressSpaces = container.getAddressSpaces();

		if (addressSpaces == null)
		{
			// We are dealing with views from a module here.
			final INaviModule module = container.getModules().get(0);

			add(new ViewSelectionModuleNode(dialog, module, model));
		}
		else
		{
			// We are dealing with views from a project here.

			// TODO: Check whether project views can be selected from this dialog.

			for (final INaviAddressSpace addressSpace : addressSpaces)
			{
				add(new CAddressSpaceNode(dialog, addressSpace, model));
			}
		}
	}

	@Override
	public void doubleClicked()
	{
		// No action is associated with double-clicking root nodes
	}

}


text:
import React, { Component, PropTypes } from 'react';
import Navigation from 'react-toolbox/lib/navigation';
import Button from 'components/Button/Button';
import { connect } from 'react-redux';
import { open as openModal } from 'redux/modules/modals';
import HeaderMenu from 'components/HeaderMenu/HeaderMenu';
import SocialButton from 'components/SocialButton/SocialButton';
import classnames from 'classnames';

const menuLinks = [
  // {to: '/terms', label: 'Условия использования'},
  {to: '/about', label: 'Как это работает'},
  {to: '/lunches', label: 'Обеды', index: true},
  {to: '/about', label: 'О Нас'}
];

@connect(state => ({user: state.auth.user}), {openModal})
export default class Footer extends Component {
  static propTypes = {
    user: PropTypes.object,
    openModal: PropTypes.func.isRequired
  };

  static contextTypes = {
    router: PropTypes.object.isRequired
  };

  openLoginModal = () => {
    this.props.openModal('LoginForm', 'Авторизация');
  };

  render() {
    const styles = require('./Footer.scss');
    const { user } = this.props;

    return (

          <HeaderMenu className={styles.menu} links={menuLinks}/>

          {!user &&
            <Navigation className={styles.loginSignUp}>
              <Button flat outlined label="Войти" onClick={this.openLoginModal} />
              <Button flat outlined label="Зарегистрироваться" onClick={() => this.context.router.push('/join')}/>
            </Navigation>
          }

            2016 Appetini. Все права защищены и соблюдены.

          <Navigation className={styles.social}>
            Присоединяйтесь к нам:

              <SocialButton className={styles.socialButton} name="vk"
                            href="http://vk.com/appetini" target="_blank"/>
              <SocialButton className={styles.socialButton} name="fb"
                            href="https://www.facebook.com/appetinicom/" target="_blank"/>
              <SocialButton className={styles.socialButton} name="instagram"
                            href="https://www.instagram.com/appetinicom/" target="_blank"/>

          </Navigation>

    );
  }
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.marvinformatics.formatter.tests</groupId>
	<artifactId>buildhelper-002</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<build>
		<plugins>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>build-helper-maven-plugin</artifactId>
				<version>1.5</version>
				<executions>
					<execution>
						<id>add-source</id>
						<phase>process-resources</phase>
						<goals>
							<goal>add-source</goal>
						</goals>
						<configuration>
							<sources>
								<source>src/custom/main/java</source>
							</sources>
						</configuration>
					</execution>
					<execution>
						<id>add-resource</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>add-resource</goal>
						</goals>
						<configuration>
							<resources>
								<resource>
									<directory>src/custom/main/resources</directory>
								</resource>
							</resources>
						</configuration>
					</execution>
					<execution>
						<id>add-test-source</id>
						<phase>generate-test-sources</phase>
						<goals>
							<goal>add-test-source</goal>
						</goals>
						<configuration>
							<sources>
								<source>src/custom/test/java</source>
							</sources>
						</configuration>
					</execution>
					<execution>
						<id>add-test-resource</id>
						<phase>generate-test-resources</phase>
						<goals>
							<goal>add-test-resource</goal>
						</goals>
						<configuration>
							<resources>
								<resource>
									<directory>src/custom/test/resources</directory>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>

		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-compiler-plugin</artifactId>
					<version>2.0.2</version>
				</plugin>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-resources-plugin</artifactId>
					<version>2.4.1</version>
				</plugin>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-surefire-plugin</artifactId>
					<version>2.4.3</version>
				</plugin>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-jar-plugin</artifactId>
					<version>2.2</version>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

</project>


text:
using System.Diagnostics;
using Mono.Cecil;

public partial class InnerWeaver
{
    public virtual void WriteModule()
    {
        var stopwatch = Stopwatch.StartNew();
        Logger.LogDebug($"Writing assembly to '{AssemblyFilePath}'.");

        var parameters = new WriterParameters
        {
            StrongNameKeyPair = StrongNameKeyPair,
            WriteSymbols = hasSymbols
        };

        ModuleDefinition.Assembly.Name.PublicKey = PublicKey;
        ModuleDefinition.Write(AssemblyFilePath, parameters);
        Logger.LogDebug($"Finished writing assembly {stopwatch.ElapsedMilliseconds}ms.");
    }
}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AvaTaxConnector.Models
{
    public class Account
    {
        public string id { get; set; }
        public string name { get; set; }
        public string accountStatusId { get; set; }
    }
}


text:
package main

import (
	"bytes"
	"sort"
	"text/template"

	. "github.com/google/syzkaller/sysparser"
)

type Arch struct {
	Name  string
	CARCH []string
}

var archs = []*Arch{
	{"amd64", []string{"__x86_64__"}},
	{"arm64", []string{"__aarch64__"}},
	{"ppc64le", []string{"__ppc64__", "__PPC64__", "__powerpc64__"}},
}

var syzkalls = map[string]uint64{
	"syz_test":          1000001,
	"syz_open_dev":      1000002,
	"syz_open_pts":      1000003,
	"syz_fuse_mount":    1000004,
	"syz_fuseblk_mount": 1000005,
}

func generateExecutorSyscalls(syscalls []Syscall, consts map[string]map[string]uint64) {
	var data SyscallsData
	for _, arch := range archs {
		var calls []SyscallData
		for _, c := range syscalls {
			syscallNR := -1
			if nr, ok := consts[arch.Name]["__NR_"+c.CallName]; ok {
				syscallNR = int(nr)
			}
			calls = append(calls, SyscallData{c.Name, syscallNR})
		}
		data.Archs = append(data.Archs, ArchData{arch.CARCH, calls})
	}
	for name, nr := range syzkalls {
		data.FakeCalls = append(data.FakeCalls, SyscallData{name, int(nr)})
	}
	sort.Sort(SyscallArray(data.FakeCalls))

	hdrcode := "executor/syscalls.h"
	logf(1, "Generate header with syscall numbers in %v", hdrcode)
	buf := new(bytes.Buffer)
	if err := syscallsTempl.Execute(buf, data); err != nil {
		failf("failed to execute syscalls template: %v", err)
	}
	writeFile(hdrcode, buf.Bytes())
}

type SyscallsData struct {
	Archs     []ArchData
	FakeCalls []SyscallData
}

type ArchData struct {
	CARCH []string
	Calls []SyscallData
}

type SyscallData struct {
	Name string
	NR   int
}

type SyscallArray []SyscallData

func (a SyscallArray) Len() int           { return len(a) }
func (a SyscallArray) Less(i, j int) bool { return a[i].Name < a[j].Name }
func (a SyscallArray) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

var syscallsTempl = template.Must(template.New("").Parse(
	`// AUTOGENERATED FILE

{{range $c := $.FakeCalls}}#define __NR_{{$c.Name}}	{{$c.NR}}
{{end}}

struct call_t {
	const char*	name;
	int		sys_nr;
};

{{range $arch := $.Archs}}
#if {{range $cdef := $arch.CARCH}}defined({{$cdef}}) || {{end}}0
call_t syscalls[] = {
{{range $c := $arch.Calls}}	{"{{$c.Name}}", {{$c.NR}}},
{{end}}
};
#endif
{{end}}
`))


text:
package org.apache.zeppelin.livy;

import com.cloudera.livy.test.framework.Cluster;
import com.cloudera.livy.test.framework.Cluster$;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.zeppelin.interpreter.*;
import org.apache.zeppelin.user.AuthenticationInfo;
import org.junit.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class LivyInterpreterIT {

  private static Logger LOGGER = LoggerFactory.getLogger(LivyInterpreterIT.class);
  private static Cluster cluster;
  private static Properties properties;

  @BeforeClass
  public static void setUp() {
    if (!checkPreCondition()) {
      return;
    }
    cluster = Cluster$.MODULE$.get();
    LOGGER.info("Starting livy at {}", cluster.livyEndpoint());
    properties = new Properties();
    properties.setProperty("zeppelin.livy.url", cluster.livyEndpoint());
    properties.setProperty("zeppelin.livy.session.create_timeout", "120");
    properties.setProperty("zeppelin.livy.spark.sql.maxResult", "100");
  }

  @AfterClass
  public static void tearDown() {
    if (cluster != null) {
      LOGGER.info("Shutting down livy at {}", cluster.livyEndpoint());
      cluster.cleanUp();
    }
  }

  public static boolean checkPreCondition() {
    if (System.getenv("LIVY_HOME") == null) {
      LOGGER.warn(("livy integration is skipped because LIVY_HOME is not set"));
      return false;
    }
    if (System.getenv("SPARK_HOME") == null) {
      LOGGER.warn(("livy integration is skipped because SPARK_HOME is not set"));
      return false;
    }
    return true;
  }

  @Test
  public void testSparkInterpreterRDD() {
    if (!checkPreCondition()) {
      return;
    }
    InterpreterGroup interpreterGroup = new InterpreterGroup("group_1");
    interpreterGroup.put("session_1", new ArrayList<Interpreter>());
    final LivySparkInterpreter sparkInterpreter = new LivySparkInterpreter(properties);
    sparkInterpreter.setInterpreterGroup(interpreterGroup);
    interpreterGroup.get("session_1").add(sparkInterpreter);
    AuthenticationInfo authInfo = new AuthenticationInfo("user1");
    MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
    InterpreterOutput output = new InterpreterOutput(outputListener);
    final InterpreterContext context = new InterpreterContext("noteId", "paragraphId", "livy.spark",
        "title", "text", authInfo, null, null, null, null, null, output);
    sparkInterpreter.open();

    try {
      // detect spark version
      InterpreterResult result = sparkInterpreter.interpret("sc.version", context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(1, result.message().size());

      boolean isSpark2 = isSpark2(sparkInterpreter, context);

      // test RDD api
      result = sparkInterpreter.interpret("sc.parallelize(1 to 10).sum()", context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(1, result.message().size());
      assertTrue(result.message().get(0).getData().contains("Double = 55.0"));

      // single line comment
      String singleLineComment = "println(1)// my comment";
      result = sparkInterpreter.interpret(singleLineComment, context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(1, result.message().size());

      // multiple line comment
      String multipleLineComment = "println(1)/* multiple \n" + "line \n" + "comment */";
      result = sparkInterpreter.interpret(multipleLineComment, context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(1, result.message().size());

      // multi-line string
      String multiLineString = "val str = \"\"\"multiple\n" +
          "line\"\"\"\n" +
          "println(str)";
      result = sparkInterpreter.interpret(multiLineString, context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(1, result.message().size());
      assertTrue(result.message().get(0).getData().contains("multiple\nline"));

      // case class
      String caseClassCode = "case class Person(id:Int, \n" +
          "name:String)\n" +
          "val p=Person(1, \"name_a\")";
      result = sparkInterpreter.interpret(caseClassCode, context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(1, result.message().size());
      assertTrue(result.message().get(0).getData().contains("p: Person = Person(1,name_a)"));

      // object class
      String objectClassCode = "object Person {}";
      result = sparkInterpreter.interpret(objectClassCode, context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(1, result.message().size());
      if (!isSpark2) {
        assertTrue(result.message().get(0).getData().contains("defined module Person"));
      } else {
        assertTrue(result.message().get(0).getData().contains("defined object Person"));
      }

      // error
      result = sparkInterpreter.interpret("println(a)", context);
      assertEquals(InterpreterResult.Code.ERROR, result.code());
      assertEquals(InterpreterResult.Type.TEXT, result.message().get(0).getType());
      assertTrue(result.message().get(0).getData().contains("error: not found: value a"));

      // incomplete code
      result = sparkInterpreter.interpret("if(true){", context);
      assertEquals(InterpreterResult.Code.ERROR, result.code());
      assertEquals(InterpreterResult.Type.TEXT, result.message().get(0).getType());
      assertTrue(result.message().get(0).getData().contains("incomplete statement"));

      // cancel
      if (sparkInterpreter.livyVersion.newerThanEquals(LivyVersion.LIVY_0_3_0)) {
        Thread cancelThread = new Thread() {
          @Override
          public void run() {
            // invoke cancel after 3 seconds to wait job starting
            try {
              Thread.sleep(3000);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
            sparkInterpreter.cancel(context);
          }
        };
        cancelThread.start();
        result = sparkInterpreter
            .interpret("sc.parallelize(1 to 10).foreach(e=>Thread.sleep(10*1000))", context);
        assertEquals(InterpreterResult.Code.ERROR, result.code());
        String message = result.message().get(0).getData();
        // 2 possibilities, sometimes livy doesn't return the real cancel exception
        assertTrue(message.contains("cancelled part of cancelled job group") ||
            message.contains("Job is cancelled"));
      }

    } finally {
      sparkInterpreter.close();
    }
  }

  @Test
  public void testSparkInterpreterDataFrame() {
    if (!checkPreCondition()) {
      return;
    }
    InterpreterGroup interpreterGroup = new InterpreterGroup("group_1");
    interpreterGroup.put("session_1", new ArrayList<Interpreter>());
    LivySparkInterpreter sparkInterpreter = new LivySparkInterpreter(properties);
    sparkInterpreter.setInterpreterGroup(interpreterGroup);
    interpreterGroup.get("session_1").add(sparkInterpreter);
    AuthenticationInfo authInfo = new AuthenticationInfo("user1");
    MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
    InterpreterOutput output = new InterpreterOutput(outputListener);
    InterpreterContext context = new InterpreterContext("noteId", "paragraphId", "livy.spark",
        "title", "text", authInfo, null, null, null, null, null, output);
    sparkInterpreter.open();

    LivySparkSQLInterpreter sqlInterpreter = new LivySparkSQLInterpreter(properties);
    interpreterGroup.get("session_1").add(sqlInterpreter);
    sqlInterpreter.setInterpreterGroup(interpreterGroup);
    sqlInterpreter.open();

    try {
      // detect spark version
      InterpreterResult result = sparkInterpreter.interpret("sc.version", context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(1, result.message().size());

      boolean isSpark2 = isSpark2(sparkInterpreter, context);

      // test DataFrame api
      if (!isSpark2) {
        result = sparkInterpreter.interpret(
            "val df=sqlContext.createDataFrame(Seq((\"hello\",20))).toDF(\"col_1\", \"col_2\")\n"
                + "df.collect()", context);
        assertEquals(InterpreterResult.Code.SUCCESS, result.code());
        assertEquals(1, result.message().size());
        assertTrue(result.message().get(0).getData()
            .contains("Array[org.apache.spark.sql.Row] = Array([hello,20])"));
      } else {
        result = sparkInterpreter.interpret(
            "val df=spark.createDataFrame(Seq((\"hello\",20))).toDF(\"col_1\", \"col_2\")\n"
                + "df.collect()", context);
        assertEquals(InterpreterResult.Code.SUCCESS, result.code());
        assertEquals(1, result.message().size());
        assertTrue(result.message().get(0).getData()
            .contains("Array[org.apache.spark.sql.Row] = Array([hello,20])"));
      }
      sparkInterpreter.interpret("df.registerTempTable(\"df\")", context);
      // test LivySparkSQLInterpreter which share the same SparkContext with LivySparkInterpreter
      result = sqlInterpreter.interpret("select * from df where col_1='hello'", context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType());
      assertEquals("col_1\tcol_2\nhello\t20", result.message().get(0).getData());
      // double quotes
      result = sqlInterpreter.interpret("select * from df where col_1=\"hello\"", context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType());
      assertEquals("col_1\tcol_2\nhello\t20", result.message().get(0).getData());

      // only enable this test in spark2 as spark1 doesn't work for this case
      if (isSpark2) {
        result = sqlInterpreter.interpret("select * from df where col_1=\"he\\\"llo\" ", context);
        assertEquals(InterpreterResult.Code.SUCCESS, result.code());
        assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType());
      }

      // single quotes inside attribute value
      result = sqlInterpreter.interpret("select * from df where col_1=\"he'llo\"", context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType());

      // test sql with syntax error
      result = sqlInterpreter.interpret("select * from df2", context);
      assertEquals(InterpreterResult.Code.ERROR, result.code());
      assertEquals(InterpreterResult.Type.TEXT, result.message().get(0).getType());

      if (!isSpark2) {
        assertTrue(result.message().get(0).getData().contains("Table not found"));
      } else {
        assertTrue(result.message().get(0).getData().contains("Table or view not found"));
      }
    } finally {
      sparkInterpreter.close();
      sqlInterpreter.close();
    }
  }

  @Test
  public void testSparkSQLInterpreter() {
    if (!checkPreCondition()) {
      return;
    }
    InterpreterGroup interpreterGroup = new InterpreterGroup("group_1");
    interpreterGroup.put("session_1", new ArrayList<Interpreter>());
    LazyOpenInterpreter sparkInterpreter = new LazyOpenInterpreter(
        new LivySparkInterpreter(properties));
    sparkInterpreter.setInterpreterGroup(interpreterGroup);
    interpreterGroup.get("session_1").add(sparkInterpreter);
    LazyOpenInterpreter sqlInterpreter = new LazyOpenInterpreter(
        new LivySparkSQLInterpreter(properties));
    interpreterGroup.get("session_1").add(sqlInterpreter);
    sqlInterpreter.setInterpreterGroup(interpreterGroup);
    sqlInterpreter.open();

    try {
      AuthenticationInfo authInfo = new AuthenticationInfo("user1");
      MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
      InterpreterOutput output = new InterpreterOutput(outputListener);
      InterpreterContext context = new InterpreterContext("noteId", "paragraphId", "livy.sql",
          "title", "text", authInfo, null, null, null, null, null, output);
      InterpreterResult result = sqlInterpreter.interpret("show tables", context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType());
      assertTrue(result.message().get(0).getData().contains("tableName"));
    } finally {
      sqlInterpreter.close();
    }
  }

  @Test
  public void testPySparkInterpreter() {
    if (!checkPreCondition()) {
      return;
    }

    final LivyPySparkInterpreter pysparkInterpreter = new LivyPySparkInterpreter(properties);
    AuthenticationInfo authInfo = new AuthenticationInfo("user1");
    MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
    InterpreterOutput output = new InterpreterOutput(outputListener);
    final InterpreterContext context = new InterpreterContext("noteId", "paragraphId", "livy.pyspark",
        "title", "text", authInfo, null, null, null, null, null, output);
    pysparkInterpreter.open();

    try {
      InterpreterResult result = pysparkInterpreter.interpret("sc.version", context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(1, result.message().size());

      boolean isSpark2 = isSpark2(pysparkInterpreter, context);

      // test RDD api
      result = pysparkInterpreter.interpret("sc.range(1, 10).sum()", context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(1, result.message().size());
      assertTrue(result.message().get(0).getData().contains("45"));

      // test DataFrame api
      if (!isSpark2) {
        pysparkInterpreter.interpret("from pyspark.sql import SQLContext\n"
            + "sqlContext = SQLContext(sc)", context);
        result = pysparkInterpreter.interpret("df=sqlContext.createDataFrame([(\"hello\",20)])\n"
            + "df.collect()", context);
        assertEquals(InterpreterResult.Code.SUCCESS, result.code());
        assertEquals(1, result.message().size());
        assertTrue(result.message().get(0).getData().contains("[Row(_1=u'hello', _2=20)]"));
      } else {
        result = pysparkInterpreter.interpret("df=spark.createDataFrame([(\"hello\",20)])\n"
            + "df.collect()", context);
        assertEquals(InterpreterResult.Code.SUCCESS, result.code());
        assertEquals(1, result.message().size());
        assertTrue(result.message().get(0).getData().contains("[Row(_1=u'hello', _2=20)]"));
      }

      // test magic api
      pysparkInterpreter.interpret("t = [{\"name\":\"userA\", \"role\":\"roleA\"},"
          + "{\"name\":\"userB\", \"role\":\"roleB\"}]", context);
      result = pysparkInterpreter.interpret("%table t", context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(1, result.message().size());
      assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType());
      assertTrue(result.message().get(0).getData().contains("userA"));

      // error
      result = pysparkInterpreter.interpret("print(a)", context);
      assertEquals(InterpreterResult.Code.ERROR, result.code());
      assertEquals(InterpreterResult.Type.TEXT, result.message().get(0).getType());
      assertTrue(result.message().get(0).getData().contains("name 'a' is not defined"));

      // cancel
      if (pysparkInterpreter.livyVersion.newerThanEquals(LivyVersion.LIVY_0_3_0)) {
        Thread cancelThread = new Thread() {
          @Override
          public void run() {
            // invoke cancel after 3 seconds to wait job starting
            try {
              Thread.sleep(3000);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
            pysparkInterpreter.cancel(context);
          }
        };
        cancelThread.start();
        result = pysparkInterpreter
            .interpret("import time\n" +
                "sc.range(1, 10).foreach(lambda a: time.sleep(10))", context);
        assertEquals(InterpreterResult.Code.ERROR, result.code());
        String message = result.message().get(0).getData();
        // 2 possibilities, sometimes livy doesn't return the real cancel exception
        assertTrue(message.contains("cancelled part of cancelled job group") ||
            message.contains("Job is cancelled"));
      }
    } finally {
      pysparkInterpreter.close();
    }
  }

  @Test
  public void testSparkInterpreterWithDisplayAppInfo() {
    if (!checkPreCondition()) {
      return;
    }
    InterpreterGroup interpreterGroup = new InterpreterGroup("group_1");
    interpreterGroup.put("session_1", new ArrayList<Interpreter>());
    Properties properties2 = new Properties(properties);
    properties2.put("zeppelin.livy.displayAppInfo", "true");
    // enable spark ui because it is disabled by livy integration test
    properties2.put("livy.spark.ui.enabled", "true");
    LivySparkInterpreter sparkInterpreter = new LivySparkInterpreter(properties2);
    sparkInterpreter.setInterpreterGroup(interpreterGroup);
    interpreterGroup.get("session_1").add(sparkInterpreter);
    AuthenticationInfo authInfo = new AuthenticationInfo("user1");
    MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
    InterpreterOutput output = new InterpreterOutput(outputListener);
    InterpreterContext context = new InterpreterContext("noteId", "paragraphId", "livy.spark",
        "title", "text", authInfo, null, null, null, null, null, output);
    sparkInterpreter.open();

    try {
      InterpreterResult result = sparkInterpreter.interpret("sc.version", context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(2, result.message().size());

      assertTrue(result.message().get(1).getData().contains("Spark Application Id"));
    } finally {
      sparkInterpreter.close();
    }
  }

  @Test
  public void testSparkRInterpreter() throws LivyException {
    if (!checkPreCondition()) {
      return;
    }

    final LivySparkRInterpreter sparkRInterpreter = new LivySparkRInterpreter(properties);
    try {
      sparkRInterpreter.getLivyVersion();
    } catch (APINotFoundException e) {
      // don't run sparkR test for livy 0.2 as there's some issues for livy 0.2
      return;
    }
    AuthenticationInfo authInfo = new AuthenticationInfo("user1");
    MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
    InterpreterOutput output = new InterpreterOutput(outputListener);
    final InterpreterContext context = new InterpreterContext("noteId", "paragraphId", "livy.sparkr",
        "title", "text", authInfo, null, null, null, null, null, output);
    sparkRInterpreter.open();

    try {
      // only test it in livy newer than 0.2.0
      boolean isSpark2 = isSpark2(sparkRInterpreter, context);
      InterpreterResult result = null;
      // test DataFrame api
      if (isSpark2) {
        result = sparkRInterpreter.interpret("df <- as.DataFrame(faithful)\nhead(df)", context);
        assertEquals(InterpreterResult.Code.SUCCESS, result.code());
        assertEquals(1, result.message().size());
        assertTrue(result.message().get(0).getData().contains("eruptions waiting"));

        // cancel
        Thread cancelThread = new Thread() {
          @Override
          public void run() {
            // invoke cancel after 3 seconds to wait job starting
            try {
              Thread.sleep(3000);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
            sparkRInterpreter.cancel(context);
          }
        };
        cancelThread.start();
        result = sparkRInterpreter.interpret("df <- as.DataFrame(faithful)\n" +
            "df1 <- dapplyCollect(df, function(x) " +
            "{ Sys.sleep(10); x <- cbind(x, x$waiting * 60) })", context);
        assertEquals(InterpreterResult.Code.ERROR, result.code());
        String message = result.message().get(0).getData();
        // 2 possibilities, sometimes livy doesn't return the real cancel exception
        assertTrue(message.contains("cancelled part of cancelled job group") ||
            message.contains("Job is cancelled"));
      } else {
        result = sparkRInterpreter.interpret("df <- createDataFrame(sqlContext, faithful)" +
            "\nhead(df)", context);
        assertEquals(InterpreterResult.Code.SUCCESS, result.code());
        assertEquals(1, result.message().size());
        assertTrue(result.message().get(0).getData().contains("eruptions waiting"));
      }

      // error
      result = sparkRInterpreter.interpret("cat(a)", context);
      //TODO @zjffdu, it should be ERROR, it is due to bug of LIVY-313
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(InterpreterResult.Type.TEXT, result.message().get(0).getType());
      assertTrue(result.message().get(0).getData().contains("object 'a' not found"));
    } finally {
      sparkRInterpreter.close();
    }
  }

  @Test
  public void testLivyTutorialNote() throws IOException {
    if (!checkPreCondition()) {
      return;
    }
    InterpreterGroup interpreterGroup = new InterpreterGroup("group_1");
    interpreterGroup.put("session_1", new ArrayList<Interpreter>());
    LazyOpenInterpreter sparkInterpreter = new LazyOpenInterpreter(
        new LivySparkInterpreter(properties));
    sparkInterpreter.setInterpreterGroup(interpreterGroup);
    interpreterGroup.get("session_1").add(sparkInterpreter);
    LazyOpenInterpreter sqlInterpreter = new LazyOpenInterpreter(
        new LivySparkSQLInterpreter(properties));
    interpreterGroup.get("session_1").add(sqlInterpreter);
    sqlInterpreter.setInterpreterGroup(interpreterGroup);
    sqlInterpreter.open();

    try {
      AuthenticationInfo authInfo = new AuthenticationInfo("user1");
      MyInterpreterOutputListener outputListener = new MyInterpreterOutputListener();
      InterpreterOutput output = new InterpreterOutput(outputListener);
      InterpreterContext context = new InterpreterContext("noteId", "paragraphId", "livy.sql",
          "title", "text", authInfo, null, null, null, null, null, output);

      String p1 = IOUtils.toString(getClass().getResourceAsStream("/livy_tutorial_1.scala"));
      InterpreterResult result = sparkInterpreter.interpret(p1, context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());

      String p2 = IOUtils.toString(getClass().getResourceAsStream("/livy_tutorial_2.sql"));
      result = sqlInterpreter.interpret(p2, context);
      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
      assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType());
    } finally {
      sparkInterpreter.close();
      sqlInterpreter.close();
    }
  }

  private boolean isSpark2(BaseLivyInterprereter interpreter, InterpreterContext context) {
    InterpreterResult result = null;
    if (interpreter instanceof LivySparkRInterpreter) {
      result = interpreter.interpret("sparkR.session()", context);
      // SparkRInterpreter would always return SUCCESS, it is due to bug of LIVY-313
      if (result.message().get(0).getData().contains("Error")) {
        return false;
      } else {
        return true;
      }
    } else {
      result = interpreter.interpret("spark", context);
      if (result.code() == InterpreterResult.Code.SUCCESS) {
        return true;
      } else {
        return false;
      }
    }
  }

  public static class MyInterpreterOutputListener implements InterpreterOutputListener {
    @Override
    public void onAppend(int index, InterpreterResultMessageOutput out, byte[] line) {
    }

    @Override
    public void onUpdate(int index, InterpreterResultMessageOutput out) {

    }

    @Override
    public void onUpdateAll(InterpreterOutput out) {

    }
  }
}


text:
/**
 * Created by wuhao on 2017-03-16.
 */
(function () {
    angular
        .module("WebAppMaker")
        .factory("FlickrService", FlickrService);

    function FlickrService($http) {
        var key = "de78745485e1e9e91dc7923aa5f121bb";
        var urlBase =
            "https://api.flickr.com/services/rest/?method=flickr.photos.search&format=json&api_key=API_KEY&text=TEXT";

        var api = {
            "searchPhotos": searchPhotos
        };
        return api;

        function searchPhotos(searchTerm) {
            var url = urlBase.replace("API_KEY", key).replace("TEXT", searchTerm);
            return $http.get(url);
        }
    }
})();


text:
package com.teamwizardry.refraction.api.book;

import com.teamwizardry.librarianlib.features.gui.component.GuiComponent;
import com.teamwizardry.librarianlib.features.math.Vec2d;

public interface ITextModularCallback {

	String addCustomComponent(GuiComponent component);
}


text:
title: Über uns
menu:
  main:
    weight: 10
    name: Über uns
footerHideTopMargin: true
---

{{< headline-icon icon="icon-info.svg" >}}

{{< headline-brackets-h1 color="blue" >}}
Über uns
{{< /headline-brackets-h1 >}}

{{< hero-block-center >}}
Code for Germany ist ein Netzwerk von Open-Government-Expert\*innen, die sich als ehrenamtlich aktive Stadtentwickler\*innen für einen nachhaltigen digitalen Wandel in Politik und Verwaltung einsetzen.
{{< /hero-block-center >}}

{{< paragraph-center >}}
Code for Germany ist ein Projekt des gemeinnützigen Vereins Open Knowledge Foundation Deutschland. Daher leitet sich der Name unserer lokalen Organisationseinheiten ab: Open Knowledge Labs, kurz OK Labs. Hier treffen deutschlandweit digital affine Menschen aufeinander. Gemeinsam arbeiten wir auf der Basis Offener Daten an analogen und digitalen Lösungen für mehr demokratische Teilhabe und Offenes Wissen.

Die Labs sind Experimentierräume für die digitale Stadtgesellschaft. Expert\*innen aus Entwicklung, Design, Politik, Verwaltung, Geisteswissenschaften und viele weitere entwickeln hier selbstständig Open-Source-Software, die Behörden für ihre tägliche Arbeit implementieren können. Mit diesen praktischen Anwendungen zeigen wir auf, wie unsere Gesellschaft jeden Tag von Open-Government-Prozessen profitiert und ein nachhaltiger digitaler Wandel gestaltet werden kann.

Seit seiner Gründung 2014 ist es auf {{< num-labs >}} Labs angewachsen und umfasst eine Community von mehr als 500 Freiwilligen. Wir arbeiten im Austausch mit kommunalen Behörden und unterstützen sie darin, ihre Dienstleistungen zeitgemäß, effizient und transparent zu gestalten.

Nachhaltiger digitaler Wandel bedeutet für uns, Open Government unter folgenden Leitlinien umzusetzen:

[OFFENE DATEN:]({{< relref "/ziele#heading-01-open-data" >}}) Verwaltungsdaten maschinenlesbar und standardisiert veröffentlichen.

[TECH OHNE SELBSTZWECK:]({{< relref "/ziele#heading-02-open-government" >}}) Technologie an menschlichen Bedürfnissen ausrichten.

[ÖFFENTLICHES GELD - ÖFFENTLICHES GUT:]({{< relref "/ziele#heading-04-open-software" >}}) Steuergelder in Freie und Offene Software
investieren.

[DIGITALES EHRENAMT:]({{< relref "/ziele#heading-05-digitales-ehrenamt" >}}) Zivilgesellschaft einbinden und nachhaltig fördern.

[ÖKOLOGISCHE NACHHALTIGKEIT:]({{< relref "/ziele#heading-06-oekologische-nachhaltigkeit" >}}) Natürliche Ressourcen schützen.

**Im Folgenden geben wir einen kurzen Überblick darüber, was das für unsere Partner\*innen und uns in der Umsetzung bedeutet.**

{{< /paragraph-center  >}}

{{< ueber/blocks-ueber-uns "about-us-blocks-de" >}}


text:
package org.springframework.cloud.loadbalancer.cache;

import java.time.Duration;

import org.junit.jupiter.api.Test;

import org.springframework.cache.CacheManager;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.springframework.cloud.loadbalancer.core.CachingServiceInstanceListSupplier.SERVICE_INSTANCE_CACHE_NAME;

/**
 * Tests for {@link DefaultLoadBalancerCacheManager}.
 *
 * @author Olga Maciaszek-Sharma
 */
class DefaultLoadBalancerCacheManagerTests {

	@SuppressWarnings("ConstantConditions")
	@Test
	void shouldCreateLoadBalancerCacheFromProperties() {
		LoadBalancerCacheProperties properties = new LoadBalancerCacheProperties();
		properties.setTtl(Duration.ofMinutes(5));
		properties.setCapacity(128);

		DefaultLoadBalancerCacheManager cacheManager = new DefaultLoadBalancerCacheManager(properties);

		assertThat(cacheManager.getCacheNames()).hasSize(1);
		assertThat(cacheManager.getCache(SERVICE_INSTANCE_CACHE_NAME)).isInstanceOf(DefaultLoadBalancerCache.class);
		assertThat(((DefaultLoadBalancerCache) cacheManager.getCache(SERVICE_INSTANCE_CACHE_NAME)).getEvictMs())
				.isEqualTo(300000);
	}

	@Test
	void shouldNotThrowExceptionOnDuplicateCacheName() {
		LoadBalancerCacheProperties properties = new LoadBalancerCacheProperties();

		assertThatCode(() -> new DefaultLoadBalancerCacheManager(properties, "test", "test"))
				.doesNotThrowAnyException();
	}

	@Test
	void shouldOnlyCreateOneCacheWithGivenName() {
		LoadBalancerCacheProperties properties = new LoadBalancerCacheProperties();

		CacheManager cacheManager = new DefaultLoadBalancerCacheManager(properties, "test", "test");

		assertThat(cacheManager.getCacheNames()).hasSize(1);
		assertThat(cacheManager.getCache("test")).isInstanceOf(DefaultLoadBalancerCache.class);
	}

}


text:
package com.intel.sparkbench

import java.io.{File, FileInputStream, IOException, InputStreamReader}
import java.util.Properties

import org.apache.hadoop.io.compress.CompressionCodec
import org.apache.hadoop.io.{NullWritable, Text}
import org.apache.hadoop.mapred.SequenceFileOutputFormat
import org.apache.spark.SparkContext._
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkContext, SparkException}

import scala.collection.JavaConversions._
import scala.collection.mutable.HashMap
import scala.reflect.ClassTag
import scala.reflect.runtime.universe.TypeTag

class IOCommon(val sc:SparkContext) {
  def load[T:ClassTag:TypeTag](filename:String, force_format:Option[String]=None) = {
    val input_format = force_format.getOrElse(
      IOCommon.getProperty("sparkbench.inputformat").getOrElse("Text"))

    input_format match {
      case "Text" =>
        sc.textFile(filename)

      case "Sequence" =>
        sc.sequenceFile[NullWritable, Text](filename).map(_._2.toString)

      case _ => throw new UnsupportedOperationException(s"Unknown inpout format: $input_format")
    }
  }

  def save(filename:String, data:RDD[_], prefix:String) = {
    val output_format = IOCommon.getProperty(prefix).getOrElse("Text")
    val output_format_codec =
      loadClassByName[CompressionCodec](IOCommon.getProperty(prefix + ".codec"))

    output_format match {
      case "Text" =>
        if (output_format_codec.isEmpty)  data.saveAsTextFile(filename)
        else data.saveAsTextFile(filename, output_format_codec.get)

      case "Sequence" =>
        val sequence_data = data.map(x => (NullWritable.get(), new Text(x.toString)))
        if (output_format_codec.isEmpty) {
          sequence_data.saveAsHadoopFile[SequenceFileOutputFormat[NullWritable, Text]](filename)
        } else {
          sequence_data.saveAsHadoopFile[SequenceFileOutputFormat[NullWritable, Text]](filename,
            output_format_codec.get)
        }

      case _ => throw new UnsupportedOperationException(s"Unknown output format: $output_format")
    }
  }

  def save(filename:String, data:RDD[_]):Unit = save(filename, data, "sparkbench.outputformat")

  private def loadClassByName[T](name:Option[String]) = {
    if (!name.isEmpty) Some(Class.forName(name.get)
      .newInstance.asInstanceOf[T].getClass) else None
  }

  private def callMethod[T, R](obj:T, method_name:String) =
    obj.getClass.getMethod(method_name).invoke(obj).asInstanceOf[R]
}

object IOCommon{
  private val sparkbench_conf: HashMap[String, String] =
    getPropertiesFromFile(System.getenv("SPARKBENCH_PROPERTIES_FILES"))

  def getPropertiesFromFile(filenames: String): HashMap[String, String] = {
    val result = new HashMap[String, String]
    filenames.split(',').filter(_.stripMargin.length > 0).foreach { filename =>
      val file = new File(filename)
      require(file.exists, s"Properties file $file does not exist")
      require(file.isFile, s"Properties file $file is not a normal file")

      val inReader = new InputStreamReader(new FileInputStream(file), "UTF-8")
      try {
        val properties = new Properties()
        properties.load(inReader)
        result ++= properties.stringPropertyNames()
          .map(k => (k, properties(k).trim)).toMap
      } catch {
        case e: IOException =>
          val message = s"Failed when loading Sparkbench properties file $file"
          throw new SparkException(message, e)
      } finally {
        inReader.close()
      }
    }
    result.filter{case (key, value) => value.toLowerCase != "none"}
  }

  def getProperty(key:String):Option[String] = sparkbench_conf.get(key)

  def dumpProperties(): Unit = sparkbench_conf
      .foreach{case (key, value)=> println(s"$key\t\t$value")}
}


text:
namespace devtools_crosstool_autofdo {

// Interface for storing NodeChainAssemblies in a priority queue.
class NodeChainAssemblyQueue {
 public:
  virtual ~NodeChainAssemblyQueue() = default;

  // Returns true iff there are any assemblies to be retrieved.
  virtual bool empty() const = 0;

  // Returns the best (highest-score) assembly. The behavior is undefined if
  // `empty()` returns `true`.
  virtual NodeChainAssembly GetBestAssembly() const = 0;

  // Removes the assembly associated with the ordered `NodeChain` pair
  // `<split_chain, unsplit_chain>`.
  virtual void RemoveAssembly(NodeChainPair chain_pair) = 0;

  // Inserts `assembly` into the queue. `assembly` is associated with the
  // `NodeChain` pair `<assembly.split_chain(), assembly.unsplit_chain>`. If an
  // assembly is already associated with this pair, it will be replaced by
  // `assembly`.
  virtual void InsertAssembly(NodeChainAssembly assembly) = 0;
};

// Balanced-binary-tree implementation for `NodeChainAssemblyQueue`.
// `GetBestAssembly` has constant time complexity
// `RemoveAssembly` and `InsertAssembly` have logarithmic time complexity.
class NodeChainAssemblyBalancedTreeQueue : public NodeChainAssemblyQueue {
 public:
  NodeChainAssembly GetBestAssembly() const override {
    return *assemblies_.rbegin();
  }

  bool empty() const override { return assemblies_.empty(); }

  void RemoveAssembly(NodeChainPair chain_pair) override {
    auto it = handles_.find(chain_pair);
    if (it == handles_.end()) return;
    assemblies_.erase(it->second);
    handles_.erase(it);
  }

  void InsertAssembly(NodeChainAssembly assembly) override {
    NodeChainPair chain_pair{.split_chain = &assembly.split_chain(),
                             .unsplit_chain = &assembly.unsplit_chain()};
    auto handle_it = handles_.find(chain_pair);
    if (handle_it != handles_.end()) assemblies_.erase(handle_it->second);
    handles_.insert_or_assign(chain_pair,
                              assemblies_.insert(std::move(assembly)).first);
  }

 private:
  // All `NodeChainAssembly` records, ordered by score.
  // Assemblies are stored in std::set which provides logarithmic-time
  // complexity insertions and deletion operations. It uses the score-based
  // comparator to allow retrieval of the max element in constant time.
  // Note that we can't use the recommended absl::btree_set because insertions
  // and deletions can invalidate all iterators.
  std::set<NodeChainAssembly, NodeChainAssembly::NodeChainAssemblyComparator>
      assemblies_;

  // Map from each `NodeChain` pair to its associated `NodeChainAssembly` record
  // in `assemblies_`. We use this map to lookup the `NodeChainAssembly`
  // record associated with each `NodeChain` pair. When one record in
  // `assemblies_` is deleted, its iterator in this map should also be removed
  // and vice versa. Other iterators will remain valid as this is guaranteed by
  // std::set.
  absl::flat_hash_map<NodeChainPair,
           std::set<NodeChainAssembly,
                    NodeChainAssembly::NodeChainAssemblyComparator>::iterator>
      handles_;
};

// Iteration-based implementation of NodeChainAssemblyQueue.
// GetBestAssembly has linear-time complexity.
// `RemoveAssembly` and `InsertAssembly` have logarithmic-time complexity.
class NodeChainAssemblyIterativeQueue : public NodeChainAssemblyQueue {
 public:
  bool empty() const override { return assemblies_.empty(); }

  NodeChainAssembly GetBestAssembly() const override {
    auto best_assembly =
        absl::c_max_element(assemblies_, [](const auto &lhs, const auto &rhs) {
          return NodeChainAssembly::NodeChainAssemblyComparator()(lhs.second,
                                                                  rhs.second);
        });
    return best_assembly->second;
  }

  void RemoveAssembly(NodeChainPair chain_pair) override {
    assemblies_.erase(chain_pair);
  }

  void InsertAssembly(NodeChainAssembly assembly) override {
    assemblies_.insert_or_assign(assembly.chain_pair(), std::move(assembly));
  }

 private:
  absl::flat_hash_map<NodeChainPair, NodeChainAssembly> assemblies_;
};

// TODO(b/159842094): Make NodeChainBuilder exception-block aware.
// This class builds BB chains for one or multiple CFGs.
class NodeChainBuilder {
 public:
  template <class AssemblyQueueImpl = NodeChainAssemblyIterativeQueue>
  static NodeChainBuilder CreateNodeChainBuilder(
      const PropellerCodeLayoutScorer &scorer,
      const std::vector<ControlFlowGraph *> &cfgs, CodeLayoutStats &stats) {
    return NodeChainBuilder(scorer, cfgs, stats,
                            std::make_unique<AssemblyQueueImpl>());
  }

  const PropellerCodeLayoutScorer &code_layout_scorer() const {
    return code_layout_scorer_;
  }

  // Const public accessors for the internal data structures of chain. Used for
  // testing only.
  const std::vector<ControlFlowGraph *> &cfgs() const { return cfgs_; }

  const std::map<uint64_t, std::unique_ptr<NodeChain>> &chains() const {
    return chains_;
  }

  const NodeChainAssemblyQueue &node_chain_assemblies() const {
    return *node_chain_assemblies_;
  }

  // This function initializes the chains and then iteratively constructs larger
  // chains by merging the best chains, to achieve the highest score.
  // Clients of this class must use this function after calling the constructor.
  std::vector<std::unique_ptr<NodeChain>> BuildChains();

  // function and they are public for testing only. Clients must use the
  // BuildChains function instead.

  // Initializes the basic block chains and bundles from nodes of the CFGs.
  void InitNodeChains();

  // Initializes the edges between chains from edges of the CFGs.
  void InitChainEdges();

  // Initializes the chain assemblies, which are all profitable ways of merging
  // chains together, with their scores.
  void InitChainAssemblies();

  // Coalesces all the built chains together to form a single chain.
  // NodeChainBuilder calls this function at the end to ensure that all hot
  // BB chains are placed together at the beginning of the function.
  void CoalesceChains();

  // Merges two chains according to a given chain assembly. The two chains are
  // merged into `assembly.split_chain()`. `assembly.unsplit_chain()` will be
  // garbage-collected at the end of this call. The provided assembly will be
  // killed by this call and shall not be used.
  void MergeChains(NodeChainAssembly assembly);

  // Merges `right_chain` to the right side of `left_chain`.
  void MergeChains(NodeChain &left_chain, NodeChain &right_chain);

 private:
  explicit NodeChainBuilder(
      const PropellerCodeLayoutScorer &scorer,
      const std::vector<ControlFlowGraph *> &cfgs, CodeLayoutStats &stats,
      std::unique_ptr<NodeChainAssemblyQueue> node_chain_assemblies)
      : code_layout_scorer_(scorer),
        cfgs_(cfgs),
        stats_(stats),
        node_chain_assemblies_(std::move(node_chain_assemblies)) {}

  // Returns the score for `chain`.
  int64_t ComputeScore(NodeChain &chain) const;

  // Updates and removes the assemblies for `kept_chain` and `defunct_chain`.
  // This method is called after `defunct_chain` is merged into `kept_chain` and
  // serves to update all assemblies between `kept_chain` and other chains and
  // also to remove all assemblies related to `defunct_chain`. `defunct_chain`
  // will be removed after this call.
  void UpdateAssembliesAfterMerge(NodeChain &kept_chain,
                                  NodeChain &defunct_chain);

  // Finds and updates the best (highest-gain) assembly for two chains.
  void UpdateNodeChainAssembly(NodeChain &split_chain,
                               NodeChain &unsplit_chain);

  // Returns whether `edge` should be considered in constructing the chains.
  bool ShouldVisitEdge(const CFGEdge &edge) {
    return edge.weight() != 0 && !edge.IsReturn() &&
           (code_layout_scorer_.code_layout_params()
                .inter_function_reordering() ||
            !edge.IsCall());
  }

  const PropellerCodeLayoutScorer code_layout_scorer_;

  // CFGs targeted for BB chaining.
  const std::vector<ControlFlowGraph *> cfgs_;

  CodeLayoutStats &stats_;

  // Constructed chains. This starts by having one chain for every CFGNode and
  // as chains keep merging together, defunct chains are removed from this.
  std::map<uint64_t, std::unique_ptr<NodeChain>> chains_;

  // Assembly (merge) candidates. This maps every pair of chains to its
  // (non-zero) merge score.
  std::unique_ptr<NodeChainAssemblyQueue> node_chain_assemblies_;
};

// Returns vectors of nodes which form forced-fallthrough paths. These are
// all the paths which -- based on the profile -- always execute from beginning
// to end once execution enters their source node.
// The idea here is that these edges must be attached together by the optimal
// layout, regardless of how other basic blocks are laid out. For example,
// consider the following CFG:
//            A      B
//           50\    /100
//              \  /
//               VV     150        150
//                C  --------> D --------> E
//                                        / \
//                                    20 /   \130
//                                      V     V
//                                      F     G
// The edges C->D and D->E can be bundled (frozen) in the layout independently
// of how other edges are treated by the layout algorithm.
// Note: The returned paths are sorted in increasing order of their first node's
// symbol ordinal.
std::vector<std::vector<CFGNode *>> GetForcedPaths(const ControlFlowGraph &cfg);

// Returns all mutually-forced edges as a map from their source to their sink.
// These are the edges which -- based on the profile -- are the only outgoing
// edges from their source and the only incoming edges to their sinks.
// Note that the paths represented by these edges may include cycles.
std::map<CFGNode *, CFGNode *, CFGNodePtrLessComparator> GetForcedEdges(
    const ControlFlowGraph &cfg);

// Breaks cycles in the `path_next` map by cutting the edge sinking to the
// smallest address in every cycle (hopefully a loop backedge).
void BreakCycles(
    std::map<CFGNode *, CFGNode *, CFGNodePtrLessComparator> &path_next);
}  // namespace devtools_crosstool_autofdo
#endif  // AUTOFDO_LLVM_PROPELLER_NODE_CHAIN_BUILDER_H_


text:
To develop sketches for SAM3X cores we provide the same way to program Arduino DUE. You can use the internal Arduino IDE preinstalled on the UDOObuntu releases.

After you connected the board and boot the UDOObuntu 2 desktop environment:

1. Start -> Programming -> Arduino IDE or the Arduino IDE desktop link.
2. Tools -> Board -> UDOO QDL (Arduino Due)
3. Tools -> Port -> /dev/ttymxc3
4. File -> Examples -> Basics -> Blink
5. Click on "Upload" button.
6. Wait "Compiling sketch..." until "Upload is complete".

As you can see this is the same procedure you usually use with all the others Arduino board.


text:
#ifndef _BLACKFIN_PGTABLE_H
#define _BLACKFIN_PGTABLE_H

#include <asm-generic/4level-fixup.h>

#include <asm/page.h>
#include <asm/def_LPBlackfin.h>

typedef pte_t *pte_addr_t;
/*
* Trivial page table functions.
*/
#define pgd_present(pgd)	(1)
#define pgd_none(pgd)		(0)
#define pgd_bad(pgd)		(0)
#define pgd_clear(pgdp)
#define kern_addr_valid(addr)	(1)

#define pmd_offset(a, b)	((void *)0)
#define pmd_none(x)		(!pmd_val(x))
#define pmd_present(x)		(pmd_val(x))
#define pmd_clear(xp)		do { set_pmd(xp, __pmd(0)); } while (0)
#define pmd_bad(x)		(pmd_val(x) & ~PAGE_MASK)

#define kern_addr_valid(addr) (1)

#define PAGE_NONE		__pgprot(0)	/* these mean nothing to NO_MM */
#define PAGE_SHARED		__pgprot(0)	/* these mean nothing to NO_MM */
#define PAGE_COPY		__pgprot(0)	/* these mean nothing to NO_MM */
#define PAGE_READONLY		__pgprot(0)	/* these mean nothing to NO_MM */
#define PAGE_KERNEL		__pgprot(0)	/* these mean nothing to NO_MM */
#define pgprot_noncached(prot)	(prot)

extern void paging_init(void);

#define __swp_type(x)		(0)
#define __swp_offset(x)		(0)
#define __swp_entry(typ,off)	((swp_entry_t) { ((typ) | ((off) << 7)) })
#define __pte_to_swp_entry(pte)	((swp_entry_t) { pte_val(pte) })
#define __swp_entry_to_pte(x)	((pte_t) { (x).val })

static inline int pte_file(pte_t pte)
{
	return 0;
}

#define set_pte(pteptr, pteval) (*(pteptr) = pteval)
#define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)

/*
 * Page assess control based on Blackfin CPLB management
 */
#define _PAGE_RD	(CPLB_USER_RD)
#define _PAGE_WR	(CPLB_USER_WR)
#define _PAGE_USER	(CPLB_USER_RD | CPLB_USER_WR)
#define _PAGE_ACCESSED	CPLB_ALL_ACCESS
#define _PAGE_DIRTY	(CPLB_DIRTY)

#define PTE_BIT_FUNC(fn, op) \
	static inline pte_t pte_##fn(pte_t _pte) { _pte.pte op; return _pte; }

PTE_BIT_FUNC(rdprotect, &= ~_PAGE_RD);
PTE_BIT_FUNC(mkread, |= _PAGE_RD);
PTE_BIT_FUNC(wrprotect, &= ~_PAGE_WR);
PTE_BIT_FUNC(mkwrite, |= _PAGE_WR);
PTE_BIT_FUNC(exprotect, &= ~_PAGE_USER);
PTE_BIT_FUNC(mkexec, |= _PAGE_USER);
PTE_BIT_FUNC(mkclean, &= ~_PAGE_DIRTY);
PTE_BIT_FUNC(mkdirty, |= _PAGE_DIRTY);
PTE_BIT_FUNC(mkold, &= ~_PAGE_ACCESSED);
PTE_BIT_FUNC(mkyoung, |= _PAGE_ACCESSED);

/*
 * ZERO_PAGE is a global shared page that is always zero: used
 * for zero-mapped memory areas etc..
 */
#define ZERO_PAGE(vaddr)	virt_to_page(empty_zero_page)
extern char empty_zero_page[];

extern unsigned int kobjsize(const void *objp);

#define swapper_pg_dir ((pgd_t *) 0)
/*
 * No page table caches to initialise.
 */
#define pgtable_cache_init()	do { } while (0)
#define io_remap_pfn_range      remap_pfn_range

/*
 * All 32bit addresses are effectively valid for vmalloc...
 * Sort of meaningless for non-VM targets.
 */
#define	VMALLOC_START	0
#define	VMALLOC_END	0xffffffff

/* provide a special get_unmapped_area for framebuffer mmaps of nommu */
extern unsigned long get_fb_unmapped_area(struct file *filp, unsigned long,
					  unsigned long, unsigned long,
					  unsigned long);
#define HAVE_ARCH_FB_UNMAPPED_AREA

#include <asm-generic/pgtable.h>

#endif				/* _BLACKFIN_PGTABLE_H */


text:
using System;
using System.Collections.Generic;
using UnityEngine;
using PolyToolkitInternal;
using System.Collections;

namespace PolyToolkit {
  /// <summary>
  /// Represents a Poly asset (the information about a 3D object in Poly).
  /// </summary>
  /// <remarks>
  /// This is not the actual object that is added to the scene. This is just a container for
  /// the object's data, from which a GameObject can eventually be constructed.
  /// </remarks>
  [AutoStringifiable]
  public class PolyAsset {
    /// <summary>
    /// Format of the URL to a particular asset, given its ID.
    /// </summary>
    private const string URL_FORMAT = "https://poly.google.com/view/{0}";
    /// <summary>
    /// Identifier for the asset. This is an alphanumeric string that identifies the asset,
    /// but is not meant for display. For example, "assets/L1o2e3m4I5p6s7u8m".
    /// </summary>
    public string name;
    /// <summary>
    /// Human-readable name of the asset.
    /// </summary>
    public string displayName;
    /// <summary>
    /// Name of the asset's author.
    /// </summary>
    public string authorName;
    /// <summary>
    /// Human-readable description of the asset.
    /// </summary>
    public string description;
    /// <summary>
    /// Date and time when the asset was created.
    /// </summary>
    public DateTime createTime;
    /// <summary>
    /// Date and time when the asset was last updated.
    /// </summary>
    public DateTime updateTime;
    /// <summary>
    /// A list of the available formats for this asset. Each format describes a content-type of a
    /// representation of the asset, and specifies where the underlying data files can be found.
    /// </summary>
    public List<PolyFormat> formats = new List<PolyFormat>();
    /// <summary>
    /// Thumbnail image information for this asset.
    /// </summary>
    public PolyFile thumbnail;
    /// <summary>
    /// The license under which the author has made this asset available for use, if any.
    /// </summary>
    public PolyAssetLicense license;
    /// <summary>
    /// Visibility of this asset (who can access it).
    /// </summary>
    public PolyVisibility visibility;
    /// <summary>
    /// If true, the asset was manually curated by the Poly team.
    /// </summary>
    public bool isCurated;

    /// <summary>
    /// The texture with the asset's thumbnail image. Only available after successfully fetched.
    /// </summary>
    public Texture2D thumbnailTexture;

    /// <summary>
    /// Returns a PolyFormat of the given type, if it exists.
    /// If the asset has more than one format of the given type, returns the first one seen.
    /// If the asset does not have a format of the given type, returns null.
    /// </summary>
    public PolyFormat GetFormatIfExists(PolyFormatType type) {
      foreach (PolyFormat format in formats) {
        if (format == null) {
          continue;
        }
        if (format.formatType == type) return format;
      }
      return null;
    }

    /// <summary>
    /// Returns whether the asset is known to be mutable, due to its visibility.
    /// Public and unlisted assets are immutable. Private assets are mutable.
    /// </summary>
    /// <remarks>
    /// Immutable assets can be cached indefinitely, since they can't be modified.
    /// Depending on your use-case, you may wish to frequently re-download mutable assets, if you expect them to be
    /// changed while your app is running.
    /// </remarks>
    public bool IsMutable {
      get {
        return visibility == PolyVisibility.PRIVATE || visibility == PolyVisibility.UNSPECIFIED;
      }
    }

    /// <summary>
    /// Returns the Poly url of the asset.
    /// </summary>
    public string Url {
      get {
        return string.Format(URL_FORMAT, name.Replace("assets/", ""));
      }
    }

    /// <summary>
    /// Returns attribution information about the asset.
    /// </summary>
    public string AttributionInfo {
      get {
        return AttributionGeneration.GenerateAttributionString(displayName, authorName, Url,
          license == PolyAssetLicense.CREATIVE_COMMONS_BY ? AttributionGeneration.CC_BY_LICENSE
          : "All Rights Reserved");
      }
    }

    public override string ToString() {
      return AutoStringify.Stringify(this);
    }
  }

  /// <summary>
  /// A specific representation of an asset, containing all the information needed to retrieve and
  /// describe this representation.
  /// </summary>
  /// <remarks>
  /// Each format is a "package" of files, with one root file and any number of resource files that accompany
  /// it. For example, for the OBJ format, the root file is the OBJ file that contains the asset's geometry
  /// and the corresponding MTL files are resource files.
  /// </remarks>
  [AutoStringifiable]
  public class PolyFormat {
    /// <summary>
    /// Format type (OBJ, GLTF, etc).
    /// </summary>
    public PolyFormatType formatType;
    /// <summary>
    /// The root (main) file for this format.
    /// </summary>
    public PolyFile root;
    /// <summary>
    /// The list of resource (auxiliary) files for this format.
    /// </summary>
    public List<PolyFile> resources = new List<PolyFile>();
    /// <summary>
    /// Complexity of this format.
    /// </summary>
    public PolyFormatComplexity formatComplexity;

    public override string ToString() {
      return AutoStringify.Stringify(this);
    }
  }

  /// <summary>
  /// Represents a Poly file.
  /// </summary>
  [AutoStringifiable]
  public class PolyFile {
    /// <summary>
    /// The relative path of the file in the local filesystem when it was uploaded.
    /// For resource files, the path is relative to the root file. This always includes the name fo the
    /// file, and may or may not include a directory path.
    /// </summary>
    public string relativePath;
    /// <summary>
    /// The URL at which the contents of this file can be retrieved.
    /// </summary>
    public string url;
    /// <summary>
    /// The content type of this file. For example, "text/plain".
    /// </summary>
    public string contentType;
    /// <summary>
    /// Binary contents of this file. Only available after fetched.
    /// </summary>
    [AutoStringifyAbridged]
    public byte[] contents;
    /// <summary>
    /// Cached text contents of this file (lazily decoded from binary).
    /// </summary>
    [AutoStringifyAbridged]
    private string text;

    public PolyFile(string relativePath, string url, string contentType) {
      this.relativePath = relativePath;
      this.url = url;
      this.contentType = contentType;
    }

    /// <summary>
    /// Returns the contents of this file as text.
    /// </summary>
    public string Text {
      get {
        if (text == null) text = System.Text.Encoding.UTF8.GetString(contents);
        return text;
      }
    }

    public override string ToString() {
      return AutoStringify.Stringify(this);
    }
  }

  /// <summary>
  /// Information on the complexity of a format.
  /// </summary>
  [AutoStringifiable]
  public class PolyFormatComplexity {
    /// <summary>
    /// Approximate number of triangles in the asset's geometry.
    /// </summary>
    public long triangleCount;
    /// <summary>
    /// Hint for the level of detail (LOD) of this format relative to the other formats in this
    /// same asset. 0 is the most detailed version.
    /// </summary>
    public int lodHint;

    public override string ToString() {
      return AutoStringify.Stringify(this);
    }
  }

 /// <summary>
 /// Possible format types that can be returned from the Poly REST API.
 /// </summary>
 public enum PolyFormatType {
  UNKNOWN = 0,
  OBJ = 1,
  GLTF = 2,
  GLTF_2 = 3,
  TILT = 4,
  FBX = 5,
 }

 /// <summary>
 /// Possible asset licenses.
 /// </summary>
 public enum PolyAssetLicense {
    /// <summary>
    /// License unknown/unspecified.
    /// </summary>
    UNKNOWN = 0,
    /// <summary>
    /// Creative Commons license.
    /// </summary>
    CREATIVE_COMMONS_BY = 1,
    /// <summary>
    /// All Rights Reserved by author (not licensed).
    /// </summary>
    ALL_RIGHTS_RESERVED = 2,
  }

  /// <summary>
  /// Visibility filters for a PolyListUserAssets request.
  /// </summary>
  public enum PolyVisibilityFilter {
    /// <summary>
    /// No visibility specified. Returns all assets.
    /// </summary>
    UNSPECIFIED = 0,
    /// <summary>
    /// Return only private assets.
    /// </summary>
    PRIVATE = 1,
    /// <summary>
    /// Return only published assets, including unlisted assets.
    /// </summary>
    PUBLISHED = 2,
  }

  /// <summary>
  /// Visibility of a Poly asset.
  /// </summary>
  public enum PolyVisibility {
    /// <summary>
    /// Unknown (and invalid) visibility.
    /// </summary>
    UNSPECIFIED = 0,
    /// <summary>
    /// Only the owner of the asset can access it.
    /// </summary>
    PRIVATE = 1,
    /// <summary>
    /// Read access to anyone who knows the asset ID (link to the asset), but the
    /// logged-in user's unlisted assets are returned in PolyListUserAssets.
    /// </summary>
    UNLISTED = 2,
    /// <summary>
    /// Read access for everyone.
    /// </summary>
    PUBLISHED = 3,
  }

  /// <summary>
  /// Category of a Poly asset.
  /// </summary>
  public enum PolyCategory {
    UNSPECIFIED = 0,
    ANIMALS = 1,
    ARCHITECTURE = 2,
    ART = 3,
    FOOD = 4,
    NATURE = 5,
    OBJECTS = 6,
    PEOPLE = 7,
    PLACES = 8,
    TECH = 9,
    TRANSPORT = 10,
  }

  /// <summary>
  /// How the requested assets should be ordered in the response.
  /// </summary>
  public enum PolyOrderBy {
    BEST,
    NEWEST,
    OLDEST,
    // Liked time is only a valid in a PolyListLikedAssetsRequest.
    LIKED_TIME
  }

  /// <summary>
  /// Options for filtering to return only assets that contain the given format.
  /// </summary>
  public enum PolyFormatFilter {
    BLOCKS = 1,
    FBX = 2,
    GLTF = 3,
    GLTF_2 = 4,
    OBJ = 5,
    TILT = 6,
  }

  /// <summary>
  /// Options for filtering on the maximum complexity of the asset.
  /// </summary>
  public enum PolyMaxComplexityFilter {
    UNSPECIFIED = 0,
    SIMPLE = 1,
    MEDIUM = 2,
    COMPLEX = 3,
  }

  /// <summary>
  /// Base class that all request types derive from.
  /// </summary>
  public abstract class PolyRequest {
    /// <summary>
    /// How to sort the results.
    /// </summary>
    public PolyOrderBy orderBy = PolyOrderBy.NEWEST;
    /// <summary>
    /// Size of each returned page.
    /// </summary>
    public int pageSize = 45;
    /// <summary>
    /// Page continuation token for pagination.
    /// </summary>
    public string pageToken = null;
  }

  /// <summary>
  /// Represents a set of Poly request parameters determining which assets should be returned.
  /// null values mean "don't filter by this parameter".
  /// </summary>
  [AutoStringifiable]
  public class PolyListAssetsRequest : PolyRequest {
    public string keywords = "";
    public bool curated = false;
    /// <summary>
    /// Category can be any of the PolyCategory object categories (e.g. "PolyCategory.ANIMALS").
    /// </summary>
    public PolyCategory category = PolyCategory.UNSPECIFIED;
    public PolyMaxComplexityFilter maxComplexity = PolyMaxComplexityFilter.UNSPECIFIED;
    public PolyFormatFilter? formatFilter = null;

    public PolyListAssetsRequest() {}

    /// <summary>
    /// Returns a ListAssetsRequest that requests the featured assets. This approximates what the
    /// user would see in the Poly main page, but the ordering might be different.
    /// </summary>
    public static PolyListAssetsRequest Featured() {
      PolyListAssetsRequest featured = new PolyListAssetsRequest();
      featured.curated = true;
      featured.orderBy = PolyOrderBy.BEST;
      return featured;
    }

    /// <summary>
    /// Returns a ListAssetsRequest that requests the latest assets. This query is not curated,
    /// so it will return the latest assets regardless of whether they have been reviewed.
    /// If you wish to enable curation, set curated=true on the returned object.
    /// </summary>
    public static PolyListAssetsRequest Latest() {
      PolyListAssetsRequest latest = new PolyListAssetsRequest();
      latest.orderBy = PolyOrderBy.NEWEST;
      return latest;
    }

    public override string ToString() {
      return AutoStringify.Stringify(this);
    }
  }

  /// <summary>
  /// Represents a set of Poly request parameters determining which of the user's assets should be returned.
  /// null values mean "don't filter by this parameter".
  /// </summary>
  [AutoStringifiable]
  public class PolyListUserAssetsRequest : PolyRequest {
    public PolyFormatType format = PolyFormatType.UNKNOWN;
    public PolyVisibilityFilter visibility = PolyVisibilityFilter.UNSPECIFIED;
    public PolyFormatFilter? formatFilter = null;

    public PolyListUserAssetsRequest() { }

    /// <summary>
    /// Returns a ListUserAssetsRequest that requests the user's latest assets.
    /// </summary>
    public static PolyListUserAssetsRequest MyNewest() {
      PolyListUserAssetsRequest myNewest = new PolyListUserAssetsRequest();
      myNewest.orderBy = PolyOrderBy.NEWEST;
      return myNewest;
    }

    public override string ToString() {
      return AutoStringify.Stringify(this);
    }
  }

  /// <summary>
  /// Represents a set of Poly request parameters determining which liked assets should be returned.
  /// Currently, only requests for the liked assets of the logged in user are supported.
  /// null values mean "don't filter by this parameter".
  /// </summary>
  [AutoStringifiable]
  public class PolyListLikedAssetsRequest : PolyRequest {
    /// <summary>
    // A valid user id. Currently, only the special value 'me', representing the
    // currently-authenticated user is supported. To use 'me', you must pass
    // an OAuth token with the request.
    /// </summary>
    public string name = "me";

    public PolyListLikedAssetsRequest() { }

    /// <summary>
    /// Returns a ListUserAssetsRequest that requests the user's most recently liked assets.
    /// </summary>
    public static PolyListLikedAssetsRequest MyLiked() {
      PolyListLikedAssetsRequest myLiked = new PolyListLikedAssetsRequest();
      myLiked.orderBy = PolyOrderBy.LIKED_TIME;
      return myLiked;
    }

    public override string ToString() {
      return AutoStringify.Stringify(this);
    }
  }

  /// <summary>
  /// Represents the status of an operation: success or failure + error message.
  ///
  /// A typical pattern is to return a PolyStatus to indicate the success of an operation, instead of just a bool.
  /// So your code would do something like:
  ///
  /// @{
  /// PolyStatus MyMethod() {
  ///   if (somethingWentWrong) {
  ///     return PolyStatus.Error("Failed to reticulate spline.");
  ///   }
  ///   ...
  ///   return PolyStatus.Success();
  /// }
  /// @}
  ///
  /// You can also chain PolyStatus failures, using one PolyStatus as the cause of another:
  ///
  /// @{
  /// PolyStatus MyMethod() {
  ///   PolyStatus status = TesselateParabolicNonUniformDarkMatterQuantumSuperManifoldWithCheese();
  ///   if (!status.ok) {
  ///     return PolyStatus.Error(status, "Tesselation failure.");
  ///   }
  ///   ...
  ///   return PolyStatus.Success();
  /// }
  /// @}
  ///
  /// Using PolyStatus vs. throwing exceptions: PolyStatus typically represents an "expected" failure, that is,
  /// an operation where failure is common and acceptable. For example, validating user input, consuming some
  /// external file which might or might not be well formatted, sending a web request, etc. For unexpected
  /// failures (logic errors, assumption violations, etc), it's best to use exceptions.
  /// </summary>
  public struct PolyStatus {
    /// <summary>
    /// Indicates whether the operation succeeded.
    /// </summary>
    public bool ok;
    /// <summary>
    /// If the operation failed, this is the error message. This is an error message suitable for
    /// logging, not necessarily a user-friendly message.
    /// </summary>
    public string errorMessage;

    /// <summary>
    /// Creates a new PolyStatus with the given success status and error message.
    /// </summary>
    /// <param name="ok">Whether the operation succeeded.</param>
    /// <param name="errorMessage">The error message (only relevant if ok == false).</param>
    public PolyStatus(bool ok, string errorMessage = "") {
      this.ok = ok;
      this.errorMessage = errorMessage;
    }

    /// <summary>
    /// Creates a new success status.
    /// </summary>
    public static PolyStatus Success() {
      return new PolyStatus(true);
    }

    /// <summary>
    /// Creates a new error status with the given error message.
    /// </summary>
    public static PolyStatus Error(string errorMessage) {
      return new PolyStatus(false, errorMessage);
    }

    /// <summary>
    /// Creates a new error status with the given error message.
    /// </summary>
    public static PolyStatus Error(string format, params object[] args) {
      return new PolyStatus(false, string.Format(format, args));
    }

    /// <summary>
    /// Creates a new error status with the given error message and cause.
    /// The error message will automatically include all error messages in the causal chain.
    /// </summary>
    public static PolyStatus Error(PolyStatus cause, string errorMessage) {
      return new PolyStatus(false, errorMessage + "\nCaused by: " + cause.errorMessage);
    }

    /// <summary>
    /// Creates a new error status with the given error message and cause.
    /// The error message will automatically include all error messages in the causal chain.
    /// </summary>
    public static PolyStatus Error(PolyStatus cause, string format, params object[] args) {
      return new PolyStatus(false, string.Format(format, args) + "\nCaused by: " + cause.errorMessage);
    }

    public override string ToString() {
      return ok ? "OK" : string.Format("ERROR: {0}", errorMessage);
    }
  }

  /// <summary>
  /// A union of a PolyStatus and a type. Used to represent the result of an operation, which can either
  /// be an error (represented as a PolyStatus), or a result object (the parameter type T).
  /// </summary>
  /// <typeparam name="T">The result object.</typeparam>
  public class PolyStatusOr<T> {
    private PolyStatus status;
    private T value;

    /// <summary>
    /// Creates a PolyStatusOr with the given error status.
    /// </summary>
    /// <param name="status">The error status with which to create it.</param>
    public PolyStatusOr(PolyStatus status) {
      if (status.ok) {
        throw new Exception("PolyStatusOr(PolyStatus) can only be used with an error status.");
      }
      this.status = status;
      this.value = default(T);
    }

    /// <summary>
    /// Creates a PolyStatusOr with the given value.
    /// The status will be set to success.
    /// </summary>
    /// <param name="value">The value with which to create it.</param>
    public PolyStatusOr(T value) {
      this.status = PolyStatus.Success();
      this.value = value;
    }

    /// <summary>
    /// Returns the status.
    /// </summary>
    public PolyStatus Status { get { return status; } }

    /// <summary>
    /// Shortcut to Status.ok.
    /// </summary>
    public bool Ok { get { return status.ok; } }

    /// <summary>
    /// Returns the value. The value can only be obtained if the status is successful. If the status
    /// is an error, reading this property will throw an exception.
    /// </summary>
    public T Value {
      get {
        if (!status.ok) {
          throw new Exception("Can't get value from an unsuccessful PolyStatusOr: " + this);
        }
        return value;
      }
    }

    public override string ToString() {
      return string.Format("PolyStatusOr<{0}>: {1}{2}", typeof(T).Name, status,
        status.ok ? (value == null ? "(null)" : value.ToString()) : "");
    }
  }

  /// <summary>
  /// Base class for all result types.
  /// </summary>
  public abstract class PolyBaseResult {
    /// <summary>
    /// The status of the operation (success or failure).
    /// </summary>
    public PolyStatus status;
  }

  /// <summary>
  /// Represents the result of a PolyListAssetsRequest or PolyListUserAssetsRequest.
  /// </summary>
  [AutoStringifiable]
  public class PolyListAssetsResult : PolyBaseResult {
    /// <summary>
    /// A list of assets that match the criteria specified in the request.
    /// </summary>
    public List<PolyAsset> assets;
    /// <summary>
    /// The total number of assets in the list, without pagination.
    /// </summary>
    public int totalSize;
    /// <summary>
    /// The token to retrieve the next page of results, if any.
    /// If there is no next page, this will be null.
    /// </summary>
    public string nextPageToken;

    public PolyListAssetsResult(PolyStatus status, int totalSize = 0, List<PolyAsset> assets = null,
      string nextPageToken = null) {
      this.status = status;
      this.assets = assets;
      this.totalSize = totalSize;
      this.nextPageToken = nextPageToken;
    }

    public override string ToString() {
      return AutoStringify.Stringify(this);
    }
  }

  /// <summary>
  /// Represents the result of importing an asset.
  /// </summary>
  public class PolyImportResult {
    /// <summary>
    /// The GameObject representing the imported asset.
    /// </summary>
    public GameObject gameObject;

    /// <summary>
    /// The main thread throttler object, if importing in "throttled" mode. This will be null if not
    /// in throttled mode. Enumerate this on the main thread to gradually perform necessary main
    /// thread operations like creating meshes, textures, etc (see documentation for PolyImportOptions for
    /// more details).
    ///
    /// IMPORTANT: this enumerator is not designed to be used across scene (level) loads. Always finish
    /// enumerating it before loading a new scene.
    /// </summary>
    public IEnumerable mainThreadThrottler;

    public PolyImportResult(GameObject gameObject) {
      this.gameObject = gameObject;
    }
  }

  /// <summary>
  /// Represents the result of fetching files for an asset.
  /// </summary>
  [AutoStringifiable]
  public class PolyFormatTypeFetchResult : PolyBaseResult {
    public PolyAsset asset;

    public PolyFormatTypeFetchResult(PolyStatus status, PolyAsset asset) {
      this.status = status;
      this.asset = asset;
    }

    public override string ToString() {
      return AutoStringify.Stringify(this);
    }
  }

  /// <summary>
  /// Options for fetching a thumbnail.
  /// </summary>
  public class PolyFetchThumbnailOptions {
    /// <summary>
    /// If nonzero, this is the requested thumbnail image size, in pixels. This is the size
    /// of the image's largest dimension (width, for most thumbnails).
    /// This is just a hint that the implementation will try (but is not guaranteed) to honor.
    /// </summary>
    public int requestedImageSize { get; private set; }

    public PolyFetchThumbnailOptions() {}

    public void SetRequestedImageSize(int requestedImageSize) {
      this.requestedImageSize = requestedImageSize;
    }
  }
}