text:
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var DetailsView = (function() {
  'use strict';

  // We inherit from DivView.
  var superClass = DivView;

  /**
   * The DetailsView displays the "log" view. This class keeps track of the
   * selected SourceEntries, and repaints when they change.
   *
   * @constructor
   */
  function DetailsView(boxId) {
    superClass.call(this, boxId);
    this.sourceEntries_ = [];
    // Map of source IDs to their corresponding DIVs.
    this.sourceIdToDivMap_ = {};
    // True when there's an asychronous repaint outstanding.
    this.outstandingRepaint_ = false;
    // ID of source entry we should jump to after the oustanding repaint.
    // 0 if none, or there's no such repaint.
    this.outstandingScrollToId_ = 0;
  }

  // The delay between updates to repaint.
  var REPAINT_TIMEOUT_MS = 50;

  DetailsView.prototype = {
    // Inherit the superclass's methods.
    __proto__: superClass.prototype,

    setData: function(sourceEntries) {
      // Make a copy of the array (in case the caller mutates it), and sort it
      // by the source ID.
      this.sourceEntries_ = createSortedCopy_(sourceEntries);

      // Repaint the view.
      if (this.isVisible() && !this.outstandingRepaint_) {
        this.outstandingRepaint_ = true;
        window.setTimeout(this.repaint.bind(this),
                          REPAINT_TIMEOUT_MS);
      }
    },

    repaint: function() {
      this.outstandingRepaint_ = false;
      this.sourceIdToDivMap_ = {};
      this.getNode().innerHTML = '';

      var node = this.getNode();

      for (var i = 0; i < this.sourceEntries_.length; ++i) {
        if (i != 0)
          addNode(node, 'hr');

        var sourceEntry = this.sourceEntries_[i];
        var div = addNode(node, 'div');
        div.className = 'log-source-entry';

        var p = addNode(div, 'p');
        addNodeWithText(p, 'h4',
                        sourceEntry.getSourceId() + ': ' +
                            sourceEntry.getSourceTypeString());

        if (sourceEntry.getDescription())
          addNodeWithText(p, 'h4', sourceEntry.getDescription());

        var logEntries = sourceEntry.getLogEntries();
        var startDate = timeutil.convertTimeTicksToDate(logEntries[0].time);
        var startTimeDiv = addNodeWithText(p, 'div', 'Start Time: ');
        timeutil.addNodeWithDate(startTimeDiv, startDate);

        sourceEntry.printAsText(div);

        this.sourceIdToDivMap_[sourceEntry.getSourceId()] = div;
      }

      if (this.outstandingScrollToId_) {
        this.scrollToSourceId(this.outstandingScrollToId_);
        this.outstandingScrollToId_ = 0;
      }
    },

    show: function(isVisible) {
      superClass.prototype.show.call(this, isVisible);
      if (isVisible) {
        this.repaint();
      } else {
        this.getNode().innerHTML = '';
      }
    },

    /**
     * Scrolls to the source indicated by |sourceId|, if displayed.  If a
     * repaint is outstanding, waits for it to complete before scrolling.
     */
    scrollToSourceId: function(sourceId) {
      if (this.outstandingRepaint_) {
        this.outstandingScrollToId_ = sourceId;
        return;
      }
      var div = this.sourceIdToDivMap_[sourceId];
      if (div)
        div.scrollIntoView();
    }
  };

  function createSortedCopy_(origArray) {
    var sortedArray = origArray.slice(0);
    sortedArray.sort(function(a, b) {
      return a.getSourceId() - b.getSourceId();
    });
    return sortedArray;
  }

  return DetailsView;
})();


text:
package eskimo.invoker.executers;

import eskimo.invoker.entity.AbstractTestParams;
import eskimo.invoker.entity.ExecutionResult;
import eskimo.invoker.entity.TestData;
import eskimo.invoker.entity.TestResult;
import eskimo.invoker.enums.TestVerdict;
import eskimo.invoker.utils.InvokerUtils;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.List;

import static eskimo.invoker.executers.TesterWindows.DEFAULT_CHECK_COMMAND;

public class TesterMac implements Tester {

    private static final Logger logger = LoggerFactory.getLogger(TesterMac.class);

    private InvokerUtils invokerUtils;
    private AbstractTestParams testParams;
    private boolean stopOnFirstFail;
    private File executableFile;
    private File checkerFile;
    private File inputFile;
    private File answerFile;
    private File outputFile;
    private ExecutionResult solutionExecutionResult;
    private ExecutionResult checkerExecutionResult;

    public TesterMac(InvokerUtils invokerUtils, AbstractTestParams testParams) {
        this.invokerUtils = invokerUtils;
        this.testParams = testParams;
    }

    @Override
    public TestResult[] test() {
        TestResult[] testResults = new TestResult[testParams.getNumberTests()];
        for (int i = 0; i < testResults.length; ++i) {
            testResults[i] = new TestResult();
            testResults[i].setVerdict(TestVerdict.SKIPPED);
            testResults[i].setIndex(i + 1);
        }
        for (int i = 0; i < testParams.getNumberTests(); ++i) {
            File folder = null;
            try {
                TestData testData = testParams.getTestData(i, !testParams.isCheckerDisabled());
                folder = invokerUtils.createTempFolder();
                prepareFolder(testData, folder);
                runSolution();
                if (!testParams.isCheckerDisabled()) {
                    if (solutionExecutionResult.getExitCode() == 0 && !solutionExecutionResult.getTimeOutExceeded()) {
                        runChecker();
                    }
                }
                testResults[i] = getTestResult();
                testResults[i].setIndex(testData.getIndex());
                if (stopOnFirstFail && TestVerdict.ACCEPTED != testResults[i].getVerdict()) {
                    return testResults;
                }
            } catch (Throwable e) {
                testResults[i].setVerdict(TestVerdict.INTERNAL_INVOKER_ERROR);
                logger.error("Error during testing " + e.getMessage(), e);
                return testResults;
            }
        }
        return testResults;
    }

    private TestResult getTestResult() {
        TestResult testResult = new TestResult();
        testResult.setUsedTime(solutionExecutionResult.getTimeOutExceeded() ? testParams.getTimeLimit() : 0);
        testResult.setUsedMemory(0);
        testResult.setOutputData(solutionExecutionResult.getStdout());
        if (solutionExecutionResult.getExitCode() != 0) {
            testResult.setVerdict(TestVerdict.RUNTIME_ERROR);
        } else if (solutionExecutionResult.getTimeOutExceeded()) {
            testResult.setVerdict(TestVerdict.TIME_LIMIT_EXCEED);
        } else if (testParams.isCheckerDisabled()) {
            testResult.setVerdict(TestVerdict.CHECKER_DISABLED);
        } else if (checkerExecutionResult.getTimeOutExceeded()) {
            testResult.setVerdict(TestVerdict.CHECKER_ERROR);
        } else if (checkerExecutionResult.getStderr().startsWith("ok")) {
            testResult.setVerdict(TestVerdict.ACCEPTED);
        } else if (checkerExecutionResult.getStderr().startsWith("wrong answer") || checkerExecutionResult.getStderr().startsWith("FAIL")) {
            testResult.setVerdict(TestVerdict.WRONG_ANSWER);
        } else if (checkerExecutionResult.getStderr().startsWith("wrong output format")) {
            testResult.setVerdict(TestVerdict.PRESENTATION_ERROR);
        } else if (checkerExecutionResult.getStderr().startsWith("RUNTIME_ERROR")) {
            testResult.setVerdict(TestVerdict.RUNTIME_ERROR);
        } else {
            testResult.setVerdict(TestVerdict.CHECKER_ERROR);
        }
        return testResult;
    }

    private void runChecker() throws IOException, InterruptedException {
        testParams.setCheckCommand(DEFAULT_CHECK_COMMAND);
        List<String> command = testParams.prepareCheckCommand(checkerFile.getAbsolutePath(), inputFile.getAbsolutePath(), outputFile.getAbsolutePath(), answerFile.getAbsolutePath(), "");
        checkerExecutionResult = invokerUtils.executeCommand(command, 30000, null);
    }

    private void runSolution() throws IOException, InterruptedException {
        List<String> command = testParams.prepareRunCommand(executableFile.getAbsolutePath(), inputFile.getAbsolutePath(), outputFile.getAbsolutePath());
        solutionExecutionResult = invokerUtils.executeCommand(command, testParams.getTimeLimit(), inputFile, outputFile, null, null);
    }

    private void prepareFolder(TestData testData, File folder) throws IOException, InterruptedException {
        executableFile = new File(folder.getAbsolutePath() + File.separator + testParams.getExecutableName());
        checkerFile = new File(folder.getAbsolutePath() + File.separator + testParams.getCheckerName());
        inputFile = new File(folder.getAbsolutePath() + File.separator + testParams.getInputName());
        answerFile = new File(folder.getAbsolutePath() + File.separator + testParams.getAnswerName());
        outputFile = new File(folder.getAbsolutePath() + File.separator + testParams.getOutputName());
        FileUtils.writeByteArrayToFile(executableFile, testParams.getExecutable());
        if (!testParams.isCheckerDisabled()) {
            FileUtils.writeByteArrayToFile(checkerFile, testParams.getChecker());
            FileUtils.writeStringToFile(answerFile, testData.getAnswerData());
            invokerUtils.executeCommand(new String[]{"chmod", "+x", checkerFile.getAbsolutePath()}, 0, null, null, null, null);
        }
        FileUtils.writeStringToFile(inputFile, testData.getInputData());
        invokerUtils.executeCommand(new String[]{"chmod", "+x", executableFile.getAbsolutePath()}, 0, null, null, null, null);
    }
}

