text:
'use strict';

/* eslint-env worker, serviceworker */

importScripts('/sw-toolbox.js');

self.toolbox.options.cache = {
  name: 'precache-valid'
};

self.toolbox.precache([
  new Request('/test/data/files/text.txt', {mode: 'cors'}),
  '/test/data/files/text-1.txt'
]);

self.toolbox.precache(Promise.resolve([
  '/test/data/files/text-2.txt'
]));

self.toolbox.precache(Promise.resolve([
  new Request('/test/data/files/text-3.txt', {mode: 'cors'}),
  '/test/data/files/text-4.txt'
]));

self.toolbox.precache([
  '/test/data/files/text-5.txt'
]);


text:
using StackExchange.Redis;
using StackExchange.Redis.Extensions.Core;
using StackExchange.Redis.Extensions.Newtonsoft;
using System;
using System.Collections.Generic;

namespace DNCP.Cache.Redis
{
    public static class RedisCacheProvider
    {
        /// <summary>
        /// redis 连接对象
        /// </summary>
        private static IConnectionMultiplexer ConnMultiplexer;

        /// <summary>
        /// 默认的 Key 值(用来当作 RedisKey 的前缀)
        /// </summary>
        private static readonly string DefaultKey;

        /// <summary>
        /// 锁
        /// </summary>
        private static readonly object Locker = new object();

        /// <summary>
        /// 数据DB
        /// </summary>
        private static readonly IDatabase _db;

        private static readonly ICacheClient _cacheClient;

        static RedisCacheProvider()
        {
            var serializer = new NewtonsoftSerializer();
            DefaultKey = "redis";
            GetConnectionRedisMultiplexer();
            _db = ConnMultiplexer.GetDatabase();
            _cacheClient = new StackExchangeRedisCacheClient(ConnMultiplexer, serializer, 0, $"{DefaultKey}:");
        }

        private static string GetFullKey(string key)
        {
            return $"{DefaultKey}:{key}";
        }

        /// <summary>
        /// 获取 Redis 连接对象
        /// </summary>
        /// <returns></returns>
        private static IConnectionMultiplexer GetConnectionRedisMultiplexer()
        {
            if ((ConnMultiplexer == null) || !ConnMultiplexer.IsConnected)
            {
                lock (Locker)
                {
                    var options = new ConfigurationOptions();
                    options.EndPoints.Add("104.223.65.91", 6379);
                    options.ClientName = "redis";
                    options.Password = "hausthy@123";

                    if ((ConnMultiplexer == null) || !ConnMultiplexer.IsConnected)
                        ConnMultiplexer = ConnectionMultiplexer.Connect(options);
                }
            }

            return ConnMultiplexer;
        }

        public static bool SetValue<T>(string key, T value)
        {
            return _cacheClient.Add(key, value);
        }

        public static string GetValue(string key)
        {
            return _cacheClient.Get<string>(key);
        }

        public static T GetValue<T>(string key)
        {
            return _cacheClient.Get<T>(key);
        }

        public static bool Remove(string key)
        {
            return _cacheClient.Remove(key);
        }

        public static IEnumerable<string> SearchKeys(string keyPrefix)
        {
            return _cacheClient.SearchKeys($"{keyPrefix}*");
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
$: << File.dirname(__FILE__) + '/../lib/'
require 'cobravsmongoose'
require 'test/unit'
begin
  require 'json'
rescue LoadError
  $stderr.puts 'You need to install the JSON library for Ruby (http://json.rubyforge.org/)'
  $stderr.puts 'to use and test the XML<->JSON features of Cobra vs Mongoose.'
end

class HashToXMLTest < Test::Unit::TestCase

  def test_xml_to_json
    xml = '<alice><bob>charlie</bob><bob>david</bob></alice>'
    assert_equal(
      '{"alice":{"bob":[{"$":"charlie"},{"$":"david"}]}}',
      CobraVsMongoose.xml_to_json(xml)
    )
  end

  def test_json_to_xml
    json = '{"alice":{"$":"bob","@charlie":"david"}}'
    assert_equal(
      "<alice charlie='david'>bob</alice>",
      CobraVsMongoose.json_to_xml(json)
    )
  end

end


text:
package gov.nasa.ensemble.common.functional;

import java.io.File;

import fj.F;

public class IO {
	public static final F<String, File> pathToFile = new F<String, File>() {
		@Override
		public File f(final String path) {
			return new File(path);
		}
	};
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="JavaScriptLibraryMappings">
    <file url="file://$PROJECT_DIR$" libraries="{ToDoList node_modules}" />
  </component>
</project>


text:
/* */
"use strict";

exports.__esModule = true;
exports["default"] = isRequiredForA11y;

function isRequiredForA11y(propType) {
  return function validate(props, propName, componentName) {
    if (props[propName] == null) {
      return new Error("The prop '" + propName + "' is required to make '" + componentName + "' accessible" + " for users using assistive technologies such as screen readers");
    }

    return propType(props, propName, componentName);
  };
}

module.exports = exports["default"];


text:
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion

class Migration(migrations.Migration):

    dependencies = [
        ('accounting', '0002_auto_20170207_1411'),
    ]

    operations = [
        migrations.CreateModel(
            name='Budget',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('amount', models.DecimalField(decimal_places=2, max_digits=8, verbose_name='Montant')),
                ('analytic', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='accounting.Analytic', verbose_name='Analytique')),
            ],
        ),
    ]


text:
<ruby>

So far we've looked at two different ways to run tests, the console and rake.

In this chapter we'll cover running using the flaky gem, locally, on Jenkins,
and on Sauce.

</ruby>

<java>

So far we've looked at running the tests using maven. In this chapter we'll
cover running via Jenkins, and on Sauce.

</java>


text:
package org.xchain.framework.jxpath;

import org.apache.commons.jxpath.Function;
import org.apache.commons.jxpath.Functions;
import org.apache.commons.jxpath.PackageFunctions;
import org.apache.commons.jxpath.functions.MethodFunction;
import org.apache.commons.jxpath.util.MethodLookupUtils;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.lang.reflect.Method;

/**
 * @author Christian Trimble
 */
public class StandardFunctions
  implements Functions
{
  private String namespace;
  private PackageFunctions packageFunctions = new PackageFunctions("", null);

  public StandardFunctions( String namespace ) {
    this.namespace = namespace;
  }

  public Set<String> getUsedNamespaces() {
    return Collections.singleton(namespace);
  }

  public Function getFunction( String namespace, String name, Object[] parameters )
  {
    if( (this.namespace == null && namespace != null) || (this.namespace != null && !this.namespace.equals(namespace)) ) {
      return null;
    }

    if (parameters == null) { parameters = new Object[]{}; }

    if( "string-join".equals( name ) ) {
      Method method = MethodLookupUtils.lookupStaticMethod( StandardFunctions.class, "stringJoin", parameters );

      if( method == null ) {
        return packageFunctions.getFunction( namespace, name, parameters );
      }

      return new MethodFunction( method );
    }

    return packageFunctions.getFunction( namespace, name, parameters );
  }

  public static String stringJoin( Collection<Object> collection, String seperator )
  {
    StringBuilder stringBuilder = new StringBuilder();
    if( collection != null ) {
    Iterator<Object> iterator = collection.iterator();
    while( iterator.hasNext() ) {
      stringBuilder.append(iterator.next());
      if( iterator.hasNext() ) {
        stringBuilder.append(seperator);
      }
    }
    }
    return stringBuilder.toString();
  }

  public static String stringJoin( Object[] array, String seperator )
  {
    StringBuilder stringBuilder = new StringBuilder();
    for( int i = 0; i < array.length; i++ ) {
      stringBuilder.append(array[i]);
      if( i < array.length + 1 ) {
        stringBuilder.append(seperator);
      }
    }
    return stringBuilder.toString();
  }
}


text: export default ({ language }) => language;


text:
class BoidManager;
class KinematicComponent;

class BoidHandler
{
public:
	BoidHandler();
	~BoidHandler();

	void initialize(const Mesh& boidMesh, ID3D11VertexShader* vertShader, ID3D11PixelShader* pixelShader);

	void clear();

	void addBoid(float x, float y, float z);
	void addBoidGroup(unsigned count = 5);
	void removeRandomBoid();

	bool loadConfiguration();
	void saveConfiguration();

	void loadDefaultValues();

	void updateBoidParameters();

	void printParameters();

	void onKeyDown(IEventDataPtr e);

private:
	static const std::string BEHAVIOR_NAMES[3];
	static const std::string PARAMETER_NAMES[3];

private:
	void hookInputEvents();
	void unhookInputEvents();

	void addSteeringBehaviors(KinematicComponent*);

private:
	unsigned mCurrentID;

	BoidManager* mpBoidManager;
	std::vector<KinematicComponent*> mBoids;

	float mBoidParameters[3][3];

	int mSelectedBehavior;
	int mSelectedParameter;
	float mIncrementValue;

	Mesh mBoidMesh;
	ID3D11VertexShader* mpVertexShader;
	ID3D11PixelShader* mpPixelShader;

