text:
<?php

namespace App\Modules\Api\Http\Controllers {

    use Core\Controller;
    use Psr\Http\Message\ResponseInterface as Response;
    use Psr\Http\Message\ServerRequestInterface as Request;

    class ApiController extends Controller
    {
        /**
         * @param Request $request
         * @param Response $response
         * @return mixed
         */
        public function index(Request $request, Response $response)
        {
            $data['data'] = [
                'title'=>"Ozone",
                "detail"=>"Php Modular framework"
            ];
            return $response->withJSON($data,200,JSON_PRETTY_PRINT);
        }
    }
}


text:
package main

import (
	"fmt"
	"os"
	"path"
	"strings"
	"text/template"

	"github.com/minio/cli"
)

// Generate lambda.
var genCmd = cli.Command{
	Name:   "gen",
	Usage:  "Generates lambda",
	Action: mainGen,
	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "bucket",
			Usage: "Bucket to run lambda on.",
		},
		cli.StringFlag{
			Name:  "prefix",
			Usage: "Prefix to run lambda on.",
		},
		cli.StringFlag{
			Name:  "suffix",
			Usage: "Suffix to run lambda on.",
		},
		cli.StringFlag{
			Name:  "events",
			Usage: "Events to run lambda on.",
			Value: "s3:ObjectCreated:*,s3:ObjectRemoved:*",
		},
	},
	CustomHelpTemplate: `NAME:
   minl {{.Name}} - {{.Usage}}

USAGE:
   minl {{.Name}} [FLAGS]

FLAGS:
  {{range .Flags}}{{.}}
  {{end}}
`,
}

// LambdaMetadata struct.
type LambdaMetadata struct {
	PackageName string
	Endpoint    string
	AccessKey   string
	SecretKey   string
	Secure      bool
	Region      string
	Bucket      string
	Events      []string
	Prefix      string
	Suffix      string
}

var notificationFile = `
package main

import (
        "fmt"
        "github.com/minio/minio-go/v6"
)

func enableBucketNotification(s3Client *minio.Client, lambdaArn minio.Arn) error {
       // ARN represents a notification channel that needs to be created in your S3 provider
       //  (e.g. http://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html)

       // An example of an lambda ARN:
       //             arn:minio:lambda:us-east-1:myfunc:lambda
       //                  ^      ^      ^         ^       ^
       //       Provider __|      |      |         |       |
       //                         |    Region  Account ID  |_ Notification Name
       //                Service _|
       //
       // You should replace YOUR-PROVIDER, YOUR-SERVICE, YOUR-REGION, YOUR-ACCOUNT-ID and YOUR-RESOURCE
       // with actual values that you receive from the S3 provider

       // Here you create a new lambda notification
       lambdaConfig := minio.NewNotificationConfig(lambdaArn)
       {{range $event := .Events}}
       lambdaConfig.AddEvents(minio.NotificationEventType("{{ $event }}"))
       {{end}}
       {{if .Prefix}} lambdaConfig.AddFilterPrefix("{{ .Prefix }}") {{end}}
       {{if .Suffix}} lambdaConfig.AddFilterSuffix("{{ .Suffix }}") {{end}}

       // Now, set all previously created notification configs
       bucketNotification := minio.BucketNotification{}
       bucketNotification.AddLambda(lambdaConfig)
       err := s3Client.SetBucketNotification("{{ .Bucket }}", bucketNotification)
       if err != nil {
            return err
       }
       return nil
}

func listenBucketNotification(s3Client *minio.Client, bucket string, lambdaArn minio.Arn, lambdaFn LambdaFunc) error {
       // Create a done channel to control 'ListenBucketNotification' go routine.
       doneCh := make(chan struct{})

       // Indicate a background go-routine to exit cleanly upon return.
       defer close(doneCh)

       // Notification account ARN, variable fields to note here are:
       //  - region
       //  - account-id
       // Account id here is the same which was chosen during SetBucketNotification.
       for notificationInfo := range s3Client.ListenBucketNotification(bucket, lambdaArn, doneCh) {
               if err := lambdaFn(notificationInfo.Records, notificationInfo.Err); err != nil {
                       return err
               }
       }
       return nil
}

func main() {
       // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
       // This boolean value is the last argument for New().

       // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
       // determined based on the Endpoint value.
       s3Client, err := minio.New("{{ .Endpoint }}", "{{ .AccessKey }}", "{{ .SecretKey }}", {{ .Secure }})
       if err != nil {
             fmt.Println("Unable to initialize minio client", err)
             return
       }

       // Create a new lambda ARN.
       lambdaArn := minio.NewArn("minio", "lambda", "{{ .Region }}", "{{ .PackageName }}", "lambda")

       // Enable bucket notifications.
       if err = enableBucketNotification(s3Client, lambdaArn); err != nil {
              fmt.Println("Unable to enable bucket notification.", err)
              return
       }

       // Listen bucket notification.
       if err = listenBucketNotification(s3Client, "{{ .Bucket }}", lambdaArn, YourFunc); err != nil {
              fmt.Println("Unable to listen bucket notification.", err)
              return
       }
}

type LambdaFunc func(events []minio.NotificationEvent, err error) error

func YourFunc(events []minio.NotificationEvent, err error) error {
       if err != nil {
               return err
       }
       /// Your code here.
       return nil
}
`

var supportedEventTypes = []string{
	"s3:ObjectCreated:*",
	"s3:ObjectCreated:Put",
	"s3:ObjectCreated:Post",
	"s3:ObjectCreated:Copy",
	"sh:ObjectCreated:CompleteMultipartUpload",
	"s3:ObjectRemoved:*",
	"s3:ObjectRemoved:Delete",
}

func isValidEventType(eventType string) bool {
	for _, supportedEventType := range supportedEventTypes {
		if supportedEventType == eventType {
			return true
		}
	}
	return false
}

func parseEvents(events []string) (parsedEvents []string) {
	for _, eventType := range events {
		if isValidEventType(eventType) {
			parsedEvents = append(parsedEvents, eventType)
		}
	}
	return parsedEvents
}

// checkGenSyntax - validate all the passed arguments
func checkGenSyntax(ctx *cli.Context) {
	if !ctx.Args().Present() {
		cli.ShowCommandHelpAndExit(ctx, ctx.Args().First(), 1)
	}
}

func initLambdaDir(lambda string) error {
	return os.MkdirAll(lambda, 0755)
}

func newLambdaMeta(ctx *cli.Context) LambdaMetadata {
	lmeta := LambdaMetadata{
		PackageName: ctx.Args().First(),
		Endpoint:    os.Getenv("S3_ENDPOINT"),
		AccessKey:   os.Getenv("ACCESS_KEY"),
		SecretKey:   os.Getenv("SECRET_KEY"),
		Secure:      os.Getenv("S3_SECURE") == "1",
		Region:      os.Getenv("S3_REGION"),
		Bucket:      ctx.String("bucket"),
		Events:      parseEvents(strings.Split(ctx.String("events"), ",")),
		Prefix:      ctx.String("prefix"),
		Suffix:      ctx.String("suffix"),
	}
	return lmeta
}

func mainGen(ctx *cli.Context) {
	checkGenSyntax(ctx)

	lambda := ctx.Args().First()
	tmpl := template.Must(template.New(lambda).Parse(notificationFile))

	initLambdaDir(lambda)
	lmeta := newLambdaMeta(ctx)

	templateFile := path.Join(lambda, lambda+".go")
	w, err := os.Create(templateFile)
	if err != nil {
		fmt.Println("Unable to write", templateFile, err)
		return
	}
	defer w.Close()
	err = tmpl.Execute(w, lmeta)
	if err != nil {
		fmt.Println("Unable to write", templateFile, err)
		return
	}
}

redpajama_set_name: RedPajamaGithub


text:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal">

        <view class="com.njfsoft_utils.cropimage.CropImageView" android:id="@+id/crimage"
                android:background="#55000000"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_x="0dip"
                android:layout_y="0dip"
        />
        <RelativeLayout android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingLeft="10dip"
                android:paddingRight="10dip"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true">
            <Button
                    android:id="@+id/save"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
          android:textColor="#88ffffff"
	    android:background="@drawable/rounded_corners"
                    android:text="  Save  "
android:paddingLeft="10dip"
    android:paddingRight="10dip"
            />
            <Button
                    android:id="@+id/discard"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@id/save"
          android:textColor="#88ffffff"
	    android:background="@drawable/rounded_corners"
                    android:text="  Close  "
android:textSize="18sp"
android:paddingLeft="10dip"
    android:paddingRight="10dip"
            />

        </RelativeLayout>
    </RelativeLayout>

</FrameLayout>


text:
<?php
use Symfony\Component\PropertyAccess\PropertyAccess;

require_once __DIR__ . '/vendor/autoload.php';

/**
 * goal
 * - provide a united way to access array index, object public variable, getXX/isXX/hasXX, __get.
 *
 * source
 * PropertyAccessor::getValue($objectOrArray, $propertyPath)
 *  $propertyPath = $this->getPropertyPath($propertyPath);
 *  $propertyValues = $this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices);
 *
 * PropertyAccessor::getPropertyPath($propertyPath)
 *  if cache hit: return
 *  return cache.set new PropertyPath($propertyPath) // why cache? regex operations in a long loop may be expensive.
 *
 * PropertyAccessor::readPropertiesUntil(...)
 *  for each path elements
 *   try to call getXX things. for expensive reflections, use cache.
 */

$accessor = PropertyAccess::createPropertyAccessor();

class Person {
    public $firstName;
    private $children = [];

    public function setChildren($children) {
        $this->children = $children;
    }

    public function getChildren() {
        return $this->children;
    }
}

$person = new Person();

$accessor->setValue($person, 'children[0]', new Person);
// equal to $person->getChildren()[0] = new Person()

$accessor->setValue($person, 'children[0].firstName', 'Wouter');
// equal to $person->getChildren()[0]->firstName = 'Wouter'

var_dump('Hello ' . $accessor->getValue($person, 'children[0].firstName')); // 'Wouter'
// equal to $person->getChildren()[0]->firstName