redpajama_set_name: RedPajamaGithub


text:
layout: page
title: Wallace Studios Executive Retreat
date: 2016-05-24
author: Maria Lyons
tags: weekly links, java
status: published
summary: Sed quis diam augue. Curabitur a malesuada quam, eget.
banner: images/banner/meeting-01.jpg
booking:
  startDate: 01/31/2016
  endDate: 02/03/2016
  ctyhocn: DALPLHX
  groupCode: WSER
published: true
---
Morbi in elit vel leo lobortis congue. Morbi eros tellus, rhoncus a nisl nec, congue vulputate elit. Integer volutpat tempor urna, id posuere enim ornare in. Mauris cursus egestas euismod. Mauris fermentum dui eget quam tincidunt, consequat finibus lacus efficitur. Mauris auctor ante ac blandit malesuada. Sed tincidunt justo ut massa lobortis, ut maximus libero commodo. Etiam placerat erat eu dolor consectetur venenatis.

* Proin convallis velit dignissim ipsum congue, a accumsan diam blandit
* Morbi et augue ultrices, lobortis orci id, bibendum libero.

Vivamus rhoncus erat libero, et pulvinar tortor hendrerit at. Morbi mattis pellentesque vulputate. Nunc sit amet neque vel nisl porttitor eleifend. Morbi sed semper arcu, eget facilisis tellus. Aenean eleifend sodales finibus. Aliquam nec aliquet ipsum, a pulvinar ante. Mauris sit amet massa tellus. Vivamus id urna finibus, lobortis lorem quis, faucibus sem. Fusce et cursus libero. Pellentesque vitae maximus est. Vestibulum hendrerit risus nec nisi condimentum maximus. Cras venenatis rutrum risus.