	//float mSeparationRadius, mSeparationMinDot, mSeparationWeight;
	//float mCohesionRadius, mCohesionMinDot, mCohesionWeight;
	//float mAlignRadius, mAlignMinDot, mAlignWeight;
};


text:
import os
import io

from pytest import raises
from pando.website import Website
from pando.http.response import Response
from pando.exceptions import BadLocation

simple_error_spt = """
[---]
[---] text/plain via stdlib_format
{response.body}
"""

# Tests
# =====

def test_basic():
    website = Website(www_root='pando/www')
    expected = os.path.join(os.getcwd(), 'pando', 'www')
    actual = website.www_root
    assert actual == expected

def test_website_is_accessible_from_first_page_of_simplates(harness):
    harness.fs.www.mk(('index.spt', "website\n[---]\n[---]\n"))
    response = harness.client.GET(raise_immediately=False)
    assert response.code == 200, response.body

def test_normal_response_is_returned(harness):
    harness.fs.www.mk(('index.html', "Greetings, program!"))
    expected = b'\r\n'.join(b"""\
HTTP/1.1
Content-Type: text/html

Greetings, program!
""".splitlines())
    actual = harness.client.GET()._to_http('1.1')
    assert actual == expected

def test_fatal_error_response_is_returned(harness):
    harness.fs.www.mk(('index.html.spt', "[---]\nraise heck\n[---]\n"))
    expected = 500
    actual = harness.client.GET(raise_immediately=False).code
    assert actual == expected

def test_dispatch_redirect_works(harness):
    harness.fs.www.mk(('foobar/index.spt', ""))
    r = harness.client.GET('/foobar', raise_immediately=False)
    assert r.code == 302
    assert r.headers[b'Location'] == b'/foobar/'

def test_dispatch_redirect_works_with_unicode(harness):
    harness.fs.www.mk(('%foobar/index.spt', ""))
    r = harness.client.GET('/f%C3%A9e', raise_immediately=False)
    assert r.code == 302
    assert r.headers[b'Location'] == b'/f%C3%A9e/'

def test_redirect_has_only_location(harness):
    harness.fs.www.mk(('index.html.spt', """
        from pando import Response
        [---]
        website.redirect('http://elsewhere', code=304)
        [---]
    """))
    actual = harness.client.GET(raise_immediately=False)
    assert actual.code == 304
    headers = actual.headers
    assert list(headers.keys()) == [b'Location']

def test_nice_error_response_is_returned(harness):
    harness.short_circuit = False
    harness.fs.www.mk(('index.html.spt', """
        from pando import Response
        [---]
        raise Response(500)
        [---]
    """))
    assert harness.client.GET(raise_immediately=False).code == 500

def test_nice_error_response_is_returned_for_404(harness):
    harness.fs.www.mk(('index.html.spt', """
        from pando import Response
        [---]
        raise Response(404)
        [---]
    """))
    assert harness.client.GET(raise_immediately=False).code == 404

def test_response_body_doesnt_expose_traceback_by_default(harness):
    harness.fs.project.mk(('error.spt', simple_error_spt))
    harness.fs.www.mk(('index.html.spt', """
        [---]
        raise Exception("Can I haz traceback ?")
        [---]
    """))
    response = harness.client.GET(raise_immediately=False)
    assert response.code == 500
    assert b"Can I haz traceback ?" not in response.body

def test_response_body_exposes_traceback_for_show_tracebacks(harness):
    harness.fs.project.mk(('error.spt', simple_error_spt))
    harness.fs.www.mk(('index.html.spt', """
        [---]
        raise Exception("Can I haz traceback ?")
        [---]
    """))
    harness.client.hydrate_website(show_tracebacks=True)
    response = harness.client.GET(raise_immediately=False)
    assert response.code == 500
    assert b"Can I haz traceback ?" in response.body

def test_default_error_simplate_doesnt_expose_raised_body_by_default(harness):
    harness.fs.www.mk(('index.html.spt', """
        from pando import Response
        [---]
        raise Response(404, "Um, yeah.")
        [---]
    """))
    response = harness.client.GET(raise_immediately=False)
    assert response.code == 404
    assert b"Um, yeah." not in response.body

def test_default_error_simplate_exposes_raised_body_for_show_tracebacks(harness):
    harness.fs.www.mk(('index.html.spt', """
        from pando import Response
        [---]
        raise Response(404, "Um, yeah.")
        [---]
    """))
    harness.client.hydrate_website(show_tracebacks=True)
    response = harness.client.GET(raise_immediately=False)
    assert response.code == 404
    assert b"Um, yeah." in response.body

def test_nice_error_response_can_come_from_user_error_spt(harness):
    harness.fs.project.mk(('error.spt', '[---]\n[---] text/plain\nTold ya.'))
    harness.fs.www.mk(('index.html.spt', """
        from pando import Response
        [---]
        raise Response(420)
        [---]
    """))
    response = harness.client.GET(raise_immediately=False)
    assert response.code == 420
    assert response.body == b'Told ya.'

def test_nice_error_response_can_come_from_user_420_spt(harness):
    harness.fs.project.mk(('420.spt', """
        [---]
        msg = "Enhance your calm." if response.code == 420 else "Ok."
        [---] text/plain
        %(msg)s
    """))
    harness.fs.www.mk(('index.html.spt', """
        from pando import Response
        [---]
        raise Response(420)
        [---]
    """))
    response = harness.client.GET(raise_immediately=False)
    assert response.code == 420
    assert response.body == b'Enhance your calm.\n'

def test_delegate_error_to_simplate_favors_already_negotiated_media_type(harness):
    harness.fs.project.mk(('error.spt', """
        [---]
        [---] text/fake
        Lorem ipsum
        [---] text/html

Error

        [---] text/plain
        Error
    """))
    harness.fs.www.mk(('foo.spt', """
        from pando import Response
        [---]
        raise Response(403)
        [---] text/plain
    """))
    response = harness.client.GET('/foo', raise_immediately=False, HTTP_ACCEPT=b'text/fake')
    assert response.code == 403
    # If it hadn't raised an exception `foo.spt` would have returned
    # `text/plain`, so that's what `error.spt` should return.
    assert b'text/plain' in response.headers[b'Content-Type']

def test_delegate_error_to_simplate_falls_back_to_original_accept_header(harness):
    harness.fs.project.mk(('error.spt', """
        [---]
        [---] text/plain
        Error
        [---] text/fake
        Lorem ipsum
    """))
    response = harness.client.GET('/foo', raise_immediately=False, HTTP_ACCEPT=b'text/fake')
    assert response.code == 404
    assert b'text/fake' in response.headers[b'Content-Type']

def test_default_error_spt_handles_text_html(harness):
    harness.fs.www.mk(('foo.html.spt', """
        from pando import Response
        [---]
        raise Response(404)
        [---]
    """))
    response = harness.client.GET('/foo.html', raise_immediately=False)
    assert response.code == 404
    assert b'text/html' in response.headers[b'Content-Type']

def test_default_error_spt_handles_application_json(harness):
    harness.fs.www.mk(('foo.json.spt', """
        from pando import Response
        [---]
        raise Response(404)
        [---]
    """))
    response = harness.client.GET('/foo.json', raise_immediately=False)
    assert response.code == 404
    assert response.headers[b'Content-Type'] == b'application/json; charset=UTF-8'
    assert response.body == b'''\
{ "error_code": 404
, "error_message_short": "Not Found"
, "error_message_long": ""
 }
'''

def test_default_error_spt_application_json_includes_msg_for_show_tracebacks(harness):
    harness.fs.www.mk(('foo.json.spt', """
        from pando import Response
        [---]
        raise Response(404, "Right, sooo...")
        [---]
    """))
    harness.client.hydrate_website(show_tracebacks=True)
    response = harness.client.GET('/foo.json', raise_immediately=False)
    assert response.code == 404
    assert response.headers[b'Content-Type'] == b'application/json; charset=UTF-8'
    assert response.body == b'''\
{ "error_code": 404
, "error_message_short": "Not Found"
, "error_message_long": "Right, sooo..."
 }
'''

def test_default_error_spt_falls_through_to_text_plain(harness):
    harness.fs.www.mk(('foo.xml.spt', """
        from pando import Response
        [---]
        raise Response(404)
        [---]
    """))
    response = harness.client.GET('/foo.xml', raise_immediately=False)
    assert response.code == 404
    assert response.headers[b'Content-Type'] == b'text/plain; charset=UTF-8'
    assert response.body == b"Not found, program!\n\n"

def test_default_error_spt_fall_through_includes_msg_for_show_tracebacks(harness):
    harness.fs.www.mk(('foo.xml.spt', """
        from pando import Response
        [---]
        raise Response(404, "Try again!")
        [---]
    """))
    harness.client.hydrate_website(show_tracebacks=True)
    response = harness.client.GET('/foo.xml', raise_immediately=False)
    assert response.code == 404
    assert response.headers[b'Content-Type'] == b'text/plain; charset=UTF-8'
    assert response.body == b"Not found, program!\nTry again!\n"

def test_custom_error_spt_without_text_plain_doesnt_result_in_406(harness):
    harness.fs.project.mk(('error.spt', """
        [---]
        [---] text/html

Oh no!

    """))
    harness.fs.www.mk(('foo.xml.spt', """
        from pando import Response
        [---]
        raise Response(404)
        [---]
    """))
    response = harness.client.GET('/foo.xml', raise_immediately=False)
    assert response.code == 404
    assert response.body == b"
Oh no!
\n"

def test_custom_error_spt_with_text_plain_works(harness):
    harness.fs.project.mk(('error.spt', """
        [---]
        [---] text/plain
        Oh no!
    """))
    harness.fs.www.mk(('foo.xml.spt', """
        from pando import Response
        [---]
        raise Response(404)
        [---]
    """))
    response = harness.client.GET('/foo.xml', raise_immediately=False)
    assert response.code == 404
    assert response.headers[b'Content-Type'] == b'text/plain; charset=UTF-8'
    assert response.body == b"Oh no!\n"

def test_autoindex_response_is_404_by_default(harness):
    harness.fs.www.mk(('README', "Greetings, program!"))
    assert harness.client.GET(raise_immediately=False).code == 404

def test_autoindex_response_is_returned(harness):
    harness.fs.www.mk(('README', "Greetings, program!"))
    harness.client.hydrate_website(list_directories=True)
    body = harness.client.GET(raise_immediately=False).body
    assert b'README' in body

def test_resources_can_import_from_project_root(harness):
    harness.fs.project.mk(('foo.py', 'bar = "baz"'))
    harness.fs.www.mk(('index.html.spt', "from foo import bar\n[---]\n[---]\nGreetings, %(bar)s!"))
    assert harness.client.GET(raise_immediately=False).body == b"Greetings, baz!"

def test_non_500_response_exceptions_dont_get_folded_to_500(harness):
    harness.fs.www.mk(('index.html.spt', '''
        from pando import Response
        [---]
        raise Response(400)
        [---]
'''))
    response = harness.client.GET(raise_immediately=False)
    assert response.code == 400

def test_errors_show_tracebacks(harness):
    harness.fs.www.mk(('index.html.spt', '''
        from pando import Response
        [---]
        website.show_tracebacks = 1
        raise Response(400,1,2,3,4,5,6,7,8,9)
        [---]
    '''))
    response = harness.client.GET(raise_immediately=False)
    assert response.code == 500
    assert b'Response(400,1,2,3,4,5,6,7,8,9)' in response.body

class _TestMiddleware:
    """Simple WSGI middleware for testing."""

    def __init__(self, app):
        self.app = app

    def __call__(self, environ, start_response):
        if environ[b'PATH_INFO'] == '/middleware':
            start_response('200 OK', [('Content-Type', 'text/plain')])
            return ['_TestMiddleware']
        return self.app(environ, start_response)

def build_environ(path):
    """Build WSGI environ for testing.

    It's intentional that some keys and values are unicode instead of bytes, we
    need to support both and this is where we test that.
    """
    return {
        b'REQUEST_METHOD': b'GET',
        b'PATH_INFO': path,
        'QUERY_STRING': '',
        b'SERVER_SOFTWARE': b'build_environ/1.0',
        b'SERVER_PROTOCOL': 'HTTP/1.1',
        'wsgi.input': io.BytesIO(),
    }

def test_call_wraps_wsgi_middleware(client):
    client.website.state_chain.default_short_circuit = False
    client.website.wsgi_app = _TestMiddleware(client.website.wsgi_app)
    respond = [False, False]

    def start_response_should_404(status, headers):
        assert status.lower().strip() == '404 not found'
        respond[0] = True

    client.website(build_environ('/'), start_response_should_404)
    assert respond[0]

    def start_response_should_200(status, headers):
        assert status.lower().strip() == '200 ok'
        respond[1] = True

    client.website(build_environ('/middleware'), start_response_should_200)
    assert respond[1]

def test_raised_unicode_response_is_encoded_with_configured_charset(harness):
    harness.fs.www.mk(('index.html.spt', '''
        from pando import Response
        [---]
        raise Response(200, "touch\\u00e9")
        [---]
    '''))
    harness.client.hydrate_website(encode_output_as='latin9')

    def start_response(*a):
        pass