text:
this is a chronic pain management system where user can come and log his symptoms goals and activities in order to understand correlations between them.
user can see charts displaying pain mood and cognitive performance against daily activities
[![Build Status](https://travis-ci.org/peel3r/cpms.svg?branch=master)](https://travis-ci.org/peel3r/cpms)
#to do
update readme file
create articles for services
add help button on goals and activities
~~revamp targets view~~
add % of target completed for a day
add remaining time to achieve daily target
add more data about activity on the activities view

new feature
think about dashboard service
-----------
~~add esa assessment service~~
~~add pip assessment service - started~~
add quantitative chart for body parts pain
~~Travis~~
~~rearange show pain log~~
add other types data recording services

~~activity log~~
envelope log
~~symptom log~~

-------------
~~finish charts~~
~~add goals feature~~
0auth implement
~~integrate tinymce~~
~~input text on diary creator~~

~~add tabs for mood and cognitive performance~~

~~email field for user signup and sign in~~

~~DEACTIVATE USER LIST AT~~

EXPLORE PUSHER Twitter

~~add overall pain and fatigue levels~~

~~add previous diaries and pagination and arrange from newest to oldest~~

add file uploader ================> ???

~~add WYSIWYG ======================> ???~~

~~add deployment script to server~~

ansible

log pain view
-------------

add scroller to show one question at the time

~~add fatigue and cognitive questions~~

charts dashboard
----------------
~~dashboard with charts for all symptoms and pains~~

~~implement per user pain log~~

# Angular2 Webpack Starter

> An Angular 2 starter kit featuring [Angular 2](https://angular.io) ([Router](https://angular.io/docs/js/latest/api/router/), [Forms](https://angular.io/docs/js/latest/api/forms/),
[Http](https://angular.io/docs/js/latest/api/http/),

[Tests](https://angular.io/docs/js/latest/api/test/), [E2E](https://angular.github.io/protractor/#/faq#what-s-the-difference-between-karma-and-protractor-when-do-i-use-which-)), [Material](https://github.com/angular/material2), [Karma](https://karma-runner.github.io/), [Protractor](https://angular.github.io/protractor/), [Jasmine](https://github.com/jasmine/jasmine), [Istanbul](https://github.com/gotwarlost/istanbul), [TypeScript](http://www.typescriptlang.org/), [@types](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&uact=8&ved=0ahUKEwjgjdrR7u_NAhUQ7GMKHXgpC4EQFggnMAI&url=https%3A%2F%2Fwww.npmjs.com%2F~types&usg=AFQjCNG2PFhwEo88JKo12mrw_4d0w1oNiA&sig2=N69zbO0yN8ET7v4KVCUOKA), [TsLint](http://palantir.github.io/tslint/), [Codelyzer](https://github.com/mgechev/codelyzer), [Hot Module Replacement](https://webpack.github.io/docs/hot-module-replacement-with-webpack.html), and [Webpack 2](http://webpack.github.io/)

> If you're looking to learn TypeScript see [TypeStrong/learn-typescript](https://github.com/TypeStrong/learn-typescript)

This seed repo serves as an Angular 2 starter for anyone looking to get up and running with Angular 2 and TypeScript fast. Using a [Webpack 2](http://webpack.github.io/) for building our files and assisting with boilerplate. We're also using Protractor for our end-to-end story and Karma for our unit tests.
* Best practices in file and application organization for Angular 2.
* Ready to go build system using Webpack for working with TypeScript.
* Angular 2 examples that are ready to go when experimenting with Angular 2.
* A great Angular 2 seed repo for anyone who wants to start their project.
* Testing Angular 2 code with Jasmine and Karma.
* Coverage with Istanbul and Karma
* End-to-end Angular 2 code using Protractor.
* Type manager with @types
* Hot Module Replacement with Webpack
* Material Design with [angular/material2](https://github.com/angular/material2)

### Quick start
**Make sure you have Node version >= 5.0 and NPM >= 3**
> Clone/Download the repo then edit `app.ts` inside [`/src/app/app.ts`](/src/app/app.ts)

```bash

npm install

# start the server
npm start

# use Hot Module Replacement
npm run server:dev:hmr

```
go to [http://0.0.0.0:3000](http://0.0.0.0:3000) or [http://localhost:3000](http://localhost:3000) in your browser

# Getting Started
## Dependencies
What you need to run this app:
* `node` and `npm` (`brew install node`)
* Ensure you're running the latest versions Node `v4.x.x`+ (or `v5.x.x`) and NPM `3.x.x`+

> If you have `nvm` installed, which is highly recommended (`brew install nvm`) you can do a `nvm install --lts && nvm use` in `$` to run with the latest Node LTS. You can also have this `zsh` done for you [automatically](https://github.com/creationix/nvm#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)

Once you have those, you should install these globals with `npm install --global`:
* `webpack` (`npm install --global webpack`)
* `webpack-dev-server` (`npm install --global webpack-dev-server`)
* `karma` (`npm install --global karma-cli`)
* `protractor` (`npm install --global protractor`)
* `typescript` (`npm install --global typescript`)

## Running the app
After you have installed all dependencies you can now run the app. Run `npm run server` to start a local server using `webpack-dev-server` which will watch, build (in-memory), and reload for you. The port will be displayed to you as `http://0.0.0.0:3000` (or if you prefer IPv6, if you're using `express` server, then it's `http://[::1]:3000/`).

### server
```bash
# development
npm run server
# production
npm run build:prod
npm run server:prod
```

## Other commands

### build files
```bash
# development
npm run build:dev
# production
npm run build:prod
```

### hot module replacement
```bash
npm run server:dev:hmr
```

### watch and build files
```bash
npm run watch
```

### run tests
```bash
npm run test
```

### watch and run our tests
```bash
npm run watch:test
```

### run end-to-end tests
```bash
# make sure you have your server running in another terminal
npm run e2e
```

### run webdriver (for end-to-end)
```bash
npm run webdriver:update
npm run webdriver:start
```

### run Protractor's elementExplorer (for end-to-end)
```bash
npm run webdriver:start
# in another terminal
npm run e2e:live
```

### build Docker
```bash
npm run build:docker
```

# Configuration
Configuration files live in `config/` we are currently using webpack, karma, and protractor for different stages of your application

## Use latest TypeScript compiler
TypeScript 1.7.x includes everything you need. Make sure to upgrade, even if you installed TypeScript previously.

```
npm install --global typescript
```

# Types
> When you include a module that doesn't include Type Definitions inside of the module you can include external Type Definitions with @types

i.e, to have youtube api support, run this command in terminal:
```shell
npm i @types/youtube @types/gapi @types/gapi.youtube
```
In some cases where your code editor doesn't support Typescript 2 yet or these types weren't listed in ```tsconfig.json```, add these to **"src/custom-typings.d.ts"** to make peace with the compile check:
```es6
import '@types/gapi.youtube';
import '@types/gapi';
import '@types/youtube';
```

## Custom Type Definitions
When including 3rd party modules you also need to include the type definition for the module
if they don't provide one within the module. You can try to install it with @types

```
npm install @types/node
npm install @types/lodash
```

If you can't find the type definition in the registry we can make an ambient definition in
this file for now. For example

```typescript
declare module "my-module" {
  export function doesSomething(value: string): string;
}
```

If you're prototyping and you will fix the types later you can also declare it as type any

```typescript
declare var assert: any;
declare var _: any;
declare var $: any;
```

If you're importing a module that uses Node.js modules which are CommonJS you need to import as

```typescript
import * as _ from 'lodash';
```

# License
 [MIT](/LICENSE)


text:
#ifndef H_AXPLUGINDEFS
#define H_AXPLUGINDEFS

#include "FBControl.h"

namespace FB { namespace ActiveX {
    char FBCONTROL0_MIMETYPE[];
    typedef FB::ActiveX::CFBControl<&CLSID_FBControl0, FBCONTROL0_MIMETYPE, IFBControl, &DIID_IFBComEventSource, &FB_LIBID> CFBControl0;
} }
typedef FB::ActiveX::CFBControl0 CFBControl0;
OBJECT_ENTRY_AUTO(__uuidof(FBControl0), CFBControl0);
#endif


text:
package org.apache.kafka.streams.kstream.internals;

import org.apache.kafka.common.serialization.Serde;
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.common.utils.Bytes;
import org.apache.kafka.streams.kstream.Aggregator;
import org.apache.kafka.streams.kstream.Initializer;
import org.apache.kafka.streams.kstream.KTable;
import org.apache.kafka.streams.kstream.Materialized;
import org.apache.kafka.streams.kstream.Merger;
import org.apache.kafka.streams.kstream.Reducer;
import org.apache.kafka.streams.kstream.SessionWindowedKStream;
import org.apache.kafka.streams.kstream.SessionWindows;
import org.apache.kafka.streams.kstream.Windowed;
import org.apache.kafka.streams.kstream.internals.graph.StreamsGraphNode;
import org.apache.kafka.streams.state.SessionBytesStoreSupplier;
import org.apache.kafka.streams.state.SessionStore;
import org.apache.kafka.streams.state.StoreBuilder;
import org.apache.kafka.streams.state.Stores;

import java.util.Objects;
import java.util.Set;

import static org.apache.kafka.streams.kstream.internals.KGroupedStreamImpl.AGGREGATE_NAME;
import static org.apache.kafka.streams.kstream.internals.KGroupedStreamImpl.REDUCE_NAME;

public class SessionWindowedKStreamImpl<K, V> extends AbstractStream<K> implements SessionWindowedKStream<K, V> {
    private final SessionWindows windows;
    private final Serde<K> keySerde;
    private final Serde<V> valSerde;
    private final GroupedStreamAggregateBuilder<K, V> aggregateBuilder;
    private final Merger<K, Long> countMerger = (aggKey, aggOne, aggTwo) -> aggOne + aggTwo;

    SessionWindowedKStreamImpl(final SessionWindows windows,
                               final InternalStreamsBuilder builder,
                               final Set<String> sourceNodes,
                               final String name,
                               final Serde<K> keySerde,
                               final Serde<V> valSerde,
                               final GroupedStreamAggregateBuilder<K, V> aggregateBuilder,
                               final StreamsGraphNode streamsGraphNode) {
        super(builder, name, sourceNodes, streamsGraphNode);
        Objects.requireNonNull(windows, "windows can't be null");
        this.windows = windows;
        this.keySerde = keySerde;
        this.valSerde = valSerde;
        this.aggregateBuilder = aggregateBuilder;
    }

    @Override
    public KTable<Windowed<K>, Long> count() {
        return doCount(Materialized.with(keySerde, Serdes.Long()));
    }

    @Override
    public KTable<Windowed<K>, Long> count(final Materialized<K, Long, SessionStore<Bytes, byte[]>> materialized) {
        Objects.requireNonNull(materialized, "materialized can't be null");

        // TODO: remove this when we do a topology-incompatible release
        // we used to burn a topology name here, so we have to keep doing it for compatibility
        if (new MaterializedInternal<>(materialized).storeName() == null) {
            builder.newStoreName(AGGREGATE_NAME);
        }

        return doCount(materialized);
    }

    private KTable<Windowed<K>, Long> doCount(final Materialized<K, Long, SessionStore<Bytes, byte[]>> materialized) {
        final MaterializedInternal<K, Long, SessionStore<Bytes, byte[]>> materializedInternal = new MaterializedInternal<>(materialized);
        materializedInternal.generateStoreNameIfNeeded(builder, AGGREGATE_NAME);
        if (materializedInternal.keySerde() == null) {
            materializedInternal.withKeySerde(keySerde);
        }
        if (materializedInternal.valueSerde() == null) {
            materializedInternal.withValueSerde(Serdes.Long());
        }

        return aggregateBuilder.build(
            new KStreamSessionWindowAggregate<>(
                windows, materializedInternal.storeName(),
                aggregateBuilder.countInitializer,
                aggregateBuilder.countAggregator,
                countMerger
            ),
            AGGREGATE_NAME,
            materialize(materializedInternal),
            materializedInternal.isQueryable()
        );
    }

    @Override
    public KTable<Windowed<K>, V> reduce(final Reducer<V> reducer) {
        return reduce(reducer, Materialized.with(keySerde, valSerde));
    }

    @Override
    public KTable<Windowed<K>, V> reduce(final Reducer<V> reducer,
                                         final Materialized<K, V, SessionStore<Bytes, byte[]>> materialized) {
        Objects.requireNonNull(reducer, "reducer can't be null");
        Objects.requireNonNull(materialized, "materialized can't be null");
        final Aggregator<K, V, V> reduceAggregator = aggregatorForReducer(reducer);
        final MaterializedInternal<K, V, SessionStore<Bytes, byte[]>> materializedInternal = new MaterializedInternal<>(materialized);
        materializedInternal.generateStoreNameIfNeeded(builder, REDUCE_NAME);
        if (materializedInternal.keySerde() == null) {
            materializedInternal.withKeySerde(keySerde);
        }
        if (materializedInternal.valueSerde() == null) {
            materializedInternal.withValueSerde(valSerde);
        }

        return aggregateBuilder.build(
            new KStreamSessionWindowAggregate<>(
                windows,
                materializedInternal.storeName(),
                aggregateBuilder.reduceInitializer,
                reduceAggregator,
                mergerForAggregator(reduceAggregator)
            ),
            REDUCE_NAME,
            materialize(materializedInternal),
            materializedInternal.isQueryable()
        );
    }

    @Override
    public <T> KTable<Windowed<K>, T> aggregate(final Initializer<T> initializer,
                                                final Aggregator<? super K, ? super V, T> aggregator,
                                                final Merger<? super K, T> sessionMerger) {
        return aggregate(initializer, aggregator, sessionMerger, Materialized.with(keySerde, null));
    }

    @Override
    public <VR> KTable<Windowed<K>, VR> aggregate(final Initializer<VR> initializer,
                                                  final Aggregator<? super K, ? super V, VR> aggregator,
                                                  final Merger<? super K, VR> sessionMerger,
                                                  final Materialized<K, VR, SessionStore<Bytes, byte[]>> materialized) {
        Objects.requireNonNull(initializer, "initializer can't be null");
        Objects.requireNonNull(aggregator, "aggregator can't be null");
        Objects.requireNonNull(sessionMerger, "sessionMerger can't be null");
        Objects.requireNonNull(materialized, "materialized can't be null");
        final MaterializedInternal<K, VR, SessionStore<Bytes, byte[]>> materializedInternal = new MaterializedInternal<>(materialized);
        materializedInternal.generateStoreNameIfNeeded(builder, AGGREGATE_NAME);

        if (materializedInternal.keySerde() == null) {
            materializedInternal.withKeySerde(keySerde);
        }
        return aggregateBuilder.build(
            new KStreamSessionWindowAggregate<>(
                windows,
                materializedInternal.storeName(),
                initializer,
                aggregator,
                sessionMerger
            ),
            AGGREGATE_NAME,
            materialize(materializedInternal),
            materializedInternal.isQueryable()
        );
    }

    @SuppressWarnings("deprecation") // continuing to support SessionWindows#maintainMs in fallback mode
    private <VR> StoreBuilder<SessionStore<K, VR>> materialize(final MaterializedInternal<K, VR, SessionStore<Bytes, byte[]>> materialized) {
        SessionBytesStoreSupplier supplier = (SessionBytesStoreSupplier) materialized.storeSupplier();
        if (supplier == null) {
            // NOTE: in the future, when we remove Windows#maintainMs(), we should set the default retention
            // to be (windows.inactivityGap() + windows.grace()). This will yield the same default behavior.
            final long retentionPeriod = materialized.retention() != null ? materialized.retention().toMillis() : windows.maintainMs();

            if ((windows.inactivityGap() + windows.gracePeriodMs()) > retentionPeriod) {
                throw new IllegalArgumentException("The retention period of the session store "
                                                       + materialized.storeName()
                                                       + " must be no smaller than the session inactivity gap plus the"
                                                       + " grace period."
                                                       + " Got gap=[" + windows.inactivityGap() + "],"
                                                       + " grace=[" + windows.gracePeriodMs() + "],"
                                                       + " retention=[" + retentionPeriod + "]");
            }
            supplier = Stores.persistentSessionStore(
                materialized.storeName(),
                retentionPeriod
            );
        }
        final StoreBuilder<SessionStore<K, VR>> builder = Stores.sessionStoreBuilder(
            supplier,
            materialized.keySerde(),
            materialized.valueSerde()
        );

        if (materialized.loggingEnabled()) {
            builder.withLoggingEnabled(materialized.logConfig());
        } else {
            builder.withLoggingDisabled();
        }

        if (materialized.cachingEnabled()) {
            builder.withCachingEnabled();
        }
        return builder;
    }

    private Merger<K, V> mergerForAggregator(final Aggregator<K, V, V> aggregator) {
        return (aggKey, aggOne, aggTwo) -> aggregator.apply(aggKey, aggTwo, aggOne);
    }

    private Aggregator<K, V, V> aggregatorForReducer(final Reducer<V> reducer) {
        return (aggKey, value, aggregate) -> aggregate == null ? value : reducer.apply(aggregate, value);
    }
}


text:
namespace rocksdb {

class ColumnFamilyHandle;
class Comparator;
class DB;
struct ReadOptions;
struct DBOptions;

enum WriteType { kPutRecord, kMergeRecord, kDeleteRecord, kLogDataRecord };

// an entry for Put, Merge or Delete entry for write batches. Used in
// WBWIIterator.
struct WriteEntry {
  WriteType type;
  Slice key;
  Slice value;
};

// Iterator of one column family out of a WriteBatchWithIndex.
class WBWIIterator {
 public:
  virtual ~WBWIIterator() {}

  virtual bool Valid() const = 0;

  virtual void SeekToFirst() = 0;

  virtual void SeekToLast() = 0;

  virtual void Seek(const Slice& key) = 0;

  virtual void Next() = 0;

  virtual void Prev() = 0;

  // the return WriteEntry is only valid until the next mutation of
  // WriteBatchWithIndex
  virtual WriteEntry Entry() const = 0;

  virtual Status status() const = 0;
};

// A WriteBatchWithIndex with a binary searchable index built for all the keys
// inserted.
// In Put(), Merge() or Delete(), the same function of the wrapped will be
// called. At the same time, indexes will be built.
// By calling GetWriteBatch(), a user will get the WriteBatch for the data
// they inserted, which can be used for DB::Write().
// A user can call NewIterator() to create an iterator.
class WriteBatchWithIndex : public WriteBatchBase {
 public:
  // backup_index_comparator: the backup comparator used to compare keys
  // within the same column family, if column family is not given in the
  // interface, or we can't find a column family from the column family handle
  // passed in, backup_index_comparator will be used for the column family.
  // reserved_bytes: reserved bytes in underlying WriteBatch
  // overwrite_key: if true, overwrite the key in the index when inserting
  //                the same key as previously, so iterator will never
  //                show two entries with the same key.
  explicit WriteBatchWithIndex(
      const Comparator* backup_index_comparator = BytewiseComparator(),
      size_t reserved_bytes = 0, bool overwrite_key = false);
  virtual ~WriteBatchWithIndex();

  using WriteBatchBase::Put;
  void Put(ColumnFamilyHandle* column_family, const Slice& key,
           const Slice& value) override;

  void Put(const Slice& key, const Slice& value) override;

  using WriteBatchBase::Merge;
  void Merge(ColumnFamilyHandle* column_family, const Slice& key,
             const Slice& value) override;

  void Merge(const Slice& key, const Slice& value) override;

  using WriteBatchBase::Delete;
  void Delete(ColumnFamilyHandle* column_family, const Slice& key) override;
  void Delete(const Slice& key) override;

  using WriteBatchBase::PutLogData;
  void PutLogData(const Slice& blob) override;

  using WriteBatchBase::Clear;
  void Clear() override;

  using WriteBatchBase::GetWriteBatch;
  WriteBatch* GetWriteBatch() override;

  // Create an iterator of a column family. User can call iterator.Seek() to
  // search to the next entry of or after a key. Keys will be iterated in the
  // order given by index_comparator. For multiple updates on the same key,
  // each update will be returned as a separate entry, in the order of update
  // time.
  WBWIIterator* NewIterator(ColumnFamilyHandle* column_family);
  // Create an iterator of the default column family.
  WBWIIterator* NewIterator();

  // Will create a new Iterator that will use WBWIIterator as a delta and
  // base_iterator as base.
  //
  // This function is only supported if the WriteBatchWithIndex was
  // constructed with overwrite_key=true.
  //
  // The returned iterator should be deleted by the caller.
  // The base_iterator is now 'owned' by the returned iterator. Deleting the
  // returned iterator will also delete the base_iterator.
  Iterator* NewIteratorWithBase(ColumnFamilyHandle* column_family,
                                Iterator* base_iterator);
  // default column family
  Iterator* NewIteratorWithBase(Iterator* base_iterator);

  // Similar to DB::Get() but will only read the key from this batch.
  // If the batch does not have enough data to resolve Merge operations,
  // MergeInProgress status may be returned.
  Status GetFromBatch(ColumnFamilyHandle* column_family,
                      const DBOptions& options, const Slice& key,
                      std::string* value);

  // Similar to previous function but does not require a column_family.
  // Note:  An InvalidArgument status will be returned if there are any Merge
  // operators for this key.  Use previous method instead.
  Status GetFromBatch(const DBOptions& options, const Slice& key,
                      std::string* value) {
    return GetFromBatch(nullptr, options, key, value);
  }

  // Similar to DB::Get() but will also read writes from this batch.
  //
  // This function will query both this batch and the DB and then merge
  // the results using the DB's merge operator (if the batch contains any
  // merge requests).
  //
  // Setting read_options.snapshot will affect what is read from the DB
  // but will NOT change which keys are read from the batch (the keys in
  // this batch do not yet belong to any snapshot and will be fetched
  // regardless).
  Status GetFromBatchAndDB(DB* db, const ReadOptions& read_options,
                           const Slice& key, std::string* value);
  Status GetFromBatchAndDB(DB* db, const ReadOptions& read_options,
                           ColumnFamilyHandle* column_family, const Slice& key,
                           std::string* value);

  // Records the state of the batch for future calls to RollbackToSavePoint().
  // May be called multiple times to set multiple save points.
  void SetSavePoint() override;

  // Remove all entries in this batch (Put, Merge, Delete, PutLogData) since the
  // most recent call to SetSavePoint() and removes the most recent save point.
  // If there is no previous call to SetSavePoint(), behaves the same as
  // Clear().
  //
  // Calling RollbackToSavePoint invalidates any open iterators on this batch.
  //
  // Returns Status::OK() on success,
  //         Status::NotFound() if no previous call to SetSavePoint(),
  //         or other Status on corruption.
  Status RollbackToSavePoint() override;

 private:
  struct Rep;
  Rep* rep;
};

}  // namespace rocksdb

#endif  // !ROCKSDB_LITE


text:
package com.griddynamics.jagger.webclient.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.griddynamics.jagger.dbapi.model.RootNode;

import java.util.Set;

@RemoteServiceRelativePath("rpc/ControlTreeCreatorService")
public interface ControlTreeCreatorService extends RemoteService {

    @Deprecated
    RootNode getControlTreeForSession(String sessionId, boolean isShowOnlyMatchedTests) throws RuntimeException;

    RootNode getControlTreeForSessions(Set<String> sessionIds, boolean isShowOnlyMatchedTests) throws RuntimeException;

    public static class Async {
        private static final ControlTreeCreatorServiceAsync ourInstance = (ControlTreeCreatorServiceAsync) GWT.create(ControlTreeCreatorService.class);

        public static ControlTreeCreatorServiceAsync getInstance() {
            return ourInstance;
        }
    }
}


text:
package com.google.firebase.testing;

import static com.google.common.truth.Truth.assertThat;
import static com.google.firebase.testing.common.Tasks2.waitForSuccess;

import android.app.Activity;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public final class RemoteConfigTest {

  private static final String MODEL_NAME = "Acura/Honda+Mercedes-Benz";
  private static final boolean COLOR_IS_RED = true;

  @Rule public final ActivityTestRule<Activity> activity = new ActivityTestRule<>(Activity.class);

  @Before
  public void prepareRemoteConfig() throws Exception {
    FirebaseRemoteConfig frc = FirebaseRemoteConfig.getInstance();

    waitForSuccess(frc.fetch());
    waitForSuccess(frc.activate());
  }

  @Test
  public void getBooleanConvertsValueSetInConsole() {
    FirebaseRemoteConfig frc = FirebaseRemoteConfig.getInstance();

    assertThat(frc.getBoolean("COLOR_IS_RED")).isEqualTo(COLOR_IS_RED);
  }

  @Test
  public void getStringReturnsValueSetInConsole() {
    FirebaseRemoteConfig frc = FirebaseRemoteConfig.getInstance();

    assertThat(frc.getString("MODEL_NAME")).isEqualTo(MODEL_NAME);
  }

  @Test
  public void getValueNotSetInConsoleYieldsStaticSource() {
    FirebaseRemoteConfig frc = FirebaseRemoteConfig.getInstance();
    FirebaseRemoteConfigValue value = frc.getValue("GOOBER_GOOBER");

    assertThat(value.getSource()).isEqualTo(FirebaseRemoteConfig.VALUE_SOURCE_STATIC);
  }
}


text:
// TODO: arrow key navigation

/**
 * Module dependencies.
 */
var debug = require('debug')('page-filemanager');
var express = require('express');
var router = express.Router();
var accepts = require('accepts');
var createError = require('http-errors');
var defaults = require('defaults');
var escapeHtml = require('escape-html');
var ejs = require('ejs');
var fs = require('fs');
var path = require('path');
var normalize = path.normalize;
var resolve = path.resolve;
var sep = path.sep;
var extname = path.extname;
var join = path.join;
var Batch = require('batch');
var mime = require('mime-types');
var parseUrl = require('parseurl');
var prettysize = require('prettysize');

var Wrap = require('./wrap');
var c = require('./config');

/**
 * Media types and the map for content negotiation.
 */

var mediaTypes = [
  'text/html',
  'text/plain',
  'application/json'
];

var mediaType = {
  'text/html': 'html',
  'text/plain': 'plain',
  'application/json': 'json'
};

/**
 * Serve directory listings with the given `root` path.
 *
 * See Readme.md for documentation of o.
 *
 * @param {String} path
 * @param {Object} o options
 * @return {Function} middleware
 * @api public
 */

module.exports = function filemanager(o) {
  o = defaults(o, c);

  // root required
  if (!o.root) throw new TypeError('filemanager() root path required');

  // resolve root to absolute and normalize
  var relativeRoot = o.root;
  var root = resolve(o.root);
  root = normalize(root + sep);

  var hidden = o.hidden
    , icons = o.icons
    , view = o.view || 'tiles'
    , filter = o.filter
    , up = !!o.up
    , down = !!o.down
    , crumbs = !!o.crumbs
    , serve = o.serve || relativeRoot
    , mount = o.mount || '/filemanager'

  router.use(o.route, function filemanager(req, res, next) {

    if (req.method !== 'GET' && req.method !== 'HEAD') {
      res.statusCode = 'OPTIONS' === req.method
        ? 200
        : 405;
      res.setHeader('Allow', 'GET, HEAD, OPTIONS');
      res.end();
      return;
    }

    // parse original url
    var originalUrl = parseUrl.original(req);
    var originalDir = decodeURIComponent(originalUrl.pathname);
    var search = originalUrl.search ? decodeURIComponent(originalUrl.search) : '';
    var dir = normalize(originalDir.replace(mount, ''));
    var serveDir = normalize(join(serve, dir));

    // join / normalize from root dir
    var path = normalize(join(root, dir));

    // null byte(s), bad request
    if (~path.indexOf('\0')) return next(createError(400));

    // malicious path
    if ((path + sep).substr(0, root.length) !== root) {
      debug('malicious path "%s"', path);
      return next(createError(403));
    }

    // determine ".." display
    up = normalize(resolve(path) + sep) !== root && o.up;

    // check if we have a directory
    debug('stat "%s"', path);

    fs.stat(path, function(err, stat) {
      if (err && err.code === 'ENOENT') {
        if(originalDir === o.mount){
          debug('ENOENT, forward request to next middleware');
          return next();
        } else {
          debug('ENOENT, redirect to: ' + o.mount);
          return res.redirect(o.mount);
        }
      }

      if (err) {
        err.status = err.code === 'ENAMETOOLONG'
          ? 414
          : 500;
        return next(err);
      }

      if (!stat.isDirectory()) return next();

      // fetch files
      debug('readdir "%s"', path);
      fs.readdir(path, function(err, files) {
        if (err) return next(err);
        if (!hidden) files = removeHidden(files);
        if (filter) files = files.filter(function(filename, index, list) {
          return filter(filename, index, list, path);
        });

        if (up) files.unshift('..');

        statFiles(path, files, function(err, stats) {
          if (err) return next(err);

          files = files.map(function(file, i) {
            var s = stats[i];

            return {
              name: file,
              link: getLink(file, s.isDirectory(), originalDir, serveDir, search),
              size: prettysize(s.size),
              stat: s,
              isDirectory: s.isDirectory(),
              isImage: isImage(file),
              icon: iconLookup(file, s.isDirectory())
            };
          });
          files = files.filter(navigate(files, up, down));
          files.sort(fileSort);

          // content-negotiation
          var accept = accepts(req);
          var type = accept.type(mediaTypes);

          // not acceptable
          if (!type) return next(createError(406));
          var crumbsRoot = originalDir.repl;
          exports[mediaType[type]](req, res, next, files, originalDir, icons, up, down, o);
        });
      });
    });

  });

  return router;
};

/**
 * Respond with text/html.
 */

exports.html = function(req, res, next, files, dir, icons, up, down, o) {

  var search = parseUrl.original(req).search;

  res.locals.files = files;
  res.locals.crumbs = up ? breadCrumbs(dir, up, search) : [];
  res.locals.list = typeof req.query.list !== 'undefined'

  var wrap = Wrap(o);

  wrap
    .i18n(req.i18n)
    .place(req.place || o.place)
    .load(res.locals, function(err, result) {
      debug('route loaded', result);
      if (err) return next(err);
      res.send(result.page);
    })
  ;

};

/**
 * Respond with application/json.
 */

exports.json = function(req, res, next, files) {
  var body = JSON.stringify(files);
  var buf = new Buffer(body, 'utf8');

  res.setHeader('Content-Type', 'application/json; charset=utf-8');
  res.setHeader('Content-Length', buf.length);
  res.end(buf);
};

/**
 * Respond with text/plain.
 */

exports.plain = function(req, res, next, files) {
  var names = files.map(function(file) {
    return file.name
  });
  var body = names.join('\n') + '\n';
  var buf = new Buffer(body, 'utf8');

  res.setHeader('Content-Type', 'text/plain; charset=utf-8');
  res.setHeader('Content-Length', buf.length);
  res.end(buf);
};

/**
 * Normalizes the path separator from system separator
 * to URL separator, aka `/`.
 *
 * @param {String} path
 * @return {String}
 * @api private
 */

function normalizeSlashes(path) {
  return path.split(sep).join('/');
}

/**
 * Stat all files and return array of stat
 * in same order.
 */

function statFiles(dir, files, cb) {
  var batch = new Batch();

  batch.concurrency(10);

  files.forEach(function(file) {
    batch.push(function(done) {
      fs.stat(join(dir, file), function(err, stat) {
        if (err && err.code !== 'ENOENT') return done(err);

        // pass ENOENT as null stat, not error
        done(null, stat || null);
      });
    });
  });

  batch.end(cb);
}

/**
 * Sort function for with directories first.
 */

function fileSort(a, b) {
  return Number(b.name === '..') - Number(a.name === '') ||
    Number(b.stat && b.stat.isDirectory()) - Number(a.stat && a.stat.isDirectory()) ||
    Number(a.isImage) - Number(b.isImage) ||
    String(a.name).toLocaleLowerCase().localeCompare(String(b.name).toLocaleLowerCase());
}

/**
 * Filter "hidden" `files`, aka files
 * beginning with a `.`.
 *
 * @param {Array} files
 * @return {Array}
 * @api private
 */

function removeHidden(files) {
  return files.filter(function(file) {
    return '.' != file[0];
  });
}
/**
 * Determines whether navigating up or down the folder hierarchy is allowed.
 */

function navigate(file, up, down) {
  return function(file) {
    return !file.stat || !file.stat.isDirectory() || file.name == '..' && up || down;
  };
}

function getLink(name, isDirectory, dir, serveDir, search) {
  search = isDirectory ? search || '' : '';
  var d = isDirectory ? dir : serveDir;
  var p = d.split('/').map(function(c) {
    return encodeURIComponent(c);
  });
  if (name && name === '..') {
    var last = p.pop();
    if (last === '') p.pop();
  } else {
    p.push(encodeURIComponent(name));
  }
  return escapeHtml(normalizeSlashes(normalize(p.join('/')))) + search;
}

/**
 * Map html `dir`, returning a linked path.
 */

function breadCrumbs(dir, up, search) {
  search = search || '';
  var parts = dir.split('/');
  crumbs = [];
  if (up === false) return crumbs;

  for (var i = 0; i < parts.length; i++) {
    var part = parts[i];

    parts[i] = encodeURIComponent(part);

    if (part) {
      crumbs.push({
        name: escapeHtml(part),
        href: escapeHtml(parts.slice(0, i + 1).join('/')) + search,
        last: i == (parts.length - 1) || !parts[i + 1]
      });
    }

  }

  return crumbs;
}

/**
 * Image can be displayed in html
 */

function isImage(name) {
  return ['svg', 'png', 'jpg', 'jpeg', 'bmp', 'gif'].some(function(type) {
    return new RegExp('\.' + type + '$', 'i').test(name);
  });
}

/**
 * Get the icon data for the file name.
 */

function iconLookup(filename, isDirectory) {

  // is directory
  if (isDirectory) {
    return {
      className: 'filemanager-icon-directory',
      fileName: icons.folder
    }
  }

  var ext = extname(filename);

  // try by extension
  if (icons[ext]) {
    return {
      className: 'filemanager-icon-' + ext.substring(1),
      fileName: icons[ext]
    };
  }

  var mimetype = mime.lookup(ext);

  // default if no mime type
  if (mimetype === false) {
    return {
      className: 'filemanager-icon-default',
      fileName: icons.default
    };
  }

  // try by mime type
  if (icons[mimetype]) {
    return {
      className: 'filemanager-icon-' + mimetype.replace('/', '-'),
      fileName: icons[mimetype]
    };
  }

  var suffix = mimetype.split('+')[1];

  if (suffix && icons['+' + suffix]) {
    return {
      className: 'filemanager-icon-' + suffix,
      fileName: icons['+' + suffix]
    };
  }

  var type = mimetype.split('/')[0];

  // try by type only
  if (icons[type]) {
    return {
      className: 'filemanager-icon-' + type,
      fileName: icons[type]
    };
  }

  return {
    className: 'filemanager-icon-default',
    fileName: icons.default
  };
}

/**
 * Icon map.
 */

var icons = {
  // base icons
  'default': 'page_white.png',
  'folder': 'folder.png',

  // generic mime type icons
  'image': 'image.png',
  'text': 'page_white_text.png',
  'video': 'film.png',

  // generic mime suffix icons
  '+json': 'page_white_code.png',
  '+xml': 'page_white_code.png',
  '+zip': 'box.png',

  // specific mime type icons
  'application/font-woff': 'font.png',
  'application/javascript': 'page_white_code_red.png',
  'application/json': 'page_white_code.png',
  'application/msword': 'page_white_word.png',
  'application/pdf': 'page_white_acrobat.png',
  'application/postscript': 'page_white_vector.png',
  'application/rtf': 'page_white_word.png',
  'application/vnd.ms-excel': 'page_white_excel.png',
  'application/vnd.ms-powerpoint': 'page_white_powerpoint.png',
  'application/vnd.oasis.opendocument.presentation': 'page_white_powerpoint.png',
  'application/vnd.oasis.opendocument.spreadsheet': 'page_white_excel.png',
  'application/vnd.oasis.opendocument.text': 'page_white_word.png',
  'application/x-7z-compressed': 'box.png',
  'application/x-sh': 'application_xp_terminal.png',
  'application/x-font-ttf': 'font.png',
  'application/x-msaccess': 'page_white_database.png',
  'application/x-shockwave-flash': 'page_white_flash.png',
  'application/x-sql': 'page_white_database.png',
  'application/x-tar': 'box.png',
  'application/x-xz': 'box.png',
  'application/xml': 'page_white_code.png',
  'application/zip': 'box.png',
  'image/svg+xml': 'page_white_vector.png',
  'text/css': 'page_white_code.png',
  'text/html': 'page_white_code.png',
  'text/less': 'page_white_code.png',

  // other, extension-specific icons
  '.accdb': 'page_white_database.png',
  '.apk': 'box.png',
  '.app': 'application_xp.png',
  '.as': 'page_white_actionscript.png',
  '.asp': 'page_white_code.png',
  '.aspx': 'page_white_code.png',
  '.bat': 'application_xp_terminal.png',
  '.bz2': 'box.png',
  '.c': 'page_white_c.png',
  '.cab': 'box.png',
  '.cfm': 'page_white_coldfusion.png',
  '.clj': 'page_white_code.png',
  '.cc': 'page_white_cplusplus.png',
  '.cgi': 'application_xp_terminal.png',
  '.cpp': 'page_white_cplusplus.png',
  '.cs': 'page_white_csharp.png',
  '.db': 'page_white_database.png',
  '.dbf': 'page_white_database.png',
  '.deb': 'box.png',
  '.dll': 'page_white_gear.png',
  '.dmg': 'drive.png',
  '.docx': 'page_white_word.png',
  '.erb': 'page_white_ruby.png',
  '.exe': 'application_xp.png',
  '.fnt': 'font.png',
  '.gam': 'controller.png',
  '.gz': 'box.png',
  '.h': 'page_white_h.png',
  '.ini': 'page_white_gear.png',
  '.iso': 'cd.png',
  '.jar': 'box.png',
  '.java': 'page_white_cup.png',
  '.jsp': 'page_white_cup.png',
  '.lua': 'page_white_code.png',
  '.lz': 'box.png',
  '.lzma': 'box.png',
  '.m': 'page_white_code.png',
  '.map': 'map.png',
  '.msi': 'box.png',
  '.mv4': 'film.png',
  '.otf': 'font.png',
  '.pdb': 'page_white_database.png',
  '.php': 'page_white_php.png',
  '.pl': 'page_white_code.png',
  '.pkg': 'box.png',
  '.pptx': 'page_white_powerpoint.png',
  '.psd': 'page_white_picture.png',
  '.py': 'page_white_code.png',
  '.rar': 'box.png',
  '.rb': 'page_white_ruby.png',
  '.rm': 'film.png',
  '.rom': 'controller.png',
  '.rpm': 'box.png',
  '.sass': 'page_white_code.png',
  '.sav': 'controller.png',
  '.scss': 'page_white_code.png',
  '.srt': 'page_white_text.png',
  '.tbz2': 'box.png',
  '.tgz': 'box.png',
  '.tlz': 'box.png',
  '.vb': 'page_white_code.png',
  '.vbs': 'page_white_code.png',
  '.xcf': 'page_white_picture.png',
  '.xlsx': 'page_white_excel.png',
  '.yaws': 'page_white_code.png'
};


text:
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
from microsofttranslator import Translator
import re
import time
import json
import codecs
import csv
import sys
from pymongo import MongoClient, Connection
from datetime import datetime
import gensim as gs
import numpy as np
from sklearn.naive_bayes import GaussianNB
from sklearn.externals import joblib
from nltk.corpus import stopwords
from setproctitle import *

setproctitle('Stream_Mod')

###################################################################################
####################Variables that contain the user credentials for the Twitter API
access_token = "ACCESS_TOKEN"
access_token_secret = "ACCESS_TOKEN_SECRET"
consumer_key = "CONSUMER_KEY"
consumer_secret = "CONSUMER_SECRET"
####################################################################################

####################################################################################
###############Variables that contain the user credentials for the Azure Translator
client_ID = "CLIENT_ID"
client_secret="CLIENT_SECRET"
####################################################################################

#RE's for stripping unicode emoji and multiple letter instances.
emoji = re.compile(u'[^\x00-\x7F\x80-\xFF\u0100-\u017F\u0180-\u024F\u1E00-\u1EFF]',re.UNICODE)
multiple = re.compile(r"(.)\1{1,}", re.DOTALL)

#Microsoft Translator Instance

translator = Translator(client_ID, client_secret )

####################################################################################
############################### Database Setup #####################################
####################################################################################

client = Connection()

db = client.streamer
if 'tweets' in db.collection_names():
    print "Collection 'tweets' already exists"
    coll = db.tweets
else:
    print "Creating Collection: 'tweets' ... "
    db.create_collection('tweets',capped=True, size=200000, max= 3000 )
    coll = db.tweets

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

#Takes three arguments
#INPUT: (phrase=string-to-vectorize, stop=set-of-stopwords, model=loaded-word2vec-model)
#OUTPUT: Average of word vectors in string.
def phrase2vec(phrase,stop, model):
    phrase = phrase.lower().split()
    phrase_fil = [w for w in phrase if not w in stop]
    size = 0
    vec = np.zeros(300)
    for word in phrase_fil:
        try:
            vec= np.add(vec,model[word])
            size+=1
        except:
            pass
    if size==0:
        size=1
    return np.divide(vec,size)

#Takes 4 arguments
#INPUT: (text=String to sentimentize, stop= stopword set, model= w2v-model, trained_classifier = sklearn classifier model)
def get_sentiment(text, stop , model, trained_classifier):
    cl = trained_classifier
    vec = phrase2vec(text,stop,model)
    pred = cl.predict_proba(vec)[0][1]
    return pred

#Twitter API Listener Class, inherits from tweepy.streaming.StreamListener
class Listener(StreamListener):

    def __init__(self, classifier, stops, model):
        self.cl = classifier
        self.stop = stops
        self.model = model

    def on_data(self, data):
        #parse json from data event
        elem = json.loads(data)

        #### If geotagged filter text ####
        if 'coordinates' in elem:
            if elem['coordinates']!=None:
                #filter off emoji, urls, @Names, & (etc.), symbols, "RT", and '#'
                stripped = emoji.sub('',elem['text'])
                stripped = re.sub(r'http[s]?[^\s]+','', stripped)
                stripped = re.sub(r'(@[A-Za-z0-9\_]+)' , "" ,stripped)
                stripped = re.sub(r'[\&].*;','',stripped)
                stripped = re.sub(r'[#|\!|\-|\+|:|//]', " ", stripped)
                stripped = re.sub( 'RT.','', stripped)
                stripped = re.sub('[\s]+' ,' ', stripped).strip()

                #print stripped
                #### Translate in not in English ####
                if elem['lang'] !=  'en' and elem['lang'] !=  'en-gb':
                    try:

                        translated_text = translator.translate(stripped , 'en', elem['lang'])
                    except:
                        translated_text = ""
                else:
                    translated_text = stripped

                #Tweet must be longer than 2 words after filtering.
                if len(translated_text.split()) > 2:

                    sentiment = get_sentiment(translated_text,self.stop ,self.model, self.cl)
                    #after translation filter down multiple letters to 2, no non-latin alphanumric characters
                    output = multiple.sub(r"\1\1", translated_text)
                    output = re.sub('[^a-zA-Z0-9|\']', " ", output).strip()

                    lat = elem['coordinates']['coordinates'][1]
                    lon = elem['coordinates']['coordinates'][0]
                    text = elem['text'].strip()
                    trans = output

                    #setup message containing cooordinates, unfiltered text, translated and filtered text,
                    #time, and sentiment value (0-1).
                    message = {'lon': lon, 'lat': lat , 'text': text, 'trans': trans ,\
                    'time':datetime.utcnow(), 'sent': sentiment }

                    #add message to mongo collection.
                    coll.insert(message)

        return True

    def on_error(self, status):
        print status

if __name__ == '__main__':

    print "Loading Classifier...\n\n"
    #load trained sklearn classifier
    cl=joblib.load('./static/Data/PKL/RFC/random_forest_avg.pkl')

    print "Classifier Loaded...loading model...\n\n"
    #load w2v vectors from GoogleNews training set.
    model= gs.models.Word2Vec.load_word2vec_format('./static/Data/GoogleNews-vectors-negative300.bin', binary=True)

    print "Model Loaded...\n\n"
    #load set of stop words
    stop_set = set(stopwords.words("english"))

    l = Listener(cl,stop_set,model)

    #Oauth Handling
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    stream = Stream(auth, l)
    print "Listening..."
    stream.sample()


text:
'use strict';

describe('Directive: ngEnter', function () {

  // load the directive's module
  beforeEach(module('explorerWebApp'));

  var element,
    scope;

  beforeEach(inject(function ($rootScope) {
    scope = $rootScope.$new();
  }));

  it('should make hidden element visible', inject(function ($compile) {
  //  element = angular.element('<ng-enter></ng-enter>');
  //  element = $compile(element)(scope);
  //  expect(element.text()).toBe('this is the ngEnter directive');
  }));
});


text:
1. [What it does](#what-it-does)
2. [How it works](#how-it-works)
2. [Installing](#installation)
2. [The stash](#the-stash)
3. [Writing a Source Module](#writing-a-source-module)
4. [Running your source](#running-your-source)
4. [Limitations](#limitations)
5. [APPENDIX - The Stash API](#the-stash-api)

## Why?

Many IoT things are hidden behind APIs.  These APIs need access credentials, understanding by developers and then
their data needs interpretation. This often leads to linear, one-time use of the APIs.  Not very Iotic.

The Ioticiser for Bulk Data is the tool for the one-off integration of an external API and then pushing the data
 from that API into Iotic Space where it can be understood and reused by anybody.

## What?

### What it does

The Ioticiser is a tool that allows a developer to import an API on the "left" and then, in a module you write,
model the contents of the API as Iotic things in the "middle" and then push the data into Iotic space on the "right"

```
----------------       ---------------
|              |       |             |
| External API | ----> | Your Module | ----> IOTIC SPACE
|              |       |             |
----------------       ---------------
```

It's designed for APIs that contain lots of virtual things and their data, but can also be used for simulations,
monitoring hardware over radio links - anything, really, as long as it can be modelled as
above as a pull from the left and a push to the right.

## How?

### How it works
You write a module and ask the Ioticiser to run it for you using a configuration file such as
(cfg_examples_random.ini)[cfg/cfg_examples_random.ini]
The Ioticiser then imports your module and runs it in its own thread.

The Ioticiser will provide you with a "stash" api in which to store things while your module is working its way
through the API on the "left".  Once you're happy with your stash of stuff, the Ioticiser will use its
workers to update Iotic Space for you and let you get on with doing more of the API, sleeping until the next
 time or just finishing and waiting to be scheduled again.

### Installation

Download or clone the code from the repo.

#### Dependencies

To run the Ioticiser you'll need the py-IoticAgent

    1. [IoticAgent](https://pypi.python.org/pypi/py-IoticAgent/)

It's up to you how you install these and set your PYTHONPATH to access them.  I did from the root of this repo by
using the requirements.txt file to install the dependencies in the 3rd directory...
```bash
pip3 install -t 3rd -r requirements.txt
```
You can see how to [run your code](#running-your-source) later.

#### The Stash
The stash has two parts:

1. [The thing stash](#the-thing-stash)
2. [The key-value stash](#the-key-value-stash)

It's available to your module via the `self._stash` object

##### The thing stash
This is where you can create things, feeds and values and share data.  It works very similarly to the py-IoticAgent IOT
API but the Ioticiser's worker(s) don't action what you've done until you release each individual thing.

```
----------------       ---------------       --------------
|              |       |             |       |             |
| Your Module  | ----> |   Stash     | ----> |  Worker(s)  | ----> IOTIC SPACE
|              |       |             |       |             |
----------------       --------------        ---------------
```

##### The key-value Stash
This allows you to store things in your stash using the simple, key-value pair model.  It's useful for storing
 variables for the next time you're scheduled.  For example storing the last time your
 API was updated so you don't bother re-processing old data.
`Note` that all values in the stash are treated as strings, so remember to stringify and un-stringify them

More details on the stash API are in the [appendix](#the-stash-api)

### Writing a Source Module
A "Source" is the collective noun for all the things from an individual API.
We've written three examples for you as guidelines - Each has a different style

##### Our Worked Examples

`Note` - These are examples to show you how to run the the Ioticiser.  We already run them, so please don't run
them yourself.

1. [Random](examples/Random) - this is the simplest. It creates one thing and various feeds on it for random numbers,
 letters of the alphabet etc.  There's no "API" on the left - it's just simulated data
2. [SF Schools](examples/SFSchools) - this reads an API of school information for schools around the Bay Area,
San Francisco

#### Write a config file for your source
The config file contains parameters and file locations, etc. in the the well-known `ini` format.

##### config `[main]`
The `[main]` section is for the Ioticiser, where you specify where you want it to persist your stash
data (`datapath`) and the name of the sources you want to run (`sources`).

##### config `[<source>]`
The `[<source>]` section is for your module.  In here you can specify any key/value pairs you want.
It is _your responsibility_ to validate anything you put in here.  T
he only thing the Ioticiser needs to know is the number of `workers`  you want to action your activities.

##### example
```ini
[main]
datapath = ../data
; Names of config sections must be separated with \n\t
sources =
    SFopendata_schools

[SFopendata_schools]
; Required config options
import = SFSchools.SchoolsPublisher
agent = ../cfg/sfopendata_schools.ini
; Optional config passed to Source

; Set app key to get unlimited request
;app_key=my_app_key

; Time to update the values
refresh_time = 3600

; total Workers, default = 1
workers = 4
```

#### Create a directory in [examples](examples) (or anywhere else you like) for your module
put an `__init__.py` in it to make it a module

#### Write your module object
##### Inheritance and instantiation
Your object has to inherit from SourceBase and call `super()` at the beginning of `__init__()`
```python
class Random(SourceBase):
    def __init__(self, stash, config, stop):
        super(Random, self).__init__(stash, config, stop)
```

##### Thread `run()` method
This is the main entry point to your thread.  You can choose to run in either

1. `Continuous mode` - where you wait for the `stop` event to be set
2. `Single-shot mode` - where you ignore `stop` and just run.

###### Continuous mode:
Example from [Schools.py](examples/SFSchools/Schools.py)
```python
    def run(self):
        lasttime = 0
        while not self._stop.is_set():
            nowtime = monotonic()
            if nowtime - lasttime > self.__refresh_time:
                lasttime = nowtime
                self.get_schools_from_API()
            self._stop.wait(timeout=5)
```
This code compares the time now with the last time it ran and only runs `get()` if they differ
by the specified interval.  It then waits for a 5 second pause and does it all again.

###### Single shot mode
Example (fabricated)
```python
    def run(self):
        if self.__get_some_data():
            self.__publish_some_stuff()
        else:
            logger.info("Nothing to do - new data not available")

        logger.info("Finished")
```
In this fabricated example:  `__get_some_data()` returns true when the data is newer than the last time it ran.
This could be in a year's time.  We'd expect this kind of source to be scheduled using Cron rather than using python
timing as in the previous example

### Running your source
There's a [run script](src/run.sh) to run the Ioticiser Module.
Change the line to make sure PYTHONPATH includes all your dependencies and point the Ioticiser at your `.ini` file
```bash
#!/bin/bash
PYTHONPATH=../3rd:../examples/SFSchools/3rd:../examples python3 -m Ioticiser ../cfg/cfg_examples_schools.ini
```

### Limitations
1. The Ioticiser does not detect if things you created last time you ran your module have been deleted,
so it won't delete them for you.

### APPENDIX 1
#### The Stash API

The stash API is a lighter mimic of the IOT api in the Iotic Agent. [Documentation](https://iotic-labs.github.io/py-IoticAgent/)

The reason it exists is that you can create things and feeds /in the stash/ and when you release your stash thing,
the Ioticiser will go away and make your changes real in Iotic Space, allowing you to continue processing the API.

#### Key differences between Stash API and Agent API

##### Implicit vs Explicit Point.share()

The Stash API adds kwarg data to Point.create_value.  These are stashed and finally shared as a dictionary.  To add a *specific* time to the values the share function can be called with time only.
Calling the share function is optional when create_value(data=) is used *and* you're happy to share with datetime.utcnow().

```python
    feed.create_value("value", vtype=Datatypes.INTEGER, description="random number",
                      data=random.randint(0, 10))
    feed.share(time=reading['time'])
```

```python
    feed.create_value("value", vtype=Datatypes.INTEGER, description="random number")
    feed.share(data={"value": random.randint(0, 10)}))
```

more details on create value and share are [here](#create-values-on-a-feed-and-share-data)

##### No Follow/Attach

Feed Follow and Control Attach are not currently supported by the Stash API.

##### Create a `Thing`

###### Parameters
```python
   create_thing(lid):
```
|parameter|type|optional|comment|
|---|---|---|---|
|`lid`|string|no|Local Id of your thing|

###### Returns
a `Stash.Thing` instance

###### Example
Using code from [Schools.py](examples/SFSchools/Schools.py#L216) as an example (annotated)

```python
    with self._stash.create_thing(thing_name) as thing:  # Create a stash thing
        self._set_thing_attributes(school, thing)        # Set its attributes
        self._set_thing_description(school, thing)       # Description, etc.
        self._set_thing_points(school, thing)            # Add the feeds
```
Using the python `with` syntax allows you to build up everthing you want about your thing.  When you exit the `with`,
 the workers you've allocated to Ioticiser will go away and perform your updates for you.

##### Create a `feed` (or `control`)

###### Parameters
```python
    create_feed(pid)
    create_control(pid)
```
|parameter|type|optional|comment|
|---|---|---|---|
|`pid`|string|no|Local Point Id of your feed or control.  Note `Feed`s and `Control`s are sub-classes of `Point`, hence point_id|

###### Returns
a `Stash.Point` instance

###### Example
```python
self.__feed = self.__thing.create_feed("my_point")
```

##### Set the metadata for a `thing`, `feed` or `control`
These functions allow easy setting of metadata for the things you create.  `set_location()` only applies to `Thing`s
###### Parameters
```python
    set_label(label, lang=None)
    set_description(description, lang=None)
    create_tag(taglist)
    # Note Thing only
    set_location(lat, long)
```
|parameter|type|optional|comment|
|---|---|---|---|
|`label`|string|no|Short description for your thing, feed, etc - max 64 chars|
|`description`|string|no|Long description for your thing, feed, etc - max 256 chars|
|`taglist`|list of strings|no|List of tags for your thing, feed, etc. Each tag has min 3, max 16 chars no embedded spaces|
|`lat`|float|no|Latitude of your thing in WGS84 coordinates|
|`long`|float|no|Longitude of your thing in WGS84 coordinates|
|`lang`|string|yes|2-char language code, e.g. "de".  If `lang=None` then use the container default language (recommended)|

###### Returns
None of these functions return anything

###### Examples
```python
    thing.set_label(label, lang=LANG)
    thing.set_description(THING_DESCRIPTION, lang=LANG)
    thing.set_location(lat, lon)
    thing.create_tag(['School', 'SanFrancisco', 'OpenData'])
```

##### Create Values on a `feed` and share data
These functions allow you to set metadata for individual data points in a feed. Once these Value functions have
been called, you can call share, but it's not necessary if you've passed data to the `create_value()` function and
are happy to share with the current time
###### create_value() Parameters
```python
    create_value(label,
                 vtype=TYPE,
                 lang=LANG,
                 description=DESC,
                 unit=UNIT,
                 data=DATA)
```
|parameter|type|optional|comment|
|---|---|---|---|
|`label`|string|no|Name of the value (used as the json key)|
|`vtype`|string|no|value type from Datatypes.py, e.g. Datatypes.DECIMAL|
|`lang`|string|yes|2-char language code, e.g. "de".  If `lang=None` then use the container default language (recommended)|
|`description`|string|no|Text description of the value e.g. "External temperature"|
|`unit`|url|no|unit of the value from Units.py e.g. Units.CELSIUS - or (advanced) the correct URI from a units ontology e.g. "http://purl.obolibrary.org/obo/UO_0000301" is micrograms per liter|
|`data`|n/a|no|the data to share for this value (or use share(data=xxx))|

###### share() Parameters

It's only necessary to call `share()` if
- you want a different timestamp from the current time - for example if your data has a reading time which is different from now.
- you want to share some data, but you didn't use the `data=` keyword argument in the `create_value()` call

In cases such as the example below, the data for the `power` value is assigned in the call, and you're happy to share
with time of datetime.utcnow() (the default), then there's no need to call share at all, it'll be done for you.

`note` If you call share with no aguments, it will raise a ValueError

```python
    share(time=TIME
          data=DATA)
```
|parameter|type|optional|comment|
|---|---|---|---|
|`time`|timestamp|yes|Name of the value (used as the json key)|
|`data`|n/a|yes|the data to share for this *value*|

###### Examples
Implicit share

```python
    feed.create_value('power',
                      vtype=Datatypes.INT,
                      description='Power consumption in Watts',
                      unit=Units.WATT,
                      data=reading['power'])
```

Explicit share
```python
    feed.create_value('power',
                      vtype=Datatypes.INT,
                      description='Power consumption in Watts',
                      unit=Units.WATT)
    feed.share(data={'power': reading['power']})
```

###### Returns
Neither of these functions return anything

##### Store a key-value pair
These 2 functions allow you to store a key-value pair in your stash persistently - i.e. they will be available in
the stash the next time your code runs.

`Note`:  When you're testing, you're likely to be running with limit_things set to a smallish number and to
to be deleting your things before your next test.  In this case, remember to delete your stash `json` files
or you might get unpredicable results.
The files are in the `data/` directory and are called `<your_module>*.json`

###### Parameters
```python
    get_property(key):
    set_property(key, value=None):
```
|parameter|type|optional|comment|
|---|---|---|---|
|`key`|string|no|The key-name of the thing you want to save|
|`value`|`string` or `int`|no|the value you want to save|

###### Returns
1. `get_property` returns the value you saved or `None` if the key doesn't exist
1. `set_property` returns the nothing, but raises `ValueError` if your value is not a `string` or `int`

###### Example

```python
#save
self._stash.set_property("Last-Modified", str(self.__last_mod_time))
#retrieve
last_mod_str = self._stash.get_property("Last-Modified")
```


text:
'''
best_hit_congruency.py
=======================

:Author: Nick Ilott
:Release: $Id$
:Date: |today|
:Tags: Python

Purpose
-------

.. Overall purpose and function of the script>

Take a file of reads and test for congruency of hits in terms
of COG annotations.

Usage
-----

.. Example use case

Example::

   python best_hit_congruency.py

Type::

   python best_hit_congruency.py --help

for command line help.

Command line options
--------------------

'''

import sys
import CGAT.Experiment as E
import random
import CGAT.Diamond as Diamond
import CGAT.IOTools as IOTools

def main(argv=None):
    """script main.
    parses command line options in sys.argv, unless *argv* is given.
    """

    if argv is None:
        argv = sys.argv

    # setup command line parser
    parser = E.OptionParser(version="%prog version: $Id$",
                            usage=globals()["__doc__"])

    parser.add_option("-r", "--reads", dest="reads", type="string",
                      help="supply list of reads")

    parser.add_option("-m", "--map", dest="map", type="string",
                      help="gene2cog mapping file")

    parser.add_option("-a", "--alignment-file", dest="alignment_file", type="string",
                      help="alignment file")

    # add common options (-h/--help, ...) and parse command line
    (options, args) = E.Start(parser, argv=argv)

    E.info("reading mapping file %s" % options.map)
    gene2cog={}
    for line in IOTools.openFile(options.map):
        gene, cog = line[:-1].split("\t")
        gene2cog[gene] = cog
    E.info("loaded mapping file")

    E.info("loading reads")
    reads = set([x[:-1] for x in IOTools.openFile(options.reads).readlines()])

    E.info("loaded reads")

    E.info("iterating over reads and testing congruency")
    options.stdout.write("read\tnhits\tncongruent\tpcongruent\n")
    for alignments in Diamond.query_iterator( \
        Diamond.alignment_iterator( \
            IOTools.openFile(options.alignment_file))):

        # skip those not in reads list
        if alignments[0].qid not in reads: continue

        # total number of hits
        n_hits = float(len(alignments))
        if n_hits == 1.0:
            continue

        # get the best alignment
        scores = []
        for alignment in alignments:
            scores.append(alignment.score)
        best = max(scores)
        best_alignments = [x for x in alignments if x.score == best]

        # if there are more than one best hit
        if len(best_alignments) > 1:
            best_alignments = random.sample(best_alignments, 1)
        best_alignment = best_alignments[0]

        # get the COG associated with the alignment
        best_ref = best_alignment.ref
        best_cog = gene2cog[best_alignment.ref]
        n_congruent = float(len([x.ref for x in alignments if gene2cog[x.ref] == best_cog and x.ref != best_ref]))
        p_congruent = (n_congruent/(n_hits-1))*100

        options.stdout.write("%s\t%i\t%i\t%f\n" % (alignments[0].qid, n_hits, n_congruent, p_congruent))

    # write footer and output benchmark information.
    E.Stop()

if __name__ == "__main__":
    sys.exit(main(sys.argv))


text:
@class IDENavigableItem;

@protocol IDEStructureEditingTarget <NSObject>
- (id <IDEStructureEditingRemoveSubitemsTarget>)structureEditingRemoveSubitemsTargetForParentNavigableItem:(IDENavigableItem *)arg1;
- (id <IDEStructureEditingGroupingTarget>)structureEditingGroupingTargetForProposedNavigableItem:(IDENavigableItem *)arg1 proposedChildIndex:(long long)arg2;
- (id <IDEStructureEditingDropTarget>)structureEditingTargetForProposedNavigableItem:(IDENavigableItem *)arg1 proposedChildIndex:(long long)arg2;
- (id <IDEStructureEditingDraggingSource>)structureEditingDraggingSource;
@end


text:
(function () {
  'use strict';

  angular.module('reviews').factory('dataService', ['Guid', 'localStorageService', function(Guid, localStorageService) {
    return {
      get: localStorageService.get,
      save: function(r) {
        var review = { id: Guid.newGuid(), detail: { date:  Date.now(), text: r } };
        localStorageService.save(review);
      }
    };
  }]);
})(); // We're not concatenating all of our source files into a single file


text:
import scala.quoted._

import scala.tasty.Reflection

object Macros {

  def impl(reflect: Reflection): Unit = {
    import reflect.{_, given _}

    def foo(tree: Tree, term: Term, typeTree: TypeTree, parent: Tree) = {

      tree match {
        case tree: Tree =>
      }

      term match {
        case term: Term =>
      }

      typeTree match {
        case typeTree: TypeTree =>
      }

      parent match {
        case typeTree: Term =>
        case typeTree: TypeTree =>
      }

    }
  }

}


text:
require 'spec_helper'

describe "Pages" do
  describe "Home page" do
    it "should have some content" do
      visit '/'
      page.should have_content "Learnstream"
    end
  end

  describe "Tools page" do

    let(:user) { FactoryGirl.create :user }

    it "should be accessible and have stuff" do
      sign_in user
      visit '/'
      click_link 'Tools'
      page.should have_content 'Bookmarklet'
    end
  end
end


text:
D3 is often used to create SVG elements that display data visualizations. The [D3.js homepage](https://d3js.org/) has lots of example visualizations built with D3:

![d3 for data vis](./images/d3-for-data-vis.png)

Let's continue practicing data bindings by putting together some sample SVG charts. To do so, let's restore the HTML to a blank canvas:

```html
<!DOCTYPE html>
<html>
  <head>
    <meta charset='UTF-8'>
    <title>Hello There!</title>
    <link href='style.css' rel='stylesheet'>
  </head>
  <body>
    <div id='content'></div>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/d3/4.11.0/d3.min.js'></script>
    <script src='script.js'></script>
  </body>
</html>
```

#### Creating the SVG Tag

Next let's use D3 to add an `SVG` element to the page with a particular height and width:

```
var height = 500;
var width = 500;

var svg = d3.select('#content').append('svg')
    .attr('width', width)
    .attr('height', height)
```

If you run those lines then examine the resulting HTML page, you'll see it contains an `SVG` element with a height attribute set to 500 and a width attribute set to 500:

![svg attributes](./images/svg-attributes.png)

#### Generating Sample Data

For the present, let's suppose we want to make a scatterplot on the `SVG`. To do so, let's add to `data` 10 [`Objects`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects) with `x` and `y` attributes set to random numbers:

```javascript
var data = [];
for (var i=0; i<10; i++) {
  data.push({
    x: Math.random() * 500,
    y: Math.random() * 500
  })
}
```

If you run that code then type `data` in your developer tools and hit enter, you'll be able to investigate the `data` object:

![sample data structure](./images/sample-data-structure.png)

#### Basic Shapes in SVG

Great! Now we can use the data to add some shapes to the SVG. Here are some **[basic shapes in SVG](https://developer.mozilla.org/en-US/docs/Web/SVG/Element)** and their required attributes:

| Element Tag | Required Attributes |
| --- | --- |
| `<circle>` | **`cx`** x-position, **`cy`** y-position, **`r`** radius |
| `<line>` | **`x1`** x-start, **`x2`** x-end, **`y1`** y-start, **`y2`** y-end |
| `<rect>` | **`x`** x-position, **`y`** y-position, **`width`** width, **`height`** height |

Let's use the **data binding** techniques we covered above to add one circle to the SVG for each item in `data`:

```javascript
var selection = d3.select('svg').selectAll('circle').data(data);

selection.enter()
  .append('circle')
    .attr('cx', function(d) { return d.x; })
    .attr('cy', function(d) { return d.y; })
    .attr('r', 4)
```

If you reload the page, you should see the start of your scatter plot!

## Responding to User Actions

Awesome! Now let's add a button users can click to add a point to the chart:

```
d3.select('body').append('button')
  .text('Add Point')
```

To make the page look a little nicer, let's add a few lines of CSS to the `style.css` file:

```css
svg {
  display: block;
  margin: 0 auto;
}

button {
  padding: 10px;
  background: red;
  color: #fff;
  font-size: 14px;
  display: block;
  margin: 0 auto;
  cursor: pointer;
}
```

Great, now we can add some interactivity to the page. To do so, let's create a function that adds the `circle` elements to the SVG:

```javascript
function render(data) {
  // Create a data binding
  var selection = d3.select('svg').selectAll('circle').data(data);

  // Enter block
  selection.enter()
    .append('circle')
      .attr('cx', function(d) { return d.x; })
      .attr('cy', function(d) { return d.y; })
      .attr('r', 4)
}
```

Then we'll bind an event listener to the button we add to the page. When that button is clicked, we'll add an additional Object with random `x` and `y` attributes to `data`, then we'll call the `render()` function we just defined:

```javascript
// Add a button that lets users add points to `data`
d3.select('body').append('button')
  .text('Add Point')
  .on('click', function() {
    data.push({
      x: Math.random() * 500,
      y: Math.random() * 500
    })
    render(data)
  })
```

Your `script.js` file should now look like this:

```javascript
// Generate 10 observations with random x,y attributes
var data = [];
for (var i=0; i<10; i++) {
  data.push({
    x: Math.random() * 500,
    y: Math.random() * 500
  })
}

// Add a button that lets users add points to `data`
d3.select('body').append('button')
  .text('Add Point')
  .on('click', function() {
    data.push({
      x: Math.random() * 500,
      y: Math.random() * 500
    })
    render(data)
  })

// Specify the Chart Attributes
var height = 500;
var width = 500;

// Create the SVG
var svg = d3.select('#content').append('svg')
  .attr('width', width)
  .attr('height', height)

// Create data binding and run updates
function render(data) {
  var selection = d3.select('svg').selectAll('circle').data(data);

  // Enter block
  selection.enter()
    .append('circle')
      .attr('cx', function(d) { return d.x; })
      .attr('cy', function(d) { return d.y; })
      .attr('r', 4)
}

render(data)
```

If you refresh the page and click the button a few times, you should see some new points appear!

![adding points](./images/adding-points.gif)

## Animating Transitions

One of the most impressive features of D3 are the animation features. To get a taste of these animation features, let's add the `.transition()` and `.exit()` blocks to the `render()` function:

```javascript
function render(data) {
  var selection = d3.select('svg').selectAll('circle').data(data);

  // Enter block
  selection.enter()
    .append('circle')
      .attr('cx', function(d) { return d.x; })
      .attr('cy', function(d) { return d.y; })
      .attr('r', 4)

  // Transition block
  selection.transition()
    .duration(1000)
    .attr('cx', function(d) { return d.x; })
    .attr('cy', function(d) { return d.y; })

  // Exit block
  selection.exit()
    .remove()
}
```

Next, let's update the block that adds the button to the page. Previously when users clicked the button, we used the `.push()` method to add a new Object to the end of `data`. Let's instead use `.unshift()` to add a new Object to the start of `data`:

```
// Add a button that lets users add points to `data`
d3.select('body').append('button')
  .text('Add Point')
  .on('click', function() {
    data.unshift({
      x: Math.random() * 500,
      y: Math.random() * 500
    })
    render(data)
  })
```

Your full `script.js` code should look like the following:

```javascript
// Generate 10 observations with random x,y attributes
var data = [];
for (var i=0; i<10; i++) {
  data.push({
    x: Math.random() * 500,
    y: Math.random() * 500
  })
}

// Add a button that lets users add points to `data`
d3.select('body').append('button')
  .text('Add Point')
  .on('click', function() {
    data.unshift({
      x: Math.random() * 500,
      y: Math.random() * 500
    })
    render(data)
  })

// Specify the Chart Attributes
var height = 500;
var width = 500;

// Create the SVG
var svg = d3.select('#content').append('svg')
  .attr('width', width)
  .attr('height', height)

// Create data binding and run updates
function render(data) {
  var selection = d3.select('svg').selectAll('circle').data(data);

  // Enter block
  selection.enter()
    .append('circle')
      .attr('cx', function(d) { return d.x; })
      .attr('cy', function(d) { return d.y; })
      .attr('r', 4)

  // Transition block
  selection.transition()
    .duration(1000)
    .attr('cx', function(d) { return d.x; })
    .attr('cy', function(d) { return d.y; })

  // Exit block
  selection.exit()
    .remove()
}

render(data)
```

If you refresh the page and click the button a few times, you'll see your points transitioning! As you can see, by simply implementing a data binding, changing the data, and using the `.enter()`, `.transition()`, and `.exit()` blocks, we get smooth transitions between the data states!

![transitions](./images/transitions.gif)

# Next Steps

Great work! Next [let's build a proper chart with D3](https://github.com/YaleDHLab/lab-workshops/blob/master/intro-to-d3/lets-make-a-chart.md).


text:
module Seek
  module Scalable
    def self.included(mod)
      mod.extend(ClassMethods)
    end

    module ClassMethods

      def acts_as_scalable
        acts_as_annotatable :name_field=>:title
        include Seek::Scalable::InstanceMethods
        include Seek::Scalable::WithParamsInstanceMethods
      end
    end

    module InstanceMethods

      def scales= scales, source=User.current_user
        scales = resolve_types(scales)

        remove = self.scales - scales
        add = scales - self.scales
        add.each do |scale|
          annotation = Annotation.new(
              :source => source,
              :annotatable => self,
              :attribute_name => "scale",
              :value => scale
          )
          annotation.save
        end
        remove.each do |scale|
          annotation = Annotation.for_annotatable(self.class.name,self.id).with_attribute_name("scale").select{|an| an.value == scale}.first
          annotation.destroy unless annotation.nil?
          remove_additional_scale_info(scale.id)
        end
      end

      def scales
        self.annotations_with_attribute("scale",true).collect{|an| an.value}.sort_by(&:pos)
      end

      private

      #handles scales passed as Id's, invalid or blank ids, or a single item
      def resolve_types scales
        scales = Array(scales).collect do |scale|
          if scale.is_a?(Numeric) || scale.is_a?(String)
            scale=Scale.find_by_id(scale)
          end
          scale
        end.compact
      end
    end

    module WithParamsInstanceMethods
      def attach_additional_scale_info scale_id, other_info={},source=User.current_user
        other_info[:scale_id]=scale_id.to_s
        value = TextValue.new
        value.text=other_info.to_json
        annotation = Annotation.new(
            :source => source,
            :annotatable => self,
            :attribute_name => "additional_scale_info",
            :value => value
        )
        annotation.save
      end

      def fetch_additional_scale_info scale_id
        self.annotations_with_attribute("additional_scale_info",true).select do |an|
          json = JSON.parse(an.value.text)
          json["scale_id"]==scale_id.to_s
        end.collect do |an|
          json = JSON.parse(an.value.text)
          json["param"] = h(json["param"])
          json["unit"] = h(json["unit"])
          json
        end
      end

      def remove_additional_scale_info scale_id
        self.annotations_with_attribute("additional_scale_info",true).select do |an|
          json = JSON.parse(an.value.text)
          json["scale_id"]==scale_id.to_s
        end.each do |an|
          an.destroy
        end
      end
    end

  end
end

ActiveRecord::Base.class_eval do
  include Seek::Scalable
end