text:
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Sounds.Properties {

    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {

        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

        public static Settings Default {
            get {
                return defaultInstance;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("True")]
        public bool ShowStatusBar {
            get {
                return ((bool)(this["ShowStatusBar"]));
            }
            set {
                this["ShowStatusBar"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("True")]
        public bool ShowToolBar {
            get {
                return ((bool)(this["ShowToolBar"]));
            }
            set {
                this["ShowToolBar"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("True")]
        public bool ShowInfoPane {
            get {
                return ((bool)(this["ShowInfoPane"]));
            }
            set {
                this["ShowInfoPane"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("False")]
        public bool DeleteOnNext {
            get {
                return ((bool)(this["DeleteOnNext"]));
            }
            set {
                this["DeleteOnNext"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("False")]
        public bool Repeat {
            get {
                return ((bool)(this["Repeat"]));
            }
            set {
                this["Repeat"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("15")]
        public int TimeShortcutSeconds {
            get {
                return ((int)(this["TimeShortcutSeconds"]));
            }
            set {
                this["TimeShortcutSeconds"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("True")]
        public bool AddFolderRecursive {
            get {
                return ((bool)(this["AddFolderRecursive"]));
            }
            set {
                this["AddFolderRecursive"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("5")]
        public int VolumeShortcutIncrement {
            get {
                return ((int)(this["VolumeShortcutIncrement"]));
            }
            set {
                this["VolumeShortcutIncrement"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("True")]
        public bool NativeToolStripRendering {
            get {
                return ((bool)(this["NativeToolStripRendering"]));
            }
            set {
                this["NativeToolStripRendering"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("True")]
        public bool FileDragAppendPlaylist {
            get {
                return ((bool)(this["FileDragAppendPlaylist"]));
            }
            set {
                this["FileDragAppendPlaylist"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("True")]
        public bool ShowConfirmationDialogs {
            get {
                return ((bool)(this["ShowConfirmationDialogs"]));
            }
            set {
                this["ShowConfirmationDialogs"] = value;
            }
        }
    }
}


text:
<HTML>
<BODY>
<script type = "text/JavaScript">
var color = window.prompt("Foregroutn Color?");
document.fgColor = color;

var color = window.prompt("Background Color?");
document.bgColor = color;

var name = window.prompt("Name?");
document.write("Hello " + name);

</script>
</BODY>
</HTML>


text:
id: anti-patterns
title: Anti-patterns
---

This page will contain common promise anti-patterns that are exercised in the wild.

- [The explicit construction anti-pattern](#the-explicit-construction-anti-pattern)
- [The `.then(success, fail)` anti-pattern](#the-.then)

##The Explicit Construction Anti-Pattern

This is the most common anti-pattern. It is easy to fall into this when you don't really understand promises and think of them as glorified event emitters or callback utility. It's also sometimes called the promise constructor anti-pattern. Let's recap: promises are about making asynchronous code retain most of the lost properties of synchronous code such as flat indentation and one exception channel. This pattern is also called the deferred anti-pattern.

In the explicit construction anti-pattern, promise objects are created for no reason, complicating code.

First example is creating deferred object when you already have a promise or thenable:

```js
//Code copyright by Twisternha http://stackoverflow.com/a/19486699/995876 CC BY-SA 2.5
myApp.factory('Configurations', function (Restangular, MotorRestangular, $q) {
    var getConfigurations = function () {
        var deferred = $q.defer();

        MotorRestangular.all('Motors').getList().then(function (Motors) {
            //Group by Config
            var g = _.groupBy(Motors, 'configuration');
            //Map values
            var mapped = _.map(g, function (m) {
                return {
                    id: m[0].configuration,
                    configuration: m[0].configuration,
                    sizes: _.map(m, function (a) {
                        return a.sizeMm
                    })
                }
            });
            deferred.resolve(mapped);
        });
        return deferred.promise;
    };

    return {
        config: getConfigurations()
    }

});
```

This superfluous wrapping is also dangerous, any kind of errors and rejections are swallowed and not propagated to the caller of this function.

Instead of using the Deferred anti-pattern, the code should simply return the promise it already has and propagate values using `return`:

```js
myApp.factory('Configurations', function (Restangular, MotorRestangular, $q) {
    var getConfigurations = function () {
        //Just return the promise we already have!
        return MotorRestangular.all('Motors').getList().then(function (Motors) {
            //Group by Cofig
            var g = _.groupBy(Motors, 'configuration');
            //Return the mapped array as the value of this promise
            return _.map(g, function (m) {
                return {
                    id: m[0].configuration,
                    configuration: m[0].configuration,
                    sizes: _.map(m, function (a) {
                        return a.sizeMm
                    })
                }
            });
        });
    };

    return {
        config: getConfigurations()
    }

});
```

Not only is the code shorter but more importantly, if there is any error it will propagate properly to the final consumer.

Second example is creating a function that does nothing but manually wrap a callback API and doing a poor job at that:

```js
function applicationFunction(arg1) {
    return new Promise(function(resolve, reject){ //Or Q.defer() in Q
      libraryFunction(arg1, function (err, value) {
        if (err) {
          reject(err);
        } else {
          resolve(value);
        }
    });
}
```

This is reinventing the square wheel because any callback API wrapping can and should be done immediately using the promise library's promisification methods:

```js
var applicationFunction = Promise.promisify(libraryFunction);
```

The generic promisification is likely to be faster because it can use internals directly but also handles edge cases like `libraryFunction` throwing synchronously or using multiple success values.

**So when should deferred be used?**

Well simply, when you have to.

You might have to use a deferred object when wrapping a callback API that doesn't follow the standard convention. Like `setTimeout`:

```js
//setTimeout that returns a promise
function delay(ms) {
    var deferred = Promise.defer(); // warning, defer is deprecated, use the promise constructor
    setTimeout(function(){
        deferred.fulfill();
    }, ms);
    return deferred.promise;
}
```

Such wrappers should be rare, if they're common for the reason that the promise library cannot generically promisify them, you should file an issue.

If you cannot do static promisification (promisify and promisifyAll perform too slowly to use at runtime), you may use [Promise.fromCallback](.).

Also see [this StackOverflow question](http://stackoverflow.com/questions/23803743/what-is-the-deferred-antipattern-and-how-do-i-avoid-it) for more examples and a debate around it.

##The `.then(success, fail)` anti-pattern

*Almost* a sure sign of using promises as glorified callbacks. Instead of `doThat(function(err, success))` you do `doThat().then(success, err)` and rationalize to yourself that at least the code is "less coupled" or something.

The `.then` signature is mostly about interop, there is *almost* never a reason to use `.then(success, fail)` in application code. It is even awkward to express it in the sync parallel:

```js
var t0;
try {
    t0 = doThat();
}
catch(e) {

}
//deal with t0 here and waste the try-catch
var stuff = JSON.parse(t0);
```

It is more likely that you would write this instead in the sync world:

```js
try {
    var stuff = JSON.parse(doThat());
}
catch(e) {

}
```

So please write the same when using promises too:

```js
doThat()
.then(function(v) {
    return JSON.parse(v);
})
.catch(function(e) {

});
```

`.catch` is specified for built-in Javascript promises and is "sugar" for `.then(null, function(){})`. Since the way errors work in promises is almost the entire point (and the only thing jQuery never got right, even if it used `.pipe` as a `.then`), I really hope the implementation you are using provides this method for readability.


text:
// <copyright file="MetricsHostedMetricsJsonOutputFormatter.cs" company="App Metrics Contributors">
// Copyright (c) App Metrics Contributors. All rights reserved.
// </copyright>

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using App.Metrics.Serialization;
using App.Metrics.Internal;

namespace App.Metrics.Formatters.GrafanaCloudHostedMetrics
{
    public class MetricsHostedMetricsJsonOutputFormatter : IMetricsOutputFormatter
    {
        private readonly TimeSpan _flushInterval;
        private readonly MetricsHostedMetricsOptions _options;

        public MetricsHostedMetricsJsonOutputFormatter(TimeSpan flushInterval)
        {
            _flushInterval = flushInterval;
            _options = new MetricsHostedMetricsOptions();
        }

        public MetricsHostedMetricsJsonOutputFormatter(TimeSpan flushInterval, MetricFields metricFields)
        {
            _flushInterval = flushInterval;
            _options = new MetricsHostedMetricsOptions();
            MetricFields = metricFields;
        }

        public MetricsHostedMetricsJsonOutputFormatter(TimeSpan flushInterval, MetricsHostedMetricsOptions options)
        {
            _flushInterval = flushInterval;
            _options = options ?? throw new ArgumentNullException(nameof(options));
        }

        public MetricsHostedMetricsJsonOutputFormatter(
            TimeSpan flushInterval,
            MetricsHostedMetricsOptions options,
            MetricFields metricFields)
        {
            _flushInterval = flushInterval;
            _options = options ?? throw new ArgumentNullException(nameof(options));
            MetricFields = metricFields;
        }

        /// <inheritdoc />
        public MetricsMediaTypeValue MediaType => new MetricsMediaTypeValue("text", "vnd.appmetrics.metrics.hostedmetrics", "v1", "plain");

        /// <inheritdoc />
        public MetricFields MetricFields { get; set; } = new MetricFields();

        /// <inheritdoc />
        public async Task WriteAsync(
            Stream output,
            MetricsDataValueSource metricsData,
            CancellationToken cancellationToken = default)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var serializer = new MetricSnapshotSerializer();

            await using var jsonWriter = new MetricSnapshotHostedMetricsJsonWriter(
                output,
                _flushInterval,
                _options.MetricNameFormatter);

            serializer.Serialize(jsonWriter, metricsData, MetricFields);
        }
    }
}


text:
title: Jens Lindström
link: http://jenslindstrom.net/
---


text:
volunteers = 10
goal = 50

##if volunteers < goal:
##    print "More volunteers are needed."
##    print "{0} more volunteers are needed.".format(goal-volunteers)
##elif volunteers == goal:
##    print "We have enough volunteers."
##elif volunteers > goal:
##    print "We have a volunteer surplus."
##else:
##    print "This is unexpected......"

if volunteers < goal:
    print "You are {0} below your goal".format(goal - volunteers)
elif volunteers == goal:
    print "At your goal"
elif volunteers > goal:
    print "You're above your goal"
else:
    print "er, something weird happened"


text:
<!DOCTYPE html>

        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="author" content="HarryOh">

        <title>dev.print() - Tags</title>

        <link rel="stylesheet" href="/theme/css/style.css">

        	<link rel="stylesheet" href="/theme/css/colors/blue.css" id="colors">

            <link href="/theme/css/code_blocks/darkly.css" rel="stylesheet">

                <meta property="og:locale" content="">
		<meta property="og:site_name" content="dev.print()">

dev.print()

Home

You are here:

Home

Tags

Tags

angularjs (1)

apigateway (1)

aws (1)

docker (1)

ionic (1)

lambda (1)

laravel (1)

mssql (1)

serverless (1)

Blog powered by Pelican


text:
@class ZZArchiveEntry;

@interface FMProviderFileItem : NSObject

@property (readonly, weak) ZZArchiveEntry *archiveEntry;

@property (readonly) NSString *filePath;
@property (readonly) long long fileSize;
@property (readonly) long long fileSizeCompressed;
@property (readonly) NSDate *modificationDate;
@property (readonly) BOOL isDirectory;
@property (readonly) BOOL isSymbolicLink;
@property (readonly) BOOL isHidden;

@property id volumeId;

- (id)initWithArchiveEntry:(ZZArchiveEntry *)entry;
- (id)initWithFileItem:(FMProviderFileItem *)item;
- (id)initDirectoryItem:(FMProviderFileItem *)item withPath:(NSString *)path;

@end


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="generator" content="pandoc" />
  <title></title>

Call for Papers ScipyLA 2017

! [Alt text] (/ imgs / scipyla2017_banner.png)

May 2017, Havana, Cuba

ScipyLA 2017 Official Site

"More python, more science"

The 5th SciPy Conference will be held in May 2017, in Havana, Cuba.

Goals

To promote the use of affordable and reproducible approaches in scientific research.

To present recent scientific and technical advances using tools made in Python.

To promote the use of Python programming language in scientific research activities.

To contribute to the technological development of Cuba and Latin America.

Topics

Agricultural and Biological Sciences

Arts and Humanities

Biochemistry, Genetics and Molecular Biology

Business, Management and Accounting

Economy and Finance

Chemical Engineering

Computer Science and Informatics

Telecommunications and Electronics

Science of Decision Making

Geophysics and Earth Sciences

Energy, Engineering and Environment

Health, Immunology and Microbiology

Pharmacology, Toxicology

Neurosciences, Medicine, Nursing and Pharmacy

Materials Science

Maths

Physics and Astronomy

Help us to organize your interests and the schedule of the conference by sending your specific area of research to Contacts. Thanks to the contribution of Cuban and international researchers you can access our current list of areas of interest.

Publication

The conference offers researchers and PhD candidates in the region the opportunity to publish in an international journal, indexed in:

Google Scholar

DRJI

DOAJ

Others...

Languages

Spanish, Portuguese, English

Important dates

Conference website: August 2016

Reviewers acceptance: November 2016

Works reception: January 2017

Reviewers response: February 2017

Sending of corrections: March 2017

Activities

Tutorials

Workshops on Python tools offered by experts and aimed at improving the productivity of researchers, automating data analysis, as well as ensuring the attainment of reliable and reproducible results.

Presentations and lectures

Keynote speakers will talk about global trends and best practices in science. Authors submitting the most relevant articles (as assessed by peer reviewers) and those proposing the most popular topics (according to participants) will expose their methods and results.

Poster Sessions

Posters are a visually appealing tool that allows to promote research and explain the details to those concerned.

Note: Acceptance of posters at the conference does not require a prior process of peer review.

Sprints

Meet the authors of recognized libraries in order to implement more efficient ways to perform scientific calculations.

Lightning Talks

Promote and expand the scope of researches by briefly presenting ideas to specialists of the region.

About this call

This early call is intended to give those interested in participating some time to prepare any work under implementation. Only required: novelty, scientific value, practical application and good writing. Solutions related to Python language will be prioritized, as well as researches aimed at improving the quality of life of the citizens of the region and works with instructions leading to experiment repetition.

Contacts

2017@scipyla.org

scipyla2017@pythoncuba.org

scipyla2017@cuban.tech

Organizers

SciPy Latin America Community

Python Cuba Workgroup - Python Software Foundation

Sponsors

Scipy Latin America [] (/imgs/scipyla.logo.png)

Courses

TBD

Projects, Libraries and Technologies promoted

TBD

Version 0.4, July 26, 2016

Author: Abel Meneses Abad


text:
<!DOCTYPE html>

  <link rel="manifest" href="tab_strip_customizations.json">
  <link rel="icon" href="basic-48.png">

Web app with tab strip


text:
"""Classes for managing processing Queues.
"""

import cPickle as pickle
from collections import defaultdict
import functools
import heapq
import logging
import random
import time
import traceback
import zlib

import gevent

from taba.server.model import model_provider
from taba.server.model.identity_registry import ServerRoles
from taba.server.storage import util
from taba.util import thread_util
from taba.util.ttl_heartbeat_cache import TtlHeartbeatCache

LOG = logging.getLogger(__name__)

# Redis keys for the Shard <--> Server mapping.
KEY_SHARD_MAP = 'ShMapH'
KEY_LAST_COMPUTED = 'ShMapLast'
KEY_LOCK_NAME = 'ShMapLock'

# Redis keys for storing the processing queues.
KEY_PATTERN_SHARD_QUEUE = 'QSh%d'
KEY_PATTERN_SHARD_AGE = 'QShAg%d'

# Redis keys for assignment statistics.
KEY_QUEUE_WEIGHTS = 'QWg'
KEY_SERVER_WEIGHTS = 'SWg'

# The target probability that shard assignment recalculation will happen at each
# round. Lower values (exponentially) allow each server to attempt to
# participate in fewer rounds, lowering DB contention for the lock. (Setting
# this to 1.0 will force all servers to attempt to participate in each round).
RECALC_CLUSTER_PROB = 0.999

# Queue and Server Weight carry-over fractions on (0, 1]. Higher values will
# cause weights to change more slowly.
QUEUE_WEIGHT_DECAY = 0.75
SERVER_WEIGHT_DECAY = 0.75

# Number of Queues to shard updates into.
DEFAULT_NUM_SHARDS = 10000

# Default frequency at which Queue assignments are recalculated. Higher values
# reduce contention, but decrease responsiveness to changes in the cluster.
DEFAULT_SHARD_COMPUTATION_SEC = 120

# Default maximum number of Tasks to allow in all the Queues before rejecting
# all incoming updates from front-ends. Higher values allow for higher total
# throughput, at the expense of maximal latency.
DEFAULT_MAX_QUEUE_CAPACITY = 2000000

# Default number of Tasks in all the Queues at which point soft throttling of
# updates from front-ends begins. Higher values allow lower overall front-end
# latency, at the expense of higher back-end and database load.
DEFAULT_QUEUE_THROTTLE_CAPACITY = 50000

# Frequency at which the cached number of Tasks will be refreshed locally.
# Higher values increase responsiveness to Queue capacity, but increase
# database load.
QUEUE_MONITOR_FREQUENCY_SEC = 30

# Assigned Shards cache constants.
ASSIGNED_SHARDS_CACHE_TTL = 2
ASSIGNED_SHARDS_KEY = 'k'
ASSIGNED_SHARDS_VAL = 'v'

# Duration of the shard recalculation lock.
LOCK_DURATION_SEC = 10.0

# Maximum number of shards of process simultaneously when flushing the queues.
MAX_PARALLEL_FLUSH = 200

# Maximum size of the compressed data to retrieve for a single Task.
MAX_TASK_SIZE = 1024 * 1024 * 2

# Task generator constants.
TASK_QUEUE_LENGTH = 2
NUM_TASK_WORKERS = 2

class Task(object):
  """Contained objects for a single entry in a processing queue.
  """

  def __init__(self, nid, cid, sstate_part, enqueue_time):
    """
    Args:
      nid - NID of the task.
      cid - CID of the task.
      sstate_part - Serialized State binary string representing a partial State.
      enqueue_time - UTC creation timestamp of the Task (used to track queue
          processing latency).
    """
    self.nid = nid
    self.cid = cid
    self.sstate_part = sstate_part
    self.enqueue_time = enqueue_time

class QueueRegistry(object):
  """Class for managing processing Queues.
  """

  def __init__(self,
      engine,
      num_shards=DEFAULT_NUM_SHARDS,
      compute_sec=DEFAULT_SHARD_COMPUTATION_SEC,
      queue_capacity=DEFAULT_MAX_QUEUE_CAPACITY,
      queue_throttle_capacity=DEFAULT_QUEUE_THROTTLE_CAPACITY):
    """
    Args:
      engine - RedisEngine compatible storage manager.
      num_shards - Total number of processing queues to use.
      compute_sec - Frequency in seconds of queue assignment recalculation.
      queue_capacity - Total maximum number of Tasks allowed in all the queues.
      queue_throttle_capacity - Total number of Tasks allowed in all the queues
          before soft throttling of incoming updates is applied.
    """
    self.engine = engine

    self.num_shards = num_shards
    self.compute_freq = compute_sec
    self.queue_capacity = queue_capacity
    self.queue_throttle_capacity = queue_throttle_capacity

    self.assigned_shards_cache = TtlHeartbeatCache(
        ASSIGNED_SHARDS_CACHE_TTL,
        heartbeat_width=1)
    self.assigned_shards = []
    self.assigned_timestamp = None

    # Start the background process to contribute to shard re-mapping.
    self.stop = False
    self.worker = gevent.spawn(self._RecomputeWorker)

    # Start the background greenlet to monitor queue overflow.
    self.total_tasks = 0
    self.queue_monitor = thread_util.ScheduleOperationWithPeriod(
        QUEUE_MONITOR_FREQUENCY_SEC,
        self._QueueMonitor)

    # Task generator member.
    self.shard_queue = gevent.queue.Queue(maxsize=1)
    self.task_queue = gevent.queue.Queue(maxsize=1)

    self.shard_worker = None
    self.task_workers = None

    self.task_generator_started = False

  def ShutDown(self):
    """Shut-down hook. Stops background processes.
    """
    self.stop = True

  #########################################################
  # Front-end Interface
  #########################################################

  def CanAcceptUpdate(self):
    """Determine whether an update from the front-end should be accepted, based
    on the total number of Tasks in all the Queues. The rules are:

    - If tasks are below the 'throttle capacity', then new updated are always
      accepted.
    - If tasks it above the 'capacity', then new updates are always rejected.
    - If tasks is between the two capacities, then tasks are randomly rejected
      with a probability linearly related to the distence the number of tasks
      is between the two capacities (e.g. tasks == 'throttle capacity' -> 0%;
      tasks == 'capacity' -> 100%).

    Returns:
      True if the update is accepted; False if it is rejected.
    """
    if self.total_tasks > self.queue_capacity:
      LOG.error('Task queues are Full!')
      return False

    elif self.total_tasks > self.queue_throttle_capacity:
      pct_over = (
          float(self.total_tasks - self.queue_throttle_capacity) /
          float((self.queue_capacity - self.queue_throttle_capacity)))

      if random.random() < pct_over:
        LOG.warning('Throttling frontend updates')
        return False

      else:
        return True

    else:
      return True

  def EnqueueUpdate(self, nid, cid, sstate):
    """Put a batch of State updates in the queue for reducing into the global
    state.

    Args:
      nid - NID being updated.
      cid - CID of the update.
      sstate - Serialized State binary string.

    Returns:
      Operation object.
    """
    now = time.time()
    shard = self._ShardForNid(nid)

    payload = zlib.compress(pickle.dumps(Task(nid, cid, sstate, now)))

    queue_op = util.StrictOp('enqueuing for %d:%d to %d' % (cid, nid, shard),
        self.engine.ListLeftPush,
        KEY_PATTERN_SHARD_QUEUE % shard, payload)

    # Set the shard age flag. We only set it if it doesn't exist, since if it
    # does, it will have a value older than the timestamp we were attempting to
    # put. The flag therefore represents the oldest Task in the queue.
    age_op = util.StrictOp('setting update time for shard queue %d' % shard,
        self.engine.PutNotExist,
        KEY_PATTERN_SHARD_AGE % shard, now)

    return util.CompoundOperation(queue_op, age_op)

  def _QueueMonitor(self):
    """Cache the total number of Tasks that are in the processing queue.
    """
    try:
      keys = [KEY_PATTERN_SHARD_QUEUE % s for s in xrange(self.num_shards)]
      op = self.engine.ListLenBatch(keys)
      if not op.success:
        return

      self.total_tasks = sum(map(int, op.response_value))

    except Exception:
      LOG.error('Exception in queue monitor')
      LOG.error(traceback.format_exc())

  #########################################################
  # Back-end Interface
  #########################################################

  def GetTask(self):
    """Pull a chunk of work from one of the queues assigned to this server
    process.

    Returns:
      Tuple of (
          {NID, {CID: [SerializedState]}},
          [Enqueue Times])
    """
    if not self.task_generator_started:
      self._InitializeTaskGenerator()

    return self.task_queue.get()

  def _InitializeTaskGenerator(self):
    """Start the task generator components.
    """
    self.shard_worker = gevent.spawn(self._ShardWorker)
    self.task_workers = [
        gevent.spawn(self._TaskWorker) for _ in xrange(NUM_TASK_WORKERS)]

    self.task_generator_started = True

  def _TaskWorker(self):
    """Worker to produce tasks for this server process. Pulls shard numbers
    from the Shards Queue and puts associated Tasks on the Task Queue.
    """
    while True:
      try:
        # Determine the next shard that to process.
        shard = self.shard_queue.get()
        if shard is None:
          continue

        # Retrieve the list of updates to apply for this shard, and remove the
        # queue age marker. Note that we delete the age marker first, so that
        # in the event of a concurrent write, we won't have updates without an
        # age marker.
        util.StrictOp('removing age key for shard %d' % shard,
            self.engine.Delete,
            KEY_PATTERN_SHARD_AGE % shard)

        queue_op = util.StrictOp('pulling updates for shard %d' % shard,
            self.engine.ListGetAndDeleteAtomic,
            KEY_PATTERN_SHARD_QUEUE % shard)

        if not queue_op.response_value:
          continue

        # Format the returned task data.
        task_data = defaultdict(functools.partial(defaultdict, list))
        enqueue_times = []
        task_len = 0

        for task_enc in queue_op.response_value:
          task = pickle.loads(zlib.decompress(task_enc))
          task_data[task.nid][task.cid].append(task.sstate_part)
          enqueue_times.append(task.enqueue_time)
          task_len += len(task_enc)

          if task_len > MAX_TASK_SIZE:
            model_provider.GetLatency().RecordForDequeue(enqueue_times)
            self.task_queue.put((task_data, enqueue_times))
            gevent.sleep(0)

            task_data = defaultdict(functools.partial(defaultdict, list))
            enqueue_times = []
            task_len = 0

        model_provider.GetLatency().RecordForDequeue(enqueue_times)
        self.task_queue.put((task_data, enqueue_times))

      except Exception:
        LOG.error('Error in task generator loop')
        LOG.error(traceback.format_exc())

  def _ShardWorker(self):
    """Worker to produce shard numbers for this server to process, based on the
    current Queue assignments. Puts shard numbers onto the Shards Queue.
    """
    shard_generator = self._NextShardGenerator()

    while True:
      gevent.sleep(0)

      try:
        self.shard_queue.put(shard_generator.next())

      except Exception:
        LOG.error('Error in shard generator loop')
        LOG.error(traceback.format_exc())

  def _NextShardGenerator(self):
    """Generator which yields a stream of the next queue number to process.
    Queue numbers are generated in order of oldest pending Task (although that
    is not strictly guaranteed).
    """
    while True:
      try:
        # Fetch the task age of all the shards assigned to this server.
        shards = self.GetAssignedShardNumbers()
        shard_age_keys = [KEY_PATTERN_SHARD_AGE % s for s in shards]

        op = util.StrictOp('retrieving shard ages',
            self.engine.BatchGet,
            shard_age_keys)

        if not op.response_value:
          yield None
          continue

        shard_ages = filter(
            lambda e: e[1] is not None,
            zip(shards, op.response_value))

        if not shard_ages:
          yield None
          continue

        # Sort the shards from oldest to newest. Yield the shard numbers in that
        # order (we can do this without having to go back to the database since
        # we know that any shard age added since we last fetched must be newer
        # than the newest from the last fetch).
        shard_ages = sorted(shard_ages, key=lambda e: float(e[1]))

        for shard, age in shard_ages:
          # Double-check that the shard is still assigned to this server.
          shards = self.GetAssignedShardNumbers()
          if age is not None and shard in shards:
            yield shard

      except Exception:
        LOG.error('Exception in _NextShardGenerator')
        LOG.error(traceback.format_exc())
        yield None

  def FlushAll(self):
    """Delete all pending Tasks in all queues. Use with caution!
    """
    def _flush_shard(shard):
      util.StrictOp('flushing age key for shard %d' % shard,
          self.engine.Delete,
          KEY_PATTERN_SHARD_AGE % shard)

      util.StrictOp('flushing shard %d' % shard,
          self.engine.Delete,
          KEY_PATTERN_SHARD_QUEUE % shard)

    for i in xrange(0, self.num_shards, MAX_PARALLEL_FLUSH):
      greenlets = [
          gevent.spawn(_flush_shard, shard)
          for shard in xrange(i, i + MAX_PARALLEL_FLUSH)]
      gevent.joinall(greenlets)

  #########################################################
  # Shard Mapping Methods
  #########################################################

  def GetAssignedShardNumbers(self):
    """Retrieve the list of queue numbers assigned to the current server.

    Returns:
      List of queue numbers (integers).
    """
    # Check in the cache to determine whether the TTL has expired.
    sentinel = self.assigned_shards_cache[ASSIGNED_SHARDS_KEY]
    if sentinel is not None:
      return self.assigned_shards

    # The cache has expired -- check the last updated timestamp for the mapping
    # in the DB. If it hasn't changed since we last fetched the mapping, use the
    # current values.
    op = util.CheckedOp('retrieving last shard mapping computation',
        self.engine.Get,
        KEY_LAST_COMPUTED)
    assignment_time = op.response_value

    if assignment_time and assignment_time == self.assigned_timestamp:
      # Mapping hasn't changed -- refresh the TTL and return the last mapping.
      self.assigned_shards_cache[ASSIGNED_SHARDS_KEY] = ASSIGNED_SHARDS_VAL
      return self.assigned_shards

    # The mapping has changed since it was last fetched -- re-fetch and update
    # the local values.
    name = model_provider.GetIdentity().GetName()
    op = util.StrictOp('retrieving shards for server %s' % name,
        self.engine.HashGet,
        KEY_SHARD_MAP, name)

    self.assigned_timestamp = assignment_time
    self.assigned_shards_cache[ASSIGNED_SHARDS_KEY] = ASSIGNED_SHARDS_VAL

    if not op.response_value:
      self.assigned_shards = []
    else:
      self.assigned_shards = map(int, op.response_value.split(','))

    return self.assigned_shards

  def ForceRecomputeShards(self):
    """Recompute the shard mapping, whether or not it's needed based on the last
    computation time. This is useful e.g. when a new server comes up, so that it
    is added to the backend rotation immediately.
    """
    self._TryRecomputeMapping(force=True)

  def _RecomputeWorker(self):
    """Worker loop to monitor the time until the next mapping re-computation
    and execute that process when appropriate.
    """
    while not self.stop:
      try:

        # Randomly determine whether to participate in this round. As the
        # number of registered servers increases, each individual server has to
        # participate less often, even while maintaining a similar probability
        # of the entire operation happening at each round.
        num_servers = float(model_provider.GetIdentity().NumServers())
        threshold = (1.0 - RECALC_CLUSTER_PROB) ** (1.0 / num_servers)
        if random.random() < threshold:
          gevent.sleep(self.compute_freq)
          continue

        # Check the last computation time of the shard mapping.
        next_compute_delay = self._GetSecsUntilNextRecompute()
        if next_compute_delay is None:
          gevent.sleep(1)  # Avoid a fast loop on lookup failures.
          continue

        # If we passed the next computation time, attempt to set the new mapping
        if next_compute_delay <= 0:
          try:
            self._TryRecomputeMapping()
          except Exception:
            LOG.error('Error attempting to recompute mapping')
            LOG.error(traceback.format_exc())

          next_compute_delay = self.compute_freq

        # Sleep the remainder of the gap, with some randomness so that all
        # clients don't wake up at the same time (+- 2%).
        gevent.sleep(next_compute_delay * (1 - 0.04 * (random.random() - 0.5)))

      except Exception:
        LOG.error('Unknown exception in shard recompute worker.')
        LOG.error(traceback.format_exc())

  def _GetSecsUntilNextRecompute(self):
    """Retrieve the last update time for the shard mapping from the DB, and
    compute the number of seconds until the next update.

    Returns:
      Number of seconds until the next re-computation (may be fractional). If
      the DB lookup failed, None is returned.
    """
    op = util.CheckedOp('retrieving last shard mapping computation',
        self.engine.Get,
        KEY_LAST_COMPUTED)

    if not op.success:
      return None

    last_compute = float(op.response_value) if op.response_value else 0
    return last_compute + self.compute_freq - time.time()

  def _TryRecomputeMapping(self, force=False):
    """Compute the current desired shard mapping, and attempt to write it into
    the DB. The operation is done with a global lock, since it's possible (and
    likely) that multiple clients will attempt to recompute the mapping. The
    first server to acquire the lock gets precedence.

    Args:
      force - If True, recompute the mapping, whether or not it needs it.
    """
    # Acquire the global lock on the shard mapping. Also double-check that
    # another server didn't update the mapping between the time we identified
    # it needed updating, and when we acquire the lock.
    with self.engine.Lock(KEY_LOCK_NAME, LOCK_DURATION_SEC):
      if self._GetSecsUntilNextRecompute() > 0 and not force:
        return

      LOG.info('Recalculating Queue Assignments.')

      # Pull the data needed for the computation.
      servers, _ = model_provider.GetIdentity().GetAllServers(
          ServerRoles.BACKEND)

      if len(servers) == 0:
        util.StrictOp('updating shard mapping last updated',
            self.engine.Put,
            KEY_LAST_COMPUTED, '%.3f' % time.time())

        util.StrictOp('setting new shard mapping',
            self.engine.Delete,
            KEY_SHARD_MAP)

        util.StrictOp('updating Queue weights',
            self.engine.Delete,
            KEY_QUEUE_WEIGHTS)

        util.StrictOp('updating Server weights',
            self.engine.Delete,
            KEY_SERVER_WEIGHTS)

        return

      queue_weight_op = util.StrictOp('retrieving Queue weights',
          self.engine.HashGetAll,
          KEY_QUEUE_WEIGHTS)
      queue_weights = dict(
          (int(k), float(v))
          for k, v in queue_weight_op.response_value.iteritems())

      server_weight_op = util.StrictOp('retrieving Queue weights',
          self.engine.HashGetAll,
          KEY_SERVER_WEIGHTS)
      server_weights = dict(
          (k, float(v))
          for k, v in server_weight_op.response_value.iteritems())

      len_op = util.StrictOp('retrieving Queue Lengths',
          self.engine.ListLenBatch,
          [KEY_PATTERN_SHARD_QUEUE % s for s in xrange(self.num_shards)])
      queue_lengths = map(int, len_op.response_value)

      map_op = util.StrictOp('retrieving shard mapping',
          self.engine.HashGetAll,
          KEY_SHARD_MAP)
      current_mapping = dict(
          (server, map(int, shards_str.split(',') if shards_str else []))
          for server, shards_str in map_op.response_value.iteritems())

      # Compute and encode the new desired mapping.
      new_mapping, new_qweights, new_server_weights = self._ComputeMapping(
          servers.keys(),
          current_mapping,
          queue_weights,
          queue_lengths,
          server_weights)

      # Put the updated data in the database.

      #
      # TODO: Compress this somehow (makes a really long string).
      #
      new_mapping_enc = dict(
          (server, ','.join(map(str, shards)))
          for server, shards in new_mapping.iteritems())

      util.StrictOp('setting new shard mapping',
          self.engine.HashReplace,
          KEY_SHARD_MAP, new_mapping_enc)

      util.StrictOp('updating shard mapping last updated',
          self.engine.Put,
          KEY_LAST_COMPUTED, '%.3f' % time.time())

      util.StrictOp('updating Queue weights',
          self.engine.HashReplace,
          KEY_QUEUE_WEIGHTS, new_qweights)

      util.StrictOp('updating Server weights',
          self.engine.HashReplace,
          KEY_SERVER_WEIGHTS, new_server_weights)

  def _ComputeMapping(self,
      server_names,
      current_mapping,
      queue_weights,
      queue_lengths,
      server_weights):
    """Core logic to compute the desired mapping of {Server Name: [Queues]}.

    Args:
      server_names - List of Server name strings to distribute Queues among.
      current_mapping - Current assignment of {Server Name: [Queue Numbers]}
      queue_weights - Current Queue weights: {Queue Number: Weight}
      queue_lengths - List of number of tasks in each Queue.
      server_weights - Current Server weights: {Server Name: Weight}

    Returns:
      Tuple of (
          New Server => Queue mapping: {Server Name: [Queue Numbers]},
          Updated Queue weights: {Queue Number: Weight},
          Updated Server weights: {Server Name: Weight})
    """
    all_tasks = float(sum(queue_lengths))
    num_queues = self.num_shards

    # Calculate the instantaneous load of each Queue.
    if all_tasks:
      queue_loads = [queue_lengths[q] / all_tasks for q in xrange(num_queues)]
    else:
      queue_loads = [0.0] * num_queues

    # Update the decayed Queue weights with the current loads.
    new_qweights = {}
    for q in xrange(num_queues):
      old_weight = queue_weights.get(q, 1)
      load = queue_loads[q]
      new_qweights[q] = load + (old_weight - load) * QUEUE_WEIGHT_DECAY

    # Calculate the instantaneous load of each Server.
    server_loads = {}
    for server in server_names:
      shards = current_mapping.get(server, [])
      if all_tasks:
        server_loads[server] = (
            sum(queue_lengths[q] for q in shards if q < len(queue_lengths))
            / all_tasks)
      else:
        server_loads[server] = 0

    # Update the decayed Server weights with the current loads.
    new_sweights = {}
    for server in server_names:
      load = server_loads.get(server, 1)
      old_weight = server_weights.get(server, 1)
      new_sweights[server] = load + (old_weight - load) * SERVER_WEIGHT_DECAY

    min_weight = min(new_sweights.values())
    max_weight = max(new_sweights.values())

    if min_weight == max_weight:
      new_sweights_norm = new_sweights
    else:
      new_sweights_norm = dict(
          (server, (sweight - min_weight) / (max_weight - min_weight))
          for server, sweight in new_sweights.iteritems())

    # Distribute the Queues among the Servers. Each Server is tracked with it's
    # total assigned weight (initialized to 0) in a heap. The first (and
    # therefore least assigned) Server is repeatedly pop'ed from the heap,
    # assigned the next Queue, and put back in the heap. The weight each Queue
    # contributes to each Server is partially scaled by the Server's weight.
    # This heuristic, while not optimal, will more-or-less evenly distribute
    # Tasks to Servers, based on each Server's exhibited capacity.
    server_assignments = defaultdict(list)

    server_total_weight = [(0, s) for s in server_names]
    heapq.heapify(server_total_weight)

    for q, qweight in thread_util.YieldByCount(new_qweights.iteritems(), 10):
      total_weight, server = heapq.heappop(server_total_weight)

      server_assignments[server].append(q)

      updated_weight = total_weight + qweight * (new_sweights_norm[server] + 1)

      heapq.heappush(server_total_weight, (updated_weight, server))

    if model_provider.debug:
      self._PrintQueueAssignmentDebugInfo(
          queue_lengths, queue_loads, queue_weights, new_qweights,
          current_mapping, server_names, server_loads, server_weights,
          new_sweights, server_assignments)

    return server_assignments, new_qweights, new_sweights

  #########################################################
  # Monitoring
  #########################################################

  def GetQueueStats(self):
    """Retrieve current statistics about Queues and Servers.

    Returns:
      Dict of statistics per server containing:
        queues - Number of Queues assigned to the Server.
        tasks - Number of total Tasks pending for the Server.
        age - Age in seconds of the oldest pending Task for the Server.
        load - Relative load on the Server (in per-mill).
        weight - Current handicap of the Server used to calculate assignments.
    """
    now = time.time()

    # Max Task Age.
    age_op = util.StrictOp('retrieving Queue Ages',
        self.engine.BatchGet,
        [KEY_PATTERN_SHARD_AGE % s for s in xrange(self.num_shards)])
    ages = [
        now - float(a) if a is not None else 0
        for a in age_op.response_value]

    # Number of Tasks.
    len_op = util.StrictOp('retrieving Queue lengths',
        self.engine.ListLenBatch,
        [KEY_PATTERN_SHARD_QUEUE % s for s in xrange(self.num_shards)])
    lengths = len_op.response_value

    # Server => Queues mapping.
    map_op = util.CheckedOp('retrieving Queue map',
        self.engine.HashGetAll,
        KEY_SHARD_MAP)
    shard_map = map_op.response_value if map_op.success else None

    # Server weights.
    server_weight_op = util.StrictOp('retrieving Queue weights',
        self.engine.HashGetAll,
        KEY_SERVER_WEIGHTS)
    weights = server_weight_op.response_value

    # Build the output.
    all_tasks = float(sum(lengths))
    server_stats = {}

    for server, shards_str in shard_map.iteritems():
      shards = map(int, shards_str.split(',')) if shards_str else []

      server_ages = filter(None, [ages[s] for s in shards])
      server_age = max(server_ages) if server_ages else 0

      tasks = sum([lengths[s] for s in shards])
      load = (tasks / all_tasks) - 1.0 / len(shard_map) if all_tasks else 0.0
      weight = float(weights.get(server, 0))

      server_stats[server] = {
          'queues': len(shards),
          'tasks': tasks,
          'age': server_age,
          'load': load * 1000,
          'weight': weight * 1000}

    return {
        'total_tasks': all_tasks,
        'max_age': max(ages) if ages else 0,
        'servers': server_stats}

  #########################################################
  # Misc.
  #########################################################

  def _PrintQueueAssignmentDebugInfo(self,
      qlengths, qloads, qweights, new_qweights, old_mapping, snames, sloads,
      sweights, new_sweights, new_mapping):
    """Print to the logger detailed information about a queue assignment run.
    """
    # Convert float values to per-mill for easy printing/reading.
    pm = lambda v: int(v * 1000)

    for server in sorted(snames):
      queues =  old_mapping.get(server, None)
      LOG.info('  S) %s | T: %4s | L: %3d | W: %3s => %3d | Q: %4d | NT: %d' % (
          server,
          sum(qlengths[q] for q in queues if q < len(qlengths)) \
              if queues is not None else 'xx',
          pm(sloads[server]),
          pm(sweights[server]) if server in sweights else 'xx',
          pm(new_sweights[server]),
          len(new_mapping[server]),
          sum(qlengths[q] for q in new_mapping[server])))

  def _ShardForNid(self, nid):
    """Calculate the Shard Number for an NID.

    Args:
      nid - Name ID.

    Returns:
      Shard number on (0, self.num_shards-1).
    """
    # Mix the bits in the NID so that we have a more uniform distribution
    # (especially for the case where the number of NIDs < self.num_shards)
    h = nid
    h = ((h >> 16) ^ h) * 0x45d9f3b;
    h = ((h >> 16) ^ h) * 0x45d9f3b;
    h = ((h >> 16) ^ h);

    return h % self.num_shards


text:
package com.google.javascript.jscomp;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.truth.Truth.assertThat;
import static com.google.javascript.jscomp.testing.JSErrorSubject.assertError;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import junit.framework.TestCase;

public abstract class BaseReplaceScriptTestCase extends TestCase {
  protected static final Joiner LINE_JOINER = Joiner.on('\n');

  protected static final String CLOSURE_BASE =
      LINE_JOINER.join(
          "/** @const */ var goog = goog || {};",
          "goog.require = function(x) {};",
          "goog.provide = function(x) {};");

  protected static final ImmutableList<SourceFile> EXTERNS =
      ImmutableList.of(SourceFile.fromCode("externs", "var extVar = 3;"));

  /**
   * In addition to the passed parameter adds a few options necessary options for
   * {@code replaceScript} and creates a {@code CompilerOptions}.
   */
  protected CompilerOptions getOptions(DiagnosticGroup... typesOfGuard) {
    CompilerOptions options = new CompilerOptions();
    options.declaredGlobalExternsOnWindow = false;
    options.setClosurePass(true);
    // These are the options that are always on in JsDev which is the only
    // use-case for replaceScript currently.
    options.setInferTypes(true);
    options.setAllowHotswapReplaceScript(true);
    options.setChecksOnly(true);
    options.setContinueAfterErrors(true);

    for (DiagnosticGroup group : typesOfGuard) {
      options.setWarningLevel(group, CheckLevel.ERROR);
    }
    return options;
  }

  protected void flushResults(Compiler compiler) {
    // TODO(bashir) Maybe implement error-flush functionality in Compiler?
    compiler.setErrorManager(new PrintStreamErrorManager(System.err));
  }

  protected void runReplaceScriptNoWarnings(
      List<String> sources, String newSource, int newSourceInd) {
    Result result =
        runReplaceScript(getOptions(), sources, 0, 0, newSource, newSourceInd, true).getResult();
    assertNoWarningsOrErrors(result);
    assertThat(result.success).isTrue();
  }

  protected void runReplaceScriptWithError(
      List<String> sources, String newSource, int newSourceInd, DiagnosticType errorType) {
    Result result =
        runReplaceScript(getOptions(), sources, 0, 0, newSource, newSourceInd, true).getResult();
    assertNumWarningsAndErrors(result, 1, 0);
    assertError(result.errors[0]).hasType(errorType);
  }

  /**
   * For a given set of sources, first runs a full compile, then replaces one source with a given
   * new version and calls {@code replaceScript}.
   *
   * @param options Compiler options.
   * @param sources The list of sources.
   * @param expectedCompileErrors Expected number of errors after full compile.
   * @param expectedCompileWarnings Expected number of warnings of full compile.
   * @param newSource The source version.
   * @param newSourceInd Index of the source in {@code sources} to be replaced.
   * @param flushResults Whether to flush results after full-build or not.
   * @return The compiler which can be reused for further inc-compiles.
   */
  protected Compiler runReplaceScript(
      CompilerOptions options,
      List<String> sources,
      int expectedCompileErrors,
      int expectedCompileWarnings,
      String newSource,
      int newSourceInd,
      boolean flushResults) {
    checkArgument(newSourceInd < sources.size());

    // First do a full compile.
    Compiler compiler =
        runFullCompile(
            options, sources, expectedCompileErrors, expectedCompileWarnings, flushResults);

    // Now replace one of the source files and run replaceScript.
    doReplaceScript(compiler, newSource, newSourceInd);
    return compiler;
  }

  protected Compiler runAddScript(
      CompilerOptions options,
      List<String> sources,
      int expectedCompileErrors,
      int expectedCompileWarnings,
      String newSource,
      boolean flushResults) {
    // First do a full compile.
    Compiler compiler =
        runFullCompile(
            options, sources, expectedCompileErrors, expectedCompileWarnings, flushResults);

    // Now replace one of the source files and run replaceScript.
    doAddScript(compiler, newSource, sources.size());
    return compiler;
  }

  protected Compiler runFullCompile(
      CompilerOptions options,
      List<String> sources,
      int expectedCompileErrors,
      int expectedCompileWarnings,
      boolean flushResults) {
    List<SourceFile> inputs = new ArrayList<>();
    int i = 0;
    for (String source : sources) {
      inputs.add(SourceFile.fromCode("in" + i, source));
      i++;
    }
    Compiler compiler = new Compiler();
    Compiler.setLoggingLevel(Level.INFO);
    Result result = compiler.compile(EXTERNS, inputs, options);
    if (expectedCompileErrors == 0) {
      assertThat(compiler.getErrors()).isEmpty();
      assertThat(result.success).isTrue();
    } else {
      assertThat(compiler.getErrors()).hasLength(expectedCompileErrors);
      assertThat(result.success).isFalse();
    }
    assertThat(compiler.getWarnings()).hasLength(expectedCompileWarnings);
    if (flushResults) {
      flushResults(compiler);
    }

    return compiler;
  }

  protected void doReplaceScript(Compiler compiler, String newSource, int newSourceInd) {
    SourceFile replacedSource = SourceFile.fromCode("in" + newSourceInd, newSource);
    JsAst ast = new JsAst(replacedSource);
    compiler.replaceScript(ast);
  }

  protected void doAddScript(Compiler compiler, String newSource, int newSourceInd) {
    SourceFile replacedSource = SourceFile.fromCode("in" + newSourceInd, newSource);
    JsAst ast = new JsAst(replacedSource);
    compiler.addNewScript(ast);
  }

  protected void assertNoWarningsOrErrors(Result result) {
    assertNumWarningsAndErrors(result, 0, 0);
  }

  protected void assertNumWarningsAndErrors(Result result, int e, int w) {
    assertThat(result.warnings).hasLength(w);
    assertThat(result.errors).hasLength(e);
    assertThat(result.success).isEqualTo(e == 0);
  }

  protected void assertErrorType(JSError e, DiagnosticType type, int lineNumber) {
    assertError(e).hasType(type);
    assertEquals(e.lineNumber, lineNumber);
  }

}


text:
cask 'font-ultra' do
  version :latest
  sha256 :no_check

  # github.com/google/fonts was verified as official when first introduced to the cask
  url 'https://github.com/google/fonts/raw/master/apache/ultra/Ultra-Regular.ttf'
  name 'Ultra'
  homepage 'https://www.google.com/fonts/specimen/Ultra'

  font 'Ultra-Regular.ttf'
end


text:
package org.calipsoide.featurevalves;

import com.google.common.base.Objects;

/**
 * Created by epalumbo on 9/16/17.
 */
public class Tag {

    private String code;

    private String value;

    public Tag(String code, String value) {
        this.code = code;
        this.value = value;
    }

    public String getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Tag tag = (Tag) o;
        return Objects.equal(code, tag.code) &&
                Objects.equal(value, tag.value);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(code, value);
    }

    @Override
    public String toString() {
        return code + ":" + value;
    }

}


text:
<!doctype html>

	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="robots" content="noindex, nofollow">

  <title>A Semi Definitive List of Worst Nightmares by Krystal Sutherland – Suffolk Libraries</title>

	<meta name="twitter:card" content="summary_large_image">
	<meta name="twitter:site" content="@suffolklibrary">
	<meta name="twitter:title" content="A Semi Definitive List of Worst Nightmares by Krystal Sutherland">
	<meta name="twitter:description" content="A Semi Definitive List of Worst Nightmares features a sweet, slow-burning romance and deals with dark themes of mental illness beautifully.">
	<meta name="twitter:image" content="/images/featured/featured-a-semi-definitive-list-of-worst-nightmares.jpg">
	<meta name="twitter:image:alt" content="They Both Die at the End">

  <link rel="stylesheet" href="/css/style.css">
	<link rel="preload" as="font" type="font/woff2" href="/fonts/source-sans-pro-v11-latin-regular.woff2">
	<link rel="preload" as="font" type="font/woff2" href="/fonts/source-sans-pro-v11-latin-italic.woff2">
	<link rel="preload" as="font" type="font/woff2" href="/fonts/source-sans-pro-v11-latin-700.woff2">

Skip to content

Skip to navigation menu

💳 You can now pay online.
	Pay charges now →

Donate

Join

Login

Search

Home

eLibrary

Online events

Help

Contact

    Home

      → New suggestions

      → Young adult

      → A Semi Definitive List of Worst Nightmares by Krystal Sutherland

A Semi Definitive List of Worst Nightmares by Krystal Sutherland

  Written by Emily Mitchell · Published Nov 30, 2017 · Filed under Literary fiction

See A Semi Definitive List of Worst Nightmares in our catalogue

"Esther Solar's family is unusual. Her father hasn't left the basement in 6 years. Her brother is terrified of darkness. Esther isn't afraid of anything, a feat she achieves by avoiding pretty much everything. Elevators are off limits, as are open spaces, crowds, family pets, birds, needles, haircuts, dolls and mirrors.

"Then Esther is mugged by her old classmate, Jonah Walker. Jonah is just as she remembers him: rude, cocky and from a broken family. He's also utterly fearless. Jonah's theft brings their lives crashing back together, and Esther and Jonah become surprising friends. Jonah sets a challenge: every week they must work their way through the world's 50 most common phobias."

A Semi Definitive List of Worst Nightmares features a sweet, slow-burning romance and deals with dark themes of mental illness beautifully.

It instantly draws you in with its unique, quirky premise and by delving straight into the action. Krystal Sutherland writes about family, friendship and mental illness in a wonderful way and her lovely, lyrical style adds to its overall brilliance.

I absolutely loved A Semi Definitive List of Worst Nightmares. It is an exceptional YA book, with a clear grasp of the issues it addresses.

Emily Mitchell

I'm a volunteer book reviewer. Visit my book blog.

About our Young Adult section

Book reviews, reading suggestions and blog posts from our staff and young adult readers. Want to write for our website? Email us at help@suffolklibraries.co.uk.

More Young adult

New Young Adult books for March 2020

Wranglestone by Darren Charlton

Recommended Young Adult titles to mark LGBT History Month 2020

With the Fire on High by Elizabeth Acevedo

New Young Adult books for February 2020

The Poet X by Elizabeth Acevedo

Find your new favourite book with the 2020 Read for Empathy YA book collection

The Deathless Girls by Kiran Millwood Hargrave

The Beautiful by Renée Ahdieh

Feast your eyes on our stunning Young Adult comic books

More suggestions

Fiction

Audiobooks

Films & DVDs

eLibrary picks

Children's books

Young adult

Non-fiction

Music

Meet the Author interviews

Articles

 Health and wellbeing

Reviews

Book club favourites

Keep updated

Get the latest suggestions, releases and reviews delivered straight to you.

Email newsletter

Facebook

Twitter

Instagram

Do it online

Search & reserve

Login & renew

eLibrary

Get a library card

Support your library

We're a charity that makes life in Suffolk better for thousands of people.

Donate

Contact us

01473 351249

help@suffolklibraries.co.uk

Social media

Facebook

YouTube

Twitter

Instagram

LinkedIn

Email newsletter

Sections

eLibrary

Libraries

Mobile & home service

Help using the service

Recommendations & reviews

Events & activities

Research & reference

Parents, carers & children

Teachers & home educators

Health & wellbeing

Help with reading & literacy

Work & benefits

Business & room hire

BLOC

Music & Drama Library

News

Jobs

Volunteering

About us

Privacy & cookies

Find out what cookies we use and how we use your data: our privacy policies.

Privacy notice for job applicants

Suffolk Libraries HMRC charity number XT34476. Registered company number IP031542.


text:
from solum.objects import registry
from solum.objects.sqlalchemy import language_pack as lp
from solum.tests import base
from solum.tests import utils

class TestOSPlatform(base.BaseTestCase):
    def setUp(self):
        super(TestOSPlatform, self).setUp()
        self.db = self.useFixture(utils.Database())
        self.ctx = utils.dummy_context()

        self.data = [{'uuid': '123456789abcdefghi',
                      'os': 'ubuntu',
                      'version': '12.04',
                      'language_pack_id': 'java1.4'}]

        utils.create_models_from_data(lp.OSPlatform, self.data, self.ctx)

    def test_objects_registered(self):
        self.assertTrue(registry.OSPlatform)

    def test_check_data(self):
        test_cv = lp.OSPlatform().get_by_id(self.ctx, self.data[0]['id'])
        for key, value in self.data[0].items():
            self.assertEqual(value, getattr(test_cv, key))


text:
package edu.kit.dama.mdm.dataorganization.impl.staging;

import edu.kit.dama.mdm.dataorganization.entity.core.IAttribute;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import org.eclipse.persistence.oxm.annotations.XmlNamedAttributeNode;
import org.eclipse.persistence.oxm.annotations.XmlNamedObjectGraph;

/**
 *
 * @author jejkal
 */
@XmlNamedObjectGraph(
        name = "default",
        attributeNodes = {
          @XmlNamedAttributeNode("key"),
          @XmlNamedAttributeNode("value")
        })
@XmlAccessorType(XmlAccessType.FIELD)
public final class AttributeImpl implements IAttribute {

  private String key = null;
  private String value = null;

  /**
   * Default constructor.
   */
  public AttributeImpl() {
  }

  /**
   * Default constructor.
   *
   * @param pKey The key.
   * @param pValue The value.
   */
  public AttributeImpl(String pKey, String pValue) {
    setKey(pKey);
    setValue(pValue);
  }

  @Override
  public String getKey() {
    return key;
  }

  @Override
  public void setKey(String key) {
    this.key = key;
  }

  @Override
  public String getValue() {
    return value;
  }

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

  @Override
  public IAttribute clone() throws CloneNotSupportedException {
    throw new CloneNotSupportedException();
  }
}


text:
#include <aws/lambda/model/PublishLayerVersionRequest.h>
#include <aws/core/utils/json/JsonSerializer.h>

#include <utility>

using namespace Aws::Lambda::Model;
using namespace Aws::Utils::Json;
using namespace Aws::Utils;

PublishLayerVersionRequest::PublishLayerVersionRequest() :
    m_layerNameHasBeenSet(false),
    m_descriptionHasBeenSet(false),
    m_contentHasBeenSet(false),
    m_compatibleRuntimesHasBeenSet(false),
    m_licenseInfoHasBeenSet(false),
    m_compatibleArchitecturesHasBeenSet(false)
{
}

Aws::String PublishLayerVersionRequest::SerializePayload() const
{
  JsonValue payload;

  if(m_descriptionHasBeenSet)
  {
   payload.WithString("Description", m_description);

  }

  if(m_contentHasBeenSet)
  {
   payload.WithObject("Content", m_content.Jsonize());

  }

  if(m_compatibleRuntimesHasBeenSet)
  {
   Array<JsonValue> compatibleRuntimesJsonList(m_compatibleRuntimes.size());
   for(unsigned compatibleRuntimesIndex = 0; compatibleRuntimesIndex < compatibleRuntimesJsonList.GetLength(); ++compatibleRuntimesIndex)
   {
     compatibleRuntimesJsonList[compatibleRuntimesIndex].AsString(RuntimeMapper::GetNameForRuntime(m_compatibleRuntimes[compatibleRuntimesIndex]));
   }
   payload.WithArray("CompatibleRuntimes", std::move(compatibleRuntimesJsonList));

  }

  if(m_licenseInfoHasBeenSet)
  {
   payload.WithString("LicenseInfo", m_licenseInfo);

  }

  if(m_compatibleArchitecturesHasBeenSet)
  {
   Array<JsonValue> compatibleArchitecturesJsonList(m_compatibleArchitectures.size());
   for(unsigned compatibleArchitecturesIndex = 0; compatibleArchitecturesIndex < compatibleArchitecturesJsonList.GetLength(); ++compatibleArchitecturesIndex)
   {
     compatibleArchitecturesJsonList[compatibleArchitecturesIndex].AsString(ArchitectureMapper::GetNameForArchitecture(m_compatibleArchitectures[compatibleArchitecturesIndex]));
   }
   payload.WithArray("CompatibleArchitectures", std::move(compatibleArchitecturesJsonList));

  }

  return payload.View().WriteReadable();
}


text:
// -----------------------------------------------------------------------------------------
// <copyright file="HttpRequestAdapterMessage.cs" company="Microsoft">
//    Copyright 2013 Microsoft Corporation
//
//    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.
// </copyright>
// -----------------------------------------------------------------------------------------

namespace Microsoft.WindowsAzure.Storage.Table.Protocol
{
    using Microsoft.Data.OData;
    using Microsoft.WindowsAzure.Storage.Core;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using System.IO;
    using System.Linq;
    using System.Net.Http;

    internal class HttpRequestAdapterMessage : IODataRequestMessage, IDisposable
    {
        public HttpRequestMessage GetPopulatedMessage()
        {
            this.msg.Content = this.content;
            this.outStr.Seek(0, SeekOrigin.Begin);
            return this.msg;
        }

        // Summary:
        //     Initializes a new instance of the System.Net.Http.HttpRequestMessage class.
        public HttpRequestAdapterMessage(HttpRequestMessage msg, IBufferManager bufferManager, int bufferSize)
        {
            this.msg = msg;
            this.outStr = new MultiBufferMemoryStream(bufferManager, bufferSize);
            this.content = new StreamContent(this.outStr);
        }

        private StreamContent content = null;

        private HttpRequestMessage msg = null;

        private MultiBufferMemoryStream outStr = null;

        public string GetHeader(string headerName)
        {
            switch (headerName)
            {
                case "Content-Type":
                    return this.content.Headers.ContentType != null ? this.content.Headers.ContentType.ToString() : null;
                case "Content-Range":
                    return this.content.Headers.ContentRange != null ? this.content.Headers.ContentRange.ToString() : null;
                case "Content-MD5":
                    return this.content.Headers.ContentMD5 != null ? Convert.ToBase64String(this.content.Headers.ContentMD5) : null;
                case "Content-Location":
                    return this.content.Headers.ContentLocation != null ? this.content.Headers.ContentLocation.ToString() : null;
                case "Content-Length":
                    return this.content.Headers.ContentLength != null ? this.content.Headers.ContentLength.ToString() : null;
                case "Content-Language":
                    return this.content.Headers.ContentLanguage != null ? this.content.Headers.ContentLanguage.ToString() : null;
                case "Content-Encoding":
                    return this.content.Headers.ContentEncoding != null ? this.content.Headers.ContentEncoding.ToString() : null;
                case "Content-Disposition":
                    return this.content.Headers.ContentDisposition != null ? this.content.Headers.ContentDisposition.ToString() : null;
                default:
                    return this.content.Headers.Contains(headerName) ? this.content.Headers.GetValues(headerName).First() : null;
            }
        }

        public Stream GetStream()
        {
            return this.outStr;
        }

        public System.Collections.Generic.IEnumerable<KeyValuePair<string, string>> Headers
        {
            get { return this.msg.Headers.Select(kvp => new KeyValuePair<string, string>(kvp.Key, kvp.Value.FirstOrDefault())); }
        }

        public string Method
        {
            get
            {
                return this.msg.Method.Method;
            }

            set
            {
                this.msg.Method = new HttpMethod(value);
            }
        }

        public void SetHeader(string headerName, string headerValue)
        {
            if (headerName.StartsWith("Content-"))
            {
                this.content.Headers.Add(headerName, headerValue);
            }
            else
            {
                this.msg.Headers.Add(headerName, headerValue);
            }
        }

        public Uri Url
        {
            get
            {
                return this.msg.RequestUri;
            }

            set
            {
                this.msg.RequestUri = value;
            }
        }

        [SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", Justification = "Members used after adaptermessage is disposed")]
        public void Dispose()
        {
            this.msg = null;
            this.outStr = null;
            this.content = null;
        }
    }
}


text: Rails app for small catalyzer company