    body = harness.client.website(build_environ('/'), start_response)
    assert list(body) == [b'touch\xe9']

# redirect

def test_redirect_redirects(website):
    assert raises(Response, website.redirect, '/').value.code == 302

def test_redirect_code_is_settable(website):
    assert raises(Response, website.redirect, '/', code=8675309).value.code == 8675309

def test_redirect_permanent_is_301(website):
    assert raises(Response, website.redirect, '/', permanent=True).value.code == 301

def test_redirect_without_website_base_url_is_fine(website):
    assert raises(Response, website.redirect, '/').value.headers[b'Location'] == b'/'

def test_redirect_honors_website_base_url(website):
    website.base_url = 'foo'
    assert raises(Response, website.redirect, '/').value.headers[b'Location'] == b'foo/'

def test_redirect_can_override_base_url_per_call(website):
    website.base_url = 'foo'
    assert raises(Response, website.redirect, '/', base_url='b').value.headers[b'Location'] == b'b/'

def test_redirect_declines_to_construct_bad_urls(website):
    raised = raises(BadLocation, website.redirect, '../foo', base_url='http://www.example.com')
    assert raised.value.body == 'Bad redirect location: http://www.example.com../foo'

def test_redirect_declines_to_construct_more_bad_urls(website):
    with raises(BadLocation) as raised:
        website.redirect('http://www.example.org/foo', base_url='http://www.example.com')
    expected = 'Bad redirect location: http://www.example.comhttp://www.example.org/foo'
    assert raised.value.body == expected

def test_redirect_will_construct_a_good_absolute_url(website):
    response = raises(Response, website.redirect, '/foo', base_url='http://www.example.com').value
    assert response.headers[b'Location'] == b'http://www.example.com/foo'

def test_redirect_will_allow_a_relative_path(website):
    response = raises(Response, website.redirect, '../foo', base_url='').value
    assert response.headers[b'Location'] == b'../foo'

def test_redirect_will_allow_an_absolute_url(website):
    response = raises(Response, website.redirect, 'http://www.example.org/foo', base_url='').value
    assert response.headers[b'Location'] == b'http://www.example.org/foo'

def test_redirect_can_use_given_response(website):
    response = Response(65, 'Greetings, program!', {b'Location': b'A Town'})
    response = raises(Response, website.redirect, '/flah', response=response).value
    assert response.code == 302                       # gets clobbered
    assert response.headers[b'Location'] == b'/flah'  # gets clobbered
    assert response.body == 'Greetings, program!'     # not clobbered

def test_redirect_doesnt_overescape(website):
    response = raises(Response, website.redirect, '/f%C3%A9e').value
    assert response.headers[b'Location'] == b'/f%C3%A9e'

# canonicalize_base_url

def test_canonicalize_base_url_canonicalizes_base_url(harness):
    harness.fs.www.mk(('index.html', 'Greetings, program!'))
    harness.client.hydrate_website(base_url='https://example.com')
    response = harness.client.xGET()
    assert response.code == 302
    assert response.headers[b'Location'] == b'https://example.com/'

def test_canonicalize_base_url_includes_path_and_qs_for_GET(harness):
    harness.fs.www.mk(('index.html', 'Greetings, program!'))
    harness.client.hydrate_website(base_url='https://example.com')
    response = harness.client.xGET('/%40/bar?baz=1+2')
    assert response.code == 302
    assert response.headers[b'Location'] == b'https://example.com/%40/bar?baz=1+2'

def test_canonicalize_base_url_redirects_POST(harness):
    harness.fs.www.mk(('index.html', 'Greetings, program!'))
    harness.client.hydrate_website(base_url='https://example.com')
    response = harness.client.xPOST('/%40/bar?baz=1+2')
    assert response.code == 307
    assert response.headers[b'Location'] == b'https://example.com/%40/bar?baz=1+2'

def test_canonicalize_base_url_allows_good_base_url(harness):
    harness.fs.www.mk(('index.html', 'Greetings, program!'))
    harness.client.hydrate_website(base_url='https://localhost')
    response = harness.client.GET()
    assert response.code == 200
    assert response.body == b'Greetings, program!'

def test_canonicalize_base_url_is_noop_without_base_url(harness):
    harness.fs.www.mk(('index.html', 'Greetings, program!'))
    harness.client.hydrate_website()
    response = harness.client.GET()
    assert response.code == 200
    assert response.body == b'Greetings, program!'


text:
<?xml version="1.0" encoding="UTF-8"?>

<module rename-to='vibration'>

    <inherits name='com.florianf.gwtcordova.GwtCordova'/>

    <source path='client/plugin/vibration'/>

</module>


text:
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace Umbraco.Core.Models.EntityBase
{
    /// <summary>
    /// Base Abstract Entity
    /// </summary>
    [Serializable]
    [DataContract(IsReference = true)]
    [DebuggerDisplay("Id: {Id}")]
    public abstract class Entity : TracksChangesEntityBase, IEntity, IRememberBeingDirty, ICanBeDirty
    {
        private bool _hasIdentity;
        private int? _hash;
        private int _id;
        private Guid _key;
        private DateTime _createDate;
        private DateTime _updateDate;
        private bool _wasCancelled;

        private static readonly PropertyInfo IdSelector = ExpressionHelper.GetPropertyInfo<Entity, int>(x => x.Id);
        private static readonly PropertyInfo KeySelector = ExpressionHelper.GetPropertyInfo<Entity, Guid>(x => x.Key);
        private static readonly PropertyInfo CreateDateSelector = ExpressionHelper.GetPropertyInfo<Entity, DateTime>(x => x.CreateDate);
        private static readonly PropertyInfo UpdateDateSelector = ExpressionHelper.GetPropertyInfo<Entity, DateTime>(x => x.UpdateDate);
        private static readonly PropertyInfo HasIdentitySelector = ExpressionHelper.GetPropertyInfo<Entity, bool>(x => x.HasIdentity);
        private static readonly PropertyInfo WasCancelledSelector = ExpressionHelper.GetPropertyInfo<Entity, bool>(x => x.WasCancelled);

        /// <summary>
        /// Integer Id
        /// </summary>
        [DataMember]
        public int Id
        {
            get
            {
                return _id;
            }
            set
            {
                SetPropertyValueAndDetectChanges(o =>
                {
                    _id = value;
                    HasIdentity = true; //set the has Identity
                    return _id;
                }, _id, IdSelector);
            }
        }

        /// <summary>
        /// Guid based Id
        /// </summary>
        /// <remarks>The key is currectly used to store the Unique Id from the
        /// umbracoNode table, which many of the entities are based on.</remarks>
        [DataMember]
        public Guid Key
        {
            get
            {
                if (_key == Guid.Empty)
                    return _id.ToGuid();

                return _key;
            }
            set
            {
                SetPropertyValueAndDetectChanges(o =>
                {
                    _key = value;
                    return _key;
                }, _key, KeySelector);
            }
        }

        /// <summary>
        /// Gets or sets the Created Date
        /// </summary>
        [DataMember]
        public DateTime CreateDate
        {
            get { return _createDate; }
            set
            {
                SetPropertyValueAndDetectChanges(o =>
                {
                    _createDate = value;
                    return _createDate;
                }, _createDate, CreateDateSelector);
            }
        }

        /// <summary>
        /// Gets or sets the WasCancelled flag, which is used to track
        /// whether some action against an entity was cancelled through some event.
        /// This only exists so we have a way to check if an event was cancelled through
        /// the new api, which also needs to take effect in the legacy api.
        /// </summary>
        [IgnoreDataMember]
        internal bool WasCancelled
        {
            get { return _wasCancelled; }
            set
            {
                SetPropertyValueAndDetectChanges(o =>
                {
                    _wasCancelled = value;
                    return _wasCancelled;
                }, _wasCancelled, WasCancelledSelector);
            }
        }

        /// <summary>
        /// Gets or sets the Modified Date
        /// </summary>
        [DataMember]
        public DateTime UpdateDate
        {
            get { return _updateDate; }
            set
            {
                SetPropertyValueAndDetectChanges(o =>
                {
                    _updateDate = value;
                    return _updateDate;
                }, _updateDate, UpdateDateSelector);
            }
        }

        internal virtual void ResetIdentity()
        {
            _hasIdentity = false;
            _id = default(int);
        }

        /// <summary>
        /// Method to call on entity saved when first added
        /// </summary>
        internal virtual void AddingEntity()
        {
            CreateDate = DateTime.Now;
            UpdateDate = DateTime.Now;
        }

        /// <summary>
        /// Method to call on entity saved/updated
        /// </summary>
        internal virtual void UpdatingEntity()
        {
            UpdateDate = DateTime.Now;
        }

        /// <summary>
        /// Indicates whether the current entity has an identity, eg. Id.
        /// </summary>
        [DataMember]
        public virtual bool HasIdentity
        {
            get
            {
                return _hasIdentity;
            }
            protected set
            {
                SetPropertyValueAndDetectChanges(o =>
                {
                    _hasIdentity = value;
                    return _hasIdentity;
                }, _hasIdentity, HasIdentitySelector);
            }
        }

        public virtual bool SameIdentityAs(IEntity other)
        {
            if (ReferenceEquals(null, other))
                return false;
            if (ReferenceEquals(this, other))
                return true;

            return SameIdentityAs(other as Entity);
        }

        public virtual bool Equals(Entity other)
        {
            if (ReferenceEquals(null, other))
                return false;
            if (ReferenceEquals(this, other))
                return true;

            return SameIdentityAs(other);
        }

        public virtual Type GetRealType()
        {
            return GetType();
        }

        public virtual bool SameIdentityAs(Entity other)
        {
            if (ReferenceEquals(null, other))
                return false;

            if (ReferenceEquals(this, other))
                return true;

            if (GetType() == other.GetRealType() && HasIdentity && other.HasIdentity)
                return other.Id.Equals(Id);

            return false;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
                return false;
            if (ReferenceEquals(this, obj))
                return true;

            return SameIdentityAs(obj as IEntity);
        }

        public override int GetHashCode()
        {
            if (!_hash.HasValue)
                _hash = !HasIdentity ? new int?(base.GetHashCode()) : new int?(Id.GetHashCode() * 397 ^ GetType().GetHashCode());
            return _hash.Value;
        }

        public virtual object DeepClone()
        {
            //Memberwise clone on Entity will work since it doesn't have any deep elements
            // for any sub class this will work for standard properties as well that aren't complex object's themselves.
            var clone = (Entity)MemberwiseClone();
            //Automatically deep clone ref properties that are IDeepCloneable
            DeepCloneHelper.DeepCloneRefProperties(this, clone);
            clone.ResetDirtyProperties(false);
            return clone;

            //Using data contract serializer - has issues

            //var s = Serialize(this);
            //var d = Deserialize(s, this.GetType());
            //return d;

            //Using binary serializer - has issues

            //using (var memoryStream = new MemoryStream(10))
            //{
            //IFormatter formatter = new BinaryFormatter();
            //formatter.Serialize(memoryStream, this);
            //memoryStream.Seek(0, SeekOrigin.Begin);
            //return formatter.Deserialize(memoryStream);
            //}
        }

        // serialize/deserialize with data contracts:

        //public static string Serialize(object obj)
        //{
        //    using (var memoryStream = new MemoryStream())
        //    using (var reader = new StreamReader(memoryStream))
        //    {
        //        var serializer = new DataContractSerializer(obj.GetType());
        //        serializer.WriteObject(memoryStream, obj);
        //        memoryStream.Position = 0;
        //        return reader.ReadToEnd();
        //    }
        //}

        //public static object Deserialize(string xml, Type toType)
        //{
        //    using (Stream stream = new MemoryStream())
        //    {
        //        using (var writer = new StreamWriter(stream, Encoding.UTF8))
        //        {
        //            writer.Write(xml);
        //            //byte[] data = Encoding.UTF8.GetBytes(xml);
        //            //stream.Write(data, 0, data.Length);
        //            stream.Position = 0;
        //            var deserializer = new DataContractSerializer(toType);
        //            return deserializer.ReadObject(stream);
        //        }
        //    }
        //}
    }
}


text:
require "rails_helper"

module Renalware
  module Letters
    describe Delivery::PracticeEmail do
      subject(:email) { described_class.new(letter) }

