text:
package net.contra.jmd.transformers.generic;

import net.contra.jmd.util.GenericMethods;
import net.contra.jmd.util.LogHandler;
import net.contra.jmd.util.NonClassEntries;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.generic.*;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;

public class StringFixer {
    private static LogHandler logger = new LogHandler("StringFixer");
    private Map<String, ClassGen> cgs = new HashMap<String, ClassGen>();
    String JAR_NAME;
    boolean replacing = false;

    public StringFixer(String jarfile) throws Exception {
        File jar = new File(jarfile);
        JAR_NAME = jarfile;
        JarFile jf = new JarFile(jar);
        Enumeration<JarEntry> entries = jf.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();
            if (entry == null) {
                break;
            }

            if (entry.getName().endsWith(".class")) {
                ClassGen cg = new ClassGen(new ClassParser(jf.getInputStream(entry), entry.getName()).parse());
                cgs.put(cg.getClassName(), cg);
            } else {
                NonClassEntries.add(entry, jf.getInputStream(entry));
            }
        }
        jf.close();
    }

    public void removeBASA() {
        for (ClassGen cg : cgs.values()) {
            for (Method method : cg.getMethods()) {
                String type = "";
                MethodGen mg = new MethodGen(method, cg.getClassName(), cg.getConstantPool());
                InstructionList list = mg.getInstructionList();
                if (list == null) {
                    continue;
                }
                InstructionHandle[] handles = list.getInstructionHandles();
                int startLoc = -1;
                int endLoc = -1;
                int arrayLength = -1;
                for (int i = 0; i < handles.length; i++) {
                    if ((handles[i].getInstruction() instanceof NEW)
                            && (handles[i + 1].getInstruction() instanceof DUP)
                            && GenericMethods.isNumber(handles[i + 2].getInstruction())
                            && (handles[i + 3].getInstruction() instanceof NEWARRAY)) {
                        String newType = ((NEW) handles[i].getInstruction()).getLoadClassType(cg.getConstantPool()).toString();
                        type = ((NEWARRAY) handles[i + 3].getInstruction()).getType().toString();
                        logger.debug("Found new array conversion pattern: " + type + "->" + newType + " in " + cg.getClassName() + "." + method.getName());

                        //if(newType.equals("java.lang.String") && (type.equals("byte[]") || type.equals("char[]"))) {
                        if (newType.equals("java.lang.String") && type.contains("[]")) {
                            startLoc = i;
                            arrayLength = GenericMethods.getValueOfNumber(handles[i + 2].getInstruction(), cg.getConstantPool());
                            //logger.debug("Start Location for BASA replacement: " + startLoc);
                            //logger.debug("Length of Array: " + arrayLength);
                        }
                    }
                    if (startLoc >= 0 && arrayLength >= 1) {
                        if (handles.length > (i + 1)) {
                            if ((handles[i].getInstruction() instanceof BASTORE)
                                    && GenericMethods.isNumber(handles[i - 1].getInstruction())
                                    && GenericMethods.isNumber(handles[i - 2].getInstruction())
                                    && (handles[i - 3].getInstruction() instanceof DUP)) {
                                /*
                                                                                TODO: Also you need to make the endLoc INVOKESTATIC STRING<init> or something because it is leaving a trailing command and fucking up.
                                                                                */
                                if (GenericMethods.isCall(handles[i + 1].getInstruction())) {
                                    if (GenericMethods.getCallArgTypes(handles[i + 1].getInstruction(), cg.getConstantPool()) != null) {
                                        Type[] tp = GenericMethods.getCallArgTypes(handles[i + 1].getInstruction(), cg.getConstantPool());
                                        String lasttp = tp[tp.length - 1].toString();
                                        if (!lasttp.contains(type)) {
                                            int tendLoc = GenericMethods.getValueOfNumber(handles[i - 2].getInstruction(), cg.getConstantPool());
                                            if (tendLoc == (arrayLength - 1)) {
                                                endLoc = i;
                                                //logger.debug("End Location for BASA replacement: " + endLoc);
                                            }
                                        } else {
                                            logger.debug("Can't replace String(" + type + "), following method call has argument of same type");
                                            startLoc = -1;
                                            endLoc = -1;
                                            arrayLength = -1;
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if ((startLoc >= 0) && (endLoc >= 0) && (arrayLength > 1)
                            && (endLoc < handles.length)) {
                        byte[] stringBytes = new byte[arrayLength];
                        int loc = 0;
                        for (int x = startLoc; x <= endLoc; x++) {
                            if (GenericMethods.isNumber(handles[x].getInstruction())
                                    && GenericMethods.isNumber(handles[x + 1].getInstruction())
                                    && (handles[x + 2].getInstruction() instanceof BASTORE)
                                    && (GenericMethods.getValueOfNumber(handles[x].getInstruction(), cg.getConstantPool()) == loc)) {
                                stringBytes[loc] = (byte) GenericMethods.getValueOfNumber(handles[x + 1].getInstruction(), cg.getConstantPool());
                                loc++;
                                if (loc == stringBytes.length) {
                                    if (replacing) {
                                        int stringRef = cg.getConstantPool().addString(new String(stringBytes));
                                        LDC lc = new LDC(stringRef);
                                        handles[startLoc].setInstruction(lc);
                                        for (int z = startLoc + 1; z <= endLoc; z++) {
                                            NOP nop = new NOP();
                                            handles[z].setInstruction(nop);
                                        }
                                        logger.debug("Replaced conversion with string " + new String(stringBytes) + " in " + cg.getClassName() + "." + method.getName());
                                    } else {
                                        logger.debug("Found conversion, string:" + new String(stringBytes));
                                    }
                                    startLoc = -1;
                                    endLoc = -1;
                                    arrayLength = -1;
                                    type = "";
                                    mg.setInstructionList(list);
                                    mg.removeNOPs();
                                    mg.setMaxLocals();
                                    mg.setMaxStack();
                                    cg.replaceMethod(method, mg.getMethod());
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    public void dumpJar(String path) {
        FileOutputStream os;
        try {
            os = new FileOutputStream(new File(path));
        } catch (FileNotFoundException fnfe) {
            throw new RuntimeException("could not create file \"" + path + "\": " + fnfe);
        }
        JarOutputStream jos;

        try {
            jos = new JarOutputStream(os);
            for (ClassGen classIt : cgs.values()) {
                jos.putNextEntry(new JarEntry(classIt.getClassName().replace('.', '/') + ".class"));
                jos.write(classIt.getJavaClass().getBytes());
                jos.closeEntry();
                jos.flush();
            }
            for (JarEntry jbe : NonClassEntries.entries) {
                JarEntry destEntry = new JarEntry(jbe.getName());
                byte[] bite = IOUtils.toByteArray(NonClassEntries.ins.get(jbe));
                jos.putNextEntry(destEntry);
                jos.write(bite);
                jos.closeEntry();
            }
            jos.closeEntry();
            jos.close();
        } catch (IOException ioe) {
        }
    }

    public void transform() {
        logger.log("Generic String Fixer");
        logger.log("This hasn't been finished yet.");
        logger.log("Scanning/Replacing Strings hidden as byte arrays...");
        removeBASA();
        logger.log("Deobfuscation finished! Dumping jar...");
        dumpJar(JAR_NAME.replace(".jar", "") + "-deob.jar");
        logger.log("Operation Completed.");

    }
}


text:
module Spotify

  module Models

    class Copyright

      attr_reader :text, :type

      #
      # Sets the arguments to its variables.
      #
      # @param [Hash] args the arguments that will be placed on each variable.
      #
      # @return [Image] a copyright object.
      #
      def initialize(args = {})
        args = Hash(args).with_indifferent_access

        @text = args[:text]
        @type = args[:type]
      end

    end

  end

end

redpajama_set_name: RedPajamaGithub


text:
Heaven looks for information in the environments and tries to give feedback to chat rooms to everyone knows that code has been deployed. Right now it supports three networks.

All notifications run inside of [resque][3] jobs and need to define a deliver method.

### Example Provider

```ruby
module Heaven
  module Notifier
    class MyChat < Default
      def deliver(message)
      end
    end
  end
end
```

## SlackHQ

### Configuration

| Environmental Variables |                                                 |
|-------------------------|-------------------------------------------------|
| SLACK_WEBHOOK_URL       | A Slack Webhook URL from [incoming-webhook][21] section of Slack|
| SLACK_BOT_NAME          | The name to post to Slack as. Defaults to `hubot`|
| SLACK_BOT_ICON          | The icon to use for the notification. Defaults to `https://octodex.github.com/images/labtocat.png`|

## Campfire

### Configuration

| Environmental Variables |                                                 |
|-------------------------|-------------------------------------------------|
| CAMPFIRE_TOKEN          | A campfire API token from the 'my info' section of [campfire][7].                               |
| CAMPFIRE_SUBDOMAIN      | This subdomain for the campfire. For example https://atmos.campfirenow.com would be 'atmos'  |

## HipChat

### Configuration

| Environmental Variables |                                                 |
|-------------------------|-------------------------------------------------|
| HIPCHAT_TOKEN           | The notification token to send messages to hipchat. |
| HIPCHAT_ROOM            | The room to post deployment messages to.        |

## Commit Change Notifications

Successful deployments to any environment are always compared with the last
successful deployment to the production environment.

| Environmental Variables |                                                                                |
| ----------------------- | -------------------------------------------------------------------------------- |
| HEAVEN_NOTIFIER_DISPLAY_COMMITS       | Add to send a list of commit changes after a succesful deployment. |
| HEAVEN_NOTIFIER_DISPLAY_COMMITS_LIMIT | Limit the number of commits listed in the notification.            |

[1]: http://developer.github.com/v3/repos/deployments/
[2]: https://github.com/blog/1778-webhooks-level-up
[3]: https://github.com/resque/resque
[4]: https://gist.github.com/
[5]: https://developer.github.com/v3/repos/deployments/#create-a-deployment
[6]: https://developer.github.com/v3/repos/deployments/#create-a-deployment-status
[7]: https://campfirenow.com/
[8]: https://www.hipchat.com/
[9]: https://slack.com/
[10]: http://www.fabfile.org/
[11]: http://www.getchef.com/
[12]: http://puppetlabs.com/
[13]: https://devcenter.heroku.com/articles/build-and-release-using-the-api
[14]: https://developer.github.com/v3/repos/contents/#get-archive-link
[15]: http://capistranorb.com/
[16]: https://github.com/settings/applications
[17]: https://devcenter.heroku.com/articles/oauth#direct-authorization
[18]: https://www.phusionpassenger.com/
[19]: https://devcenter.heroku.com/articles/releases
[20]: https://github.com/atmos/hubot-deploy
[21]: https://my.slack.com/services/new/incoming-webhook
[23]: https://gist.github.com/Mumakil/1d184a3f06bcd087c5e2


text:
from distutils.core import setup

setup(name='langtools',
      version='1.0',
      description='Language Translation Tools',
      author='Peter Meckiffe',
      author_email='peterf.meckiffe@gmail.com',
      url='https://www.github.com/peterFran/LanguageListCreator',
      packages=['langtools'],
      package_data={'langtools': ['dictionary/dic/*', 'classify/tagger/*']}
     )


text:
angular.module('app').directive('appAdvertisements', ['$route', '$rootScope', function ($route, $rootScope) {
    return {
        restrict: "E",
        replace: true,
        scope: {

        },
        controller: ['$scope', 'AdvertisementService', function($scope, AdvertisementService){

            $scope.$on('searchComplete', function(e, args){
                $scope.advertisements = args.data;
                $scope.advertisementsAvailable = true;
                $scope.advertisementsPages = $scope.advertisements.pages;
            });

            $scope.$on('searchPageChange', function(e, args){
                $scope.advertisementPage(args.page);
            });

            $scope.advertisementPage = function(page){
                $scope.advertisementCurrentPage = page;
                $('#advertisement-pager li').each(function(index){
                    $('#advertisement-pager li').eq(index).removeClass('active');
                });
                $('#advertisement-pager li').eq(page).addClass('active');
                $rootScope.$broadcast('searchPage', {'page': page});
                $scope.page = page;
            };

            $scope.showBigImage = function(event){
                var el = event.target;
                var url = $(el).data('big-image');
                $('#advertisement-big-image').html('<img src="'+url+'" alt=""/>')
                $('#advertisement-big-image').show();
                $('#advertisement-big-image').css({'left': $(el).offset().left + $(el).width() + 50});
            };

            $scope.hideBigImage = function(){
                $('#advertisement-big-image').hide();
            };
        }],

        templateUrl: 'advertisements.html',
        link: function (scope, element, attrs) {
            scope.advertisements = [];
            scope.advertisementsAvailable = false;
            scope.advertisementCurrentPage = 0;
            scope.advertisementsPages = 0;
            scope.page = 0;
        }
    }
}]);


text:
<!doctype html>

  <meta charset="UTF-8">
  <title>Example - example-example33-production</title>

  <form name="form" class="css-form" novalidate>
    Name:
    <input type="text" ng-model="user.name" name="uName" required="" />

Tell us your name.

    E-mail:
    <input type="email" ng-model="user.email" name="uEmail" required="" />

      Tell us your email.
      This is not a valid email.

    Gender:
    <input type="radio" ng-model="user.gender" value="male" />male
    <input type="radio" ng-model="user.gender" value="female" />female

    <input type="checkbox" ng-model="user.agree" name="userAgree" required="" />

    I agree:
    <input ng-show="user.agree" type="text" ng-model="user.agreeSign" required="" />

Please agree and sign.

    <input type="button" ng-click="reset(form)" value="Reset" />
    <input type="submit" ng-click="update(user)" value="Save" />
  </form>


text:
import json

from .compat import six

def extra_as_internal(obj):
    if not hasattr(obj, 'extra'):
        return {}
    if isinstance(obj.extra, six.string_types):
        try:
            obj.extra = json.loads(obj.extra)
        except (TypeError, ValueError):
            pass
    return obj.extra

def get_extra(obj, attr_name, default=None):
    if not hasattr(obj, 'extra'):
        return default
    if isinstance(obj.extra, six.string_types):
        try:
            obj.extra = json.loads(obj.extra)
        except (TypeError, ValueError):
            return default
    return obj.extra.get(attr_name, default) if obj.extra else default


text:
#import "IRCCommands.h"
#import "IRCConnection.h"
#import "IRCClient.h"
#import "NSString+Methods.h"
#import "ConversationListViewController.h"

@implementation IRCCommands

+ (void)sendMessage:(NSString *)message toRecipient:(NSString *)recipient onClient:(IRCClient *)client
{

    /* The message may be multiple lines, we will split them by their line break and send them as inividual messages. */
    NSArray *lines = [message componentsSeparatedByString:@"\n"];
    for (NSString *line in lines) {
        if ([line length] > 0) {

            [client.connection send:[NSString stringWithFormat:@"PRIVMSG %@ :%@", recipient, line]];
            [IRCConversation getConversationOrCreate:recipient onClient:client withCompletionHandler:^(IRCConversation *conversation) {
                if (client.isConnected == NO) {
                    IRCMessage *messageObject = [[IRCMessage alloc] initWithMessage:@"Cannot send message (Not connected)"
                                                                             OfType:ET_ERROR
                                                                     inConversation:conversation
                                                                           bySender:nil
                                                                             atTime:[NSDate date]
                                                                           withTags:nil
                                                                    isServerMessage:YES
                                                                           onClient:client];
                    [Messages clientReceivedRecoverableErrorFromServer:messageObject];
                    return;
                }

                IRCUser *user = client.currentUserOnConnection;

                // Workaround to set channel status
                if ([conversation isKindOfClass:IRCChannel.class]) {
                    IRCChannel *channel = (IRCChannel *)conversation;
                    IRCUser *user2 = [IRCUser fromNickname:client.currentUserOnConnection.nick onChannel:channel];
                    if (user2.nick.length) {
                        user = user2;
                    }
                }

                IRCMessage *message = [[IRCMessage alloc] initWithMessage:line
                                                                   OfType:ET_PRIVMSG
                                                           inConversation:conversation
                                                                 bySender:user
                                                                   atTime:[NSDate date]
                                                                 withTags:[[NSDictionary alloc] init]
                                                          isServerMessage:NO
                                                                 onClient:client];

                [conversation addMessageToConversation:message];
            }];
        }
    }
}

+ (void)sendCTCPMessage:(NSString *)message toRecipient:(NSString *)recipient onClient:(IRCClient *)client
{
    [client.connection send:[NSString stringWithFormat:@"PRIVMSG %@ :\001%@\001", recipient, message]];
    [IRCConversation getConversationOrCreate:recipient onClient:client withCompletionHandler:^(IRCConversation *conversation) {
        IRCMessage *messageObj = [[IRCMessage alloc] initWithMessage:message
                                                           OfType:ET_CTCP
                                                   inConversation:conversation
                                                         bySender:client.currentUserOnConnection
                                                           atTime:[NSDate date]
                                                         withTags:[[NSDictionary alloc] init]
                                                  isServerMessage:NO
                                                         onClient:client];

        [conversation addMessageToConversation:messageObj];
    }];
}

+ (void)sendACTIONMessage:(NSString *)message toRecipient:(NSString *)recipient onClient:(IRCClient *)client
{
    [client.connection send:[NSString stringWithFormat:@"PRIVMSG %@ :\001ACTION %@\001", recipient, message]];
    [IRCConversation getConversationOrCreate:recipient onClient:client withCompletionHandler:^(IRCConversation *conversation) {
        IRCMessage *messageObj = [[IRCMessage alloc] initWithMessage:message
                                                           OfType:ET_ACTION
                                                   inConversation:conversation
                                                         bySender:client.currentUserOnConnection
                                                           atTime:[NSDate date]
                                                         withTags:[[NSDictionary alloc] init]
                                                  isServerMessage:NO
                                                         onClient:client];

        [conversation addMessageToConversation:messageObj];
    }];
}

+ (void)sendNotice:(NSString *)message toRecipient:(NSString *)recipient onClient:(IRCClient *)client
{
    [client.connection send:[NSString stringWithFormat:@"NOTICE %@ :%@", recipient, message]];
    [IRCConversation getConversationOrCreate:recipient onClient:client withCompletionHandler:^(IRCConversation *conversation) {
        IRCMessage *messageObj = [[IRCMessage alloc] initWithMessage:message
                                                           OfType:ET_NOTICE
                                                   inConversation:conversation
                                                         bySender:client.currentUserOnConnection
                                                           atTime:[NSDate date]
                                                         withTags:[[NSDictionary alloc] init]
                                                  isServerMessage:NO
                                                         onClient:client];

        [conversation addMessageToConversation:messageObj];
    }];
}

+ (void)sendCTCPReply:(NSString *)message toRecipient:(NSString *)recipient onClient:(IRCClient *)client
{
    [client.connection send:[NSString stringWithFormat:@"NOTICE %@ :\001%@\001", recipient, message]];
    [IRCConversation getConversationOrCreate:recipient onClient:client withCompletionHandler:^(IRCConversation *conversation) {
        IRCMessage *messageObj = [[IRCMessage alloc] initWithMessage:message
                                                              OfType:ET_CTCPREPLY
                                                      inConversation:conversation
                                                            bySender:client.currentUserOnConnection
                                                              atTime:[NSDate date]
                                                            withTags:[[NSDictionary alloc] init]
                                                     isServerMessage:NO
                                                            onClient:client];

        [conversation addMessageToConversation:messageObj];
    }];
}

+ (void)changeNicknameToNick:(NSString *)nickname onClient:(IRCClient *)client
{
    [client.connection send:[NSString stringWithFormat:@"NICK %@", nickname]];
}

+ (void)leaveChannel:(NSString *)channel withMessage:(NSString *)message onClient:(IRCClient *)client
{
    if (message == nil || [message length] == 0) {
        message = client.configuration.channelDepartMessage;
    }
    [client.connection send:[NSString stringWithFormat:@"PART %@ :%@", channel, message]];
}

+ (void)joinChannel:(NSString *)channel onClient:(IRCClient *)client
{
    [client.connection send:[NSString stringWithFormat:@"JOIN %@", channel]];
}

+ (void)rejoinChannel:(NSString *)channel withMessage:(NSString *)message onClient:(IRCClient *)client
{
    [IRCCommands leaveChannel:channel withMessage:message onClient:client];
    [IRCCommands joinChannel:channel onClient:client];
}

+ (void)kickUser:(NSString *)nickname onChannel:(IRCChannel *)channel withMessage:(NSString *)message
{
    if (message == nil || [message length] == 0) {
        //TODO use a default kick message.
    }
    [channel.client.connection send:[NSString stringWithFormat:@"KICK %@ %@ %@", channel.name, nickname, message]];
}

+ (void)banUser:(NSString *)nickname onChannel:(IRCChannel *)channel
{
    NSString *banMask;
    if ([nickname isValidWildcardIgnoreMask]) {
        /* The input seems to already be a hostmask. We will use it as it is. */
        banMask = nickname;
    } else {
        IRCUser *bannedUser = [IRCUser fromNickname:nickname onChannel:channel];
        if (bannedUser != nil) {
            /* We found the user in the userlist, we will use their information to ban the hostname. */
            banMask = [NSString stringWithFormat:@"*!*@%@", bannedUser.hostname];
        } else {
            /* This user dosen't seem to be online so we can't find their hostname. We will just do a general ban on their nick */
            banMask = [NSString stringWithFormat:@"%@!*@*", nickname];
        }
    }

    /* Set the ban. */
    [channel.client.connection send:[NSString stringWithFormat:@"MODE %@ +b %@", channel.name, banMask]];
}

+ (void)setTopic:(NSString *)topic onChannel:(NSString *)channel onClient:(IRCClient *)client
{
    [client.connection send:[NSString stringWithFormat:@"TOPIC %@ :%@", channel, topic]];
}

+ (void)setMode:(NSString *)mode onRecepient:(NSString *)recepient onClient:(IRCClient *)client
{
    [client.connection send:[NSString stringWithFormat:@"MODE %@ %@", recepient, mode]];
}

+ (void)kickBanUser:(NSString *)nickname onChannel:(IRCChannel *)channel withMessage:(NSString *)message
{
    [IRCCommands banUser:nickname onChannel:channel];
    [IRCCommands kickUser:nickname onChannel:channel withMessage:message];
}

+ (void)sendServerPasswordForClient:(IRCClient *)client
{
    /* Send server password if applicable */
    if ([client.configuration.serverPasswordReference length] > 0) {
        NSString *password = [SSKeychain passwordForService:@"conversation" account:client.configuration.serverPasswordReference];
        if (password != nil && [password length] > 0) {
            [client.connection send:[NSString stringWithFormat:@"PASS %@", password]];
        } else {
            [client outputToConsole:[NSString stringWithFormat:@"A server password reference was found but no password: %@", client.configuration.serverPasswordReference]];
        }
    }
}

+ (void)closeConversation:(id)conversation onClient:(IRCClient *)client
{
    ConversationListViewController *controller = ((AppDelegate *)[UIApplication sharedApplication].delegate).conversationsController;
    [controller deleteConversationWithIdentifier:[[(IRCConversation*)conversation configuration] uniqueIdentifier]];
}

+ (void)onTimer:(float)seconds runCommand:(NSString *)command inConversation:(IRCConversation *)conversation
{
    /* Create the invocation for the command */
    SEL selector = @selector(performCommand:inConversation:);
    NSMethodSignature *signature = [self methodSignatureForSelector:selector];
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
    [invocation setTarget:[InputCommands class]];
    [invocation setSelector:selector];
    [invocation setArgument:&command atIndex:2];
    [invocation setArgument:&conversation atIndex:3];

    /* Set the timer to run the invocation */
    [NSTimer scheduledTimerWithTimeInterval:seconds invocation:invocation repeats:NO];
}

@end


text:
/**
 */
package subkdm.kdmObjects;

import org.eclipse.emf.common.util.EList;

/**
 *
 * A representation of the model object 'Code Model'.
 *
 *
 *

 * The following features are supported:
 *

 *
{@link subkdm.kdmObjects.CodeModel#getCodeElement Code Element}

 *
{@link subkdm.kdmObjects.CodeModel#getName Name}

 *

 *

 *
 * @see subkdm.kdmObjects.KdmObjectsPackage#getCodeModel()
 * @model
 * @generated
 */
public interface CodeModel extends ModelElement {
	/**
	 * Returns the value of the 'Code Element' containment reference list.
	 * The list contents are of type {@link subkdm.kdmObjects.ModelElement}.
	 *
	 *

	 * If the meaning of the 'Code Element' containment reference list isn't clear,
	 * there really should be more of a description here...
	 *

	 *
	 * @return the value of the 'Code Element' containment reference list.
	 * @see subkdm.kdmObjects.KdmObjectsPackage#getCodeModel_CodeElement()
	 * @model containment="true"
	 * @generated
	 */
	EList<ModelElement> getCodeElement();

	/**
	 * Returns the value of the 'Name' attribute.
	 *
	 *

	 * If the meaning of the 'Name' attribute isn't clear,
	 * there really should be more of a description here...
	 *

	 *
	 * @return the value of the 'Name' attribute.
	 * @see #setName(String)
	 * @see subkdm.kdmObjects.KdmObjectsPackage#getCodeModel_Name()
	 * @model
	 * @generated
	 */
	String getName();

	/**
	 * Sets the value of the '{@link subkdm.kdmObjects.CodeModel#getName Name}' attribute.
	 *
	 *
	 * @param value the new value of the 'Name' attribute.
	 * @see #getName()
	 * @generated
	 */
	void setName(String value);

} // CodeModel


text:
import json
from itertools import chain
from random import randint
from time import sleep

from django.core.management.base import BaseCommand
from pykafka import KafkaClient

from ips.config import get_config

class Command(BaseCommand):
    help = 'Monitor telemetry from workers'

    def handle(self, *args, **options):
        kafka_host = None

        while not kafka_host:
            kafka_host = get_config('KAFKA_HOST')

            if not kafka_host:
                print 'Unable to get Kafka host address, will try again.'
                sleep(randint(2, 5))

        client = KafkaClient(hosts=kafka_host)
        topic = client.topics['metrics']

        consumer = topic.get_simple_consumer()
        stats = {}

        for message in consumer:
            if message is None:
                continue

            if message.value and '{' in message.value:
                try:
                    line = json.loads(message.value)
                except Exception as exc:
                    print exc
                    continue
            else:
                continue

            if type(line) is not dict or \
               not 'Host' in line or \
               not line['Host'] or \
               not line['Host'].strip():
                continue

            if not line['Host'] in stats:
                stats[line['Host']] = {}

            for key in line.keys():
                # Skip known keys with non-integer values
                if key in ('Host', 'Timestamp'):
                    continue

                # Only sum up values that are integers
                try:
                    stats[line['Host']][key] = int(line[key])
                except (KeyError, ValueError) as exc:
                    pass

            # Aggregate telemetry
            keys = set(list(chain(*[stats[host].keys()
                                    for host in stats])))

            aggregates = {key: 0 for key in keys}

            for host in stats:
                for key in keys:
                    if key in stats[host]:
                        aggregates[key] = aggregates[key] + stats[host][key]

            # Print the keys sorted by name so hopefully you can eye-ball
            # changing values better.
            print json.dumps(aggregates, sort_keys=True)


text:
module Gramz
  module CFG
    class Rule
      class Alternative
        attr_reader :left_symbol
        def initialize(lsym, alts)
          @left_symbol = lsym
          @ary = alts
        end

        def [](i)
          @ary[i]
        end

        include Enumerable
        def each(&blk)
          @ary.each { |a| yield a }
        end
      end
    end
  end
end


text:
const sub = require('../nested-sub/sub');
console.log('yo from sub');


text:
// Copyright JS Foundation and other contributors, http://js.foundation
//
// 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.

var local = 0;

switch(0) { /* This switch forces a pre-scanner run. */
default:

  function f(a = (5, local = 6),
             b = ((5 + function(a = 6) { return a }() * 3)),
             c,
             d = true ? 1 : 2)
  {
    return "" + a + ", " + b + ", " + c + ", " + d;
  }

  assert(f() === "6, 23, undefined, 1");
  assert(local === 6);

  var obj = {
    f: function(a = [10,,20],
                b,
                c = Math.cos(0),
                d)
    {
      return "" + a + ", " + b + ", " + c + ", " + d;
    }
  };

  assert(obj.f() === "10,,20, undefined, 1, undefined");

  function g(a, b = (local = 7)) { }

  local = 0;
  g();
  assert(local === 7);

  local = 0;
  g(0);
  assert(local === 7);

  local = 0;
  g(0, undefined);
  assert(local === 7);

  local = 0;
  g(0, null);
  assert(local === 0);

  local = 0;
  g(0, false);
  assert(local === 0);
  break;
}

function CheckSyntaxError(str)
{
  try {
    eval(str);
    assert(false);
  } catch (e) {
    assert(e instanceof SyntaxError);
  }
}

CheckSyntaxError('function x(a += 5) {}');
CheckSyntaxError('function x(a =, b) {}');
CheckSyntaxError('function x(a = (b) {}');
CheckSyntaxError('function x(a, a = 5) {}');
CheckSyntaxError('function x(a = 5, a) {}');


text:
namespace net {
class WebSocketChannel;
}  // namespace net

namespace mojo {
class NetworkContext;
class WebSocketReadQueue;

// Forms a bridge between the WebSocket mojo interface and the net::WebSocket
// implementation.
class WebSocketImpl : public WebSocket {
 public:
  WebSocketImpl(NetworkContext* context,
                scoped_ptr<mojo::AppRefCount> app_refcount,
                InterfaceRequest<WebSocket> request);
  ~WebSocketImpl() override;

 private:
  // WebSocket methods:
  void Connect(const String& url,
               Array<String> protocols,
               const String& origin,
               ScopedDataPipeConsumerHandle send_stream,
               WebSocketClientPtr client) override;
  void Send(bool fin, WebSocket::MessageType type, uint32_t num_bytes) override;
  void FlowControl(int64_t quota) override;
  void Close(uint16_t code, const String& reason) override;

  // Called with the data to send once it has been read from |send_stream_|.
  void DidReadFromSendStream(bool fin,
                             WebSocket::MessageType type,
                             uint32_t num_bytes,
                             const char* data);

  // The channel we use to send events to the network.
  scoped_ptr<net::WebSocketChannel> channel_;
  ScopedDataPipeConsumerHandle send_stream_;
  scoped_ptr<WebSocketReadQueue> read_queue_;
  NetworkContext* context_;
  scoped_ptr<mojo::AppRefCount> app_refcount_;
  StrongBinding<WebSocket> binding_;
};

}  // namespace mojo

#endif  // MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_


text:
Asynchronous gearman library based on asyncio implemented in pure python.

## Asynchonous Worker

### Function Registration as Worker

#### Static Registration

Once the worker gets connected to the gearman daemon, it registers all the given functions. In the example below, the only registered function is `sleep`.

```python
async def sleep(job_info):
    sleep_time = int(job_info.workload)
    print(job_info)
    print('Sleeping for ', sleep_time, ' seconds')
    await asyncio.sleep(sleep_time)
    print('Sleep is done')

async def connect_worker(loop, addr, port):
    factory = lambda: Worker(sleep, loop=loop)
    _, worker = await loop.create_connection(factory, addr, port)
    return worker
```
#### Dynamic Registration

When necessary, registration on runtime (with optional custom name) is possible too.

```python
worker.register_function(_sleep, 'sleep')
```

### Registered Function Calls

Each function assigned to a particular job must accept a sole argument `JobInfo`. It is a custom data structure which represents the job. E.g.:

```python
JobInfo(handle='H:ev-ubuntu:38', function='sleep', uuid=None, reducer=None, workload='5')
```

If needed, partial functions could be used for extra argument(s). The function, passed to `Worker` could be `(function, function_name)` pair.

```python
async def sleep(loop, job_info):
    pass

async def connect_worker(loop, addr, port):
    func = functools.partial(sleep, loop)
    factory = lambda: Worker((func, 'sleep'), loop=loop)
    _, worker = await loop.create_connection(factory, addr, port)
    return worker
```

For running more than one worker in parallel see `examples/` directory.

## Asynchonous Client

Creating client is as simple as creating tcp client.

```python
async def connect(loop, addr, port):
    client = Client()
    await loop.create_connection(lambda: client, addr, port)
    return client
```

Submitted job returns custom data structure `JobCreated` with a `handle` property which could be used to trace the job.

```python
job_created = await client.submit_job('sleep', '5')
print(job_created) # JobCreated(handle='H:ev-ubuntu:38')
```

`asyncio.Future` returning `wait_job` method could be used to asynchronously block the current context until job is finished.

```python
def job_is_complete(job_created, f):
    print('Created Job ', job_created, ' is finished')

f = client.wait_job(job_created.handle)
f.add_done_callback(partial(job_is_complete, job_created))
await f
```

For more and complete examples, please see `examples/` directory.


text:
/*
 * @(#)ErrorHandlerWrapper.java
 *
 * @project     : org.opinf.jlib.std
 * @package     : org.fugerit.java.core.xml.sax.eh
 * @creation	: 15-dic-2004 23.10.51
 * @release		: xxxx.xx.xx
 */
package org.fugerit.java.core.xml.sax.eh;

import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

/**
 *

 *
 * @author  Matteo Franci a.k.a. Fugerit
 */
public class ErrorHandlerWrapper implements ErrorHandler {

    /**
     *
Crea un nuovo ErrorHandlerWrapper

     *
     *
     */
    public ErrorHandlerWrapper(ErrorHandler handler) {
        super();
        this.wrappedErrorHandler = handler;
    }

    private ErrorHandler wrappedErrorHandler;

    /* (non-Javadoc)
     * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
     */
    public void error(SAXParseException arg0) throws SAXException {
        this.getWrappedErrorHandler().error(arg0);
    }

    /* (non-Javadoc)
     * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
     */
    public void fatalError(SAXParseException arg0) throws SAXException {
        this.getWrappedErrorHandler().fatalError(arg0);
    }

    /* (non-Javadoc)
     * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
     */
    public void warning(SAXParseException arg0) throws SAXException {
        this.getWrappedErrorHandler().warning(arg0);
    }

    /**
     *
Restituisce il valore di wrappedErrorHandler.

     *
     * @return il valore di wrappedErrorHandler.
     */
    public ErrorHandler getWrappedErrorHandler() {
        return wrappedErrorHandler;
    }

    /**
     *
Imposta wrappedErrorHandler.

     *
     * @param wrappedErrorHandler il wrappedErrorHandler da impostare.
     */
    public void setWrappedErrorHandler(ErrorHandler wrappedHandler) {
        this.wrappedErrorHandler = wrappedHandler;
    }

}


text:
package hudson.util;

import java.util.Locale;
import java.util.StringTokenizer;

/**
 * Immutable representation of a dot or '-'-separated digits (such as "1.0.1" or "1.0-52").
 *
 * {@link VersionNumber}s are {@link Comparable}.
 *
 *
Special tokens

 *

 * We allow a component to be not just a number, but also "ea", "ea1", "ea2".
 * "ea" is treated as "ea0", and eaN < M for any M > 0.
 *
 *

 * '*' is also allowed as a component, and '*' > M for any M > 0.
 *
 *

 * 'SNAPSHOT' is also allowed as a component, and "N.SNAPSHOT" is interpreted as "N-1.*"
 *
 *

 * 2.0.* > 2.0.1 > 2.0.1-SNAPSHOT > 2.0.0.99 > 2.0.0 > 2.0.ea > 2.0
 *

 *
 * @author
 *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
 * @since 1.139
 */
public class VersionNumber implements Comparable<VersionNumber> {
    private final int[] digits;

    /**
     * Parses a string like "1.0.2" into the version number.
     *
     * @throws IllegalArgumentException
     *      if the parsing fails.
     */
    public VersionNumber( String num ) {
        StringTokenizer tokens = new StringTokenizer(num,".-");
        digits = new int[tokens.countTokens()];
        if(digits.length<2)
            throw new IllegalArgumentException("Failed to parse "+num+" as version number");

        int i=0;
        while( tokens.hasMoreTokens() ) {
            String token = tokens.nextToken().toLowerCase(Locale.ENGLISH);
            if(token.equals("*")) {
                digits[i++] = 1000;
            } else
            if(token.startsWith("snapshot")) {
                digits[i-1]--;
                digits[i++] = 1000;
                break;
            } else
            if(token.startsWith("ea")) {
                if(token.length()==2)
                    digits[i++] = -1000;    // just "ea"
                else
                    digits[i++] = -1000 + Integer.parseInt(token.substring(2)); // "eaNNN"
            } else {
                digits[i++] = Integer.parseInt(token);
            }
        }
    }

    public int digit(int idx) {
        return digits[idx];
    }

    @Override
    public String toString() {
        StringBuilder buf = new StringBuilder();
        for( int i=0; i<digits.length; i++ ) {
            if(i!=0)    buf.append('.');
            buf.append( Integer.toString(digits[i]) );
        }
        return buf.toString();
    }

    public boolean isOlderThan( VersionNumber rhs ) {
        return compareTo(rhs)<0;
    }

    public boolean isNewerThan( VersionNumber rhs ) {
        return compareTo(rhs)>0;
    }

    @Override
    public boolean equals( Object o ) {
        if (!(o instanceof VersionNumber))  return false;
        return compareTo((VersionNumber)o)==0;
    }

    @Override
    public int hashCode() {
        int x=0;
        for (int i : digits)
            x = (x << 1) | i;
        return x;
    }

    public int compareTo(VersionNumber rhs) {
        for( int i=0; ; i++ ) {
            if( i==this.digits.length && i==rhs.digits.length )
                return 0;   // equals
            if( i==this.digits.length )
                return -1;  // rhs is larger
            if( i==rhs.digits.length )
                return 1;

            int r = this.digits[i] - rhs.digits[i];
            if(r!=0)    return r;
        }
    }
}


text:
module LayoutTests
  extend ActiveSupport::Testing::Declarative

  private
  def test_that_menu_is_present_on(action)
    sign_in users(:user_with_wallet_1)
    get action
    assert_select 'a', 'user_with_wallet_1@budget.shellyapp.com'
    assert_select 'a', I18n.t('header.incomes')
    assert_select 'a', I18n.t('header.expenses')
    assert_select 'a', I18n.t('header.wallets')
    assert_select 'a', I18n.t('header.members')
    assert_select 'a', I18n.t('header.edit_profile')
    assert_select 'li.visible-phone a', I18n.t('header.logout')
    assert_select 'li.hidden-phone a', I18n.t('header.logout')
  end

  def test_that_should_contain_message_with_actual_balance_on(action)
    sign_in users(:user_with_wallet_2)
    get action
    assert_select 'ul.pull-right' do
      assert_select 'a', "#{I18n.t('header.balance')}: #{number_to_currency(800)}"
    end
  end

  def test_that_footer_should_contain_add_this_buttons(action)
    sign_in users(:user_with_wallet_1)
    get action
    assert_select 'a.addthis_button_facebook_like'
    assert_select 'a.addthis_button_tweet'
    assert_select 'a.addthis_button_pinterest_pinit'
    assert_select 'a.addthis_counter'
    assert_select 'a.addthis_pill_style'
  end

  def test_of_presences_low_balance_warning(action)
    sign_in users(:user_with_low_balance)
    get action
    assert_select 'li#actual_balance.warning', count: 1
  end

  def test_of_not_presences_low_balance_warning(action)
    sign_in users(:user_without_low_balance)
    get action
    assert_select 'li#actual_balance.warning', count: 0
  end

  def test_that_guest_will_be_redirect(action)
    get action
    assert_response 302
  end

  def test_that_edit_and_delete_buttons_are_present
    get :index
    assert_select 'tbody tr td a.hidden-phone', I18n.t('edit')
    assert_select 'tbody tr td a.hidden-phone', I18n.t('delete')
  end
end


text:
<?php

//get the group id from the url parameters
$groupID = $_GET["group_id"];

global $wpdb;

//get the table name we want to work with
$rooms_options_table = $wpdb->prefix . "bookme_rooms_options";
$group_options_table = $wpdb->prefix . "bookme_group_options";

//get all the rooms associate to this group id
$selectSQL = $wpdb->get_results( "SELECT * FROM $rooms_options_table WHERE groupId = '$groupID'" );

//take the num of the rooms + 1
$numOfRooms  = sizeof($selectSQL) + 1;

//initialize default values when creating new room
$defaultRoomName = "Room " . $numOfRooms;
$defaultCapacity = 1;
$defaultServices = '';
$defaultIsActive = 1;
$defaultActiveDays = '';
$defaultDescription = '';

//execute the insert new row query
$wpdb->insert($rooms_options_table, array(
    'roomId' => '',
    'groupId' => $groupID,
    'roomName' => $defaultRoomName,
    'capacity' => $defaultCapacity,
    'services' => $defaultServices,
    'isActive' => $defaultIsActive,
    'activeDays' => $defaultActiveDays,
    'description' => $defaultDescription

));

//create array of the data we want to insert to specific row
$dataArray = array(
        'numOfRooms' => $numOfRooms
);

//create array of the condition to get the specific row
$whereArray = array( 'id' => $groupID);

//execute the update function for saving data
$wpdb->update( $group_options_table, $dataArray, $whereArray);

$siteURL = get_site_url()."/wp-admin/admin.php";

?>

    <script>

        var siteURL = <?php echo json_encode($siteURL);?>;

        window.location.replace(siteURL +"?page=wp_book_me&group_id=" + <?php echo $groupID; ?> + "&edit_rooms=true");

    </script>


text:
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
    std::string delims = std::string(1, delim);
    tokenize(s, elems, delims);
    return elems;
}

std::vector<std::string> split(const std::string &s, char delim) {
    std::vector<std::string> elems;
    return split(s, delim, elems);
}

std::vector<std::string> &split(const std::string &s, const std::string& delims, std::vector<std::string> &elems) {
    tokenize(s, elems, delims);
    return elems;
}

std::vector<std::string> split(const std::string &s, const std::string& delims) {
    std::vector<std::string> elems;
    return split(s, delims, elems);
}


text:
require 'facets/enumerable/probability'

module Enumerable

  # Shannon's entropy for an array - returns the average
  # bits per symbol required to encode the array.
  # Lower values mean less "entropy" - i.e. less unique
  # information in the array.
  #
  #   %w{ a b c d e e e }.entropy  #=>
  #
  #   CREDIT: Derek

  def entropy
    arr = to_a
    probHash = arr.probability
    # h is the Shannon entropy of the array
    h = -1.to_f * probHash.keys.inject(0.to_f) do |sum, i|
      sum + (probHash[i] * (Math.log(probHash[i])/Math.log(2.to_f)))
    end
    h
  end

  # Returns the maximum possible Shannon entropy of the array
  # with given size assuming that it is an "order-0" source
  # (each element is selected independently of the next).
  #
  #   CREDIT: Derek

  def ideal_entropy
    arr = to_a
    unitProb = 1.0.to_f / arr.size.to_f
    (-1.to_f * arr.size.to_f * unitProb * Math.log(unitProb)/Math.log(2.to_f))
  end

end


text:
package TerrariaClone;

public interface StartingWirecProvider {
    boolean[] getStartingWirec();
 }


text:
{{hero.name}}

<hero-detail ... [hero]="selectedHero"></hero-detail>

...

...

<hero-detail *ngIf="selectedHero != null" ...></hero-detail>


text:
const REFRESH_BADGE = 'refresh_badge'
const SAVE_TAGS = 'save_tags'

// data requests
const GET_TAGS = 'get_tags'
const GET_ALL_USER_PROJECTS = 'get_all_user_projects'

// events
const JUST_STARRED = 'just_starred'

// cache
const CACHE_ALL_REPOS = 'all_repos'

declare interface IUserProject {
  user: string
  project: string
}

declare interface IRepo extends IUserProject {
  name?: string
  language?: string
  tags?: string[]
  isTagged?: boolean
}

function isStarsPage(tabUrl: string) {
  return /^https?:\/\/(www\.)?github.com\/stars(\?.*)?$/.test(tabUrl)
}

function isProjectPage(tabUrl: string): IUserProject {
  let match = ('' + tabUrl).match(/^https?:\/\/(www\.)?github.com\/([^\/]+)\/([^\/]+)/)

  if (match && match.length === 4 && match[0] && match[2] && match[3]) {
    return {
      user: match[2],
      project: match[3]
    } as IUserProject
  }
  else {
    return null
  }
}

class DataStorage {
  loaded: Promise<{}>
  projects: any

  constructor() {
    this.loaded = new Promise((resolve, reject) => {
      try {
        chrome.storage.local.get(null, projects => {
          this.projects = projects || {}
          resolve()
        })
      }
      catch (err) {
        reject(err)
      }
    })
  }

  save() {
    return this.loaded.then(() => {
      chrome.storage.local.set(this.projects, () => {
        // cool, do nothing
      })
    })
  }

  getProject(name) {
    return this.loaded.then(() => {
      let project = this.projects[name]

      if (!project) {
        project = this.projects[name] = {tags: []}
      }
      return project
    })
  }

  getAllProjects() {
    return this.loaded.then(() => this.projects)
  }

  getProjectTags(name) {
    return this.loaded.then(() =>
      this.getProject(name)
        .then(project => project.tags || [])
    )
  }

  getProjectTagCount(name) {
    return this.loaded.then(() =>
      this.getProject(name).then(project =>
        project.tags ? project.tags.length : 0
      )
    )
  }

  setProjectTags(name, tags) {
    return this.loaded.then(() =>
      this.getProject(name).then(project => {
        project.tags = tags
        return this.save()
      })
    )
  }
}

class DataCache {
  cache = {}

  get(key) {
    let c = this.cache[key]
    return !c ? undefined : c.val
  }

  set(key, val) {
    this.cache[key] = {val}
  }
}

// downloads or gets cached projects - both starred and tagged
function getAllUserProjects(username): Promise<Array<IRepo>> {
  let cachedRepos = cache.get(CACHE_ALL_REPOS)
  return new Promise((resolve, reject) => {
    if (cachedRepos !== undefined)
      return cachedRepos

    downloadStarredRepos(username)
      .then(resolve)
      .catch(reject)
  })
}

function downloadStarredRepos(username) {
  return new Promise((resolve, reject) =>
    storage.getAllProjects().then(projects => {
      const PER_PAGE = 100
      let pageNo = 0
      let repos = []

      function downloadFurther() {
        pageNo++
        xhrJson('GET', `https://api.github.com/users/${username}/starred?page=${pageNo}&per_page=100`)
          .then((data: any[]) => {
            for (let repo of data) {
              const name = `${repo.owner.login}/${repo.name}`
              const project = projects[name]
              const isTagged = !!project && !!project.tags && project.tags.length > 0
              repos.push({
                name,
                repo: repo.name,
                user: repo.owner.login,
                language: repo.language,
                tags: (project && project.tags) ? project.tags : [],
                isTagged
              })
            }

            if (repos.length % PER_PAGE === 0)
              downloadFurther()
            else
              resolve(repos)
          })
          .catch(reject)
      }
      downloadFurther()
    })
  ).then(repos => {
    cache.set(CACHE_ALL_REPOS, repos)
    return repos
  })
}

function getStarPageUsername() {
  return executeCode(() => {
    const el = document.querySelector('.header-nav-current-user .css-truncate-target')
    return el.textContent
  })
}

function xhrJson(method, url, data = undefined) {
  return new Promise((resolve, reject) => {
    let x = new XMLHttpRequest()
    x.open(method, url)
    x.responseType = 'json'
    x.onload = () => {
      var response = x.response;
      if (!response) {
        reject('no response')
        return
      }

      resolve(response)
    }
    x.onerror = () => reject('network error')
    x.send()
  })
}

function $d(...args) {
  let query = arguments[arguments.length == 1 ? 0 : 1];
  let el = arguments.length == 1 ? document : arguments[0];
  return el.querySelector(query);
}
function $da() {
  var query = arguments[arguments.length == 1 ? 0 : 1];
  var el = arguments.length == 1 ? document : arguments[0];
  return el.querySelectorAll(query);
}
function $id(id) {
  return document.getElementById(id);
}

function executeCode(func): Promise<any> {
  return new Promise((resolve, reject) => {
    try {
      chrome.tabs.executeScript({
        code: '(' + func.toString() + ')()'
      }, (result) => {
        setTimeout(() => resolve(result[0]))
      })
    } catch (err) {
      setTimeout(() => reject(err))
    }
  })
}

function checkIsRepoPageStarred(): Promise<boolean> {
  return executeCode(() => {
    let btn = document.querySelector('form.unstarred button') as HTMLElement
    let isStarred = !btn.offsetHeight

    return isStarred
  })
}

// globals
let storage = new DataStorage
let cache = new DataCache


text:
angular.module('MyApp')
  .controller('CartCtrl', function($scope, Items) {
    $scope.items = Items.all();
  })
;


text:
<!DOCTYPE html>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">

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

  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />

  <title>
      The Remains of Amelia Earhart—The Appendix
    </title>
  <meta name="description" content="Ryan Harper shares a poem on mystery, doubt—and Amelia Earhart.">

  <link rel="stylesheet" href="/scripts/fancybox/jquery.fancybox.css">

  <link rel="stylesheet" href="/css/main.css">

    <link rel="stylesheet" href="/css/issue-1-1.css">

  <link rel="canonical" href="http://theappendix.net/issues/2012/12/the-remains-of-amelia-earhart">
  <link rel="alternate" type="application/rss+xml" title="The Appendix" href="http://theappendix.net/feed.xml">

        The End?—December 2012—Vol. 1, No. 1

Issues

Blog

Contributors

About

The Remains of Amelia Earhart

        By Ryan Harper –

    Published December 31, 2012

It is not that I do not believe

in mystery.  Just this morning I sat

blank and primitive under diurnal

shade, all recessive, nameless

the soft warming friction, dark on light.

Something untouchable blows overhead:

cloud of leaf imprintable;

the head is sensible to its effects.

It is that instead I believed

all uncompleted possibilities sealed;

we know all we would know

in time—the final stone had been thrown

into the final cave, the final ancient scrolls

procured, all that remained, translation.  Having flown

in the sun longer than the sphinx,

we knew all we would not know,

wise to being none the wiser, never.

So when they found personal effects—

freckle removal cream (her natural weakness;

no one knew upon her vanishing

she still anointed herself with vanishing)

a woman's shoe, the tobacco her navigator

preferred—the difficult article of faith was not

Amelia is found but Amelia, so long

visible, just now has been found

What does such an article mean

for the man of panoptic faith—the man

of global positioning, astrology finally turned over,

the sky's chart of the earth compasses-marked,

fashioned with planes and satellites

and silicon seerstones; the man of commissioned

soldiers looking grainy-green through night vision

goggles into the desert for enemies of his state;

the man of all healings' eventuality, looking grainy-green

at the golden tablature of toxicology reports,

at men as Christmas trees walking; the man of wide,

ballistic, compassionate precision; the man

of universal application, the phrenological sweep

of his finger across his handheld screen,

divining his world no bigger than a hazelnut?

Is not this thing in my right hand

All that can be seen has been should

be seen.  Saint Anthony lies dead

on some island—doesn't he?  Pray

tell, Amelia: How long after the crash

must a grounded flying woman hold

her personal effects before the sun

or lesser searchlights bleach articles

to artifacts to facts to nothing? Why

has this your atlas been so difficult

for searching men in searchable times?

Why have men searched for you,

the lost lady adventurer, like a city

of gold from whom the blemishes

like darkened pixels have vanished?  Whose pacific

tide fogs your landing strip? Whose the right

of way? What kind of faith is yours,

blessed Saint Amelia, your pacific

elusion of god knows

how many flyovers since yours

the most visible vanishing—yours the lesson

in instrumental failure, yours the call

to the man of panoptic faith

to consider new articles and become

newly sensible to the inconclusive?

**Ryan Harper** is a Ph.D candidate in Princeton University's Department of Religion. He teaches at Swarthmore College.

Elsewhere in this issue…

              1.
              Letters to The Appendix

              2.
              Letter from the Editors

              3.
              Prophecy of Benjamin,
The Anti-Christ

              4.
              Amazonia 1952: FOUND

              5.
              Time and the Maya Apocalypse: Guatemala, 1982 and 2012

              6.
              The Remains of Amelia Earhart

              7.
              Calypso's Island: A Short History of the Apocalypse

              8.
              Death by Chamomile? The Alimentary End of Henry Granville Naimbana

              9.
              Death of a Sailor: A Novel History of Murder in 1830s New York, War and Forbidden Love in the Age of Napoleon, and Captivity and Freedom in the Last Days of the Atlantic Slave Trade; in many, many Parts.

              10.
              Whose Apocalypse? A New Mercantile Meaning of the "The End" in the New World circa 1600

              11.
              Maximón, a Maya Saint in Sunglasses

              12.
              Local History: The Vulture Mine and Vulture City–Wickenburg, Arizona

              13.
              Local History Excerpt: I Rode with Red Scout: When Yellowstone's Early Tourists Stumbled into Chief Joseph and the Nez Perce's Final War

              14.
              Edward Emerson Barnard and Sylvester Graham

              15.
              Interview with Adam Hochschild: The Imaginary Cemetery

              16.
              The Ambulatory Archive: Santa Muerte Tattoos as Historical Sources

              17.
              Why Did J.P. Morgan's Prize Bulldog Die of Shame?

              18.
              Box Office Bomb: "The Beginning or the End" (1947)

              19.
              Sürgün

              20.
              Days of Future Present: Marvel Comics and "the Most Intricate Fictional Narrative in the History of the World"

              21.
              Trinity: A Graphic History of the First Atomic Bomb

              22.
              "On the Island of Thieves"

              23.
              The Appendix, Appendixed.

      Home

      Issues

      Blog

      Contributors

      Index

      About

      The Appendix was published between 2012 and 2015, released under the CC-BY license, and hosted on GitHub.

      Publication details are available on the colophon.


text:
package io.druid.query.groupby.epinephelinae;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import io.druid.java.util.common.CloseableIterators;
import io.druid.java.util.common.io.Closer;
import io.druid.java.util.common.logger.Logger;
import io.druid.java.util.common.parsers.CloseableIterator;
import io.druid.query.BaseQuery;
import io.druid.query.aggregation.AggregatorFactory;
import io.druid.query.groupby.orderby.DefaultLimitSpec;
import io.druid.segment.ColumnSelectorFactory;
import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * Grouper based around a single underlying {@link BufferHashGrouper}. Not thread-safe.
 *
 * When the underlying grouper is full, its contents are sorted and written to temporary files using "spillMapper".
 */
public class SpillingGrouper<KeyType> implements Grouper<KeyType>
{
  private static final Logger log = new Logger(SpillingGrouper.class);

  private final Grouper<KeyType> grouper;
  private static final AggregateResult DISK_FULL = AggregateResult.failure(
      "Not enough disk space to execute this query. Try raising druid.query.groupBy.maxOnDiskStorage."
  );
  private final KeySerde<KeyType> keySerde;
  private final LimitedTemporaryStorage temporaryStorage;
  private final ObjectMapper spillMapper;
  private final AggregatorFactory[] aggregatorFactories;
  private final Comparator<Grouper.Entry<KeyType>> keyObjComparator;
  private final Comparator<Grouper.Entry<KeyType>> defaultOrderKeyObjComparator;

  private final List<File> files = Lists.newArrayList();
  private final List<File> dictionaryFiles = Lists.newArrayList();
  private final boolean sortHasNonGroupingFields;

  private boolean spillingAllowed = false;

  public SpillingGrouper(
      final Supplier<ByteBuffer> bufferSupplier,
      final KeySerdeFactory<KeyType> keySerdeFactory,
      final ColumnSelectorFactory columnSelectorFactory,
      final AggregatorFactory[] aggregatorFactories,
      final int bufferGrouperMaxSize,
      final float bufferGrouperMaxLoadFactor,
      final int bufferGrouperInitialBuckets,
      final LimitedTemporaryStorage temporaryStorage,
      final ObjectMapper spillMapper,
      final boolean spillingAllowed,
      final DefaultLimitSpec limitSpec,
      final boolean sortHasNonGroupingFields,
      final int mergeBufferSize
  )
  {
    this.keySerde = keySerdeFactory.factorize();
    this.keyObjComparator = keySerdeFactory.objectComparator(false);
    this.defaultOrderKeyObjComparator = keySerdeFactory.objectComparator(true);
    if (limitSpec != null) {
      LimitedBufferHashGrouper<KeyType> limitGrouper = new LimitedBufferHashGrouper<>(
          bufferSupplier,
          keySerde,
          columnSelectorFactory,
          aggregatorFactories,
          bufferGrouperMaxSize,
          bufferGrouperMaxLoadFactor,
          bufferGrouperInitialBuckets,
          limitSpec.getLimit(),
          sortHasNonGroupingFields
      );
      // if configured buffer size is too small to support limit push down, don't apply that optimization
      if (!limitGrouper.validateBufferCapacity(mergeBufferSize)) {
        if (sortHasNonGroupingFields) {
          log.debug("Ignoring forceLimitPushDown, insufficient buffer capacity.");
        }
        // sortHasNonGroupingFields can only be true here if the user specified forceLimitPushDown
        // in the query context. Result merging requires that all results are sorted by the same
        // ordering where all ordering fields are contained in the grouping key.
        // If sortHasNonGroupingFields is true, we use the default ordering that sorts by all grouping key fields
        // with lexicographic ascending order.
        // If sortHasNonGroupingFields is false, then the OrderBy fields are all in the grouping key, so we
        // can use that ordering.
        this.grouper = new BufferHashGrouper<>(
            bufferSupplier,
            keySerde,
            columnSelectorFactory,
            aggregatorFactories,
            bufferGrouperMaxSize,
            bufferGrouperMaxLoadFactor,
            bufferGrouperInitialBuckets,
            sortHasNonGroupingFields
        );
      } else {
        this.grouper = limitGrouper;
      }
    } else {
      this.grouper = new BufferHashGrouper<>(
          bufferSupplier,
          keySerde,
          columnSelectorFactory,
          aggregatorFactories,
          bufferGrouperMaxSize,
          bufferGrouperMaxLoadFactor,
          bufferGrouperInitialBuckets,
          true
      );
    }
    this.aggregatorFactories = aggregatorFactories;
    this.temporaryStorage = temporaryStorage;
    this.spillMapper = spillMapper;
    this.spillingAllowed = spillingAllowed;
    this.sortHasNonGroupingFields = sortHasNonGroupingFields;
  }

  @Override
  public void init()
  {
    grouper.init();
  }

  @Override
  public boolean isInitialized()
  {
    return grouper.isInitialized();
  }

  @Override
  public AggregateResult aggregate(KeyType key, int keyHash)
  {
    final AggregateResult result = grouper.aggregate(key, keyHash);

    if (result.isOk() || !spillingAllowed || temporaryStorage.maxSize() <= 0) {
      return result;
    } else {
      // Warning: this can potentially block up a processing thread for a while.
      try {
        spill();
      }
      catch (TemporaryStorageFullException e) {
        return DISK_FULL;
      }
      catch (IOException e) {
        throw Throwables.propagate(e);
      }

      // Try again.
      return grouper.aggregate(key, keyHash);
    }
  }

  @Override
  public void reset()
  {
    grouper.reset();
    deleteFiles();
  }

  @Override
  public void close()
  {
    grouper.close();
    deleteFiles();
  }

  /**
   * Returns a dictionary of string keys added to this grouper.  Note that the dictionary of keySerde is spilled on
   * local storage whenever the inner grouper is spilled.  If there are spilled dictionaries, this method loads them
   * from disk and returns a merged dictionary.
   *
   * @return a dictionary which is a list of unique strings
   */
  public List<String> mergeAndGetDictionary()
  {
    final Set<String> mergedDictionary = new HashSet<>();
    mergedDictionary.addAll(keySerde.getDictionary());

    for (File dictFile : dictionaryFiles) {
      try (
          final MappingIterator<String> dictIterator = spillMapper.readValues(
              spillMapper.getFactory().createParser(new LZ4BlockInputStream(new FileInputStream(dictFile))),
              spillMapper.getTypeFactory().constructType(String.class)
          )
      ) {
        while (dictIterator.hasNext()) {
          mergedDictionary.add(dictIterator.next());
        }
      }
      catch (IOException e) {
        throw new RuntimeException(e);
      }
    }

    return new ArrayList<>(mergedDictionary);
  }

  public void setSpillingAllowed(final boolean spillingAllowed)
  {
    this.spillingAllowed = spillingAllowed;
  }

  @Override
  public CloseableIterator<Entry<KeyType>> iterator(final boolean sorted)
  {
    final List<CloseableIterator<Entry<KeyType>>> iterators = new ArrayList<>(1 + files.size());

    iterators.add(grouper.iterator(sorted));

    final Closer closer = Closer.create();
    for (final File file : files) {
      final MappingIterator<Entry<KeyType>> fileIterator = read(file, keySerde.keyClazz());
      iterators.add(
          CloseableIterators.withEmptyBaggage(
              Iterators.transform(
                  fileIterator,
                  new Function<Entry<KeyType>, Entry<KeyType>>()
                  {
                    @Override
                    public Entry<KeyType> apply(Entry<KeyType> entry)
                    {
                      final Object[] deserializedValues = new Object[entry.getValues().length];
                      for (int i = 0; i < deserializedValues.length; i++) {
                        deserializedValues[i] = aggregatorFactories[i].deserialize(entry.getValues()[i]);
                        if (deserializedValues[i] instanceof Integer) {
                          // Hack to satisfy the groupBy unit tests; perhaps we could do better by adjusting Jackson config.
                          deserializedValues[i] = ((Integer) deserializedValues[i]).longValue();
                        }
                      }
                      return new Entry<>(entry.getKey(), deserializedValues);
                    }
                  }
              )
          )
      );
      closer.register(fileIterator);
    }

    final Iterator<Entry<KeyType>> baseIterator;
    if (sortHasNonGroupingFields) {
      baseIterator = CloseableIterators.mergeSorted(iterators, defaultOrderKeyObjComparator);
    } else {
      baseIterator = sorted ?
                     CloseableIterators.mergeSorted(iterators, keyObjComparator) :
                     CloseableIterators.concat(iterators);
    }

    return CloseableIterators.wrap(baseIterator, closer);
  }

  private void spill() throws IOException
  {
    try (CloseableIterator<Entry<KeyType>> iterator = grouper.iterator(true)) {
      files.add(spill(iterator));
      dictionaryFiles.add(spill(keySerde.getDictionary().iterator()));

      grouper.reset();
    }
  }

  private <T> File spill(Iterator<T> iterator) throws IOException
  {
    try (
        final LimitedTemporaryStorage.LimitedOutputStream out = temporaryStorage.createFile();
        final LZ4BlockOutputStream compressedOut = new LZ4BlockOutputStream(out);
        final JsonGenerator jsonGenerator = spillMapper.getFactory().createGenerator(compressedOut)
    ) {
      while (iterator.hasNext()) {
        BaseQuery.checkInterrupted();

        jsonGenerator.writeObject(iterator.next());
      }

      return out.getFile();
    }
  }

  private MappingIterator<Entry<KeyType>> read(final File file, final Class<KeyType> keyClazz)
  {
    try {
      return spillMapper.readValues(
          spillMapper.getFactory().createParser(new LZ4BlockInputStream(new FileInputStream(file))),
          spillMapper.getTypeFactory().constructParametricType(Entry.class, keyClazz)
      );
    }
    catch (IOException e) {
      throw Throwables.propagate(e);
    }
  }

  private void deleteFiles()
  {
    for (final File file : files) {
      temporaryStorage.delete(file);
    }
    files.clear();
  }
}


text:
package android.text;

import com.google.android.collect.Lists;

import android.test.MoreAsserts;
import android.os.Parcel;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.style.StyleSpan;
import android.text.util.Rfc822Token;
import android.text.util.Rfc822Tokenizer;
import android.view.View;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import junit.framework.TestCase;

/**
 * TextUtilsTest tests {@link TextUtils}.
 */
public class TextUtilsTest extends TestCase {

    @SmallTest
    public void testBasic() throws Exception {
        assertEquals("", TextUtils.concat());
        assertEquals("foo", TextUtils.concat("foo"));
        assertEquals("foobar", TextUtils.concat("foo", "bar"));
        assertEquals("foobarbaz", TextUtils.concat("foo", "bar", "baz"));

        SpannableString foo = new SpannableString("foo");
        foo.setSpan("foo", 1, 2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);

        SpannableString bar = new SpannableString("bar");
        bar.setSpan("bar", 1, 2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);

        SpannableString baz = new SpannableString("baz");
        baz.setSpan("baz", 1, 2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);

        assertEquals("foo", TextUtils.concat(foo).toString());
        assertEquals("foobar", TextUtils.concat(foo, bar).toString());
        assertEquals("foobarbaz", TextUtils.concat(foo, bar, baz).toString());

        assertEquals(1, ((Spanned) TextUtils.concat(foo)).getSpanStart("foo"));

        assertEquals(1, ((Spanned) TextUtils.concat(foo, bar)).getSpanStart("foo"));
        assertEquals(4, ((Spanned) TextUtils.concat(foo, bar)).getSpanStart("bar"));

        assertEquals(1, ((Spanned) TextUtils.concat(foo, bar, baz)).getSpanStart("foo"));
        assertEquals(4, ((Spanned) TextUtils.concat(foo, bar, baz)).getSpanStart("bar"));
        assertEquals(7, ((Spanned) TextUtils.concat(foo, bar, baz)).getSpanStart("baz"));

        assertTrue(TextUtils.concat("foo", "bar") instanceof String);
        assertTrue(TextUtils.concat(foo, bar) instanceof SpannedString);
    }

    @SmallTest
    public void testTemplateString() throws Exception {
        CharSequence result;

        result = TextUtils.expandTemplate("This is a ^1 of the ^2 broadcast ^3.",
                                          "test", "emergency", "system");
        assertEquals("This is a test of the emergency broadcast system.",
                     result.toString());

        result = TextUtils.expandTemplate("^^^1^^^2^3^a^1^^b^^^c",
                                          "one", "two", "three");
        assertEquals("^one^twothree^aone^b^^c",
                     result.toString());

        result = TextUtils.expandTemplate("^");
        assertEquals("^", result.toString());

        result = TextUtils.expandTemplate("^^");
        assertEquals("^", result.toString());

        result = TextUtils.expandTemplate("^^^");
        assertEquals("^^", result.toString());

        result = TextUtils.expandTemplate("shorter ^1 values ^2.", "a", "");
        assertEquals("shorter a values .", result.toString());

        try {
            TextUtils.expandTemplate("Only ^1 value given, but ^2 used.", "foo");
            fail();
        } catch (IllegalArgumentException e) {
        }

        try {
            TextUtils.expandTemplate("^1 value given, and ^0 used.", "foo");
            fail();
        } catch (IllegalArgumentException e) {
        }

        result = TextUtils.expandTemplate("^1 value given, and ^9 used.",
                                          "one", "two", "three", "four", "five",
                                          "six", "seven", "eight", "nine");
        assertEquals("one value given, and nine used.", result.toString());

        try {
            TextUtils.expandTemplate("^1 value given, and ^10 used.",
                                     "one", "two", "three", "four", "five",
                                     "six", "seven", "eight", "nine", "ten");
            fail();
        } catch (IllegalArgumentException e) {
        }

        // putting carets in the values: expansion is not recursive.

        result = TextUtils.expandTemplate("^2", "foo", "^^");
        assertEquals("^^", result.toString());

        result = TextUtils.expandTemplate("^^2", "foo", "1");
        assertEquals("^2", result.toString());

        result = TextUtils.expandTemplate("^1", "value with ^2 in it", "foo");
        assertEquals("value with ^2 in it", result.toString());
    }

    /** Fail unless text+spans contains a span 'spanName' with the given start and end. */
    private void checkContains(Spanned text, String[] spans, String spanName,
                               int start, int end) throws Exception {
        for (String i: spans) {
            if (i.equals(spanName)) {
                assertEquals(start, text.getSpanStart(i));
                assertEquals(end, text.getSpanEnd(i));
                return;
            }
        }
        fail();
    }

    @SmallTest
    public void testTemplateSpan() throws Exception {
        SpannableString template;
        Spanned result;
        String[] spans;

        // ordinary replacement

        template = new SpannableString("a^1b");
        template.setSpan("before", 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        template.setSpan("during", 1, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        template.setSpan("after", 3, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        template.setSpan("during+after", 1, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        result = (Spanned) TextUtils.expandTemplate(template, "foo");
        assertEquals(5, result.length());
        spans = result.getSpans(0, result.length(), String.class);

        // value is one character longer, so span endpoints should change.
        assertEquals(4, spans.length);
        checkContains(result, spans, "before", 0, 1);
        checkContains(result, spans, "during", 1, 4);
        checkContains(result, spans, "after", 4, 5);
        checkContains(result, spans, "during+after", 1, 5);

        // replacement with empty string

        result = (Spanned) TextUtils.expandTemplate(template, "");
        assertEquals(2, result.length());
        spans = result.getSpans(0, result.length(), String.class);

        // the "during" span should disappear.
        assertEquals(3, spans.length);
        checkContains(result, spans, "before", 0, 1);
        checkContains(result, spans, "after", 1, 2);
        checkContains(result, spans, "during+after", 1, 2);
    }

    @SmallTest
    public void testStringSplitterSimple() {
        stringSplitterTestHelper("a,b,cde", new String[] {"a", "b", "cde"});
    }

    @SmallTest
    public void testStringSplitterEmpty() {
        stringSplitterTestHelper("", new String[] {});
    }

    @SmallTest
    public void testStringSplitterWithLeadingEmptyString() {
        stringSplitterTestHelper(",a,b,cde", new String[] {"", "a", "b", "cde"});
    }

    @SmallTest
    public void testStringSplitterWithInternalEmptyString() {
        stringSplitterTestHelper("a,b,,cde", new String[] {"a", "b", "", "cde"});
    }

    @SmallTest
    public void testStringSplitterWithTrailingEmptyString() {
        // A single trailing emtpy string should be ignored.
        stringSplitterTestHelper("a,b,cde,", new String[] {"a", "b", "cde"});
    }

    private void stringSplitterTestHelper(String string, String[] expectedStrings) {
        TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
        splitter.setString(string);
        List<String> strings = Lists.newArrayList();
        for (String s : splitter) {
            strings.add(s);
        }
        MoreAsserts.assertEquals(expectedStrings, strings.toArray(new String[]{}));
    }

    @SmallTest
    public void testTrim() {
        String[] strings = { "abc", " abc", "  abc", "abc ", "abc  ",
                             " abc ", "  abc  ", "\nabc\n", "\nabc", "abc\n" };

        for (String s : strings) {
            assertEquals(s.trim().length(), TextUtils.getTrimmedLength(s));
        }
    }

    @SmallTest
    public void testRfc822TokenizerFullAddress() {
        Rfc822Token[] tokens = Rfc822Tokenizer.tokenize("Foo Bar (something) <foo@google.com>");
        assertNotNull(tokens);
        assertEquals(1, tokens.length);
        assertEquals("foo@google.com", tokens[0].getAddress());
        assertEquals("Foo Bar", tokens[0].getName());
        assertEquals("something",tokens[0].getComment());
    }

    @SmallTest
    public void testRfc822TokenizeItemWithError() {
        Rfc822Token[] tokens = Rfc822Tokenizer.tokenize("\"Foo Bar\\");
        assertNotNull(tokens);
        assertEquals(1, tokens.length);
        assertEquals("Foo Bar", tokens[0].getAddress());
    }

    @SmallTest
    public void testRfc822FindToken() {
        Rfc822Tokenizer tokenizer = new Rfc822Tokenizer();
        //                0           1         2           3         4
        //                0 1234 56789012345678901234 5678 90123456789012345
        String address = "\"Foo\" <foo@google.com>, \"Bar\" <bar@google.com>";
        assertEquals(0, tokenizer.findTokenStart(address, 21));
        assertEquals(22, tokenizer.findTokenEnd(address, 21));
        assertEquals(24, tokenizer.findTokenStart(address, 25));
        assertEquals(46, tokenizer.findTokenEnd(address, 25));
    }

    @SmallTest
    public void testRfc822FindTokenWithError() {
        assertEquals(9, new Rfc822Tokenizer().findTokenEnd("\"Foo Bar\\", 0));
    }

    @LargeTest
    public void testEllipsize() {
        CharSequence s1 = "The quick brown fox jumps over \u00FEhe lazy dog.";
        CharSequence s2 = new Wrapper(s1);
        Spannable s3 = new SpannableString(s1);
        s3.setSpan(new StyleSpan(0), 5, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        TextPaint p = new TextPaint();
        p.setFlags(p.getFlags() & ~p.DEV_KERN_TEXT_FLAG);

        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < 3; j++) {
                TextUtils.TruncateAt kind = null;

                switch (j) {
                case 0:
                    kind = TextUtils.TruncateAt.START;
                    break;

                case 1:
                    kind = TextUtils.TruncateAt.END;
                    break;

                case 2:
                    kind = TextUtils.TruncateAt.MIDDLE;
                    break;
                }

                String out1 = TextUtils.ellipsize(s1, p, i, kind).toString();
                String out2 = TextUtils.ellipsize(s2, p, i, kind).toString();
                String out3 = TextUtils.ellipsize(s3, p, i, kind).toString();

                String keep1 = TextUtils.ellipsize(s1, p, i, kind, true, null).toString();
                String keep2 = TextUtils.ellipsize(s2, p, i, kind, true, null).toString();
                String keep3 = TextUtils.ellipsize(s3, p, i, kind, true, null).toString();

                String trim1 = keep1.replace("\uFEFF", "");

                // Are all normal output strings identical?
                assertEquals("wid " + i + " pass " + j, out1, out2);
                assertEquals("wid " + i + " pass " + j, out2, out3);

                // Are preserved output strings identical?
                assertEquals("wid " + i + " pass " + j, keep1, keep2);
                assertEquals("wid " + i + " pass " + j, keep2, keep3);

                // Does trimming padding from preserved yield normal?
                assertEquals("wid " + i + " pass " + j, out1, trim1);

                // Did preserved output strings preserve length?
                assertEquals("wid " + i + " pass " + j, keep1.length(), s1.length());

                // Does the output string actually fit in the space?
                assertTrue("wid " + i + " pass " + j, p.measureText(out1) <= i);

                // Is the padded output the same width as trimmed output?
                assertTrue("wid " + i + " pass " + j, p.measureText(keep1) == p.measureText(out1));
            }
        }
    }

    @SmallTest
    public void testDelimitedStringContains() {
        assertFalse(TextUtils.delimitedStringContains("", ',', null));
        assertFalse(TextUtils.delimitedStringContains(null, ',', ""));
        // Whole match
        assertTrue(TextUtils.delimitedStringContains("gps", ',', "gps"));
        // At beginning.
        assertTrue(TextUtils.delimitedStringContains("gps,gpsx,network,mock", ',', "gps"));
        assertTrue(TextUtils.delimitedStringContains("gps,network,mock", ',', "gps"));
        // In middle, both without, before & after a false match.
        assertTrue(TextUtils.delimitedStringContains("network,gps,mock", ',', "gps"));
        assertTrue(TextUtils.delimitedStringContains("network,gps,gpsx,mock", ',', "gps"));
        assertTrue(TextUtils.delimitedStringContains("network,gpsx,gps,mock", ',', "gps"));
        // At the end.
        assertTrue(TextUtils.delimitedStringContains("network,mock,gps", ',', "gps"));
        assertTrue(TextUtils.delimitedStringContains("network,mock,gpsx,gps", ',', "gps"));
        // Not present (but with a false match)
        assertFalse(TextUtils.delimitedStringContains("network,mock,gpsx", ',', "gps"));
    }

    @SmallTest
    public void testCharSequenceCreator() {
        Parcel p = Parcel.obtain();
        TextUtils.writeToParcel(null, p, 0);
        CharSequence text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
        assertNull("null CharSequence should generate null from parcel", text);
        p = Parcel.obtain();
        TextUtils.writeToParcel("test", p, 0);
        p.setDataPosition(0);
        text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
        assertEquals("conversion to/from parcel failed", "test", text);
    }

    @SmallTest
    public void testCharSequenceCreatorNull() {
        Parcel p;
        CharSequence text;
        p = Parcel.obtain();
        TextUtils.writeToParcel(null, p, 0);
        p.setDataPosition(0);
        text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
        assertNull("null CharSequence should generate null from parcel", text);
    }

    @SmallTest
    public void testCharSequenceCreatorSpannable() {
        Parcel p;
        CharSequence text;
        p = Parcel.obtain();
        TextUtils.writeToParcel(new SpannableString("test"), p, 0);
        p.setDataPosition(0);
        text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
        assertEquals("conversion to/from parcel failed", "test", text.toString());
    }

    @SmallTest
    public void testCharSequenceCreatorString() {
        Parcel p;
        CharSequence text;
        p = Parcel.obtain();
        TextUtils.writeToParcel("test", p, 0);
        p.setDataPosition(0);
        text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
        assertEquals("conversion to/from parcel failed", "test", text.toString());
    }

    /**
     * CharSequence wrapper for testing the cases where text is copied into
     * a char array instead of working from a String or a Spanned.
     */
    private static class Wrapper implements CharSequence {
        private CharSequence mString;

        public Wrapper(CharSequence s) {
            mString = s;
        }

        public int length() {
            return mString.length();
        }

        public char charAt(int off) {
            return mString.charAt(off);
        }

        @Override
        public String toString() {
            return mString.toString();
        }

        public CharSequence subSequence(int start, int end) {
            return new Wrapper(mString.subSequence(start, end));
        }
    }

    @LargeTest
    public void testRemoveEmptySpans() {
        MockSpanned spanned = new MockSpanned();

        spanned.test();
        spanned.addSpan().test();
        spanned.addSpan().test();
        spanned.addSpan().test();
        spanned.addEmptySpan().test();
        spanned.addSpan().test();
        spanned.addEmptySpan().test();
        spanned.addEmptySpan().test();
        spanned.addSpan().test();

        spanned.clear();
        spanned.addEmptySpan().test();
        spanned.addEmptySpan().test();
        spanned.addEmptySpan().test();
        spanned.addSpan().test();
        spanned.addEmptySpan().test();
        spanned.addSpan().test();

        spanned.clear();
        spanned.addSpan().test();
        spanned.addEmptySpan().test();
        spanned.addSpan().test();
        spanned.addEmptySpan().test();
        spanned.addSpan().test();
        spanned.addSpan().test();
    }

    protected static class MockSpanned implements Spanned {

        private List<Object> allSpans = new ArrayList<Object>();
        private List<Object> nonEmptySpans = new ArrayList<Object>();

        public void clear() {
            allSpans.clear();
            nonEmptySpans.clear();
        }

        public MockSpanned addSpan() {
            Object o = new Object();
            allSpans.add(o);
            nonEmptySpans.add(o);
            return this;
        }

        public MockSpanned addEmptySpan() {
            Object o = new Object();
            allSpans.add(o);
            return this;
        }

        public void test() {
            Object[] nonEmpty = TextUtils.removeEmptySpans(allSpans.toArray(), this, Object.class);
            assertEquals("Mismatched array size", nonEmptySpans.size(), nonEmpty.length);
            for (int i=0; i<nonEmpty.length; i++) {
                assertEquals("Span differ", nonEmptySpans.get(i), nonEmpty[i]);
            }
        }

        public char charAt(int arg0) {
            return 0;
        }

        public int length() {
            return 0;
        }

        public CharSequence subSequence(int arg0, int arg1) {
            return null;
        }

        @Override
        public <T> T[] getSpans(int start, int end, Class<T> type) {
            return null;
        }

        @Override
        public int getSpanStart(Object tag) {
            return 0;
        }

        @Override
        public int getSpanEnd(Object tag) {
            return nonEmptySpans.contains(tag) ? 1 : 0;
        }

        @Override
        public int getSpanFlags(Object tag) {
            return 0;
        }

        @Override
        public int nextSpanTransition(int start, int limit, Class type) {
            return 0;
        }
    }

    @SmallTest
    public void testGetLayoutDirectionFromLocale() {
        assertEquals(View.LAYOUT_DIRECTION_LTR, TextUtils.getLayoutDirectionFromLocale(null));
        assertEquals(View.LAYOUT_DIRECTION_LTR,
                TextUtils.getLayoutDirectionFromLocale(Locale.ROOT));
        assertEquals(View.LAYOUT_DIRECTION_LTR,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("en")));
        assertEquals(View.LAYOUT_DIRECTION_LTR,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("en-US")));
        assertEquals(View.LAYOUT_DIRECTION_LTR,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("az")));
        assertEquals(View.LAYOUT_DIRECTION_LTR,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("az-AZ")));
        assertEquals(View.LAYOUT_DIRECTION_LTR,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("az-Latn")));
        assertEquals(View.LAYOUT_DIRECTION_LTR,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("en-EG")));
        assertEquals(View.LAYOUT_DIRECTION_LTR,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("ar-Latn")));

        assertEquals(View.LAYOUT_DIRECTION_RTL,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("ar")));
        assertEquals(View.LAYOUT_DIRECTION_RTL,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("fa")));
        assertEquals(View.LAYOUT_DIRECTION_RTL,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("he")));
        assertEquals(View.LAYOUT_DIRECTION_RTL,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("iw")));
        assertEquals(View.LAYOUT_DIRECTION_RTL,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("ur")));
        assertEquals(View.LAYOUT_DIRECTION_RTL,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("dv")));
        assertEquals(View.LAYOUT_DIRECTION_RTL,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("az-Arab")));
        assertEquals(View.LAYOUT_DIRECTION_RTL,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("az-IR")));
        assertEquals(View.LAYOUT_DIRECTION_RTL,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("fa-US")));
        assertEquals(View.LAYOUT_DIRECTION_RTL,
                TextUtils.getLayoutDirectionFromLocale(Locale.forLanguageTag("tr-Arab")));
    }
}