text:
package com.catcoders.pulsafe.model.entity;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by tonimc on 17/4/15.
 */
public class Log {

    private String dateTime;
    private String typeLog;
    private int id;
    private String value;
    private String user;
    private String location;

    public Log(String dateTime, String typeLog, int id, String value, String user, String location) {
        this.dateTime = dateTime;
        this.typeLog = typeLog;
        this.id = id;
        this.value = value;
        this.user = user;
        this.location = location;
    }

    protected Log() {

    }

    public String getDateTime() {
        return dateTime;
    }

    public void setDateTime(String dateTime) {
        this.dateTime = dateTime;
    }

    public String getTypeLog() {
        return typeLog;
    }

    public void setTypeLog(String typeLog) {
        this.typeLog = typeLog;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public static Log jsonDeserialized(String json) {
        Log log = new Log();
        try {
            JSONObject jsonObject = new JSONObject(json);

            JSONObject value = jsonObject.getJSONObject("value");
            log.setId(jsonObject.getInt("id"));
            log.setUser(jsonObject.getString("name"));
            log.setTypeLog(jsonObject.getString("type_log"));
            log.setDateTime(jsonObject.getString("datatime"));
            log.setValue(jsonObject.getString("BPM"));
            log.setLocation(jsonObject.getString("location"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return log;
    }

    public static String jsonSerialized(Log log) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("id", log.getId());
            jsonObject.put("name", log.getUser());
            jsonObject.put("datatime", log.getDateTime());
            jsonObject.put("type_log", log.getTypeLog());
            JSONObject valueObject = new JSONObject();
            valueObject.put("location", log.getLocation());
            valueObject.put("BPM", log.getValue());
            jsonObject.put("value", valueObject);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject.toString();
    }
}


text:
package org.alltiny.math.vector;

import java.util.Arrays;

/**
 * This vector class represents vectors of any dimension.
 * It provides common vector operations.
 */
public class Vector {

    private final double[] values;

    public Vector(double... values) {
        this.values = values;
    }

    /** Copy-Constructor */
    public Vector(Vector vector) {
        this.values = Arrays.copyOf(vector.values, vector.values.length);
    }

    /** Creates a 0-vector with the given dimension. */
    public Vector(final int dimension) {
        values = new double[dimension];
    }

    public double get(int index) {
        return values[index];
    }

    /**
     * This method modifies the value of the given index.
     */
    public Vector set(int index, double value) {
        values[index] = value;
        return this;
    }

    /**
     * @return the dimension of this vector.
     */
    public int getDimension() {
        return values.length;
    }

    /**
     * This method calculates the square of the length of this vector.
     * Hint: This method is a bit faster then {@link #getLength()}.
     * @return the square of the length of this vector.
     */
    public double getLengthSquare() {
        double result = 0;
        for (double element : values) {
            result += element * element;
        }
        return result;
    }

    /**
     * This method calculates the length of this vector.
     * @return length of this vector.
     */
    public double getLength() {
        return Math.sqrt(getLengthSquare());
    }

    /**
     * @return a vector pointing into the same direction like this vector but with length of 1 (called normalized vector)
     * @since 1.0
     */
    public Vector normalize() {
        final double length = getLength();
        Vector normalized = new Vector(getDimension());
        for (int i = 0; i < getDimension(); i++) {
            normalized.set(i, values[i] / length);
        }
        return normalized;
    }

    /**
     * This method adds the given vector to this vector and returns the resulting vector.
     * This method does not change this vector. Both vectors must have the same dimensions.
     * @param other to add
     * @return added vector of this vector and the given vector
     * @throws IllegalDimensionException if this and the given vector have unequal dimensions.
     * @since 1.0
     */
    public Vector add(Vector other) {
        if (getDimension() != other.getDimension()) {
            throw new IllegalDimensionException("both vectors must have the same dimension");
        }
        Vector added = new Vector(getDimension());
        for (int i = 0; i < getDimension(); i++) {
            added.set(i, values[i] + other.get(i));
        }
        return added;
    }

    /**
     * This method subtracts the given vector from this vector and returns the resulting vector.
     * This method does not change this vector. Both vectors must have the same dimensions.
     * @param other to sub from this one
     * @return subtracted vector
     * @throws IllegalDimensionException if this and the given vector have unequal dimensions.
     * @since 1.0
     */
    public Vector sub(Vector other) {
        if (getDimension() != other.getDimension()) {
            throw new IllegalDimensionException("both vectors must have the same dimension");
        }
        Vector sub = new Vector(getDimension());
        for (int i = 0; i < getDimension(); i++) {
            sub.set(i, values[i] - other.get(i));
        }
        return sub;
    }

    /**
     * Multiplies this vector with the given scalar.
     * @param scalar to multiply this vector with.
     * @return the scaled vector
     * @see #scale(double)
     * @since 1.0
     */
    public Vector mul(double scalar) {
        Vector vector = new Vector(getDimension());
        for (int i = 0; i < getDimension(); i++) {
            vector.set(i, values[i] * scalar);
        }
        return vector;
    }

    /**
     * Scales this vector with the given scalar.
     * @param scalar to multiply this vector with.
     * @return the scaled vector
     * @see #mul(double)
     * @since 1.1
     */
    public Vector scale(double scalar) {
        Vector vector = new Vector(getDimension());
        for (int i = 0; i < getDimension(); i++) {
            vector.set(i, values[i] * scalar);
        }
        return vector;
    }

    /**
     * Calculates the scalar product. Both vectors must have the same dimensions.
     * @param vector to create the scalar product with
     * @return scalar product of this vector and the given vector
     * @throws IllegalDimensionException if this and the given vector have unequal dimensions.
     * @since 1.0
     */
    public double scalar(Vector vector) {
        if (getDimension() != vector.getDimension()) {
            throw new IllegalDimensionException("both vectors must have the same dimension");
        }
        double scalar = 0;
        for (int i = 0; i < getDimension(); i++) {
            scalar += get(i) * vector.get(i);
        }
        return scalar;
    }

    /**
     * This method calculates the cross product between this vector and the
     * given vector and returns the resulting vector. This method will not
     * change this vector. Note that the cross product is only defined for
     * three dimensional vectors (resp. in R3).
     * @param vector to create the cross product with
     * @return scalar product of this vector and the given vector
     * @throws IllegalDimensionException if this or the given vector has another dimension than 3.
     * @since 1.0
     */
    public Vector cross(Vector vector) {
        if (getDimension() != 3 || vector.getDimension() != 3) {
            throw new IllegalDimensionException("both vectors must have 3 dimensions");
        }
        return new Vector(
            get(1) * vector.get(2) - get(2) * vector.get(1),
            get(2) * vector.get(0) - get(0) * vector.get(2),
            get(0) * vector.get(1) - get(1) * vector.get(0)
        );
    }

    /**
     * This method projects the other vector onto this vector.
     * @return projection of the other vector onto this vector.
     * @since 1.1
     */
    public Vector project(Vector other) {
        Vector normal = normalize();
        return normal.scale(normal.scalar(other));
    }

    /**
     * This method projects this vector onto the other.
     * @return projection of this vector onto the other vector.
     * @since 1.1
     */
    public Vector projectOn(Vector other) {
        Vector normal = other.normalize();
        return normal.scale(normal.scalar(this));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o instanceof Vector) {
            Vector v = (Vector)o;
            // compare the array of values; note that Arrays.equals can't do it, because it handles "-0" versus "0" wrong.
            if (values.length == v.values.length) {
                for (int i = 0; i < values.length; i++) {
                    if (values[i] != v.values[i]) {
                        return false;
                    }
                }
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        for (double value : values) {
            hash = 31 * hash + (int)Double.doubleToLongBits(value == 0.0 ? 0 : value); // treat -0.0 and 0.0 as 0
        }
        return hash;
    }

    @Override
    public String toString() {
        return "Vector" + Arrays.toString(values);
    }
}

redpajama_set_name: RedPajamaGithub


text:
package com.navercorp.pinpoint.profiler.monitor.metric.activethread;

import com.navercorp.pinpoint.thrift.dto.TActiveTraceHistogram;

/**
 * @author HyunGil Jeong
 */
public interface ActiveTraceMetric {

    ActiveTraceMetric
            UNSUPPORTED_ACTIVE_TRACE_METRIC = new ActiveTraceMetric() {
        @Override
        public TActiveTraceHistogram activeTraceHistogram() {
            return null;
        }

        @Override
        public String toString() {
            return "Unsupported ActiveTraceMetric";
        }
    };

    TActiveTraceHistogram activeTraceHistogram();
}


text:
<resources>
    <string name="app_name">ListViewRefreshDemo</string>
</resources>


text:
This sample demonstrates how to add authentication to a Cordova application using Auth0's Lock widget from the hosted login page.

This repo is supported and maintained by Community Developers, not Auth0. For more information about different support levels check https://auth0.com/docs/support/matrix .

## Getting started

If you haven't already done so, [sign up](https://auth0.com/signup) for your free Auth0 account.

## Auth0 API Setup

**1.** Create a **New Application** in the [dashboard](https://manage.auth0.com).

**2.** Find the **Domain** and **client ID** from the settings area.

**3.** Set the **Application Type** to native.

**4.** Set **Allowed Callback URLs**

## Callback URL

A Callback URL is a location in your app that users will be redirected to once authentication is complete. For Cordova applications, the format of the **Callback URL** is as such:

```bash
YOUR_PACKAGE_ID://YOUR_AUTH0_DOMAIN/cordova/YOUR_PACKAGE_ID/callback
```
* `YOUR_PACKAGE_ID` is the app identifier found in `config.xml`. Ex: `com.auth0.cordova.example`.
* `YOUR_AUTH0_DOMAIN` is your Auth0 tenant domain found in your client settings. Ex: `<tenant>.auth0.com`.

Be sure to add the appropriate **Callback URL** to the **Allowed Callback URLs** box in the client settings for your client in the Auth0 dashboard.

## CORS

**5.** Set up **Allowed Origins (CORS)**

## Set Environment Variables

```bash
file://*
```

## Installation

* **6.Install Cordova Plugins**

## Set Environment Variables

Rename the `env.js.example` file to `env.js` and provide the keys from above.

**env.js**
```bash
module.exports = {
  AUTH0_DOMAIN: '{DOMAIN}',
  AUTH0_CLIENT_ID: '{CLIENT_ID}',
  AUTH0_AUDIENCE: 'https://{DOMAIN}/userinfo',
  PACKAGE_ID: 'com.auth0.cordova.example'
};
```

> **Note:** If you have downloaded this sample from Auth0's Cordova tutorial, a file called `env.js` will come pre-populated with the **Client ID** and **Domain** for your client, as well as a default **Audience**.

## Set AndroidLaunchMode

In your `config.xml` file, add this preference:
```
<preference name="AndroidLaunchMode" value="singleTask" />
```

## Install the Dependencies and Run the App

This sample relies on several packages, including **auth0.js** and **auth0-cordova**. Install the dependencies with npm or yarn.

```bash
# installation with npm
npm install

# installation with yarn
yarn
```

The sample uses webpack. Run a command to instruct webpack to build the application bundle.

```bash
npm run build
```

Prepare Cordova for iOS and Android.

```bash
npm run prepare
```

Finally, emulate or run the application.

```bash
# emulate the app
cordova emulate ios

# run the app on a device
cordova run ios
```

> **Note:** The **auth0-cordova** package will only work when the app is being run in an emulator or on a real device. Errors will be encountered if trying to log in when testing in the browser.

## Contribute

Feel like contributing to this repo? We're glad to hear that! Before you start contributing please visit our [Contributing Guideline](https://github.com/auth0-community/getting-started/blob/master/CONTRIBUTION.md).

Here you can also find the [PR template](https://github.com/auth0-community/auth0-cordova-samples/blob/master/PULL_REQUEST_TEMPLATE.md) to fill once creating a PR. It will automatically appear once you open a pull request.

#### Development

Run the watcher to constantly build the application and pipe it to `/www` folder.

```bash
npm run watch
```

The JavaScript project is built from `src/index.js` to `/www/index.js`.

#### Before Shipping to Production

The Content Security Policy in the sample is configured using wildcards for ease of use. For example, the value for `connect-src` is `https://*.auth0.com`. This is fine for development and testing, but be sure to change this to be your Auth0 tenant domain before putting the application into production.

## Issues Reporting

Spotted a bug or any other kind of issue? We're just humans and we're always waiting for constructive feedback! Check our section on how to [report issues](https://github.com/auth0-community/getting-started/blob/master/CONTRIBUTION.md#issues)!

Here you can also find the [Issue template](https://github.com/auth0-community/auth0-cordova-samples/blob/master/ISSUE_TEMPLATE.md) to fill once opening a new issue. It will automatically appear once you create an issue.

## Repo Community

Feel like PRs and issues are not enough? Want to dive into further discussion about the tool? We created topics for each Auth0 Community repo so that you can join discussion on stack available on our repos. Here it is for this one: [auth0-cordova-samples](https://community.auth0.com/t/auth0-community-oss-auth0-cordova-samples/15989)

## License

This project is licensed under the MIT license. See the [LICENSE](https://github.com/auth0-community/auth0-cordova-samples/blob/master/LICENSE) file for more info.

## What is Auth0?

Auth0 helps you to:

* Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like
* Google
* Facebook
* Microsoft
* Linkedin
* GitHub
* Twitter
* Box
* Salesforce
* etc.

**or** enterprise identity systems like:
* Windows Azure AD
* Google Apps
* Active Directory
* ADFS
* Any SAML Identity Provider

* Add authentication through more traditional [username/password databases](https://docs.auth0.com/mysql-connection-tutorial)
* Add support for [linking different user accounts](https://docs.auth0.com/link-accounts) with the same user
* Support for generating signed [JSON Web Tokens](https://docs.auth0.com/jwt) to call your APIs and create user identity flow securely
* Analytics of how, when and where users are logging in
* Pull data from other sources and add it to user profile, through [JavaScript rules](https://docs.auth0.com/rules)

## Create a free Auth0 account

* Go to [Auth0 website](https://auth0.com/signup)
* Hit the **SIGN UP** button in the upper-right corner


text:
Videre Acceptable Use Policy

			We're proud of the trust you place in us by using Videre. In exchange, we trust you to use our services responsibly.

			You agree not to misuse the Videre services ("Services") or help anyone else to do so. For example, you must not even try to do any of the following in connection with the Services:

probe, scan, or test the vulnerability of any system or network;

breach or otherwise circumvent any security or authentication measures;

access, tamper with, or use non-public areas or parts of the Services, or shared areas of the Services you haven't been invited to;

interfere with or disrupt any user, host, or network, for example by sending a virus, overloading, flooding, spamming, or mail-bombing any part of the Services;

access, search, or create accounts for the Services by any means other than our publicly supported interfaces (for example, creating accounts in bulk);

send unsolicited communications, promotions or advertisements, or spam;

send altered, deceptive or false source-identifying information, including "spoofing" or "phishing";

promote or advertise products or services other than your own without appropriate authorization;

circumvent storage space limits;

sell the Services unless specifically authorized to do so;

publish or share materials that are unlawfully pornographic or indecent, or that contain extreme acts of violence;

advocate bigotry or hatred against any person or group of people based on their race, religion, ethnicity, sex, gender identity, sexual preference, disability, or impairment;

violate the law in any way, including storing, publishing or sharing material that's fraudulent, defamatory, or misleading; or

violate the privacy or infringe the rights of others.


text:
<!DOCTYPE html>

  <link href="https://gmpg.org/xfn/11" rel="profile">
  <meta http-equiv="content-type" content="text/html; charset=utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">

  <title> Bye-Bye 2012, Welcome 2013  · rushiagr </title>

  <link rel="stylesheet" href="http://www.rushiagr.com/css/poole.css">
  <link rel="stylesheet" href="http://www.rushiagr.com/css/syntax.css">
  <link rel="stylesheet" href="http://www.rushiagr.com/css/hyde.css">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">

  <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144-precomposed.png">
  <link rel="shortcut icon" href="/favicon.ico">

  <link href="" rel="alternate" type="application/rss+xml" title="rushiagr" />

  <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">

  <link href='https://fonts.googleapis.com/css?family=Raleway:400,300' rel='stylesheet' type='text/css'>

rushiagr

       not your average coder

Posts

About

Code

Personal Blog

powered by Hugo

    © 2016 Rushi Agrawal. Theme by npf. All rights reserved.

Bye-Bye 2012, Welcome 2013

    Jan 2, 2013

Listing down the things which went well for me in 2012, and which didn’t, and the plans for upcoming year 2013. Beware: More technical stuff than emotional.

Things which went well in 2012

Python

Started learning Python at the start of year 2012, early January, and this same language landed me in the job which I absolutely love: working in one of the biggest ‘OpenSource’ project in the world, written in Python! Getting paid for working on an opensource project is as awesome as it can become for me.

The hunger to become different from the rest

Gathered a lot of info on how things work in computer industry. Kept myself in contact with various hot topics, opensource projects.

The job

Not faring too well on this front - the full time job. But still, I would consider I did good enough with regards to the work assigned to me. I, after six months into the job, still goes to office every morning with a thirst to make a difference.

Cleanliness

Scored much better in the second half. Spent dedicated amount of time each week to keep my room and flat clean and in order.

Maintaining a TODO list

Started late in the year, but seems a good progress on that front.

Things which didn’t go that well in 2012

Concentration

Still not able to concentrate on one thing for long. Get distracted too easily. Only rarely I sat at one place, focussed on one thing, for more than 50 minutes. Also, the last year’s resolution of opening FaceBook only once a day was put in trashcan on in the very first week of January!

Not focussed enough on the future direction

Poor goal setting. Peeked into a lot of opensource projects, dedicated proper time into none. Opensourced my projects too, but did not work on it much either. Made myself a perfect example of ‘naam bade aur darshan chhote’ (appearing like an eminent personality, acting like a jerk).

Programming contest

Only kept in touch. Not solved much problems. This year, need to focus a lot on this front.

Time management

Never was able to manage time. Was not working on the same thing for even a week. Somewhere in the middle of working on a project, I find out ‘hey, this looks cool! Time to try hands on it!’. What about the thingy you were currently working on? Into the TODO list! Such an idiot.

Work life balance

Went for a toss. Not able to regularise job timings. Started and stopped gym. Started and stopped working on many projects. Completed none. Wasted a heck of a lot of time.

Plans for upcoming year

Better planning

I need to plan things before acting on it. I would take everything into consideration before jumping into hacking something, and then set a deadline for it. And till that deadline, I would promise I would not digress getting enticed by something which makes my mouth watery.

Don’t just outright neglect daytime job

I agree my daytime job is awesome. But I end up considering the work I do at office as secondary. Need to value it much higher. I concentrate on other projects and aim to complete and polish them. What I did not thought was the work I am doing in my job itself is a project! If I am not faring well in the project on which I work 8 hours a day, how can I expect myself to do good in something I am spending only a fraction of time I spend on the daytime project! And expectedly, none of my projects are in good enough shape to talk about it confidently in public. I need to value OpenStack more. Really.

START coding for programming contests

Enough of promises, enough of ‘From next month I’m gonna do it’. I SHOULD spend a specific time every week for coding for programming contests. Looks like I need to start with solving old problems from CodeChef.com alongwith the editorials provided with them.

Facebook once in a day

Period.

Need to plan breaks too

Realised only the last month that opening facebook, checking out news, and reading articles on Hacker News does not count in a break. A break is not in front of a computer screen. A break is something which gives your strained eyes a rest, especially when you end up spending half of your year staring at a computer screen!

PS. The article is for the writer himself. It is okay if you are finding it a bad piece of English text.

Please enable JavaScript to view the comments powered by Disqus.

w


text:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/semphr.h>

#include <unity.h>
#include <esp_spi_flash.h>
#include <esp_attr.h>
#include <esp_flash_encrypt.h>

#include "test_config.h"

static uint32_t buffer[1024];

/* read-only region used for mmap tests */
static const uint32_t start = 0x100000;
static const uint32_t end = 0x200000;

TEST_CASE("Prepare data for mmap tests", "[mmap]")
{
    srand(0);
    for (int block = start / 0x10000; block < end / 0x10000; ++block) {
        printf("Writing block %d\n", block);
        for (int sector = 0; sector < 16; ++sector) {
            for (uint32_t word = 0; word < 1024; ++word) {
                uint32_t val = rand();
                if (block == start / 0x10000 && sector == 0 && word == 0) {
                    printf("first word: %08x\n", val);
                }
                buffer[word] = val;
            }
            uint32_t abs_sector = (block) * 16 + sector;
            printf("Writing sector %d\n", abs_sector);
            ESP_ERROR_CHECK( spi_flash_erase_sector((uint16_t) abs_sector) );
            ESP_ERROR_CHECK( spi_flash_write(abs_sector * SPI_FLASH_SEC_SIZE, (const uint8_t *) buffer, sizeof(buffer)) );
        }
    }
}

TEST_CASE("Can mmap into data address space", "[mmap]")
{

    printf("Mapping %x (+%x)\n", start, end - start);
    spi_flash_mmap_handle_t handle1;
    const void *ptr1;
    ESP_ERROR_CHECK( spi_flash_mmap(start, end - start, SPI_FLASH_MMAP_DATA, &ptr1, &handle1) );
    printf("mmap_res: handle=%d ptr=%p\n", handle1, ptr1);

    spi_flash_mmap_dump();

    srand(0);
    const uint32_t *data = (const uint32_t *) ptr1;
    for (int block = 0; block < (end - start) / 0x10000; ++block) {
        for (int sector = 0; sector < 16; ++sector) {
            for (uint32_t word = 0; word < 1024; ++word) {
                TEST_ASSERT_EQUAL_UINT32(rand(), data[(block * 16 + sector) * 1024 + word]);
            }
        }
    }
    printf("Mapping %x (+%x)\n", start - 0x10000, 0x20000);
    spi_flash_mmap_handle_t handle2;
    const void *ptr2;
    ESP_ERROR_CHECK( spi_flash_mmap(start - 0x10000, 0x20000, SPI_FLASH_MMAP_DATA, &ptr2, &handle2) );
    printf("mmap_res: handle=%d ptr=%p\n", handle2, ptr2);
    spi_flash_mmap_dump();

    printf("Mapping %x (+%x)\n", start, 0x10000);
    spi_flash_mmap_handle_t handle3;
    const void *ptr3;
    ESP_ERROR_CHECK( spi_flash_mmap(start, 0x10000, SPI_FLASH_MMAP_DATA, &ptr3, &handle3) );
    printf("mmap_res: handle=%d ptr=%p\n", handle3, ptr3);
    spi_flash_mmap_dump();

    printf("Unmapping handle1\n");
    spi_flash_munmap(handle1);
    spi_flash_mmap_dump();

    printf("Unmapping handle2\n");
    spi_flash_munmap(handle2);
    spi_flash_mmap_dump();

    printf("Unmapping handle3\n");
    spi_flash_munmap(handle3);
}

TEST_CASE("flash_mmap invalidates just-written data", "[spi_flash]")
{
    spi_flash_mmap_handle_t handle1;
    const void *ptr1;

    const size_t test_size = 128;

    if (esp_flash_encryption_enabled()) {
        TEST_IGNORE_MESSAGE("flash encryption enabled, spi_flash_write_encrypted() test won't pass as-is");
    }

    ESP_ERROR_CHECK( spi_flash_erase_sector(TEST_REGION_START / SPI_FLASH_SEC_SIZE) );

    /* map erased test region to ptr1 */
    ESP_ERROR_CHECK( spi_flash_mmap(TEST_REGION_START, test_size, SPI_FLASH_MMAP_DATA, &ptr1, &handle1) );
    printf("mmap_res ptr1: handle=%d ptr=%p\n", handle1, ptr1);

    /* verify it's all 0xFF */
    for (int i = 0; i < test_size; i++) {
        TEST_ASSERT_EQUAL_HEX(0xFF, ((uint8_t *)ptr1)[i]);
    }

    /* unmap the erased region */
    spi_flash_munmap(handle1);

    /* write flash region to 0xEE */
    uint8_t buf[test_size];
    memset(buf, 0xEE, test_size);
    ESP_ERROR_CHECK( spi_flash_write(TEST_REGION_START, buf, test_size) );

    /* re-map the test region at ptr1.

       this is a fresh mmap call so should trigger a cache flush,
       ensuring we see the updated flash.
    */
    ESP_ERROR_CHECK( spi_flash_mmap(TEST_REGION_START, test_size, SPI_FLASH_MMAP_DATA, &ptr1, &handle1) );
    printf("mmap_res ptr1 #2: handle=%d ptr=%p\n", handle1, ptr1);

    /* assert that ptr1 now maps to the new values on flash,
       ie contents of buf array.
    */
    TEST_ASSERT_EQUAL_HEX8_ARRAY(buf, ptr1, test_size);

    spi_flash_munmap(handle1);
}


text:
package org.utplsql.api.db;

import oracle.jdbc.OracleConnection;

import java.sql.CallableStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.LinkedHashMap;
import java.util.stream.Collectors;

/** Lets you build a list of parameters for a CallableStatement
 *

 * Create it with the Builder (DynamicParameterList.builder())
 *
 * @author pesse
 */
public class DynamicParameterList {

    private LinkedHashMap<String, DynamicParameter> params;

    interface DynamicParameter {
        void setParam( CallableStatement statement, int index ) throws SQLException;

        default String getSql( String key ) {
            return key + " => ?";
        }
    }

    private DynamicParameterList(LinkedHashMap<String, DynamicParameter> params) {
        this.params = params;
    }

    /** Returns the SQL of this ParameterList as comma-separated list of the parameter identifiers:

     *
     * e.g. "a_parameter1 => ?, a_parameter2 => ?"
     *
     * @return comma-separated list of parameter identifiers
     */
    public String getSql() {
        return params.entrySet().stream()
                .map(e ->  e.getValue().getSql(e.getKey()))
                .collect(Collectors.joining(", "));
    }

    /** Sets the contained parameters in the order they were added to the given statement by index, starting with the given one
     *
     * @param statement The statement to set the parameters to
     * @param startIndex The index to start with
     * @throws SQLException SQLException of the underlying statement.setX methods
     */
    public void setParamsStartWithIndex(CallableStatement statement, int startIndex ) throws SQLException {
        int index = startIndex;
        for ( DynamicParameter param : params.values() ) {
            param.setParam(statement, index++);
        }
    }

    /** Returns a builder to create a DynamicParameterList
     *
     * @return Builder
     */
    public static DynamicParameterListBuilder builder() {
        return new DynamicParameterListBuilder();
    }

    /** Builder-class for DynamicParameterList
     *

     * Usage:
     *

     *  DynamicParameterList.builder()
     *      .add("parameter1", "StringParameter")
     *      .addIfNotEmpty("parameter2", 123)
     *      .build();
     *

     *
     * @author pesse
     */
    public static class DynamicParameterListBuilder {

        private LinkedHashMap<String, DynamicParameterList.DynamicParameter> params = new LinkedHashMap<>();

        private DynamicParameterListBuilder() {

        }

        public DynamicParameterListBuilder add(String identifier, String value ) {
            params.put(identifier, new DynamicParameterList.DynamicStringParameter(value));
            return this;
        }

        public DynamicParameterListBuilder addIfNotEmpty(String identifier, String value ) {
            if ( value != null && !value.isEmpty() ) {
                add(identifier, value);
            }
            return this;
        }

        public DynamicParameterListBuilder add(String identifier, Integer value ) {
            params.put(identifier, new DynamicParameterList.DynamicIntegerParameter(value));
            return this;
        }

        public DynamicParameterListBuilder addIfNotEmpty(String identifier, Integer value ) {
            if ( value != null) {
                add(identifier, value);
            }
            return this;
        }

        public DynamicParameterListBuilder add(String identifier, Object[] value, String customTypeName, OracleConnection oraConnection ) {
            params.put(identifier, new DynamicParameterList.DynamicArrayParameter(value, customTypeName, oraConnection));
            return this;
        }

        public DynamicParameterListBuilder addIfNotEmpty(String identifier, Object[] value, String customTypeName, OracleConnection oraConnection ) {
            if ( value != null && value.length > 0 ) {
                add(identifier, value, customTypeName, oraConnection);
            }
            return this;
        }

        public DynamicParameterListBuilder add(String identifier, Boolean value) {
            params.put(identifier, new DynamicBoolParameter(value));
            return this;
        }

        public DynamicParameterListBuilder addIfNotEmpty(String identifier, Boolean value) {
            if ( value != null ) {
                add(identifier, value);
            }
            return this;
        }

        public DynamicParameterList build() {
            return new DynamicParameterList(params);
        }
    }

    /* Implementations of DynamicStringParameter */
    private static class DynamicStringParameter implements DynamicParameter {
        private final String value;

        DynamicStringParameter( String value ) {
            this.value = value;
        }

        @Override
        public void setParam(CallableStatement statement, int index) throws SQLException {
            if ( value == null ) {
                statement.setNull(index, Types.VARCHAR);
            } else {
                statement.setString(index, value);
            }
        }
    }

    private static class DynamicIntegerParameter implements DynamicParameter {
        private final Integer value;

        DynamicIntegerParameter( Integer value ) {
            this.value = value;
        }

        @Override
        public void setParam(CallableStatement statement, int index) throws SQLException {
            if ( value == null ) {
                statement.setNull(index, Types.INTEGER);
            } else {
                statement.setInt(index, value);
            }
        }
    }

    private static class DynamicBoolParameter implements DynamicParameter {
        private final Boolean value;

        DynamicBoolParameter( Boolean value ) {
            this.value = value;
        }

        @Override
        public void setParam(CallableStatement statement, int index) throws SQLException {
            if ( value == null ) {
                statement.setNull(index, Types.BOOLEAN);
            } else {
                statement.setInt(index, (value)?1:0);
            }
        }

        @Override
        public String getSql(String key) {
            return key + " => (case ? when 1 then true else false end)";
        }
    }

    private static class DynamicArrayParameter implements DynamicParameter {
        private final Object[] value;
        private final String customTypeName;
        private final OracleConnection oraConnection;

        DynamicArrayParameter( Object[] value, String customTypeName, OracleConnection oraConnection ) {
            this.value = value;
            this.customTypeName = customTypeName;
            this.oraConnection = oraConnection;
        }

        @Override
        public void setParam(CallableStatement statement, int index) throws SQLException {
            if ( value == null ) {
                statement.setNull(index, Types.ARRAY, customTypeName);
            } else {
                statement.setArray(
                        index,
                        oraConnection.createOracleArray(customTypeName, value)
                );
            }
        }
    }

}


text:
#include <linux/err.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/mtd/partitions.h>
#include <linux/mtd/cfi.h>
#include <linux/platform_device.h>
#include <linux/mtd/physmap.h>
#include <linux/of.h>

#include <lantiq_soc.h>

/*
 * The NOR flash is connected to the same external bus unit (EBU) as PCI.
 * To make PCI work we need to enable the endianness swapping for the address
 * written to the EBU. This endianness swapping works for PCI correctly but
 * fails for attached NOR devices. To workaround this we need to use a complex
 * map. The workaround involves swapping all addresses whilst probing the chip.
 * Once probing is complete we stop swapping the addresses but swizzle the
 * unlock addresses to ensure that access to the NOR device works correctly.
 */

enum {
	LTQ_NOR_PROBING,
	LTQ_NOR_NORMAL
};

struct ltq_mtd {
	struct resource *res;
	struct mtd_info *mtd;
	struct map_info *map;
};

static const char ltq_map_name[] = "ltq_nor";

static map_word
ltq_read16(struct map_info *map, unsigned long adr)
{
	unsigned long flags;
	map_word temp;

	if (map->map_priv_1 == LTQ_NOR_PROBING)
		adr ^= 2;
	spin_lock_irqsave(&ebu_lock, flags);
	temp.x[0] = *(u16 *)(map->virt + adr);
	spin_unlock_irqrestore(&ebu_lock, flags);
	return temp;
}

static void
ltq_write16(struct map_info *map, map_word d, unsigned long adr)
{
	unsigned long flags;

	if (map->map_priv_1 == LTQ_NOR_PROBING)
		adr ^= 2;
	spin_lock_irqsave(&ebu_lock, flags);
	*(u16 *)(map->virt + adr) = d.x[0];
	spin_unlock_irqrestore(&ebu_lock, flags);
}

/*
 * The following 2 functions copy data between iomem and a cached memory
 * section. As memcpy() makes use of pre-fetching we cannot use it here.
 * The normal alternative of using memcpy_{to,from}io also makes use of
 * memcpy() on MIPS so it is not applicable either. We are therefore stuck
 * with having to use our own loop.
 */
static void
ltq_copy_from(struct map_info *map, void *to,
	unsigned long from, ssize_t len)
{
	unsigned char *f = (unsigned char *)map->virt + from;
	unsigned char *t = (unsigned char *)to;
	unsigned long flags;

	spin_lock_irqsave(&ebu_lock, flags);
	while (len--)
		*t++ = *f++;
	spin_unlock_irqrestore(&ebu_lock, flags);
}

static void
ltq_copy_to(struct map_info *map, unsigned long to,
	const void *from, ssize_t len)
{
	unsigned char *f = (unsigned char *)from;
	unsigned char *t = (unsigned char *)map->virt + to;
	unsigned long flags;

	spin_lock_irqsave(&ebu_lock, flags);
	while (len--)
		*t++ = *f++;
	spin_unlock_irqrestore(&ebu_lock, flags);
}

static int
ltq_mtd_probe(struct platform_device *pdev)
{
	struct ltq_mtd *ltq_mtd;
	struct cfi_private *cfi;
	int err;

	if (of_machine_is_compatible("lantiq,falcon") &&
			(ltq_boot_select() != BS_FLASH)) {
		dev_err(&pdev->dev, "invalid bootstrap options\n");
		return -ENODEV;
	}

	ltq_mtd = devm_kzalloc(&pdev->dev, sizeof(struct ltq_mtd), GFP_KERNEL);
	if (!ltq_mtd)
		return -ENOMEM;

	platform_set_drvdata(pdev, ltq_mtd);

	ltq_mtd->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!ltq_mtd->res) {
		dev_err(&pdev->dev, "failed to get memory resource\n");
		return -ENOENT;
	}

	ltq_mtd->map = devm_kzalloc(&pdev->dev, sizeof(struct map_info),
				    GFP_KERNEL);
	if (!ltq_mtd->map)
		return -ENOMEM;

	ltq_mtd->map->phys = ltq_mtd->res->start;
	ltq_mtd->map->size = resource_size(ltq_mtd->res);
	ltq_mtd->map->virt = devm_ioremap_resource(&pdev->dev, ltq_mtd->res);
	if (IS_ERR(ltq_mtd->map->virt))
		return PTR_ERR(ltq_mtd->map->virt);

	ltq_mtd->map->name = ltq_map_name;
	ltq_mtd->map->bankwidth = 2;
	ltq_mtd->map->read = ltq_read16;
	ltq_mtd->map->write = ltq_write16;
	ltq_mtd->map->copy_from = ltq_copy_from;
	ltq_mtd->map->copy_to = ltq_copy_to;

	ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
	ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map);
	ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;

	if (!ltq_mtd->mtd) {
		dev_err(&pdev->dev, "probing failed\n");
		return -ENXIO;
	}

	ltq_mtd->mtd->dev.parent = &pdev->dev;
	mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node);

	cfi = ltq_mtd->map->fldrv_priv;
	cfi->addr_unlock1 ^= 1;
	cfi->addr_unlock2 ^= 1;

	err = mtd_device_register(ltq_mtd->mtd, NULL, 0);
	if (err) {
		dev_err(&pdev->dev, "failed to add partitions\n");
		goto err_destroy;
	}

	return 0;

err_destroy:
	map_destroy(ltq_mtd->mtd);
	return err;
}

static int
ltq_mtd_remove(struct platform_device *pdev)
{
	struct ltq_mtd *ltq_mtd = platform_get_drvdata(pdev);

	if (ltq_mtd && ltq_mtd->mtd) {
		mtd_device_unregister(ltq_mtd->mtd);
		map_destroy(ltq_mtd->mtd);
	}
	return 0;
}

static const struct of_device_id ltq_mtd_match[] = {
	{ .compatible = "lantiq,nor" },
	{},
};
MODULE_DEVICE_TABLE(of, ltq_mtd_match);

static struct platform_driver ltq_mtd_driver = {
	.probe = ltq_mtd_probe,
	.remove = ltq_mtd_remove,
	.driver = {
		.name = "ltq-nor",
		.of_match_table = ltq_mtd_match,
	},
};

module_platform_driver(ltq_mtd_driver);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
MODULE_DESCRIPTION("Lantiq SoC NOR");


text:
package com.elastisys.scale.cloudpool.openstack.requests;

import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;

import java.util.HashMap;
import java.util.Map;

import org.openstack4j.api.OSClient;
import org.openstack4j.api.compute.ServerService;
import org.openstack4j.api.exceptions.ResponseException;
import org.openstack4j.model.compute.Server;

import com.elastisys.scale.cloudpool.api.NotFoundException;
import com.elastisys.scale.commons.openstack.OSClientFactory;

/**
 * An request that, when executed, updates the metadata tags of a {@link Server}
 * instance.
 */
public class UpdateServerMetadataRequest extends AbstractOpenstackRequest<Void> {

    /** The id of the server whose metadata is to be updated. */
    private final String serverId;
    /**
     * Meta data tags to be copied to the server. Any meta data keys that
     * already exist on the node will be overwritten.
     */
    private final Map<String, String> metadata;

    /**
     * Constructs a {@link UpdateServerMetadataRequest}.
     *
     * @param clientFactory
     *            OpenStack API client factory.
     * @param serverId
     *            The server whose metadata is to be updated.
     * @param metadata
     *            Meta data tags to be copied to the server. Any meta data keys
     *            that already exist on the node will be overwritten.
     */
    public UpdateServerMetadataRequest(OSClientFactory clientFactory, String serverId, Map<String, String> metadata) {
        super(clientFactory);

        checkArgument(serverId != null, "server id cannot be null");
        checkArgument(metadata != null, "metadata map cannot be null");

        this.serverId = serverId;
        this.metadata = metadata;
    }

    @Override
    public Void doRequest(OSClient api) throws NotFoundException, ResponseException {
        ServerService serverApi = api.compute().servers();
        Server server = serverApi.get(this.serverId);
        if (server == null) {
            throw new NotFoundException(
                    format("failed to update meta data on server '%s': " + "server not found", this.serverId));
        }
        // set tags
        Map<String, String> tags = new HashMap<>(server.getMetadata());
        tags.putAll(this.metadata);
        serverApi.updateMetadata(this.serverId, tags);
        return null;
    }
}


text:
package de.holisticon.servlet4demo.serverjetty;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@SuppressWarnings("checkstyle:HideUtilityClassConstructor")
public class Application {

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

}


text:
package org.elasticsearch.rest.action.admin.indices.forcemerge;

import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestBuilderListener;

import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestStatus.OK;
import static org.elasticsearch.rest.action.support.RestActions.buildBroadcastShardsHeader;

/**
 *
 */
public class RestForceMergeAction extends BaseRestHandler {

    @Inject
    public RestForceMergeAction(Settings settings, RestController controller, Client client) {
        super(settings, controller, client);
        controller.registerHandler(POST, "/_forcemerge", this);
        controller.registerHandler(POST, "/{index}/_forcemerge", this);
    }

    @Override
    public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
        ForceMergeRequest mergeRequest = new ForceMergeRequest(Strings.splitStringByCommaToArray(request.param("index")));
        mergeRequest.indicesOptions(IndicesOptions.fromRequest(request, mergeRequest.indicesOptions()));
        mergeRequest.maxNumSegments(request.paramAsInt("max_num_segments", mergeRequest.maxNumSegments()));
        mergeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", mergeRequest.onlyExpungeDeletes()));
        mergeRequest.flush(request.paramAsBoolean("flush", mergeRequest.flush()));
        client.admin().indices().forceMerge(mergeRequest, new RestBuilderListener<ForceMergeResponse>(channel) {
            @Override
            public RestResponse buildResponse(ForceMergeResponse response, XContentBuilder builder) throws Exception {
                builder.startObject();
                buildBroadcastShardsHeader(builder, request, response);
                builder.endObject();
                return new BytesRestResponse(OK, builder);
            }
        });
    }
}