      let(:user) { build_stubbed(:user) }
      let(:practice) { build_stubbed(:practice, email: "practice@example.com") }
      let(:patient) { build_stubbed(:letter_patient, practice: practice) }
      let(:letter) { build_stubbed(:letter, patient: patient, by: user) }

      describe ".address" do
        subject { email.address }

        context "when we are permitted to send external emails" do
          before { Renalware.configure { |config| config.allow_external_mail = true } }

          it { is_expected.to eq("practice@example.com") }
        end

        context "when we are not permitted to send external emails" do
          before { Renalware.configure { |config| config.allow_external_mail = false } }

          context "when there is a fallback test email address" do
            before do
              Renalware.configure do |config|
                config.fallback_email_address_for_test_messages = "fallback@example.com"
              end
            end

            it { is_expected.to eq("fallback@example.com") }
          end
        end
      end
    end
  end
end


text:
Using Viper with the Orca screenreader in the Gnome terminal in Linux distributions
requires some adjustments.

## Function keys

Viper uses several function keys; mainly for informational purposes. In both Gnome terminal and using
the Orca screenreader, these may be mapped to other actions.

You can get the same behaviour by pressing Alt plus 1through6

## Cursor keys and movement keys.

Orca seems to suppress output on the terminal whenever cursor keys or backspace keys are pressed.
Although the action is performed, you may not get any audible feedback.

You can alias keys to existing key actions via the alias_key function in the command mode.
Viper provides a Vish script to set these for common actions in the editor.
Do the following either in command mode or by placing the line in your
~/.vishrc file:

```
source ":{vhome}/etc/keymaps/orca_alias.vsh"
```

This adds aliases for keys like Alt plus n for backspace and Shift plus Alt plus J for Page Down to go to the bottom of the buffer.

### Orca alias keys

- Alt y : left arrow
- Alt u : Down arrow
- Alt i : Up arrow
- Alt o : Right arrow
- Alt n : Backspace
- Shift Alt N : Forward delete
- Alt b : Back Tab
- Shift Alt H : Home or Move to front of line
- Shift Alt J : Page Down or move to bottom of buffer
- Shift Alt K : Page Up or move to top of buffer
- Shift Alt L : End or move to end of line


text:
namespace Moses
{

void SourceLabelsPhraseProperty::ProcessValue(const std::string &value)
{
  std::istringstream tokenizer(value);

  if (! (tokenizer >> m_nNTs)) { // first token: number of non-terminals (incl. left-hand side)
    UTIL_THROW2("SourceLabelsPhraseProperty: Not able to read number of non-terminals. Flawed property? " << value);
  }
  assert( m_nNTs > 0 );

  if (! (tokenizer >> m_totalCount)) { // second token: overall rule count
    UTIL_THROW2("SourceLabelsPhraseProperty: Not able to read overall rule count. Flawed property? " << value);
  }
  assert( m_totalCount > 0.0 );

  // read source-labelled rule items

  std::priority_queue<float> ruleLabelledCountsPQ;

  while (tokenizer.peek() != EOF) {
//    try {

    SourceLabelsPhrasePropertyItem item;
    size_t numberOfLHSsGivenRHS = std::numeric_limits<std::size_t>::max();

    if (m_nNTs == 1) {

      item.m_sourceLabelsRHSCount = m_totalCount;

    } else { // rule has right-hand side non-terminals, i.e. it's a hierarchical rule

      for (size_t i=0; i<m_nNTs-1; ++i) { // RHS source non-terminal labels
        size_t sourceLabelRHS;
        if (! (tokenizer >> sourceLabelRHS) ) { // RHS source non-terminal label
          UTIL_THROW2("SourceLabelsPhraseProperty: Not able to read right-hand side label index. Flawed property? " << value);
        }
        item.m_sourceLabelsRHS.push_back(sourceLabelRHS);
      }

      if (! (tokenizer >> item.m_sourceLabelsRHSCount)) {
        UTIL_THROW2("SourceLabelsPhraseProperty: Not able to read right-hand side count. Flawed property? " << value);
      }

      if (! (tokenizer >> numberOfLHSsGivenRHS)) {
        UTIL_THROW2("SourceLabelsPhraseProperty: Not able to read number of left-hand sides. Flawed property? " << value);
      }
    }

    for (size_t i=0; i<numberOfLHSsGivenRHS && tokenizer.peek()!=EOF; ++i) { // LHS source non-terminal labels seen with this RHS
      size_t sourceLabelLHS;
      if (! (tokenizer >> sourceLabelLHS)) { // LHS source non-terminal label
        UTIL_THROW2("SourceLabelsPhraseProperty: Not able to read left-hand side label index. Flawed property? " << value);
      }
      float ruleSourceLabelledCount;
      if (! (tokenizer >> ruleSourceLabelledCount)) {
        UTIL_THROW2("SourceLabelsPhraseProperty: Not able to read count. Flawed property? " << value);
      }
      item.m_sourceLabelsLHSList.push_back( std::make_pair(sourceLabelLHS,ruleSourceLabelledCount) );
      ruleLabelledCountsPQ.push(ruleSourceLabelledCount);
    }

    m_sourceLabelItems.push_back(item);

//    } catch (const std::exception &e) {
//      UTIL_THROW2("SourceLabelsPhraseProperty: Read error. Flawed property?");
//    }
  }

  // keep only top N label vectors
  const size_t N=50;

  if (ruleLabelledCountsPQ.size() > N) {

    float topNRuleLabelledCount = std::numeric_limits<int>::max();
    for (size_t i=0; !ruleLabelledCountsPQ.empty() && i<N; ++i) {
      topNRuleLabelledCount = ruleLabelledCountsPQ.top();
      ruleLabelledCountsPQ.pop();
    }

    size_t nKept=0;
    std::list<SourceLabelsPhrasePropertyItem>::iterator itemIter=m_sourceLabelItems.begin();
    while (itemIter!=m_sourceLabelItems.end()) {
      if (itemIter->m_sourceLabelsRHSCount < topNRuleLabelledCount) {
        itemIter = m_sourceLabelItems.erase(itemIter);
      } else {
        std::list< std::pair<size_t,float> >::iterator itemLHSIter=(itemIter->m_sourceLabelsLHSList).begin();
        while (itemLHSIter!=(itemIter->m_sourceLabelsLHSList).end()) {
          if (itemLHSIter->second < topNRuleLabelledCount) {
            itemLHSIter = (itemIter->m_sourceLabelsLHSList).erase(itemLHSIter);
          } else {
            if (nKept >= N) {
              itemLHSIter = (itemIter->m_sourceLabelsLHSList).erase(itemLHSIter,(itemIter->m_sourceLabelsLHSList).end());
            } else {
              ++nKept;
              ++itemLHSIter;
            }
          }
        }
        if ((itemIter->m_sourceLabelsLHSList).empty()) {
          itemIter = m_sourceLabelItems.erase(itemIter);
        } else {
          ++itemIter;
        }
      }
    }
  }
};

} // namespace Moses


text:
package com.yue.demo.io;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.yue.demo.R;
import com.yue.demo.MainActivity;
import com.yue.demo.util.LogUtil;

/**
 * SDcard 文件浏览器
 *
 * @author chengyue
 *
 */
public class SDFileExplorer extends Activity {
    ListView listView;
    TextView textView;
    // 记录当前的父文件夹
    File currentParent;
    // 记录当前路径下的所有文件的文件数组
    File[] currentFiles;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LinearLayout ll = new LinearLayout(this);
        ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT));
        ll.setOrientation(LinearLayout.VERTICAL);
        // ll.setGravity(Gravity.CENTER);

        textView = new TextView(this);
        textView.setLayoutParams(MainActivity.layoutParams_mw);
        textView.setGravity(Gravity.CENTER_HORIZONTAL);
        textView.setTop(20);
        ll.addView(textView);

        Button parent = new Button(this);
        parent.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        // parent.setBackgroundResource(R.drawable.home);
        parent.setLeft(10);
        parent.setText("返回上一级");
        ll.addView(parent);

        // 获取列出全部文件的ListView
        listView = new ListView(this);
        listView.setLayoutParams(MainActivity.layoutParams_ww);
        // listView.setDivider(getResources().getDrawable(Color.BLUE));
        // listView.setDividerHeight(2);
        ll.addView(listView);

        setContentView(ll);

        // 获取系统的SD卡的目录
        // File root = new File("/mnt/sdcard/");
        File root = new File(Environment.getExternalStorageDirectory()
                .getPath());
        // 如果 SD卡存在
        if (root.exists()) {
            currentParent = root;
            currentFiles = root.listFiles();
            // 使用当前目录下的全部文件、文件夹来填充ListView
            inflateListView(currentFiles);
        }
        // 为ListView的列表项的单击事件绑定监听器
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // 用户单击了文件,直接返回,不做任何处理
                if (currentFiles[position].isFile())
                    return;
                // 获取用户点击的文件夹下的所有文件
                File[] tmp = currentFiles[position].listFiles();
                if (tmp == null || tmp.length == 0) {
                    Toast.makeText(SDFileExplorer.this, "当前路径不可访问或该路径下没有文件",
                            Toast.LENGTH_SHORT).show();
                } else {
                    // 获取用户单击的列表项对应的文件夹,设为当前的父文件夹
                    currentParent = currentFiles[position]; // ②
                    // 保存当前的父文件夹内的全部文件和文件夹
                    currentFiles = tmp;
                    // 再次更新ListView
                    inflateListView(currentFiles);
                }
            }
        });
        // 获取上一级目录的按钮
        parent.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View source) {
                try {

                    if (currentParent != null
                            && !currentParent.getCanonicalPath().equals(
                                    "/mnt/sdcard")) {
                        LogUtil.d(MainActivity_IO.Tag
                                + "currentParent.getCanonicalPath() : "
                                + currentParent.getCanonicalPath());
                        LogUtil.d(MainActivity_IO.Tag + ".getAbsolutePath : "
                                + new File("../src").getAbsolutePath());
                        // 获取上一级目录
                        currentParent = currentParent.getParentFile();
                        // 列出当前目录下所有文件
                        if (currentParent != null) {
                            currentFiles = currentParent.listFiles();
                            // 再次更新ListView
                            inflateListView(currentFiles);
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private void inflateListView(File[] files) // ①
    {
        // 创建一个List集合,List集合的元素是Map
        List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < files.length; i++) {
            Map<String, Object> listItem = new HashMap<String, Object>();
            // 如果当前File是文件夹,使用folder图标;否则使用file图标
            if (files[i].isDirectory()) {
                listItem.put("icon", R.drawable.folder);
            } else {
                listItem.put("icon", R.drawable.file);
            }
            listItem.put("fileName", files[i].getName());
            // 添加List项
            listItems.add(listItem);
        }
        // 创建一个SimpleAdapter
        SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems,
                R.layout.sdcard_explorer_item_line, new String[] { "icon",
                        "fileName" }, new int[] { R.id.icon, R.id.file_name });
        // SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems,
        // line.getId(), new String[] { "icon", "fileName" }, new int[] {
        // icon.getId(), fileName.getId() });
        // 为ListView设置Adapter
        listView.setAdapter(simpleAdapter);
        try {
            textView.setText("当前路径为:" + currentParent.getCanonicalPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


text:
from google.appengine.ext import db
from spot import Spot

class TalkyUser(db.Model):

    """
    How to use:
        user = TalkyUser(fb_uid = uid)
        user.put()
    """

    #Facebook user id
    fb_uid = db.StringProperty()

    #Indicate where am I
    spot = db.ReferenceProperty(reference_class=Spot, collection_name='users')
    """
    #implicity properties
    posts:<collection of UserPost>
    replies:<collection of PostReply>
    outgoingMessages:<collection of Message>
    incomingMessages:<collection of Message>
    outgoingFriendshipRequest:<collection of FriendshipRequest>
    pendingFrinedshipRequest:<collection of FriendshipRequest>
    """
    #TODO
    #User Pereference...

    def getSpot(self):
        #return Spot.get(self.spot)
        return self.spot

    def __str__(self):
        out = "TalkyUser = ["
        out = out + 'fb_uid:' + self.fb_uid

        if self.spot == None:
            out = out + 'spot:None'
        else:
            out = out + 'spot:hasValue'

        out = out + ']'
        return out


text:
import pandas as pd
from geopy.geocoders import Nominatim
import geocoder
import csv

geolocator = Nominatim()

mydata = pd.read_csv('complaints_with_locations.csv')

mydata = mydata.rename(columns = {"Location (according to buggy OCR)" :"Location"})

locations = mydata['Location'].apply(str)

locations = locations + ", Berkeley" + ", CA"
csvfileobj = open("coordinates.csv" , "w")
writer = csv.writer(csvfileobj)
lat = []
lng = []
writer.writerow(['Latitude' , 'Longitude'])

for location in locations:
	chars = set('/')  				#need this because geolocator doesn't find cross streets denoted by '/'
	if any((c in chars) for c in location):
		geocode = geocoder.google(location)
		lat.append(geocode.lat)
		lng.append(geocode.lng)
	else:
		try:
			geocode = geolocator.geocode(location , timeout = None)
			lng.append(geocode.longitude)
			lat.append(geocode.latitude)
		except (AttributeError):		#Due to OCR, not all streets are identifiable
			lat.append("")
			lng.append("")

rows = zip(lat, lng)
for row in rows:
	writer.writerow(row)

csvfileobj.close()


text:
"""
A set of function that cleans the dataset
for machine learning process.
"""

import numpy as np
import pandas as pd

from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.utils import np_utils
from nltk import tokenize
from nltk.corpus import stopwords

from spam.common.exception import IllegalArgumentError
from spam.common.collections import Dataset, Data

class Preprocess:
    """ Preprocess class. """
    def __init__(self, **kwargs):
        self.dataset = kwargs.pop('dataset', None)
        self.max_len = kwargs.pop('max_len', 5000)
        self.max_words = kwargs.pop('max_words', 800)
        self.mode = kwargs.pop('mode', 'tfidf')
        self.classes = kwargs.pop('classes', 2)
        self.read_csv = kwargs.pop('read_csv', False)
        self.read_csv_filepath = kwargs.pop('read_csv_filepath', None)

        if self.read_csv:
            self.dataset = pd.read_csv(self.read_csv_filepath)

        for key, item in kwargs.items():
            raise IllegalArgumentError(
                'Keyword argument {} with a value of  {}, '
                'doesn\'t recognize.'.format(key, item))

    def _clean(self, text):
        """ Remove words with non alphanumeric characters and
        remove stopwords in text.
        """
        return ' '.join([w for w in tokenize.word_tokenize(text)
                         if w.isalnum()
                         if w not in stopwords.words('english')])

    def clean_data(self):
        """ Clean data. """
        self.dataset['body'] = \
            self.dataset['body'].apply(lambda text: self._clean(text))

        self.dataset['body'].replace('', np.nan, inplace=True)

        self.dataset = self.dataset.dropna()

    def transform(self, dataset=None):
        """ Transform data into vector and matrices. """
        clean = lambda words: [str(word)
                               for word in words
                               if type(word) is not float]

        x_unlabel = clean(dataset.unlabel)
        x_train = clean(dataset.train.X)
        x_test = clean(dataset.test.X)

        y_train = dataset.train.y
        y_test = dataset.test.y

        tokenizer = Tokenizer(nb_words=self.max_words)
        tokenizer.fit_on_texts(x_unlabel)

        # save the list of words in the vocabulary
        self.vocabulary = tokenizer.word_counts

        X_unlabel = tokenizer.texts_to_matrix(x_unlabel, mode=self.mode)
        X_unlabel = pad_sequences(X_unlabel, maxlen=self.max_len,
                                  dtype='float64')

        X_train = tokenizer.texts_to_matrix(x_train, mode=self.mode)
        X_train = pad_sequences(X_train, maxlen=self.max_len, dtype='float64')

        X_test = tokenizer.texts_to_matrix(x_test, mode=self.mode)
        X_test = pad_sequences(X_test, maxlen=self.max_len, dtype='float64')

        y_train = np.asarray(y_train, dtype='int32')
        y_test = np.asarray(y_test, dtype='int32')

        Y_train = np_utils.to_categorical(y_train, self.classes)
        Y_test = np_utils.to_categorical(y_test, self.classes)

        return Dataset(
            X_unlabel,
            Data(X_train, Y_train, y_train),
            Data(X_test, Y_test, y_test),
        )


text:
@implementation ImageModel

+ (NSMutableArray *)getArrayOfImagesFromModelArray:(NSMutableArray *)imageArray {

    NSMutableArray *imgArray = [[NSMutableArray alloc] init];
    for (int i = 0; i< imageArray.count; i++) {

        PHAsset *asset = [imageArray objectAtIndex:i];
        ImageModel *model = [[ImageModel alloc] init];
        model.image = asset;
        model.isSelected = false;
        [imgArray addObject:model];
    }
    return imgArray;
}

//+ (NSMutableArray *)updateArrayWithModelValues

@end


text:
#include "BodyWidget.h"
#include "Primitives.h"

#include "IrrIMGUI/IrrIMGUI.h"
#include "IrrIMGUI/IncludeIrrlicht.h"

#include <string>

using namespace irr;
using namespace irr::core;
using namespace irr::video;
using namespace irr::scene;

BodyWidget::BodyWidget(const std::string& name, irr::IrrlichtDevice* const irrDevice,
                       IrrIMGUI::IIMGUIHandle* const imGuiHandle) :
    name_{name},
    irrDevice_{irrDevice},
    imGuiHandle_{imGuiHandle}
{
    auto driver = irrDevice->getVideoDriver();
    auto sceneManager = irrDevice->getSceneManager();
    sceneNode_ = sceneManager->addEmptySceneNode();
    cameraNode_ = sceneManager->addCameraSceneNode(sceneNode_, vector3df(0, 2, 10), vector3df(0, 0, 0));
    cameraNode_->setAspectRatio(1.0);

    renderTarget_ = driver->addRenderTargetTexture(core::dimension2d<u32>(512, 512), name_.c_str());
    renderTargetID_ = imGuiHandle->createTexture(renderTarget_);

    sceneManager->setAmbientLight(SColorf(0.3f, 0.3f, 0.3f));
    auto lightNode = sceneManager->addLightSceneNode(sceneNode_,
                                                     vector3df(30, 0, 0),
                                                     SColorf(1.0f, 1.0f, 1.0f),
                                                     100.0f);

    meshTexture_ = driver->getTexture("res/Phobos.jpg");

    meshNode_ = sceneManager->addSphereSceneNode(5.0, 64, sceneNode_);
    meshNode_->setPosition(vector3df(0.0, 0.0, 0.0));
    meshNode_->setMaterialTexture(0, meshTexture_);
    meshNode_->setMaterialFlag(EMF_LIGHTING, true);

    edgeTexture_ = createColorTexture(driver, SColor(255, 0, 255, 255));
    markerMaterial_.Lighting = false;
    markerMaterial_.setTexture(0, edgeTexture_);

    auto xyPlane = createCircle(64, 6.0, SColor(255, 255, 255, 255));
    xyPlane->recalculateBoundingBox();
    xyPlane->setHardwareMappingHint(EHM_STATIC);
    meshBuffers_.push_back(xyPlane);
}

BodyWidget::~BodyWidget()
{
    for (auto meshBuffer : meshBuffers_) {
        meshBuffer->drop();
    }

    imGuiHandle_->deleteTexture(renderTargetID_);
}

void BodyWidget::render()
{
    auto sceneManager = irrDevice_->getSceneManager();
    auto driver = irrDevice_->getVideoDriver();

    driver->setRenderTarget(renderTarget_, true, true, video::SColor(255, 26, 26, 26));
    sceneNode_->setVisible(true);
    sceneManager->setActiveCamera(cameraNode_);

    meshNode_->setVisible(false);
    if (showTexture_) {
        meshNode_->setMaterialFlag(EMF_LIGHTING, true);
        meshNode_->setMaterialTexture(0, meshTexture_);
        meshNode_->setMaterialFlag(video::EMF_POINTCLOUD, false);
        meshNode_->setMaterialFlag(video::EMF_BACK_FACE_CULLING, true);
        meshNode_->setVisible(true);
    }

    if (showPointCloud_) {
        sceneManager->drawAll();
        meshNode_->setScale(vector3df(1.05, 1.05, 1.05));
        meshNode_->setMaterialFlag(EMF_LIGHTING, false);
        meshNode_->setMaterialTexture(0, edgeTexture_);
        meshNode_->setMaterialFlag(video::EMF_POINTCLOUD, true);
        meshNode_->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
        meshNode_->setVisible(true);
    }

    sceneManager->drawAll();
    meshNode_->setScale(vector3df(1, 1, 1));

    driver->setMaterial(markerMaterial_);
    for (auto meshBuffer : meshBuffers_) {
        driver->drawVertexPrimitiveList((S3DVertex*)meshBuffer->getVertices(),
                                        meshBuffer->getVertexCount(),
                                        &meshBuffer->getIndices()[0],
                                        meshBuffer->getIndexCount(),
                                        video::EVT_STANDARD,
                                        scene::EPT_LINE_LOOP);
    }

    sceneNode_->setVisible(false);
}

void BodyWidget::draw()
{
    imGuiHandle_->updateTexture(renderTargetID_, renderTarget_);

    /*    ImGui::Begin(name_.c_str(), NULL,
                 ImGuiWindowFlags_NoTitleBar
                 | ImGuiWindowFlags_NoResize
                 | ImGuiWindowFlags_NoMove
                 | ImGuiWindowFlags_NoBringToFrontOnFocus
                 | ImGuiWindowFlags_NoScrollbar);
    */
    ImGui::Begin(name_.c_str());
    ImGui::Checkbox("Texture", &showTexture_);
    ImGui::Checkbox("Point Cloud", &showPointCloud_);
    ImGui::Image(*renderTargetID_, ImVec2(512, 512));
    ImGui::End();
}


text:
find_path(NVML_INCLUDE_DIR nvml.h PATHS ${CUDA_INCLUDE_DIRS} /usr/include/nvidia/gdk /usr/include)
find_library(NVML_LIBRARY nvidia-ml)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NVML DEFAULT_MSG NVML_INCLUDE_DIR NVML_LIBRARY)

set(NVML_INCLUDE_DIRS ${NVML_INCLUDE_DIR})
set(NVML_LIBRARIES ${NVML_LIBRARY})
if(NOT NVML_LIBRARIES)
    set(NVML_LIBRARIES "")
endif()

mark_as_advanced(NVML_INCLUDE_DIR NVML_LIBRARY)


text:
package org.pitest.functional.predicate;

/**
 * @author henry
 *
 */
public class True<A> implements Predicate<A> {

  private final static True<?> INSTANCE = new True<Object>();

  @SuppressWarnings("unchecked")
  public static <A> Predicate<A> all() {
    return (True<A>) INSTANCE;
  }

  public Boolean apply(final A a) {
    return true;
  }

}


text:
@interface DefaultsManager : NSObject

+ (DefaultsManager *)sharedManager;

- (NSString *)settingValueForKey:(NSString *)key withIdentifier:(NSString *)identifier;
- (void)setSettingValue:(NSString *)value forKey:(NSString *)key Identifier:(NSString *)identifier;

@end


text:
package com.deeal.fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.deeal.activity.TalkActivity;
import com.example.deeal.R;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.SimpleAdapter;

public class Fragment_mycenter_things extends Fragment {
	private PullToRefreshListView lv_things;
	private List<HashMap<String,Object>> data = new ArrayList<HashMap<String,Object>>();
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view =inflater.inflate(R.layout.fragment_center_things, null);
		lv_things = (PullToRefreshListView) view.findViewById(R.id.lv_mycenter_things);
		for(int i=0;i<5;i++){
			HashMap<String,Object> map =new HashMap<String, Object>();
			map.put("test", "test"+i);
			data.add(map);
		}
		String[] from={};
		int[] to={};
		SimpleAdapter adapter =  new SimpleAdapter(getActivity(), data, R.layout.info_item, from, to);
		lv_things.setAdapter(adapter);
		lv_things.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				startTalkActivity();
			}
		});
		return view;
	}
	private void startTalkActivity(){
		Intent i = new Intent();
		i.setClass(getActivity(), TalkActivity.class);
		startActivity(i);
	}

}


text:
'use strict';

angular.module('hackshareApp')
    .controller('HackCtrl', function ($rootScope, $scope, $http, $stateParams, geoFactory, Auth) {
        $scope.hackId = $stateParams.hackId;
        $scope.quoteFee = '?';
        $scope.estimatedArrival = '?';

        $http.get('/api/hacks/'+$stateParams.hackId)
            .success(function(hack) {
                $scope.hack = hack;
                $scope.hack.price = $scope.hack.price.toFixed(2);
                console.log(hack);

                var geocoder = new google.maps.Geocoder();
                var latlng = new google.maps.LatLng(40.730885,-73.997383);
                var mapOptions = {
                    zoom: 13,
                    center: latlng
                };
                var map = new google.maps.Map(document.getElementById("map-container"), mapOptions);

                var address = $scope.hack.address;
                geocoder.geocode( { 'address': address}, function(results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        map.setCenter(results[0].geometry.location);
                        var marker = new google.maps.Marker({
                            map: map,
                            position: results[0].geometry.location
                        });
                    } else {
                        alert("Geocode was not successful for the following reason: " + status);
                    }
                });

                geoFactory.getPosition().then(function(position) {
                    geoFactory.getLocation(position).then(function (results) {
                        $scope.firstLocation = results[1];
                        $http.post('/api/postmates/quote', {
                            pickup_address: hack.address,
                            dropoff_address: $scope.firstLocation['formatted_address']
                        })
                            .success(function (result) {
                                if (result.kind === 'error') {
                                    console.log('Error getting quote');
                                } else if (result.kind === 'delivery_quote') {
                                    $scope.quote = result;
                                    $scope.quoteFee = (result.fee/100).toFixed(2);
                                    $scope.estimatedArrival = moment(result['dropoff_eta']).format("ddd, h:mm A");
                                    console.log($scope.estimatedArrival);
                                    console.log(result);
                                } else {
                                    console.log('whut is dis');
                                }
                            });
                    });
                });
            })
            .error(function(data, status) {
                $scope.error = status;
            });

        $scope.placeOrder = function() {
            var user = Auth.getCurrentUser();
            console.log(user);
            if(_.isEmpty(user)) {
                alert('You need to log in!');
            }
            $http.post('/api/postmates/order', {
                'manifest'              : $scope.hack.name,
                'pickup_name'           : '',
                'pickup_address'        : '',
                'pickup_phone_number'   : '',
                'pickup_business_name'  : '',
                'pickup_notes'          : '',
                'dropoff_name'          : user.name,
                'dropoff_address'       : user.address,
                'dropoff_phone_number'  : user.phoneNumber,
                'dropoff_notes'         : ''
            })
                .success(function(results) {
                    console.log(results);
                })
                .error(function(err) {
                    console.log(err);
                });
        };
    });


text:
Observation registration server
===============================

This node provides a service which registers two observations. `The
service
used <../observation_registration_services/srv/ObservationRegistrationService.srv>`__
is defined `here <../observation_registration_services>`__:

::

    string source_observation_xml
    string target_observation_xml
    ---
    geometry_msgs/Transform transform
    int32 total_correspondences

The service returns the transform which aligns the source observation to
the target observation. The underlying registration computes
correspondences between pairs of images from the source and target
observations from which the registration transformation is computed.

Test observation registration server
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For convenience, a test routine is provided in this package which takes
as input two observation xml files, calls the
``observation_registration_server`` and visualizes the registration
results. To run execute:

::

    rosrun observation_registration_server test_observation_registration XML_1 XML_2

Original page: https://github.com/strands-project/strands_3d_mapping/blob/hydro-devel/observation_registration/observation_registration_server/README.md


text:
package org.apereo.portal.security;

import java.io.IOException;

/** Used by the md5passwd task to update a user's password. */
public interface IPasswordUpdateTool {

    boolean updatePassword(String user, boolean create) throws IOException;

    void updatePassword(String user, String spass, boolean create) throws IOException;
}


text:
Input::
//// [/a/app.ts]
let x = 1

//// [/a/tsconfig.json]
{"compiler":{},"files":[]}

//// [/a/node_modules/@types/typings/index.d.ts]
export * from "./lib"

//// [/a/node_modules/@types/typings/lib.d.ts]
export const x: number

//// [/a/lib/lib.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }

/a/lib/tsc.js -w -p /a/tsconfig.json
Output::
>> Screen clear
[12:00:23 AM] Starting compilation in watch mode...

tsconfig.json:1:24 - error TS18002: The 'files' list in config file '/a/tsconfig.json' is empty.

1 {"compiler":{},"files":[]}
                         ~~

[12:00:24 AM] Found 1 error. Watching for file changes.

Program root files: []
Program options: {"watch":true,"project":"/a/tsconfig.json","configFilePath":"/a/tsconfig.json"}
Program structureReused: Not
Program files::

No cached semantic diagnostics in the builder::

No shapes updated in the builder::

PolledWatches::

FsWatches::
/a/tsconfig.json:
  {}

FsWatchesRecursive::
/a/node_modules/@types:
  {}

exitCode:: ExitStatus.undefined


text:
import sys
import time
import log_util as log

from argparse import ArgumentParser
from bash_util import Command
from bash_util import CommandException
from dict_util import deep_get
from yaml_util import load_resources_yaml

_PROG_HELP = "Deploy and run tester pods and wait for them to finish execution"

def main():
  parser = ArgumentParser(description=_PROG_HELP)
  parser.add_argument('--namespace')
  parser.add_argument('--manifest')
  parser.add_argument('--timeout', type=int, default=300)
  args = parser.parse_args()

  try:
    Command(
        '''
        kubectl apply
        --namespace="{}"
        --filename="{}"
        '''.format(args.namespace, args.manifest),
        print_call=True)
  except CommandException as ex:
    log.error("Failed to apply tester job. Reason: {}", ex.message)
    return

  resources = load_resources_yaml(args.manifest)

  test_failed = False
  for resource_def in resources:
    full_name = "{}/{}".format(resource_def['kind'],
                               deep_get(resource_def, 'metadata', 'name'))

    if resource_def['kind'] != 'Pod':
      log.info("Skip '{}'", full_name)
      continue

    start_time = time.time()
    poll_interval = 4
    tester_timeout = args.timeout

    while True:
      try:
        resource = Command(
            '''
          kubectl get "{}"
          --namespace="{}"
          -o=json
          '''.format(full_name, args.namespace),
            print_call=True).json()
      except CommandException as ex:
        log.info(str(ex))
        log.info("retrying")
        time.sleep(poll_interval)
        continue

      result = deep_get(resource, 'status', 'phase')

      if result == "Failed":
        print_tester_logs(full_name, args.namespace)
        log.error("Tester '{}' failed.", full_name)
        test_failed = True
        break

      if result == "Succeeded":
        print_tester_logs(full_name, args.namespace)
        log.info("Tester '{}' succeeded.", full_name)
        break

      if time.time() - start_time > tester_timeout:
        print_tester_logs(full_name, args.namespace)
        log.error("Tester '{}' timeout.", full_name)
        test_failed = True
        break

      time.sleep(poll_interval)

  if test_failed:
    sys.exit("At least 1 test failed or timed out.")

def print_tester_logs(full_name, namespace):
  try:
    Command(
        'kubectl logs {} --namespace="{}"'.format(full_name, namespace),
        print_call=True,
        print_result=True)
  except CommandException as ex:
    log.error(str(ex))
    log.error("Failed to get the tester logs.")

if __name__ == "__main__":
  main()


text:
require 'spec_helper'

describe Roller do
  it "should be valid" do
    Roller.should be_a(Module)
  end
end


text:
#include <kernel.h>
#include <string.h>
#include <misc/__assert.h>
#include <misc/mempool_base.h>
#include <misc/mempool.h>

static bool level_empty(struct sys_mem_pool_base *p, int l)
{
	return sys_dlist_is_empty(&p->levels[l].free_list);
}

static void *block_ptr(struct sys_mem_pool_base *p, size_t lsz, int block)
{
	return (u8_t *)p->buf + lsz * block;
}

static int block_num(struct sys_mem_pool_base *p, void *block, int sz)
{
	return ((u8_t *)block - (u8_t *)p->buf) / sz;
}

/* Places a 32 bit output pointer in word, and an integer bit index
 * within that word as the return value
 */
static int get_bit_ptr(struct sys_mem_pool_base *p, int level, int bn,
		       u32_t **word)
{
	u32_t *bitarray = level <= p->max_inline_level ?
		&p->levels[level].bits : p->levels[level].bits_p;

	*word = &bitarray[bn / 32];

	return bn & 0x1f;
}

static void set_free_bit(struct sys_mem_pool_base *p, int level, int bn)
{
	u32_t *word;
	int bit = get_bit_ptr(p, level, bn, &word);

	*word |= (1<<bit);
}

static void clear_free_bit(struct sys_mem_pool_base *p, int level, int bn)
{
	u32_t *word;
	int bit = get_bit_ptr(p, level, bn, &word);

	*word &= ~(1<<bit);
}

/* Returns all four of the free bits for the specified blocks
 * "partners" in the bottom 4 bits of the return value
 */
static int partner_bits(struct sys_mem_pool_base *p, int level, int bn)
{
	u32_t *word;
	int bit = get_bit_ptr(p, level, bn, &word);

	return (*word >> (4*(bit / 4))) & 0xf;
}

static size_t buf_size(struct sys_mem_pool_base *p)
{
	return p->n_max * p->max_sz;
}

static bool block_fits(struct sys_mem_pool_base *p, void *block, size_t bsz)
{
	return ((u8_t *)block + bsz - 1 - (u8_t *)p->buf) < buf_size(p);
}

void _sys_mem_pool_base_init(struct sys_mem_pool_base *p)
{
	int i;
	size_t buflen = p->n_max * p->max_sz, sz = p->max_sz;
	u32_t *bits = (u32_t *)((u8_t *)p->buf + buflen);

	p->max_inline_level = -1;

	for (i = 0; i < p->n_levels; i++) {
		int nblocks = buflen / sz;

		sys_dlist_init(&p->levels[i].free_list);

		if (nblocks < 32) {
			p->max_inline_level = i;
		} else {
			p->levels[i].bits_p = bits;
			bits += (nblocks + 31)/32;
		}

		sz = _ALIGN4(sz / 4);
	}

	for (i = 0; i < p->n_max; i++) {
		void *block = block_ptr(p, p->max_sz, i);

		sys_dlist_append(&p->levels[0].free_list, block);
		set_free_bit(p, 0, i);
	}
}

/* A note on synchronization:
 *
 * For k_mem_pools which are interrupt safe, all manipulation of the actual
 * pool data happens in one of alloc_block()/free_block() or break_block().
 * All of these transition between a state where the caller "holds" a block
 * pointer that is marked used in the store and one where she doesn't (or else
 * they will fail, e.g. if there isn't a free block).  So that is the basic
 * operation that needs synchronization, which we can do piecewise as needed in
 * small one-block chunks to preserve latency.  At most (in free_block) a
 * single locked operation consists of four bit sets and dlist removals. If the
 * overall allocation operation fails, we just free the block we have (putting
 * a block back into the list cannot fail) and return failure.
 *
 * For user mode compatible sys_mem_pool pools, a semaphore is used at the API
 * level since using that does not introduce latency issues like locking
 * interrupts does.
 */

static inline int pool_irq_lock(struct sys_mem_pool_base *p)
{
	if (p->flags & SYS_MEM_POOL_KERNEL) {
		return irq_lock();
	} else {
		return 0;
	}
}

static inline void pool_irq_unlock(struct sys_mem_pool_base *p, int key)
{
	if (p->flags & SYS_MEM_POOL_KERNEL) {
		irq_unlock(key);
	}
}

static void *block_alloc(struct sys_mem_pool_base *p, int l, size_t lsz)
{
	sys_dnode_t *block;

	block = sys_dlist_get(&p->levels[l].free_list);
	if (block != NULL) {
		clear_free_bit(p, l, block_num(p, block, lsz));
	}
	return block;
}

/* Called with lock held */
static unsigned int bfree_recombine(struct sys_mem_pool_base *p, int level,
				    size_t *lsizes, int bn, unsigned int key)
{
	int i, lsz = lsizes[level];
	void *block = block_ptr(p, lsz, bn);

	__ASSERT(block_fits(p, block, lsz), "");

	/* Put it back */
	set_free_bit(p, level, bn);
	sys_dlist_append(&p->levels[level].free_list, block);

	/* Relax the lock (might result in it being taken, which is OK!) */
	pool_irq_unlock(p, key);
	key = pool_irq_lock(p);

	/* Check if we can recombine its superblock, and repeat */
	if (level == 0 || partner_bits(p, level, bn) != 0xf) {
		return key;
	}

	for (i = 0; i < 4; i++) {
		int b = (bn & ~3) + i;

		if (block_fits(p, block_ptr(p, lsz, b), lsz)) {
			clear_free_bit(p, level, b);
			sys_dlist_remove(block_ptr(p, lsz, b));
		}
	}

	/* Free the larger block (tail recursion!) */
	return bfree_recombine(p, level - 1, lsizes, bn / 4, key);
}

static void block_free(struct sys_mem_pool_base *p, int level,
		       size_t *lsizes, int bn)
{
	unsigned int key = pool_irq_lock(p);

	key = bfree_recombine(p, level, lsizes, bn, key);
	pool_irq_unlock(p, key);
}

/* Takes a block of a given level, splits it into four blocks of the
 * next smaller level, puts three into the free list as in
 * block_free() but without the need to check adjacent bits or
 * recombine, and returns the remaining smaller block.
 */
static void *block_break(struct sys_mem_pool_base *p, void *block, int l,
				size_t *lsizes)
{
	int i, bn;

	bn = block_num(p, block, lsizes[l]);

	for (i = 1; i < 4; i++) {
		int lbn = 4*bn + i;
		int lsz = lsizes[l + 1];
		void *block2 = (lsz * i) + (char *)block;

		set_free_bit(p, l + 1, lbn);
		if (block_fits(p, block2, lsz)) {
			sys_dlist_append(&p->levels[l + 1].free_list, block2);
		}
	}

	return block;
}

int _sys_mem_pool_block_alloc(struct sys_mem_pool_base *p, size_t size,
			      u32_t *level_p, u32_t *block_p, void **data_p)
{
	int i, from_l, alloc_l = -1, free_l = -1;
	unsigned int key;
	void *data = NULL;
	size_t lsizes[p->n_levels];

	/* Walk down through levels, finding the one from which we
	 * want to allocate and the smallest one with a free entry
	 * from which we can split an allocation if needed.  Along the
	 * way, we populate an array of sizes for each level so we
	 * don't need to waste RAM storing it.
	 */
	lsizes[0] = _ALIGN4(p->max_sz);
	for (i = 0; i < p->n_levels; i++) {
		if (i > 0) {
			lsizes[i] = _ALIGN4(lsizes[i-1] / 4);
		}

		if (lsizes[i] < size) {
			break;
		}

		alloc_l = i;
		if (!level_empty(p, i)) {
			free_l = i;
		}
	}

	if (alloc_l < 0 || free_l < 0) {
		*data_p = NULL;
		return -ENOMEM;
	}

	/* Now walk back down the levels (i.e. toward bigger sizes)
	 * looking for an available block.  Start at the smallest
	 * enclosing block found above (note that because that loop
	 * was done without synchronization, it may no longer be
	 * available!) as a useful optimization.  Note that the
	 * removal of the block from the list and the re-addition of
	 * its the three unused children needs to be performed
	 * atomically, otherwise we open up a situation where we can
	 * "steal" the top level block of the whole heap, causing a
	 * spurious -ENOMEM.
	 */
	key = pool_irq_lock(p);
	for (i = free_l; i >= 0; i--) {
		data = block_alloc(p, i, lsizes[i]);

		/* Found one.  Iteratively break it down to the size
		 * we need.  Note that we relax the lock to allow a
		 * pending interrupt to fire so we don't hurt latency
		 * by locking the full loop.
		 */
		if (data != NULL) {
			for (from_l = i; from_l < alloc_l; from_l++) {
				data = block_break(p, data, from_l, lsizes);
				pool_irq_unlock(p, key);
				key = pool_irq_lock(p);
			}
			break;
		}
	}
	pool_irq_unlock(p, key);

	*level_p = alloc_l;
	*block_p = block_num(p, data, lsizes[alloc_l]);
	*data_p = data;

	return 0;
}

void _sys_mem_pool_block_free(struct sys_mem_pool_base *p, u32_t level,
			      u32_t block)
{
	size_t lsizes[p->n_levels];
	int i;

	/* As in _sys_mem_pool_block_alloc(), we build a table of level sizes
	 * to avoid having to store it in precious RAM bytes.
	 * Overhead here is somewhat higher because block_free()
	 * doesn't inherently need to traverse all the larger
	 * sublevels.
	 */
	lsizes[0] = _ALIGN4(p->max_sz);
	for (i = 1; i <= level; i++) {
		lsizes[i] = _ALIGN4(lsizes[i-1] / 4);
	}

	block_free(p, level, lsizes, block);
}

/*
 * Functions specific to user-mode blocks
 */

void *sys_mem_pool_alloc(struct sys_mem_pool *p, size_t size)
{
	struct sys_mem_pool_block *blk;
	u32_t level, block;
	char *ret;

	k_mutex_lock(p->mutex, K_FOREVER);

	size += sizeof(struct sys_mem_pool_block);
	if (_sys_mem_pool_block_alloc(&p->base, size, &level, &block,
				      (void **)&ret)) {
		ret = NULL;
		goto out;
	}

	blk = (struct sys_mem_pool_block *)ret;
	blk->level = level;
	blk->block = block;
	blk->pool = p;
	ret += sizeof(*blk);
out:
	k_mutex_unlock(p->mutex);
	return ret;
}

void sys_mem_pool_free(void *ptr)
{
	struct sys_mem_pool_block *blk;
	struct sys_mem_pool *p;

	if (ptr == NULL) {
		return;
	}

	blk = (struct sys_mem_pool_block *)((char *)ptr - sizeof(*blk));
	p = blk->pool;

	k_mutex_lock(p->mutex, K_FOREVER);
	_sys_mem_pool_block_free(&p->base, blk->level, blk->block);
	k_mutex_unlock(p->mutex);
}


text:
"""Test helper for the Mbed TLS configuration file tool

Run config.py with various parameters and write the results to files.

This is a harness to help regression testing, not a functional tester.
Sample usage:

    test_config_script.py -d old
    ## Modify config.py and/or config.h ##
    test_config_script.py -d new
    diff -ru old new
"""

## Copyright The Mbed TLS Contributors
## SPDX-License-Identifier: Apache-2.0
##
## 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.

import argparse
import glob
import os
import re
import shutil
import subprocess

OUTPUT_FILE_PREFIX = 'config-'

def output_file_name(directory, stem, extension):
    return os.path.join(directory,
                        '{}{}.{}'.format(OUTPUT_FILE_PREFIX,
                                         stem, extension))

def cleanup_directory(directory):
    """Remove old output files."""
    for extension in []:
        pattern = output_file_name(directory, '*', extension)
        filenames = glob.glob(pattern)
        for filename in filenames:
            os.remove(filename)

def prepare_directory(directory):
    """Create the output directory if it doesn't exist yet.

    If there are old output files, remove them.
    """
    if os.path.exists(directory):
        cleanup_directory(directory)
    else:
        os.makedirs(directory)

def guess_presets_from_help(help_text):
    """Figure out what presets the script supports.

    help_text should be the output from running the script with --help.
    """
    # Try the output format from config.py
    hits = re.findall(r'\{([-\w,]+)\}', help_text)
    for hit in hits:
        words = set(hit.split(','))
        if 'get' in words and 'set' in words and 'unset' in words:
            words.remove('get')
            words.remove('set')
            words.remove('unset')
            return words
    # Try the output format from config.pl
    hits = re.findall(r'\n +([-\w]+) +- ', help_text)
    if hits:
        return hits
    raise Exception("Unable to figure out supported presets. Pass the '-p' option.")

def list_presets(options):
    """Return the list of presets to test.

    The list is taken from the command line if present, otherwise it is
    extracted from running the config script with --help.
    """
    if options.presets:
        return re.split(r'[ ,]+', options.presets)
    else:
        help_text = subprocess.run([options.script, '--help'],
                                   check=False, # config.pl --help returns 255
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.STDOUT).stdout
        return guess_presets_from_help(help_text.decode('ascii'))

def run_one(options, args, stem_prefix='', input_file=None):
    """Run the config script with the given arguments.

    Take the original content from input_file if specified, defaulting
    to options.input_file if input_file is None.

    Write the following files, where xxx contains stem_prefix followed by
    a filename-friendly encoding of args:
    * config-xxx.h: modified file.
    * config-xxx.out: standard output.
    * config-xxx.err: standard output.
    * config-xxx.status: exit code.

    Return ("xxx+", "path/to/config-xxx.h") which can be used as
    stem_prefix and input_file to call this function again with new args.
    """
    if input_file is None:
        input_file = options.input_file
    stem = stem_prefix + '-'.join(args)
    data_filename = output_file_name(options.output_directory, stem, 'h')
    stdout_filename = output_file_name(options.output_directory, stem, 'out')
    stderr_filename = output_file_name(options.output_directory, stem, 'err')
    status_filename = output_file_name(options.output_directory, stem, 'status')
    shutil.copy(input_file, data_filename)
    # Pass only the file basename, not the full path, to avoid getting the
    # directory name in error messages, which would make comparisons
    # between output directories more difficult.
    cmd = [os.path.abspath(options.script),
           '-f', os.path.basename(data_filename)]
    with open(stdout_filename, 'wb') as out:
        with open(stderr_filename, 'wb') as err:
            status = subprocess.call(cmd + args,
                                     cwd=options.output_directory,
                                     stdin=subprocess.DEVNULL,
                                     stdout=out, stderr=err)
    with open(status_filename, 'w') as status_file:
        status_file.write('{}\n'.format(status))
    return stem + "+", data_filename

### A list of symbols to test with.
### This script currently tests what happens when you change a symbol from
### having a value to not having a value or vice versa. This is not
### necessarily useful behavior, and we may not consider it a bug if
### config.py stops handling that case correctly.
TEST_SYMBOLS = [
    'CUSTOM_SYMBOL', # does not exist
    'MBEDTLS_AES_C', # set, no value
    'MBEDTLS_MPI_MAX_SIZE', # unset, has a value
    'MBEDTLS_NO_UDBL_DIVISION', # unset, in "System support"
    'MBEDTLS_PLATFORM_ZEROIZE_ALT', # unset, in "Customisation configuration options"
]

def run_all(options):
    """Run all the command lines to test."""
    presets = list_presets(options)
    for preset in presets:
        run_one(options, [preset])
    for symbol in TEST_SYMBOLS:
        run_one(options, ['get', symbol])
        (stem, filename) = run_one(options, ['set', symbol])
        run_one(options, ['get', symbol], stem_prefix=stem, input_file=filename)
        run_one(options, ['--force', 'set', symbol])
        (stem, filename) = run_one(options, ['set', symbol, 'value'])
        run_one(options, ['get', symbol], stem_prefix=stem, input_file=filename)
        run_one(options, ['--force', 'set', symbol, 'value'])
        run_one(options, ['unset', symbol])

def main():
    """Command line entry point."""
    parser = argparse.ArgumentParser(description=__doc__,
                                     formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('-d', metavar='DIR',
                        dest='output_directory', required=True,
                        help="""Output directory.""")
    parser.add_argument('-f', metavar='FILE',
                        dest='input_file', default='include/mbedtls/config.h',
                        help="""Config file (default: %(default)s).""")
    parser.add_argument('-p', metavar='PRESET,...',
                        dest='presets',
                        help="""Presets to test (default: guessed from --help).""")
    parser.add_argument('-s', metavar='FILE',
                        dest='script', default='scripts/config.py',
                        help="""Configuration script (default: %(default)s).""")
    options = parser.parse_args()
    prepare_directory(options.output_directory)
    run_all(options)

if __name__ == '__main__':
    main()


text:
package weibo4j.util;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.BitSet;
/**
 * @author sinaWeibo
 *
 */
public class URLEncodeUtils {

	static BitSet dontNeedEncoding;

	static {

		/*
		 * The list of characters that are not encoded has been determined as
		 * follows:
		 *
		 * RFC 2396 states: ----- Data characters that are allowed in a URI but
		 * do not have a reserved purpose are called unreserved. These include
		 * upper and lower case letters, decimal digits, and a limited set of
		 * punctuation marks and symbols.
		 *
		 * unreserved = alphanum | mark
		 *
		 * mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
		 *
		 * Unreserved characters can be escaped without changing the semantics
		 * of the URI, but this should not be done unless the URI is being used
		 * in a context that does not allow the unescaped character to appear.
		 * -----
		 *
		 * It appears that both Netscape and Internet Explorer escape all
		 * special characters from this list with the exception of "-", "_",
		 * ".", "*". While it is not clear why they are escaping the other
		 * characters, perhaps it is safest to assume that there might be
		 * contexts in which the others are unsafe if not escaped. Therefore, we
		 * will use the same list. It is also noteworthy that this is consistent
		 * with O'Reilly's "HTML: The Definitive Guide" (page 164).
		 *
		 * As a last note, Intenet Explorer does not encode the "@" character
		 * which is clearly not unreserved according to the RFC. We are being
		 * consistent with the RFC in this matter, as is Netscape.
		 */

		dontNeedEncoding = new BitSet(256);
		int i;
		for (i = 'a'; i <= 'z'; i++) {
			dontNeedEncoding.set(i);
		}
		for (i = 'A'; i <= 'Z'; i++) {
			dontNeedEncoding.set(i);
		}
		for (i = '0'; i <= '9'; i++) {
			dontNeedEncoding.set(i);
		}
		dontNeedEncoding.set(' '); /*
									 * encoding a space to a + is done in the
									 * encode() method
									 */
		dontNeedEncoding.set('-');
		dontNeedEncoding.set('_');
		dontNeedEncoding.set('.');
		dontNeedEncoding.set('*');

		dontNeedEncoding.set('+');
		dontNeedEncoding.set('%');

	}

	/**
	 * 判断段落文本是否被urlencode过
	 *
	 * @param str
	 * @return
	 */
	public static final boolean isURLEncoded(String str) {
		if (str==null||"".equals(str)) {
			return false;
		}
		char[] chars = str.toCharArray();
		boolean containsPercent = false;
		for (char c : chars) {
			if (Character.isWhitespace(c)) {
				return false;
			}
			if (!dontNeedEncoding.get(c)) {
				return false;
			}
			if(c == '%'){
				containsPercent = true;
			}
		}
		if(!containsPercent){
			return false;
		}
		return true;
	}

	public static final String encodeURL(String str) {
		try {
			return URLEncoder.encode(str, "utf-8");
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}
	public static final String decodeURL(String str) {
		try {
			return URLDecoder.decode(str, "utf-8");
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}

}


text:
namespace CSBackend
{
	namespace Android
	{
		namespace
		{
			const std::string k_amazonPrivateKeyKey("AmazonPrivateKey");

            //---------------------------------------------------------------
            /// @author Ian Copland
            ///
            /// @param List of product registrations
            /// @param Product Id to find
            ///
            /// @return Whether a product reg info exists in the list
            /// with the given Id.
            //---------------------------------------------------------------
            bool ContainsProductId(const std::vector<CSNetworking::IAPSystem::ProductRegInfo>& in_productInfos, const std::string& in_productId)
            {
                for(u32 i=0; i<in_productInfos.size(); ++i)
                {
                    if(in_productInfos[i].m_id == in_productId)
                    {
                        return true;
                    }
                }

                return false;
            }
		}

		CS_DEFINE_NAMEDTYPE(AmazonIAPSystem);

    	//---------------------------------------------------------------
    	//---------------------------------------------------------------
		AmazonIAPSystem::AmazonIAPSystem(const CSCore::ParamDictionary& in_params)
		{
			CS_ASSERT(in_params.HasKey(k_amazonPrivateKeyKey) == true, "Cannot create Amazon IAP system without store key - AmazonPrivateKey");
			m_privateKey = in_params.GetValue(k_amazonPrivateKeyKey);
		}
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        bool AmazonIAPSystem::IsA(CSCore::InterfaceIDType in_interfaceId) const
        {
            return in_interfaceId == CSNetworking::IAPSystem::InterfaceID || in_interfaceId == AmazonIAPSystem::InterfaceID;
        }
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        void AmazonIAPSystem::OnInit()
        {
			m_javaInterface = JavaInterfaceManager::GetSingletonPtr()->GetJavaInterface<AmazonIAPJavaInterface>();
			if (m_javaInterface == nullptr)
			{
				CSCore::Device* device = CSCore::Application::Get()->GetSystem<CSCore::Device>();
				m_javaInterface = AmazonIAPJavaInterfaceSPtr(new AmazonIAPJavaInterface(m_privateKey, device->GetUDID()));
	        	JavaInterfaceManager::GetSingletonPtr()->AddJavaInterface(m_javaInterface);
			}
        }
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        void AmazonIAPSystem::RegisterProducts(const std::vector<ProductRegInfo>& in_productInfos)
        {
        	CS_ASSERT(in_productInfos.empty() == false, "Must register at least one product");
            m_productRegInfos = in_productInfos;
        }
        //---------------------------------------------------------------
        //---------------------------------------------------------------
		std::string AmazonIAPSystem::GetProviderID() const
		{
			return "AmazonAppStore";
		}
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        bool AmazonIAPSystem::IsPurchasingEnabled()
        {
        	return m_javaInterface->IsPurchasingEnabled();
        }
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        void AmazonIAPSystem::StartListeningForTransactionUpdates(const TransactionStatusDelegate& in_delegate)
        {
        	CS_ASSERT(in_delegate != nullptr, "Cannot have null transaction delegate");
        	m_javaInterface->StartListeningForTransactionUpdates(in_delegate);
        }
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        void AmazonIAPSystem::StopListeningForTransactionUpdates()
        {
        	m_javaInterface->StopListeningForTransactionUpdates();
        }
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        void AmazonIAPSystem::RequestProductDescriptions(const std::vector<std::string>& in_productIds, const ProductDescDelegate& in_delegate)
        {
            CS_ASSERT(in_productIds.empty() == false, "Cannot request no product descriptions");
            CS_ASSERT(in_delegate != nullptr, "Cannot have null product description delegate");
        	m_javaInterface->RequestProductDescriptions(in_productIds, in_delegate);
        }
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        void AmazonIAPSystem::RequestAllProductDescriptions(const ProductDescDelegate& in_delegate)
        {
            std::vector<std::string> productIds;
            productIds.reserve(m_productRegInfos.size());

            for(u32 i=0; i<m_productRegInfos.size(); ++i)
            {
            	productIds.push_back(m_productRegInfos[i].m_id);
            }

            RequestProductDescriptions(productIds, in_delegate);
        }
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        void AmazonIAPSystem::CancelProductDescriptionsRequest()
        {
        	m_javaInterface->CancelProductDescriptionsRequest();
        }
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        void AmazonIAPSystem::RequestProductPurchase(const std::string& in_productId)
        {
        	CS_ASSERT(ContainsProductId(m_productRegInfos, in_productId), "Products must be registered with the IAP system before purchasing");
        	m_javaInterface->RequestProductPurchase(in_productId);
        }
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        void AmazonIAPSystem::CloseTransaction(const TransactionSPtr& in_transaction, const TransactionCloseDelegate& in_delegate)
        {
        	m_javaInterface->CloseTransaction(in_transaction->m_productId, in_transaction->m_transactionId, in_delegate);
        }
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        void AmazonIAPSystem::RestoreManagedPurchases()
        {
        	m_javaInterface->RestoreManagedPurchases();
        }
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        void AmazonIAPSystem::OnDestroy()
        {
        	m_javaInterface = nullptr;
            m_productRegInfos.clear();
            m_productRegInfos.shrink_to_fit();
        }
	}
}

#endif

#endif


text:
/* */
var baseDifference = require('../internal/baseDifference'),
    isArrayLike = require('../internal/isArrayLike'),
    restParam = require('../function/restParam');
var without = restParam(function(array, values) {
  return isArrayLike(array) ? baseDifference(array, values) : [];
});
module.exports = without;