text:
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Globalization;
//using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging.Internal;

namespace Microsoft.Framework.Logging
{
    /// <summary>
    /// ILogger extension methods for common scenarios.
    /// </summary>
    public static class LoggerExtensions
    {
        //------------------------------------------DEBUG------------------------------------------//

        /// <summary>
        /// Writes a debug log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="data">The message to log.</param>
        // FYI, this field is called data because naming it message triggers CA1303 and CA2204 for callers.
        public static void LogDebug(this ILogger logger, string data)
        {
            logger.Log(LogLevel.Debug, 0, data, null, MessageFormatter);
        }

        /// <summary>
        /// Writes a debug log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="data">The message to log.</param>
        public static void LogDebug(this ILogger logger, int eventId, string data)
        {
            logger.Log(LogLevel.Debug, eventId, data, null, MessageFormatter);
        }

        /// <summary>
        /// Formats and writes a debug log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="format">Format string of the log message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        public static void LogDebug(this ILogger logger, string format, params object[] args)
        {
            logger.Log(LogLevel.Debug, 0, new FormattedLogValues(format, args), null, MessageFormatter);
        }

        /// <summary>
        /// Formats and writes a debug log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="format">Format string of the log message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        public static void LogDebug(this ILogger logger, int eventId, string format, params object[] args)
        {
            logger.Log(LogLevel.Debug, eventId, new FormattedLogValues(format, args), null, MessageFormatter);
        }

        /// <summary>
        /// Formats the given <see cref="ILogValues"/> and writes a debug log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="state">The <see cref="ILogValues"/> to write.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogDebug(
            this ILogger logger,
            ILogValues state,
            Exception error = null)
        {
            logger.Log(LogLevel.Debug, state, error);
        }

        /// <summary>
        /// Formats the given <see cref="ILogValues"/> and writes a debug log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="state">The <see cref="ILogValues"/> to write.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogDebug(
            this ILogger logger,
            int eventId,
            ILogValues state,
            Exception error = null)
        {
            logger.LogWithEvent(LogLevel.Debug, eventId, state, error);
        }

        //------------------------------------------VERBOSE------------------------------------------//

        /// <summary>
        /// Writes a verbose log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="data">The message to log.</param>
        // FYI, this field is called data because naming it message triggers CA1303 and CA2204 for callers.
        public static void LogVerbose(this ILogger logger, string data)
        {
            logger.Log(LogLevel.Verbose, 0, data, null, MessageFormatter);
        }

        /// <summary>
        /// Writes a verbose log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="data">The message to log.</param>
        public static void LogVerbose(this ILogger logger, int eventId, string data)
        {
            logger.Log(LogLevel.Verbose, eventId, data, null, MessageFormatter);
        }

        /// <summary>
        /// Formats and writes a verbose log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="format">Format string of the log message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        public static void LogVerbose(this ILogger logger, string format, params object[] args)
        {
            logger.Log(LogLevel.Verbose, 0, new FormattedLogValues(format, args), null, MessageFormatter);
        }

        /// <summary>
        /// Formats and writes a verbose log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="format">Format string of the log message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        public static void LogVerbose(this ILogger logger, int eventId, string format, params object[] args)
        {
            logger.Log(LogLevel.Verbose, eventId, new FormattedLogValues(format, args), null, MessageFormatter);
        }

        /// <summary>
        /// Formats the given <see cref="ILogValues"/> and writes a verbose log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="state">The <see cref="ILogValues"/> to write.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogVerbose(
            this ILogger logger,
            ILogValues state,
            Exception error = null)
        {
            logger.Log(LogLevel.Verbose, state, error);
        }

        /// <summary>
        /// Formats the given <see cref="ILogValues"/> and writes a verbose log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="state">The <see cref="ILogValues"/> to write.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogVerbose(
            this ILogger logger,
            int eventId,
            ILogValues state,
            Exception error = null)
        {
            logger.LogWithEvent(LogLevel.Verbose, eventId, state, error);
        }

        //------------------------------------------INFORMATION------------------------------------------//

        /// <summary>
        /// Writes an informational log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="message">The message to log.</param>
        public static void LogInformation(this ILogger logger, string message)
        {
            logger.Log(LogLevel.Information, 0, message, null, MessageFormatter);
        }

        /// <summary>
        /// Writes an informational log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="message">The message to log.</param>
        public static void LogInformation(this ILogger logger, int eventId, string message)
        {
            logger.Log(LogLevel.Information, eventId, message, null, MessageFormatter);
        }

        /// <summary>
        /// Formats and writes an informational log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="format">Format string of the log message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        public static void LogInformation(this ILogger logger, string format, params object[] args)
        {
            logger.Log(LogLevel.Information, 0, new FormattedLogValues(format, args), null, MessageFormatter);
        }

        /// <summary>
        /// Formats and writes an informational log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="format">Format string of the log message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        public static void LogInformation(this ILogger logger, int eventId, string format, params object[] args)
        {
            logger.Log(LogLevel.Information, eventId, new FormattedLogValues(format, args), null, MessageFormatter);
        }

        /// <summary>
        /// Formats the given <see cref="ILogValues"/> and writes an informational log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="state">The <see cref="ILogValues"/> to write.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogInformation(
            this ILogger logger,
            ILogValues state,
            Exception error = null)
        {
            logger.Log(LogLevel.Information, state, error);
        }

        /// <summary>
        /// Formats the given <see cref="ILogValues"/> and writes an informational log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="state">The <see cref="ILogValues"/> to write.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogInformation(
            this ILogger logger,
            int eventId,
            ILogValues state,
            Exception error = null)
        {
            logger.LogWithEvent(LogLevel.Information, eventId, state, error);
        }

        //------------------------------------------WARNING------------------------------------------//

        /// <summary>
        /// Writes a warning log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="message">The message to log.</param>
        public static void LogWarning(this ILogger logger, string message)
        {
            logger.Log(LogLevel.Warning, 0, message, null, MessageFormatter);
        }

        /// <summary>
        /// Writes a warning log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="message">The message to log.</param>
        public static void LogWarning(this ILogger logger, int eventId, string message)
        {
            logger.Log(LogLevel.Warning, eventId, message, null, MessageFormatter);
        }

        /// <summary>
        /// Formats and writes a warning log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="format">Format string of the log message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        public static void LogWarning(this ILogger logger, string format, params object[] args)
        {
            logger.Log(LogLevel.Warning, 0, new FormattedLogValues(format, args), null, MessageFormatter);
        }

        /// <summary>
        /// Formats and writes a warning log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="format">Format string of the log message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        public static void LogWarning(this ILogger logger, int eventId, string format, params object[] args)
        {
            logger.Log(LogLevel.Warning, eventId, new FormattedLogValues(format, args), null, MessageFormatter);
        }

        /// <summary>
        /// Formats the given message and error and writes a warning log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="message">The message to log.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogWarning(this ILogger logger, string message, Exception error)
        {
            logger.Log(LogLevel.Warning, 0, message, error, MessageFormatter);
        }

        /// <summary>
        /// Formats the given message and error and writes a warning log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="message">The message to log.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogWarning(this ILogger logger, int eventId, string message, Exception error)
        {
            logger.Log(LogLevel.Warning, eventId, message, error, MessageFormatter);
        }

        /// <summary>
        /// Formats the given <see cref="ILogValues"/> and writes a warning log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="state">The <see cref="ILogValues"/> to write.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogWarning(
            this ILogger logger,
            ILogValues state,
            Exception error = null)
        {
            logger.Log(LogLevel.Warning, state, error);
        }

        /// <summary>
        /// Formats the given <see cref="ILogValues"/> and writes a warning log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="state">The <see cref="ILogValues"/> to write.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogWarning(
            this ILogger logger,
            int eventId,
            ILogValues state,
            Exception error = null)
        {
            logger.LogWithEvent(LogLevel.Warning, eventId, state, error);
        }

        //------------------------------------------ERROR------------------------------------------//

        /// <summary>
        /// Writes an error log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="message">The message to log.</param>
        public static void LogError(this ILogger logger, string message)
        {
            logger.Log(LogLevel.Error, 0, message, null, MessageFormatter);
        }

        /// <summary>
        /// Writes an error log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="message">The message to log.</param>
        public static void LogError(this ILogger logger, int eventId, string message)
        {
            logger.Log(LogLevel.Error, eventId, message, null, MessageFormatter);
        }

        /// <summary>
        /// Formats and writes an error log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="format">Format string of the log message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        public static void LogError(this ILogger logger, string format, params object[] args)
        {
            logger.Log(LogLevel.Error, 0, new FormattedLogValues(format, args), null, MessageFormatter);
        }

        /// <summary>
        /// Formats and writes an error log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="format">Format string of the log message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        public static void LogError(this ILogger logger, int eventId, string format, params object[] args)
        {
            logger.Log(LogLevel.Error, eventId, new FormattedLogValues(format, args), null, MessageFormatter);
        }

        /// <summary>
        /// Formats the given message and error and writes an error log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="message">The message to log.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogError(this ILogger logger, string message, Exception error)
        {
            logger.Log(LogLevel.Error, 0, message, error, MessageFormatter);
        }

        /// <summary>
        /// Formats the given message and error and writes an error log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="message">The message to log.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogError(this ILogger logger, int eventId, string message, Exception error)
        {
            logger.Log(LogLevel.Error, eventId, message, error, MessageFormatter);
        }

        /// <summary>
        /// Formats the given <see cref="ILogValues"/> and writes an error log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="state">The <see cref="ILogValues"/> to write.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogError(
            this ILogger logger,
            ILogValues state,
            Exception error = null)
        {
            logger.Log(LogLevel.Error, state, error);
        }

        /// <summary>
        /// Formats the given <see cref="ILogValues"/> and writes an error log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="state">The <see cref="ILogValues"/> to write.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogError(
            this ILogger logger,
            int eventId,
            ILogValues state,
            Exception error = null)
        {
            logger.LogWithEvent(LogLevel.Error, eventId, state, error);
        }

        //------------------------------------------CRITICAL------------------------------------------//

        /// <summary>
        /// Writes a critical log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="message">The message to log.</param>
        public static void LogCritical(this ILogger logger, string message)
        {
            logger.Log(LogLevel.Critical, 0, message, null, MessageFormatter);
        }

        /// <summary>
        /// Writes a critical log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="message">The message to log.</param>
        public static void LogCritical(this ILogger logger, int eventId, string message)
        {
            logger.Log(LogLevel.Critical, eventId, message, null, MessageFormatter);
        }

        /// <summary>
        /// Formats and writes a critical log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="format">Format string of the log message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        public static void LogCritical(this ILogger logger, string format, params object[] args)
        {
            logger.Log(LogLevel.Critical, 0, new FormattedLogValues(format, args), null, MessageFormatter);
        }

        /// <summary>
        /// Formats and writes a critical log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="format">Format string of the log message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        public static void LogCritical(this ILogger logger, int eventId, string format, params object[] args)
        {
            logger.Log(LogLevel.Critical, eventId, new FormattedLogValues(format, args), null, MessageFormatter);
        }

        /// <summary>
        /// Formats the given message and error and writes a critical log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="message">The message to log.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogCritical(this ILogger logger, string message, Exception error)
        {
            logger.Log(LogLevel.Critical, 0, message, error, MessageFormatter);
        }

        /// <summary>
        /// Formats the given message and error and writes a critical log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="message">The message to log.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogCritical(this ILogger logger, int eventId, string message, Exception error)
        {
            logger.Log(LogLevel.Critical, eventId, message, error, MessageFormatter);
        }

        /// <summary>
        /// Formats the given <see cref="ILogValues"/> and writes a critical log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="state">The <see cref="ILogValues"/> to write.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogCritical(
            this ILogger logger,
            ILogValues state,
            Exception error = null)
        {
            logger.Log(LogLevel.Critical, state, error);
        }

        /// <summary>
        /// Formats the given <see cref="ILogValues"/> and writes a critical log message.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to write to.</param>
        /// <param name="eventId">The event id associated with the log.</param>
        /// <param name="state">The <see cref="ILogValues"/> to write.</param>
        /// <param name="error">The exception to log.</param>
        public static void LogCritical(
            this ILogger logger,
            int eventId,
            ILogValues state,
            Exception error = null)
        {
            logger.LogWithEvent(LogLevel.Critical, eventId, state, error);
        }

        //------------------------------------------Scope------------------------------------------//

        /// <summary>
        /// Formats the message and creates a scope.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/> to create the scope in.</param>
        /// <param name="messageFormat">Format string of the scope message.</param>
        /// <param name="args">An object array that contains zero or more objects to format.</param>
        /// <returns>A disposable scope object. Can be null.</returns>
        public static IDisposable BeginScope(
            this ILogger logger,
            string messageFormat,
            params object[] args)
        {
            return logger.BeginScope(new FormattedLogValues(messageFormat, args));
        }

        //------------------------------------------HELPERS------------------------------------------//

        private static void Log(
            this ILogger logger,
            LogLevel logLevel,
            ILogValues state,
            Exception exception = null)
        {
            logger.Log(logLevel, 0, state, exception, MessageFormatter);
        }

        private static void LogWithEvent(
            this ILogger logger,
            LogLevel logLevel,
            int eventId,
            ILogValues state,
            Exception exception = null)
        {
            logger.Log(logLevel, eventId, state, exception, MessageFormatter);
        }

        private static string MessageFormatter(object state, Exception error)
        {
            if (state == null && error == null)
            {
                throw new InvalidOperationException("No message or exception details were found " +
                    "to create a message for the log.");
            }

            if (state == null)
            {
                return error.ToString();
            }

            if (error == null)
            {
                return state.ToString();
            }

            return string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", state, Environment.NewLine, error);
        }
    }
}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace AppNetDotNet.Model
{
    public class Entities
    {
        public interface IEntity
        {
            int pos { get; set; }
            int len { get; set; }
        }

        public Entities()
        {
            mentions = new List<Mention>();
            tags = new List<Hashtag>();
            links = new List<Link>();
        }

        public List<Mention> mentions { get; set; }
        public List<Hashtag> tags { get; set; }
        public List<Link> links { get; set; }
        public bool? parse_links { get; set; }
        public bool? parse_markdown_links { get; set; }

        [JsonIgnore]
        public List<IEntity> allEntities
        {
            get
            {
                if (_allEntities != null)
                {
                    return _allEntities;
                }
                else
                {
                    _allEntities = new List<IEntity>();
                    if (mentions != null)
                    {
                        foreach (Mention mention in mentions)
                        {
                            _allEntities.Add(mention);
                        }
                    }
                    if(tags != null) {
                        foreach (Hashtag hashtag in tags)
                        {
                            _allEntities.Add(hashtag);
                        }
                    }
                    if(links != null) {
                        foreach (Link link in links)
                        {
                            _allEntities.Add(link);
                        }
                    }
                    _allEntities.Sort();

                    return _allEntities;
                }
            }
        }
        private List<IEntity> _allEntities { get; set; }

        public class Mention : IEntity, IComparable
        {
            public string text { get; set; }
            public string id { get; set; }
            public int pos { get; set; }
            public int len { get; set; }

            public int CompareTo(IEntity b)
            {
                // sorting by start point
                return this.pos.CompareTo(b.pos);
            }

            public int CompareTo(object obj)
            {
                IEntity entity = obj as IEntity;
                if (entity != null)
                {
                    return CompareTo(entity);
                }
                return this.pos;
            }
        }

        public class Hashtag : IEntity, IComparable
        {
            public string text { get; set; }
            public int pos { get; set; }
            public int len { get; set; }

            public int CompareTo(IEntity b)
            {
                // sorting by start point
                return this.pos.CompareTo(b.pos);
            }

            public int CompareTo(object obj)
            {
                IEntity entity = obj as IEntity;
                if (entity != null)
                {
                    return CompareTo(entity);
                }
                return this.pos;
            }

        }

        public class Link : IEntity, IComparable
        {
            public string text { get; set; }
            public string link { get; set; }
            public int pos { get; set; }
            public int len { get; set; }

            public int CompareTo(IEntity b)
            {
                // sorting by start point
                return this.pos.CompareTo(b.pos);
            }

            public int CompareTo(object obj)
            {
                IEntity entity = obj as IEntity;
                if (entity != null)
                {
                    return CompareTo(entity);
                }
                return this.pos;
            }
        }
    }

    /// <summary>
    /// Provides a list of entities without the nice allEntities property - used to send entities without not supported parameters
    /// </summary>
    public class EntitiesWithoutAllProperty
    {
        public List<Entities.Mention> mentions { get; set; }
        public List<Entities.Hashtag> tags { get; set; }
        public List<Entities.Link> links { get; set; }
        public bool? parse_links { get; set; }

        public EntitiesWithoutAllProperty(Entities entities)
        {
            mentions = null;
            tags = null;
            links = null;
            if (entities != null)
            {
                if (entities.mentions != null)
                {
                    if (entities.mentions.Count > 0)
                    {
                        mentions = entities.mentions;
                    }
                }

                if (entities.tags != null)
                {
                    if (entities.tags.Count > 0)
                    {
                        tags = entities.tags;
                    }
                }

                if (entities.links != null)
                {
                    if (entities.links.Count > 0)
                    {
                        links = entities.links;
                    }
                }
            }
        }

    }
}

redpajama_set_name: RedPajamaGithub


text:
import abc
from itertools import chain

import toolz

import ibis.expr.analysis as an
import ibis.expr.operations as ops
import ibis.util as util

class DML(abc.ABC):
    @abc.abstractmethod
    def compile(self):
        pass

class DDL(abc.ABC):
    @abc.abstractmethod
    def compile(self):
        pass

class QueryAST:

    __slots__ = 'context', 'dml', 'setup_queries', 'teardown_queries'

    def __init__(self, context, dml, setup_queries=None, teardown_queries=None):
        self.context = context
        self.dml = dml
        self.setup_queries = setup_queries
        self.teardown_queries = teardown_queries

    @property
    def queries(self):
        return [self.dml]

    def compile(self):
        compiled_setup_queries = [q.compile() for q in self.setup_queries]
        compiled_queries = [q.compile() for q in self.queries]
        compiled_teardown_queries = [q.compile() for q in self.teardown_queries]
        return self.context.collapse(
            list(
                chain(
                    compiled_setup_queries,
                    compiled_queries,
                    compiled_teardown_queries,
                )
            )
        )

class SetOp(DML):
    def __init__(self, tables, node, context, distincts):
        assert isinstance(node, ops.Node)
        assert all(isinstance(table, ops.Node) for table in tables)
        self.context = context
        self.tables = tables
        self.table_set = node
        self.distincts = distincts
        self.filters = []

    @classmethod
    def keyword(cls, distinct):
        return cls._keyword + (not distinct) * " ALL"

    def _get_keyword_list(self):
        return map(self.keyword, self.distincts)

    def _extract_subqueries(self):
        self.subqueries = _extract_common_table_expressions(
            [self.table_set, *self.filters]
        )
        for subquery in self.subqueries:
            self.context.set_extracted(subquery)

    def format_subqueries(self):
        context = self.context
        subqueries = self.subqueries

        return ',\n'.join(
            '{} AS (\n{}\n)'.format(
                context.get_ref(expr),
                util.indent(context.get_compiled_expr(expr), 2),
            )
            for expr in subqueries
        )

    def format_relation(self, expr):
        ref = self.context.get_ref(expr)
        if ref is not None:
            return f'SELECT *\nFROM {ref}'
        return self.context.get_compiled_expr(expr)

    def compile(self):
        self._extract_subqueries()

        extracted = self.format_subqueries()

        buf = []

        if extracted:
            buf.append(f'WITH {extracted}')

        buf.extend(
            toolz.interleave(
                (
                    map(self.format_relation, self.tables),
                    self._get_keyword_list(),
                )
            )
        )
        return '\n'.join(buf)

def _extract_common_table_expressions(nodes):
    # filter out None values
    nodes = list(filter(None, nodes))
    counts = an.find_subqueries(nodes)
    duplicates = [op for op, count in counts.items() if count > 1]
    duplicates.reverse()
    return duplicates


text:
package savvytodo.ui;

import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Region;
import savvytodo.commons.util.FxViewUtil;
import savvytodo.model.task.ReadOnlyTask;

//@@author A0140036X
/**
 * @author A0140036X The Browser Panel of the App.
 */
public class BrowserPanel extends UiPart<Region> {

    private static final String FXML = "BrowserPanel.fxml";

    @FXML
    private GridPane content;

    @FXML
    private Label nameLabel;

    @FXML
    private Label dateLabel;

    @FXML
    private Label descriptionLabel;

    /**
     * @param placeholder
     *            The AnchorPane where the BrowserPanel must be inserted
     */
    public BrowserPanel(AnchorPane placeholder) {
        super(FXML);
        placeholder.setOnKeyPressed(Event::consume);
        FxViewUtil.applyAnchorBoundaryParameters(content, 0.0, 0.0, 0.0, 0.0);
        placeholder.getChildren().add(content);
    }

    public void loadTaskPage(ReadOnlyTask task) {
        nameLabel.setText(task.getName().toString().toUpperCase());
        dateLabel.setText(task.getDateTime().toString());
        descriptionLabel.setText(task.getDescription().toString());
    }

    /**
     * Frees resources allocated to the browser.
     */
    public void freeResources() {
        content = null;
    }

}


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

[
            Download

            ]
            | [
            Documentation Home
            ] | [
            Release Note

            ]

WSDLView - Generate the WSDL Document Starting with a Java Class

The aim of this document is to explain briefly how the WSDLView tool works.

Content

                Introduction

                Usage

                Conclusion

Introduction

        WSDLView is a handy tool available with WSO2 Application Server that
        allows the user to generate a WSDL (Web Services Definition Language)
        document from any given .class or .jar file(s).

Usage

Using WSDLView is quite straightforward. In fact, as with the other tools
            provided on the WSO2 Application Server front page, you don't even need to
            sign in.

Click on
            WSDL View
            and you will be taken to the following screen.

Here, click on
            Browse
            to search your file system for
            the .class file or the .jar file you want to generate a WSDL for. Once
            you have selected it, use the
            +
            button to add other necessary
            classes or jars.

        Note: In case of a .class file, it needs to be declared in the
            default package for WSDLView to work. If you need to WSDLView for a
            class inside a custom package, please jar up the class files first.

Once you've selected all necessary resources, click on
            Next
            to move on to the WSDLView configuration screen.

On this screen, you can customize the WSDL generation process to your liking.
            The description given against each configuration option should give you
            an idea of what it does. Some of the more importants options are described below.

                cn
                : The main class for which the WSDL should be generated. Note that it
                should be fully qualified with the package name.

sn: The name of the service

        For the options that you leave unchanged, the default values will be used
        in the generation process. Click on
        Generate
        .

If everything is in order, the generation should happen smoothly and produce the WSDL.

  In case you are taken to the "Add Resources" screen with a "
            class not found"
            message, it could mean that you specified an incorrect classname in the previous screen, or you did not
            include a necessary resource file, or as mentioned above you selected a .class that was
            declared in a package other than the default package. If that happens,
            rectify the error and click "Generate" again.

Conclusion

WSDLView provides an easy to configure and easy to use method of producing a WSDL document from
            already existing classes.


text:
package gxui

import (
	"github.com/google/gxui/interval"
	"github.com/google/gxui/math"
)

type CodeSyntaxLayer struct {
	spans           interval.IntDataList
	color           *Color
	backgroundColor *Color
	borderColor     *Color
	data            interface{}
}

func CreateCodeSyntaxLayer() *CodeSyntaxLayer { return &CodeSyntaxLayer{} }

func (l *CodeSyntaxLayer) Clear() {
	l.spans = interval.IntDataList{}
}

func (l *CodeSyntaxLayer) UpdateSpans(runeCount int, edits []TextBoxEdit) {
	min := 0
	max := runeCount
	for _, e := range edits {
		if l == nil {
			continue
		}
		for j, s := range l.spans {
			at := e.At
			start, end := s.Range()
			if start >= at {
				start = math.Clamp(start+e.Delta, min, max)
			}
			if end > at {
				end = math.Clamp(end+e.Delta, min, max)
			}
			if end < start {
				end = start
			}
			l.spans[j] = interval.CreateIntData(start, end, s.Data())
		}
	}
}

func (l *CodeSyntaxLayer) Add(start, count int) {
	l.AddData(start, count, nil)
}

func (l *CodeSyntaxLayer) AddData(start, count int, data interface{}) {
	span := interval.CreateIntData(start, start+count, data)
	interval.Replace(&l.spans, span)
}

func (l *CodeSyntaxLayer) AddSpan(span interval.IntData) {
	interval.Replace(&l.spans, span)
}

func (l *CodeSyntaxLayer) Spans() interval.IntDataList {
	return l.spans
}

func (l *CodeSyntaxLayer) SpanAt(runeIndex int) *interval.IntData {
	idx := interval.IndexOf(&l.spans, uint64(runeIndex))
	if idx >= 0 {
		return &l.spans[idx]
	} else {
		return nil
	}
}

func (l *CodeSyntaxLayer) Color() *Color {
	return l.color
}

func (l *CodeSyntaxLayer) ClearColor() {
	l.color = nil
}

func (l *CodeSyntaxLayer) SetColor(color Color) {
	l.color = &color
}

func (l *CodeSyntaxLayer) BackgroundColor() *Color {
	return l.backgroundColor
}

func (l *CodeSyntaxLayer) ClearBackgroundColor() {
	l.backgroundColor = nil
}

func (l *CodeSyntaxLayer) SetBackgroundColor(color Color) {
	l.backgroundColor = &color
}

func (l *CodeSyntaxLayer) BorderColor() *Color {
	return l.borderColor
}

func (l *CodeSyntaxLayer) ClearBorderColor() {
	l.borderColor = nil
}

func (l *CodeSyntaxLayer) SetBorderColor(color Color) {
	l.borderColor = &color
}

func (l *CodeSyntaxLayer) Data() interface{} {
	return l.data
}

func (l *CodeSyntaxLayer) SetData(data interface{}) {
	l.data = data
}

type CodeSyntaxLayers []*CodeSyntaxLayer

func (l *CodeSyntaxLayers) Get(idx int) *CodeSyntaxLayer {
	if len(*l) <= idx {
		old := *l
		*l = make(CodeSyntaxLayers, idx+1)
		copy(*l, old)
	}
	layer := (*l)[idx]
	if layer == nil {
		layer = &CodeSyntaxLayer{}
		(*l)[idx] = layer
	}
	return layer
}

func (l *CodeSyntaxLayers) Clear() {
	*l = CodeSyntaxLayers{}
}


text:
"""Simple parsers for registry keys and values."""

import re

import logging

from grr.lib import artifact_lib
from grr.lib import parsers
from grr.lib import rdfvalue
from grr.lib import type_info
from grr.lib import utils

SID_RE = re.compile(r"^S-\d-\d+-(\d+-){1,14}\d+$")

class CurrentControlSetKBParser(parsers.RegistryValueParser):
  """Parser for CurrentControlSet value."""

  output_types = ["RDFString"]
  supported_artifacts = ["CurrentControlSet"]

  def Parse(self, stat, unused_knowledge_base):
    """Parse the key currentcontrolset output."""
    value = stat.registry_data.GetValue()

    if not str(value).isdigit() or int(value) > 999 or int(value) < 0:
      raise parsers.ParseError("Invalid value for CurrentControlSet key %s" %
                               value)
    yield rdfvalue.RDFString("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet%03d" %
                             int(value))

class WinEnvironmentParser(parsers.RegistryValueParser):
  """Parser for registry retrieved environment variables."""

  output_types = ["RDFString"]
  supported_artifacts = ["WinPathEnvironmentVariable",
                         "WinDirEnvironmentVariable", "TempEnvironmentVariable",
                         "AllUsersAppDataEnvironmentVariable"]
  # Required for environment variable expansion
  knowledgebase_dependencies = ["environ_systemdrive", "environ_systemroot"]

  def Parse(self, stat, knowledge_base):
    """Parse the key currentcontrolset output."""
    value = stat.registry_data.GetValue()
    if not value:
      raise parsers.ParseError("Invalid value for key %s" % stat.pathspec.path)
    value = artifact_lib.ExpandWindowsEnvironmentVariables(value,
                                                           knowledge_base)
    if value:
      yield rdfvalue.RDFString(value)

class WinSystemDriveParser(parsers.RegistryValueParser):
  """Parser for SystemDrive environment variable."""

  output_types = ["RDFString"]
  supported_artifacts = ["SystemDriveEnvironmentVariable"]

  def Parse(self, stat, _):
    """Parse the key currentcontrolset output."""
    value = stat.registry_data.GetValue()
    if not value:
      raise parsers.ParseError("Invalid value for key %s" % stat.pathspec.path)

    systemdrive = value[0:2]
    if re.match(r"^[A-Za-z]:$", systemdrive):
      yield rdfvalue.RDFString(systemdrive)
    else:
      raise parsers.ParseError(
          "Bad drive letter for key %s" % stat.pathspec.path)

class WinSystemRootParser(parsers.RegistryValueParser):
  """Parser for SystemRoot environment variables."""

  output_types = ["RDFString"]
  supported_artifacts = ["SystemRoot"]

  def Parse(self, stat, _):
    value = stat.registry_data.GetValue()
    if value:
      yield rdfvalue.RDFString(value)
    else:
      raise parsers.ParseError("Invalid value for key %s" % stat.pathspec.path)

class CodepageParser(parsers.RegistryValueParser):
  """Parser for Codepage values."""

  output_types = ["RDFString"]
  supported_artifacts = ["WinCodePage"]

  def Parse(self, stat, knowledge_base):
    _ = knowledge_base
    value = stat.registry_data.GetValue()
    yield rdfvalue.RDFString("cp_%s" % value)

class AllUsersProfileEnvironmentVariable(parsers.RegistryParser):
  """Parser for AllUsersProfile variable.

  This requires combining two registry values together and applying a default
  if one or the registry values doesn't exist.
  """
  output_types = ["RDFString"]
  supported_artifacts = ["AllUsersProfileEnvironmentVariable"]
  # Required for environment variable expansion
  knowledgebase_dependencies = ["environ_systemdrive", "environ_systemroot"]
  process_together = True

  def ParseMultiple(self, stats, knowledge_base):
    """Parse each returned registry variable."""
    prof_directory = r"%SystemDrive%\Documents and Settings"
    all_users = "All Users"    # Default value.
    for stat in stats:
      value = stat.registry_data.GetValue()
      if stat.pathspec.Basename() == "ProfilesDirectory" and value:
        prof_directory = value
      elif stat.pathspec.Basename() == "AllUsersProfile" and value:
        all_users = value

    all_users_dir = r"%s\%s" % (prof_directory, all_users)
    all_users_dir = artifact_lib.ExpandWindowsEnvironmentVariables(
        all_users_dir, knowledge_base)
    yield rdfvalue.RDFString(all_users_dir)

class WinUserSids(parsers.RegistryParser):
  """Parser for extracting SID for multiple users.

  This reads a listing of the profile paths to extract a list of SIDS for
  users with profiles on a system.
  """
  output_types = ["KnowledgeBaseUser"]
  supported_artifacts = ["WindowsRegistryProfiles"]

  def Parse(self, stat, knowledge_base):
    """Parse each returned registry value."""
    _ = knowledge_base  # Unused.
    sid_str = stat.pathspec.Dirname().Basename()

    if SID_RE.match(sid_str):
      kb_user = rdfvalue.KnowledgeBaseUser()
      kb_user.sid = sid_str
      if stat.pathspec.Basename() == "ProfileImagePath":
        if stat.resident:
          # Support old clients.
          kb_user.homedir = utils.SmartUnicode(stat.resident)
        else:
          kb_user.homedir = stat.registry_data.GetValue()

        kb_user.userprofile = kb_user.homedir
        try:
          # Assume username is the last component of the path. This is not
          # robust, but other user artifacts will override it if there is a
          # better match.
          kb_user.username = kb_user.homedir.rsplit("\\", 1)[-1]
        except IndexError:
          pass

      yield kb_user

class WinUserSpecialDirs(parsers.RegistryParser):
  r"""Parser for extracting special folders from registry.

  Keys will come from HKEY_USERS and will list the Shell Folders and user's
  Environment key. We extract each subkey that matches on of our knowledge base
  attributes.

  Known folder GUIDs:
  http://msdn.microsoft.com/en-us/library/windows/desktop/dd378457(v=vs.85).aspx
  """
  output_types = ["KnowledgeBaseUser"]
  supported_artifacts = ["UserShellFolders"]
  process_together = True
  # Required for environment variable expansion
  knowledgebase_dependencies = ["environ_systemdrive", "environ_systemroot",
                                "users.userprofile"]

  key_var_mapping = {
      "Shell Folders": {
          "{A520A1A4-1780-4FF6-BD18-167343C5AF16}": "localappdata_low",
          "Desktop": "desktop",
          "AppData": "appdata",
          "Local AppData": "localappdata",
          "Cookies": "cookies",
          "Cache": "internet_cache",
          "Recent": "recent",
          "Startup": "startup",
          "Personal": "personal",
      },
      "Environment": {
          "TEMP": "temp",
      },
      "Volatile Environment": {
          "USERDOMAIN": "userdomain",
      },
  }

  def ParseMultiple(self, stats, knowledge_base):
    """Parse each returned registry value."""
    user_dict = {}

    for stat in stats:
      sid_str = stat.pathspec.path.split("/", 3)[2]
      if SID_RE.match(sid_str):
        if sid_str not in user_dict:
          user_dict[sid_str] = rdfvalue.KnowledgeBaseUser(sid=sid_str)

        if stat.registry_data.GetValue():
          # Look up in the mapping if we can use this entry to populate a user
          # attribute, and if so, set it.
          reg_key_name = stat.pathspec.Dirname().Basename()
          if reg_key_name in self.key_var_mapping:
            map_dict = self.key_var_mapping[reg_key_name]
            reg_key = stat.pathspec.Basename()
            kb_attr = map_dict.get(reg_key)
            if kb_attr:
              value = artifact_lib.ExpandWindowsEnvironmentVariables(
                  stat.registry_data.GetValue(), knowledge_base)
              value = artifact_lib.ExpandWindowsUserEnvironmentVariables(
                  value, knowledge_base, sid=sid_str)
              user_dict[sid_str].Set(kb_attr, value)

    # Now yield each user we found.
    return user_dict.itervalues()

class WinServicesParser(parsers.RegistryValueParser):
  """Parser for Windows services values from the registry.

  See service key doco:
    http://support.microsoft.com/kb/103000
  """

  output_types = ["WindowsServiceInformation"]
  supported_artifacts = ["WindowsServices"]
  process_together = True

  def __init__(self):
    # The key can be "services" or "Services" on different versions of windows.
    self.service_re = re.compile(
        r".*HKEY_LOCAL_MACHINE/SYSTEM/[^/]+/services/([^/]+)(/(.*))?$",
        re.IGNORECASE)
    super(WinServicesParser, self).__init__()

  def _GetServiceName(self, path):
    return self.service_re.match(path).group(1)

  def _GetKeyName(self, path):
    return self.service_re.match(path).group(3)

  def ParseMultiple(self, stats, knowledge_base):
    """Parse Service registry keys and return WindowsServiceInformation."""
    _ = knowledge_base
    services = {}
    field_map = {"Description": "description",
                 "DisplayName": "display_name",
                 "Group": "group_name",
                 "DriverPackageId": "driver_package_id",
                 "ErrorControl": "error_control",
                 "ImagePath": "image_path",
                 "ObjectName": "object_name",
                 "Start": "startup_type",
                 "Type": "service_type",
                 "Parameters/ServiceDLL": "service_dll"}

    for stat in stats:

      # Ignore subkeys
      if not stat.HasField("registry_data"):
        continue

      service_name = self._GetServiceName(stat.pathspec.path)
      reg_key = stat.aff4path.Dirname()
      service_info = rdfvalue.WindowsServiceInformation(name=service_name,
                                                        registry_key=reg_key)
      services.setdefault(service_name, service_info)

      key = self._GetKeyName(stat.pathspec.path)

      if key in field_map:
        try:
          services[service_name].Set(field_map[key],
                                     stat.registry_data.GetValue())
        except type_info.TypeValueError:

          # Flatten multi strings into a simple string
          if stat.registry_type == rdfvalue.StatEntry.RegistryType.REG_MULTI_SZ:
            services[service_name].Set(field_map[key],
                                       utils.SmartUnicode(
                                           stat.registry_data.GetValue()))
          else:
            # Log failures for everything else
            # TODO(user): change this to yield a ParserAnomaly object.
            dest_type = type(services[service_name].Get(field_map[key]))
            logging.debug("Wrong type set for %s:%s, expected %s, got %s",
                          stat.pathspec.path, stat.registry_data.GetValue(),
                          dest_type, type(stat.registry_data.GetValue()))

    return services.itervalues()

class WinTimezoneParser(parsers.RegistryValueParser):
  """Parser for TimeZoneKeyName value."""

  output_types = ["RDFString"]
  supported_artifacts = ["WinTimeZone"]

  def Parse(self, stat, knowledge_base):
    """Convert the timezone to Olson format."""
    _ = knowledge_base
    value = stat.registry_data.GetValue()
    result = ZONE_LIST.get(value.strip())
    if not result:
      yield rdfvalue.RDFString("Unknown (%s)" % value.strip())

    yield rdfvalue.RDFString(result)

# Prebuilt from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT"
# \CurrentVersion\Time Zones\
# Note that these may not be consistent across Windows versions so may need
# adjustment in the future.
ZONE_LIST = {
    "IndiaStandardTime": "Asia/Kolkata",
    "EasternStandardTime": "EST5EDT",
    "EasternDaylightTime": "EST5EDT",
    "MountainStandardTime": "MST7MDT",
    "MountainDaylightTime": "MST7MDT",
    "PacificStandardTime": "PST8PDT",
    "PacificDaylightTime": "PST8PDT",
    "CentralStandardTime": "CST6CDT",
    "CentralDaylightTime": "CST6CDT",
    "SamoaStandardTime": "US/Samoa",
    "HawaiianStandardTime": "US/Hawaii",
    "AlaskanStandardTime": "US/Alaska",
    "MexicoStandardTime2": "MST7MDT",
    "USMountainStandardTime": "MST7MDT",
    "CanadaCentralStandardTime": "CST6CDT",
    "MexicoStandardTime": "CST6CDT",
    "CentralAmericaStandardTime": "CST6CDT",
    "USEasternStandardTime": "EST5EDT",
    "SAPacificStandardTime": "EST5EDT",
    "MalayPeninsulaStandardTime": "Asia/Kuching",
    "PacificSAStandardTime": "Canada/Atlantic",
    "AtlanticStandardTime": "Canada/Atlantic",
    "SAWesternStandardTime": "Canada/Atlantic",
    "NewfoundlandStandardTime": "Canada/Newfoundland",
    "AzoresStandardTime": "Atlantic/Azores",
    "CapeVerdeStandardTime": "Atlantic/Azores",
    "GMTStandardTime": "GMT",
    "GreenwichStandardTime": "GMT",
    "W.CentralAfricaStandardTime": "Europe/Belgrade",
    "W.EuropeStandardTime": "Europe/Belgrade",
    "CentralEuropeStandardTime": "Europe/Belgrade",
    "RomanceStandardTime": "Europe/Belgrade",
    "CentralEuropeanStandardTime": "Europe/Belgrade",
    "E.EuropeStandardTime": "Egypt",
    "SouthAfricaStandardTime": "Egypt",
    "IsraelStandardTime": "Egypt",
    "EgyptStandardTime": "Egypt",
    "NorthAsiaEastStandardTime": "Asia/Bangkok",
    "SingaporeStandardTime": "Asia/Bangkok",
    "ChinaStandardTime": "Asia/Bangkok",
    "W.AustraliaStandardTime": "Australia/Perth",
    "TaipeiStandardTime": "Asia/Bangkok",
    "TokyoStandardTime": "Asia/Tokyo",
    "KoreaStandardTime": "Asia/Seoul",
    "@tzres.dll,-10": "Atlantic/Azores",
    "@tzres.dll,-11": "Atlantic/Azores",
    "@tzres.dll,-12": "Atlantic/Azores",
    "@tzres.dll,-20": "Atlantic/Cape_Verde",
    "@tzres.dll,-21": "Atlantic/Cape_Verde",
    "@tzres.dll,-22": "Atlantic/Cape_Verde",
    "@tzres.dll,-40": "Brazil/East",
    "@tzres.dll,-41": "Brazil/East",
    "@tzres.dll,-42": "Brazil/East",
    "@tzres.dll,-70": "Canada/Newfoundland",
    "@tzres.dll,-71": "Canada/Newfoundland",
    "@tzres.dll,-72": "Canada/Newfoundland",
    "@tzres.dll,-80": "Canada/Atlantic",
    "@tzres.dll,-81": "Canada/Atlantic",
    "@tzres.dll,-82": "Canada/Atlantic",
    "@tzres.dll,-104": "America/Cuiaba",
    "@tzres.dll,-105": "America/Cuiaba",
    "@tzres.dll,-110": "EST5EDT",
    "@tzres.dll,-111": "EST5EDT",
    "@tzres.dll,-112": "EST5EDT",
    "@tzres.dll,-120": "EST5EDT",
    "@tzres.dll,-121": "EST5EDT",
    "@tzres.dll,-122": "EST5EDT",
    "@tzres.dll,-130": "EST5EDT",
    "@tzres.dll,-131": "EST5EDT",
    "@tzres.dll,-132": "EST5EDT",
    "@tzres.dll,-140": "CST6CDT",
    "@tzres.dll,-141": "CST6CDT",
    "@tzres.dll,-142": "CST6CDT",
    "@tzres.dll,-150": "America/Guatemala",
    "@tzres.dll,-151": "America/Guatemala",
    "@tzres.dll,-152": "America/Guatemala",
    "@tzres.dll,-160": "CST6CDT",
    "@tzres.dll,-161": "CST6CDT",
    "@tzres.dll,-162": "CST6CDT",
    "@tzres.dll,-170": "America/Mexico_City",
    "@tzres.dll,-171": "America/Mexico_City",
    "@tzres.dll,-172": "America/Mexico_City",
    "@tzres.dll,-180": "MST7MDT",
    "@tzres.dll,-181": "MST7MDT",
    "@tzres.dll,-182": "MST7MDT",
    "@tzres.dll,-190": "MST7MDT",
    "@tzres.dll,-191": "MST7MDT",
    "@tzres.dll,-192": "MST7MDT",
    "@tzres.dll,-200": "MST7MDT",
    "@tzres.dll,-201": "MST7MDT",
    "@tzres.dll,-202": "MST7MDT",
    "@tzres.dll,-210": "PST8PDT",
    "@tzres.dll,-211": "PST8PDT",
    "@tzres.dll,-212": "PST8PDT",
    "@tzres.dll,-220": "US/Alaska",
    "@tzres.dll,-221": "US/Alaska",
    "@tzres.dll,-222": "US/Alaska",
    "@tzres.dll,-230": "US/Hawaii",
    "@tzres.dll,-231": "US/Hawaii",
    "@tzres.dll,-232": "US/Hawaii",
    "@tzres.dll,-260": "GMT",
    "@tzres.dll,-261": "GMT",
    "@tzres.dll,-262": "GMT",
    "@tzres.dll,-271": "UTC",
    "@tzres.dll,-272": "UTC",
    "@tzres.dll,-280": "Europe/Budapest",
    "@tzres.dll,-281": "Europe/Budapest",
    "@tzres.dll,-282": "Europe/Budapest",
    "@tzres.dll,-290": "Europe/Warsaw",
    "@tzres.dll,-291": "Europe/Warsaw",
    "@tzres.dll,-292": "Europe/Warsaw",
    "@tzres.dll,-331": "Europe/Nicosia",
    "@tzres.dll,-332": "Europe/Nicosia",
    "@tzres.dll,-340": "Africa/Cairo",
    "@tzres.dll,-341": "Africa/Cairo",
    "@tzres.dll,-342": "Africa/Cairo",
    "@tzres.dll,-350": "Europe/Sofia",
    "@tzres.dll,-351": "Europe/Sofia",
    "@tzres.dll,-352": "Europe/Sofia",
    "@tzres.dll,-365": "Egypt",
    "@tzres.dll,-390": "Asia/Kuwait",
    "@tzres.dll,-391": "Asia/Kuwait",
    "@tzres.dll,-392": "Asia/Kuwait",
    "@tzres.dll,-400": "Asia/Baghdad",
    "@tzres.dll,-401": "Asia/Baghdad",
    "@tzres.dll,-402": "Asia/Baghdad",
    "@tzres.dll,-410": "Africa/Nairobi",
    "@tzres.dll,-411": "Africa/Nairobi",
    "@tzres.dll,-412": "Africa/Nairobi",
    "@tzres.dll,-434": "Asia/Tbilisi",
    "@tzres.dll,-435": "Asia/Tbilisi",
    "@tzres.dll,-440": "Asia/Muscat",
    "@tzres.dll,-441": "Asia/Muscat",
    "@tzres.dll,-442": "Asia/Muscat",
    "@tzres.dll,-447": "Asia/Baku",
    "@tzres.dll,-448": "Asia/Baku",
    "@tzres.dll,-449": "Asia/Baku",
    "@tzres.dll,-450": "Asia/Yerevan",
    "@tzres.dll,-451": "Asia/Yerevan",
    "@tzres.dll,-452": "Asia/Yerevan",
    "@tzres.dll,-460": "Asia/Kabul",
    "@tzres.dll,-461": "Asia/Kabul",
    "@tzres.dll,-462": "Asia/Kabul",
    "@tzres.dll,-471": "Asia/Yekaterinburg",
    "@tzres.dll,-472": "Asia/Yekaterinburg",
    "@tzres.dll,-511": "Asia/Aqtau",
    "@tzres.dll,-512": "Asia/Aqtau",
    "@tzres.dll,-570": "Asia/Chongqing",
    "@tzres.dll,-571": "Asia/Chongqing",
    "@tzres.dll,-572": "Asia/Chongqing",
    "@tzres.dll,-650": "Australia/Darwin",
    "@tzres.dll,-651": "Australia/Darwin",
    "@tzres.dll,-652": "Australia/Darwin",
    "@tzres.dll,-660": "Australia/Adelaide",
    "@tzres.dll,-661": "Australia/Adelaide",
    "@tzres.dll,-662": "Australia/Adelaide",
    "@tzres.dll,-670": "Australia/Sydney",
    "@tzres.dll,-671": "Australia/Sydney",
    "@tzres.dll,-672": "Australia/Sydney",
    "@tzres.dll,-680": "Australia/Brisbane",
    "@tzres.dll,-681": "Australia/Brisbane",
    "@tzres.dll,-682": "Australia/Brisbane",
    "@tzres.dll,-721": "Pacific/Port_Moresby",
    "@tzres.dll,-722": "Pacific/Port_Moresby",
    "@tzres.dll,-731": "Pacific/Fiji",
    "@tzres.dll,-732": "Pacific/Fiji",
    "@tzres.dll,-840": "America/Argentina/Buenos_Aires",
    "@tzres.dll,-841": "America/Argentina/Buenos_Aires",
    "@tzres.dll,-842": "America/Argentina/Buenos_Aires",
    "@tzres.dll,-880": "UTC",
    "@tzres.dll,-930": "UTC",
    "@tzres.dll,-931": "UTC",
    "@tzres.dll,-932": "UTC",
    "@tzres.dll,-1010": "Asia/Aqtau",
    "@tzres.dll,-1020": "Asia/Dhaka",
    "@tzres.dll,-1021": "Asia/Dhaka",
    "@tzres.dll,-1022": "Asia/Dhaka",
    "@tzres.dll,-1070": "Asia/Tbilisi",
    "@tzres.dll,-1120": "America/Cuiaba",
    "@tzres.dll,-1140": "Pacific/Fiji",
    "@tzres.dll,-1460": "Pacific/Port_Moresby",
    "@tzres.dll,-1530": "Asia/Yekaterinburg",
    "@tzres.dll,-1630": "Europe/Nicosia",
    "@tzres.dll,-1660": "America/Bahia",
    "@tzres.dll,-1661": "America/Bahia",
    "@tzres.dll,-1662": "America/Bahia",
    "Central Standard Time": "CST6CDT",
    "Pacific Standard Time": "PST8PDT",
}


text:
%% Fit a ramping model to the observed spiking trials by sampling over the
%  posterior distribution p(\Theta,lambdas|y) where
%   y = observed spikes
%   \Theta  = model parameters
%   lambdas = latent variables (diffusion-to-bound paths)
%  by taking only the samples of \Theta, we obtain a sampled estimate of
%         p(\Theta|y)
%
% model params
%  beta  - drift slope. 1 value per stimulus/coherence level.. Takes values (-\infty, \infty)
%  l_0   - initial diffusion position. 1 value. Takes values (-\infty, 1)
%  w2    - diffusion variance. 1 value. Takes values (0, \infty)
%  gamma - bound height parameter. 1 value. Takes values (0, \infty)
%
% Model of a trial (trial number j)
%
%   lambda(1) = l_0 + randn*sqrt(w2);    (randn*sqrt(w2) gives zero mean Gaussian noise with variance w2)
%
%   for t = 2...T  (T=trial length)
%     lambda(t) = lambda(t-1) + beta(timeSeries.trCoh(j)) + randn*sqrt(w2)
%   end
%   auxThreshold(j) = find first t such that lambda(t) > 1 (if doesn't exist set to T+1)
%
%   y(t|t <  auxThreshold(j))      ~ Poisson(log(1+ exp(lambda(t)*gamma))* timeSeries.delta_t)
%   y(t|t >= auxThreshold(j))      ~ Poisson(log(1+ exp(          gamma))* timeSeries.delta_t)
%
% Model fiting outputs
%   RampSamples.betas  = drift slopes (numSamples,numCoherences)
%   RampSamples.l_0    = initial drift position (numSamples,1)
%   RampSamples.w2s    = drift variance (numSamples,1)
%   RampSamples.gammas = bound height (or diffusion path scaling) parameter (numSamples,1)
%
%   RampSamples.auxThreshold = auxiliary variable to say when (if) bound was hit on each trial for each sample of lambda
%                              (NT,numSamples)
%                              if RampSamples.auxThreshold is < 0 or greater than the trial length, then bound was not hit on the sample
%
%
%
%   RampSamples includes the burnin period samples
%
%   RampFit contains sample mean of each parameter (after throwing out burnin and thinning according to params.MCMC.thin)
%           and a 95% credible interval. (This structure summarizes the RampSamples)
%        e.g., RampFit.beta.mean   contains the posterior mean over the drift slope rate parameters
%
%
%
% timeSeries - holds all trial information (NT = number of trials)
%   timeSeries.y          = spikes at each time (one long vector)
%   timeSeries.trialIndex = NT x 2 matrix, each row holds the start and end
%                           indices for each trial (with respect to timeSeries.y)
%   timeSeries.trCoh        = coherence for each trial
%
%
%   model priors
%       beta(i)  ~ normal(params.rampPrior.beta_mu, params.rampPrior.beta_sigma^2)
%       l_0      ~ normal(params.rampPrior.l0_mu, params.rampPrior.l0_sigma^2)
%       w2       ~ inverse-gamma(params.rampPrior.w2_shape,params.rampPrior.w2_scale)
%       gamma    ~ gamma(params.rampPrior.gammaAlpha,params.rampPrior.gammaBeta)
%

function [ RampFit, RampSamples, LatentDataHandler] = fitRampingSoftplusBias(timeSeries,params)

totalSamples = params.MCMC.nSamples+params.MCMC.burnIn;
timeSeries = setupTrialIndexStructure(timeSeries);
TT = size(timeSeries.y,1);
NT = size(timeSeries.trialIndex,1);
NC = max(timeSeries.trCoh);

%% max firing rate (bound) initialization ------------------------------
firingRateFunc    = @(X) log(1+exp(X))*timeSeries.delta_t;
firingRateFuncInv = @(X) log(exp(X/timeSeries.delta_t)-1);
timeIndices = timeSeries.trialIndex(: ,1);
startFR = firingRateFuncInv(  max(mean( timeSeries.y(timeIndices )), 1e-20));

timeIndices = timeSeries.trialIndex(timeSeries.choice == 1 ,2);
timeIndices = [timeIndices;timeIndices-1;timeIndices-2];
endFR1 = firingRateFuncInv(  max(mean( timeSeries.y(timeIndices )), 1e-20));

timeIndices = timeSeries.trialIndex(timeSeries.choice == 2 ,2);
timeIndices = [timeIndices;timeIndices-1;timeIndices-2];
endFR2 = firingRateFuncInv(  max(mean( timeSeries.y(timeIndices )), 1e-20));

initialGamma = max([10, startFR,endFR1,endFR2]); %initial gamma is the max of: beginning firing rate, end trial firing rate for choice 1, or end trial firing rate for choice 2 trials
initialGamma = min(initialGamma,160); %keep initial gamma within some bounds

%% Sets up space for sampling --------------------------------------
RampSamples.betas        = zeros(totalSamples,NC);
RampSamples.w2s          = zeros(totalSamples,1);
RampSamples.auxThreshold = zeros(NT,totalSamples); %auxiliary variable to say when (if) bound was hit on each trial for each sample of lambda

RampSamples.l_0      = zeros(totalSamples,1);
RampSamples.gammas   = zeros(totalSamples,1);
RampSamples.biases   = zeros(totalSamples,1);

acceptanceCount.g  = 0;
acceptanceCount.sample = zeros(totalSamples,1);

%special functions that save temp files to keep latent variables from taking over too much RAM
LatentDataHandler.DataFolder = params.tempDataFolder;
LatentDataHandler = resetLatentsDB(length(timeSeries.y), totalSamples,LatentDataHandler);
%LatentDataHandler = saveLatentsDB(RampingFit.lambdas,1,LatentDataHandler);

%% initial values
RampSamples.betas(1,:) = sort(mvnrnd(zeros(NC,1),0.001*eye(NC)),'ascend'); % 0
RampSamples.w2s(1,:)   = 5e-4 + 0.0045*rand(1,1); % 0.005
RampSamples.l_0(1)     = max(0.1,min(0.9, normrnd(startFR/initialGamma,0.01)));%0.5;
RampSamples.biases(1)  = max(0.5,normrnd(1,0.1));
RampSamples.gammas(1)  = max(1e-20,normrnd(initialGamma-RampSamples.biases(1),1));

RampSamples.rb.sig = zeros([NC+1,totalSamples]); %keeps around variables for potential Rao-Blackwell estimates over betas (I don't use these)
RampSamples.rb.mu  = zeros([NC+1,totalSamples]);

RampSamples.latent_sum = zeros(TT,1);
RampSamples.latent_sum_sqr = zeros(TT,1);
RampSamples.latent_total = 0;

%% prior parameters setup
%makes prior param structures fit the number of params
%  -the same prior might be used for several param values

beta_mu = params.rampPrior.beta_mu;
if(NC > 1 && length(beta_mu) == 1)
    beta_mu = repmat(beta_mu,NC,1);
end
beta_sigma = params.rampPrior.beta_sigma;
if(NC > 1 && length(beta_sigma) == 1)
    beta_sigma = repmat(beta_sigma,NC,1);
end

p_init  = zeros(NC+1,NC+1);
p = zeros(size(p_init));
c_init  = zeros(NC+1,1);
c = zeros(size(c_init));

for b = 1:NC
    p_init(b,b) = 1/beta_sigma(b).^2;
    c_init(b)     = beta_mu(b) / beta_sigma(b).^2;
end
c_init(end)     = params.rampPrior.l0_mu/params.rampPrior.l0_sigma^2;
p_init(end,end) = 1/params.rampPrior.l0_sigma^2;

%% Setting up the GPU variables
trIndex = zeros(NT+1,1);

betaVector = zeros(TT+1,1);
maxTrLength = 0;
for tr = 1:NT
    T1 = timeSeries.trialIndex(tr,1);
    T2 = timeSeries.trialIndex(tr,2);
    T = T2 - T1 + 1;
    maxTrLength = max(T,maxTrLength);

    trIndex(tr+1) = trIndex(tr) + T;

    betaVector(T1:T2) = timeSeries.trCoh(tr)-1;
end

lambdaBlockSize = 50; %how often to pull samples back from GPU

lambdaCounter  = 0;
lambdaBlockNum = 0;
[LB,LatentDataHandler] = loadLatentsDB(1:min(lambdaBlockSize,totalSamples),LatentDataHandler);
gpu_lambda       = kcArrayToGPU( LB); %latent variables are loaded/unloaded in blocks to the GPU
gpu_auxThreshold = kcArrayToGPUint( int32(RampSamples.auxThreshold(:,1:min(lambdaBlockSize,totalSamples))));
gpu_y            = kcArrayToGPU( timeSeries.y);
gpu_trIndex      = kcArrayToGPUint(int32(trIndex));
gpu_trBetaIndex  = kcArrayToGPUint(int32(betaVector));

%% run the sampler

fprintf('Starting Ramping MCMC sampler...\n');

for ss = 2:totalSamples
    if(mod(ss,50) == 0 || ss == totalSamples)
        fprintf('  Ramping MCMC sample %d / %d \n', ss, totalSamples);
    end

    %% sample latent states
    c(1:end)       = c_init;
    p(1:end,1:end) = p_init;
    gpu_lambdaN       = kcArrayGetColumn(gpu_lambda,mod(lambdaCounter+1,lambdaBlockSize));
    gpu_auxThresholdN = kcArrayGetColumnInt(gpu_auxThreshold,mod(lambdaCounter+1,lambdaBlockSize));

    kcRampPathSamplerBias(gpu_lambdaN,gpu_auxThresholdN,gpu_y,gpu_trIndex,gpu_trBetaIndex,RampSamples.betas(ss-1,:),RampSamples.w2s(ss-1),RampSamples.l_0(ss-1),RampSamples.gammas(ss-1),timeSeries.delta_t, params.rampSampler.numParticles, params.rampSampler.minNumParticles,params.rampSampler.sigMult,maxTrLength, c, p, RampSamples.biases(ss-1));

    % if new sample is to be kept, add the summary statistics of the latent path
    if ss > params.MCMC.burnIn && mod(ss-params.MCMC.burnIn-1,params.MCMC.thinRate)==0;
        lambdaN = kcArrayToHost(gpu_lambdaN);
        RampSamples.latent_sum = RampSamples.latent_sum+lambdaN(:);
        RampSamples.latent_sum_sqr = RampSamples.latent_sum_sqr+(lambdaN(:).^2);
        RampSamples.latent_total = RampSamples.latent_total+1;
        clear lambdaN
    end

    lambdaCounter = mod(lambdaCounter+1,lambdaBlockSize);
    if(lambdaCounter == lambdaBlockSize-1)
        LatentDataHandler = saveLatentsDB(kcArrayToHost(gpu_lambda),(1:lambdaBlockSize) + lambdaBlockNum*lambdaBlockSize,LatentDataHandler);
        RampSamples.auxThreshold(:,(1:lambdaBlockSize) + lambdaBlockNum*lambdaBlockSize) = kcArrayToHostint(gpu_auxThreshold);
        lambdaBlockNum = lambdaBlockNum + 1;
    end

    %% Sample betas, l_0
    mu = p\c;
    sig = inv(p);
    RampSamples.rb.sig(:,ss) = diag(sig);
    RampSamples.rb.mu(:,ss)  = mu;

    maxSample = 100; %samples, and resamples l_0 until a value below 1 is found (truncating the multivariate normal)
    for sampleAttempt = 1:maxSample
        driftSample = mvnrnd(mu,sig);
        if(ss < 500 && ss < params.MCMC.burnIn)

            if(driftSample(end) < 0.95)
                break;
            elseif(maxSample == sampleAttempt)
                fprintf('Warning: l_0 going too high! Attemping to correct...\n');
                driftSample(end) = 0.95;
            end
        else
            if(driftSample(end) < 1)
                break;
            elseif(maxSample == sampleAttempt)
                fprintf('Warning: l_0 going too high! Attemping to correct...\n');
                driftSample(end) = 1 - 1e-4;
            end
        end
    end

    RampSamples.betas(ss,:) = driftSample(1:end-1);

    RampSamples.l_0(ss) = driftSample(end);

    if(sum(isnan( driftSample))>0)
        RampSamples.l_0(ss)     = RampSamples.l_0(ss-1);
        RampSamples.betas(ss,:) = RampSamples.betas(ss-1,:);
        warning('Unknown problem with sampling drift rates (most likely numerical error). Keeping previous sample.');
    end

    %% Sample w^2
    [w1_c, w2_c] = kcRampVarianceSampler(gpu_lambdaN,gpu_auxThresholdN,gpu_trIndex,gpu_trBetaIndex,RampSamples.betas(ss,:),RampSamples.l_0(ss));
    w2s_1 = sum(w1_c);
    w2s_2 = sum(w2_c);

    RampSamples.w2s(ss) = 1./gamrnd(params.rampPrior.w2_shape + w2s_1,1./(params.rampPrior.w2_scale + w2s_2)); %gamrnd does not use (alpha,beta) param, uses the one with theta on the wikipedia page for gamma dist
    if(isnan( RampSamples.w2s(ss) ) )
        RampSamples.w2s(ss)     = RampSamples.w2s(ss-1);
        warning('Unknown problem with sampling drift variance (most likely numerical error). Keeping previous sample.');
        if(params.rampPrior.w2_shape <= 1)
            warning('Note: the current prior on the drift variance does not have a mean (shape <= 1). Suggested alternate values for a more constraining prior are given in setupMCMCParams.m');

        end
    end

    %% Step size setup for MALA on parameters
    if(params.rampSampler.learnStepSize && ss < params.MCMC.burnIn)
        if(ss <= 2)
            g_delta = params.rampSampler.epsilon_init;
            fprintf('Starting Langevin step size at %f\n',g_delta);
        elseif(mod(ss-1, params.rampSampler.MALAadjust) == 0)
            acceptPercent = mean(acceptanceCount.sample(ss-params.rampSampler.MALAadjust:ss-1));
            if(g_delta > params.rampSampler.epsilon_min && (acceptPercent < params.rampSampler.accept_min))
                g_delta = max(g_delta/params.rampSampler.adjustRate,params.rampSampler.epsilon_min);
                fprintf('Adjusting Langevin step size down to %f\n',g_delta);
            elseif(g_delta < params.rampSampler.epsilon_max && (acceptPercent > params.rampSampler.accept_max))
                g_delta = min(g_delta*params.rampSampler.adjustRate,params.rampSampler.epsilon_max);
                fprintf('Adjusting Langevin step size up to %f\n',g_delta);
            end
        end
    elseif(ss < params.MCMC.burnIn)
    	g_delta = params.rampSampler.epsilon_init;
    end
    if(ss == params.MCMC.burnIn + 1 && ~isnan(params.rampSampler.epsilon_fixed))
        g_delta = params.rampSampler.epsilon_fixed;
        fprintf('Fixing Langevin step size to %f\n',g_delta);
    end

    %% MALA (Metropolis-Adjusted Langevin Algorithm) sample gamma
    % this MALA proposal is conditioned using the fisher information of gamma
    gamma_a = params.rampPrior.gammaAlpha;
    gamma_b = params.rampPrior.gammaBeta;
    bias_a = 1;
    bias_b = 0.01;

    G_prior = (gamma_a-1)/RampSamples.gammas(ss-1)^2;
    der_log_prior = (gamma_a-1)/RampSamples.gammas(ss-1) - gamma_b;
    bias_g = (bias_a-1)/RampSamples.biases(ss-1)^2;
    bias_l = (bias_a-1)/RampSamples.biases(ss-1) - bias_b;

[log_p_lambda, der_log_p_y, G_log_p_y, der_log_p_y_bias, G_log_p_y_bias, G_off_diag] = kcRampBoundHeightSamplerBias(gpu_lambdaN,gpu_auxThresholdN,gpu_y,gpu_trIndex,RampSamples.gammas(ss-1),timeSeries.delta_t,G_prior,der_log_prior,RampSamples.biases(ss-1),bias_g,bias_l);
    dL = [der_log_p_y; der_log_p_y_bias];
G = [G_log_p_y G_off_diag; G_off_diag G_log_p_y_bias];

    p_mu = [RampSamples.gammas(ss-1); RampSamples.biases(ss-1)] + 1/2*g_delta^2*(G \ dL);
p_sig = (g_delta^2)*inv(G);

    params_star = mvnrnd(p_mu,p_sig)';
    gamma_star = params_star(1);
    bias_star = params_star(2);

    log_q_star = -2/2*log(2*pi) - 1/2*log(det(p_sig)) - 1/2*((params_star-p_mu)'/p_sig*(params_star-p_mu));

    G_prior_star = (gamma_a-1)/gamma_star^2;
    der_log_prior_star = (gamma_a-1)/gamma_star - gamma_b;
    bias_g_star = (bias_a-1)/bias_star^2;
    bias_l_star = (bias_a-1)/bias_star - bias_b;

[log_p_lambda_star, der_log_p_y_star, G_log_p_y_star, der_log_p_y_bias_star, G_log_p_y_bias_star, G_off_diag_star] = kcRampBoundHeightSamplerBias(gpu_lambdaN,gpu_auxThresholdN,gpu_y,gpu_trIndex,gamma_star,timeSeries.delta_t,G_prior_star,der_log_prior_star,bias_star,bias_g_star,bias_l_star);
    dL_star = [der_log_p_y_star; der_log_p_y_bias_star];
G_star = [G_log_p_y_star G_off_diag_star; G_off_diag_star G_log_p_y_bias_star];

    p_mu_star = params_star + 1/2*g_delta^2*(G_star \ dL_star);
p_sig_star = (g_delta^2)*inv(G_star);

    log_q = -2/2*log(2*pi) - 1/2*log(det(p_sig_star)) - 1/2*(([RampSamples.gammas(ss-1); RampSamples.biases(ss-1)]-p_mu_star)'/p_sig_star*([RampSamples.gammas(ss-1); RampSamples.biases(ss-1)]-p_mu_star));

    log_p_bias = bias_a*log(bias_b) - gammaln(bias_a) + (bias_a-1) * log(RampSamples.biases(ss-1))    - bias_b*RampSamples.biases(ss-1);
    log_p_bias_star = bias_a*log(bias_b) - gammaln(bias_a) + (bias_a-1) * log(bias_star)    - bias_b*bias_star;

    if(gamma_a > 0 && gamma_b > 0)
        log_p      = log_p_lambda      + gamma_a*log(gamma_b) - gammaln(gamma_a) + (gamma_a-1) * log(RampSamples.gammas(ss-1))    - gamma_b*RampSamples.gammas(ss-1);
        log_p_star = log_p_lambda_star + gamma_a*log(gamma_b) - gammaln(gamma_a) + (gamma_a-1) * log(gamma_star) - gamma_b*gamma_star;
    else
        log_p      = log_p_lambda      - log(RampSamples.gammas(ss-1));
        log_p_star = log_p_lambda_star - log(gamma_star);
    end
    log_p = log_p + log_p_bias;
    log_p_star = log_p_star + log_p_bias_star;

    log_a = log_p_star + log_q - log_p - log_q_star;
    lrand = log(rand);
    if(gamma_star > 0 && bias_star > 0 && lrand < log_a)
        RampSamples.gammas(ss) = gamma_star;
        RampSamples.biases(ss) = bias_star;
        acceptanceCount.g = acceptanceCount.g+1;
        acceptanceCount.sample(ss) = 1;
    else
        RampSamples.gammas(ss) = RampSamples.gammas(ss-1);
        RampSamples.biases(ss) = RampSamples.biases(ss-1);
        acceptanceCount.sample(ss) = 0;
    end

end

%% finish up---------------------------------------
thinRate = params.MCMC.thinRate;

%get sampling stats for path
try
    [RampFit.lambdas.mean,LatentDataHandler]   = meanLatentsDB((params.MCMC.burnIn+1):thinRate:totalSamples,LatentDataHandler);
catch exc %#ok<NASGU>
    RampFit.lambdas.mean   = [];
end
RampFit.auxThreshold.mean   = mean(RampSamples.auxThreshold(:,params.MCMC.burnIn+1:thinRate:end),2);
RampFit.auxThreshold.median = median(RampSamples.auxThreshold(:,params.MCMC.burnIn+1:thinRate:end),2);
RampFit.auxThreshold.std    = std(RampSamples.auxThreshold(:,params.MCMC.burnIn+1:thinRate:end),[],2);

RampFit.beta.mean  = mean(RampSamples.betas(params.MCMC.burnIn+1:thinRate:end,:))';
RampFit.w2.mean    = mean(RampSamples.w2s(params.MCMC.burnIn+1:thinRate:end))';
RampFit.gamma.mean = mean(RampSamples.gammas(params.MCMC.burnIn+1:thinRate:end))';
RampFit.l_0.mean   = mean(RampSamples.l_0(params.MCMC.burnIn+1:thinRate:end))';
RampFit.bias.mean = mean(RampSamples.biases(params.MCMC.burnIn+1:thinRate:end))';
RampFit.latent_path.mean = (RampSamples.latent_sum)/RampSamples.latent_total;
RampFit.latent_path.var = (RampSamples.latent_sum_sqr - (RampSamples.latent_sum.*RampSamples.latent_sum) / RampSamples.latent_total) / (RampSamples.latent_total-1);

RampFit.beta.interval  = prctile(RampSamples.betas(((params.MCMC.burnIn+1):thinRate:end),:),[2.5 97.5],1);
RampFit.w2.interval    = prctile(RampSamples.w2s((params.MCMC.burnIn+1):thinRate:end,:),[2.5 97.5],1);
RampFit.l_0.interval   = prctile(RampSamples.l_0((params.MCMC.burnIn+1):thinRate:end),[2.5 97.5],1);
RampFit.gamma.interval = prctile(RampSamples.gammas((params.MCMC.burnIn+1):thinRate:end),[2.5 97.5],1);
RampFit.bias.interval = prctile(RampSamples.biases((params.MCMC.burnIn+1):thinRate:end),[2.5 97.5],1);

try
    kcFreeGPUArray(gpu_y);
    kcFreeGPUArray(gpu_lambda);
    kcFreeGPUArray(gpu_auxThreshold);
    kcFreeGPUArray(gpu_trIndex);
    kcFreeGPUArray(gpu_trBetaIndex);
catch e
    fprintf('Error clearing cuda memory: %s\n',e);
end

fprintf('Ramping model sampler complete.\n');
end


text:
package net.oscartech.tesseract.node;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.CharsetUtil;
import net.oscartech.tesseract.node.pojo.NodeProposal;
import net.oscartech.tesseract.node.util.MarshallUtils;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Created by tylaar on 15/4/29.
*/
@ChannelHandler.Sharable
public class NodeServerHandler extends ChannelInboundHandlerAdapter {

    private NodeProposalBroker proposalBroker;
    private AtomicInteger counter = new AtomicInteger(0);

    public NodeServerHandler(final NodeProposalBroker proposalBroker) {
        this.proposalBroker = proposalBroker;
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }

    @Override
    public void channelRead(final ChannelHandlerContext ctx, Object msg) {
        ByteBuf in = (ByteBuf) msg;
        try {
            counter.getAndIncrement();
            NodeProposal proposal = MarshallUtils.fromStringToProposal(in.toString(CharsetUtil.UTF_8));
            //System.out.println("server read hit" + proposal.getProposalId() + " and type: " + proposal.getType());
            /**
             * One thing that we shall always bear in mind is that, proposal broker
             * theoretically shall be state less. The code is shared by different
             * thread.
             */
            NodeProposal reply = proposalBroker.handleProposal(proposal);

            if (reply != null && ctx.channel().isWritable()) {
                System.out.println("replying: ");
                proposalBroker.replyProposal(ctx.channel(), reply);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public int getCounter() {
        return counter.get();
    }

}


text:
<!DOCTYPE html>

    <title>Classes  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset='utf-8'>

PocketMediaNativeAds Docs (100% documented)

View on GitHub

        PocketMediaNativeAds Reference

        Classes  Reference

            Classes

                AbstractAdUnitTableViewCell

                DataSource

                FullscreenBrowser

                MarginAdPosition

                NativeAd

                NativeAdListing

                NativeAdStream

                NativeAdTableViewDataSource

                NativeAdTableViewDelegate

                NativeAdsRequest

                NativeAdsWebviewDelegate

                PocketMediaNativeAdsBundle

                PredefinedAdPosition

                StandardAdUnitTableViewCell

            Enums

                AdUnitType

                EImageType

                MarginAdPositionError

                PredefinedAdPositionError

            Extensions

                UIImageView

                UITableView

            Protocols

                AdPosition

                DataSourceProtocol

                NativeAdOpenerDelegate

                NativeAdTableViewDataSourceProtocol

                NativeAdsConnectionDelegate

                NativeAdsWebviewRedirectionsDelegate

            Structs

                NativeAdsConstants

                – Device

                – NativeAds

                SImage

            Typealiases

                AdListingsAndPositions

                AdsForSectionMap

                ImageCacheCompletion

Classes

The following classes are available globally.

                    PocketMediaNativeAdsBundle

Accessing the internal PocketMediaNativeAds Framework Bundle

                        See more

Declaration

Swift

open class PocketMediaNativeAdsBundle: NSObject

                    DataSource

Abstract class that defines the bare datasource functionality.

                        See more

Declaration

Swift

open class DataSource: NSObject, DataSourceProtocol

                    NativeAdTableViewDataSource

Wraps around a datasource so it contains both a mix of ads and none ads.

                        See more

Declaration

Swift

open class NativeAdTableViewDataSource: DataSource, UITableViewDataSource

                    NativeAdTableViewDelegate

Wraps around a UITableViewDelegate delegate and adds the ad logic.
Patching of the delegate and replaces some calls if the subject is an ad. Otherwise it’ll call the original implementation.

                        See more

Declaration

Swift

open class NativeAdTableViewDelegate: NSObject, UITableViewDelegate

                    NativeAdStream

This class is the entry point of easily integrating nativeAds in existing UI elements of the host.

                        See more

Declaration

Swift

open class NativeAdStream: NSObject, NativeAdsConnectionDelegate

                    NativeAdListing

Wraps around the native ad. It represents an ad displayed in a collection.
Contains all the logic of the position of the original host array.
The idea is that we find the last adListing in the shown list, and based on that figure out what the original position was of a non ad view.
@author Pocket Media

                        See more

Declaration

Swift

open class NativeAdListing: NSObject

                    MarginAdPosition

This ad position implementation makes the ads show up at a set interval (margin).

                        See more

Declaration

Swift

open class MarginAdPosition: NSObject, AdPosition

                    PredefinedAdPosition

This ad position implementation makes the ads show up at certain predefined positions.

                        See more

Declaration

Swift

open class PredefinedAdPosition: NSObject, AdPosition

                    NativeAdsRequest

NativeAdsRequest is a controller class that will do a network request and call a instance of NativeAdsConnectionDelegate based on the results.

                        See more

Declaration

Swift

open class NativeAdsRequest: NSObject, NSURLConnectionDelegate, UIWebViewDelegate

                    NativeAdsWebviewDelegate

Controls an instance of a webview. Adds a load indicator to give feedback back to the user.
It follows each redirect until it reaches the app store or website. Then we’ll call the delegate

                        See more

Declaration

Swift

open class NativeAdsWebviewDelegate: NSObject, UIWebViewDelegate

                    FullscreenBrowser

Controller class that is used to open the NativeAd in An FullScreen Embedded WebView.
Default implementation for the NativeAdOpenerDelegate

                        See more

Declaration

Swift

open class FullscreenBrowser: UIViewController, NativeAdOpenerDelegate

                    NativeAd

Model class. It contains all the attributes received from the API, and allows to open the click URL with a specific opener.

                        See more

Declaration

Swift

open class NativeAd: NSObject

                    AbstractAdUnitTableViewCell

Class to be subclassed for use with the AdStream.

                        See more

Declaration

Swift

open class AbstractAdUnitTableViewCell: UITableViewCell

                    StandardAdUnitTableViewCell

Standard AdUnit for TableView
*

                        See more

Declaration

Swift

open class StandardAdUnitTableViewCell: AbstractAdUnitTableViewCell

© 2017 PocketMedia.

Generated by jazzy ♪♫ v0.7.3, a Realm project.


text:
package dhcpv4

// DHCPRequest is a client message to servers either (a) requesting offered
// parameters from one server and implicitly declining offers from all others,
// (b) confirming correctness of previously allocated address after, e.g.,
// system reboot, or (c) extending the lease on a particular network address.
type DHCPRequest struct {
	Packet
	ReplyWriter
}


text:
package com.afollestad.materialdialogs;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import com.afollestad.materialdialogs.internal.MDTintHelper;
import com.afollestad.materialdialogs.util.DialogUtils;

/** @author Aidan Follestad (afollestad) */
class DefaultRvAdapter extends RecyclerView.Adapter<DefaultRvAdapter.DefaultVH> {

  private final MaterialDialog dialog;
  @LayoutRes private final int layout;
  private final GravityEnum itemGravity;
  private InternalListCallback callback;

  DefaultRvAdapter(MaterialDialog dialog, @LayoutRes int layout) {
    this.dialog = dialog;
    this.layout = layout;
    this.itemGravity = dialog.builder.itemsGravity;
  }

  void setCallback(InternalListCallback callback) {
    this.callback = callback;
  }

  @Override
  public DefaultVH onCreateViewHolder(ViewGroup parent, int viewType) {
    final View view = LayoutInflater.from(parent.getContext()).inflate(layout, parent, false);
    DialogUtils.setBackgroundCompat(view, dialog.getListSelector());
    return new DefaultVH(view, this);
  }

  @Override
  public void onBindViewHolder(DefaultVH holder, int index) {
    final View view = holder.itemView;
    boolean disabled = DialogUtils.isIn(index, dialog.builder.disabledIndices);
    int itemTextColor =
        disabled
            ? DialogUtils.adjustAlpha(dialog.builder.itemColor, 0.4f)
            : dialog.builder.itemColor;
    holder.itemView.setEnabled(!disabled);

    switch (dialog.listType) {
      case SINGLE:
        {
          @SuppressLint("CutPasteId")
          RadioButton radio = (RadioButton) holder.control;
          boolean selected = dialog.builder.selectedIndex == index;
          if (dialog.builder.choiceWidgetColor != null) {
            MDTintHelper.setTint(radio, dialog.builder.choiceWidgetColor);
          } else {
            MDTintHelper.setTint(radio, dialog.builder.widgetColor);
          }
          radio.setChecked(selected);
          radio.setEnabled(!disabled);
          break;
        }
      case MULTI:
        {
          @SuppressLint("CutPasteId")
          CheckBox checkbox = (CheckBox) holder.control;
          boolean selected = dialog.selectedIndicesList.contains(index);
          if (dialog.builder.choiceWidgetColor != null) {
            MDTintHelper.setTint(checkbox, dialog.builder.choiceWidgetColor);
          } else {
            MDTintHelper.setTint(checkbox, dialog.builder.widgetColor);
          }
          checkbox.setChecked(selected);
          checkbox.setEnabled(!disabled);
          break;
        }
    }

    holder.title.setText(dialog.builder.items.get(index));
    holder.title.setTextColor(itemTextColor);
    dialog.setTypeface(holder.title, dialog.builder.regularFont);

    setupGravity((ViewGroup) view);

    if (dialog.builder.itemIds != null) {
      if (index < dialog.builder.itemIds.length) {
        view.setId(dialog.builder.itemIds[index]);
      } else {
        view.setId(-1);
      }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      ViewGroup group = (ViewGroup) view;
      if (group.getChildCount() == 2) {
        // Remove circular selector from check boxes and radio buttons on Lollipop
        if (group.getChildAt(0) instanceof CompoundButton) {
          group.getChildAt(0).setBackground(null);
        } else if (group.getChildAt(1) instanceof CompoundButton) {
          group.getChildAt(1).setBackground(null);
        }
      }
    }
  }

  @Override
  public int getItemCount() {
    return dialog.builder.items != null ? dialog.builder.items.size() : 0;
  }

  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  private void setupGravity(ViewGroup view) {
    final LinearLayout itemRoot = (LinearLayout) view;
    final int gravityInt = itemGravity.getGravityInt();
    itemRoot.setGravity(gravityInt | Gravity.CENTER_VERTICAL);

    if (view.getChildCount() == 2) {
      if (itemGravity == GravityEnum.END
          && !isRTL(view.getContext())
          && view.getChildAt(0) instanceof CompoundButton) {
        CompoundButton first = (CompoundButton) view.getChildAt(0);
        view.removeView(first);

        TextView second = (TextView) view.getChildAt(0);
        view.removeView(second);
        second.setPadding(
            second.getPaddingRight(),
            second.getPaddingTop(),
            second.getPaddingLeft(),
            second.getPaddingBottom());

        view.addView(second);
        view.addView(first);
      } else if (itemGravity == GravityEnum.START
          && isRTL(view.getContext())
          && view.getChildAt(1) instanceof CompoundButton) {
        CompoundButton first = (CompoundButton) view.getChildAt(1);
        view.removeView(first);

        TextView second = (TextView) view.getChildAt(0);
        view.removeView(second);
        second.setPadding(
            second.getPaddingRight(),
            second.getPaddingTop(),
            second.getPaddingRight(),
            second.getPaddingBottom());

        view.addView(first);
        view.addView(second);
      }
    }
  }

  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  private boolean isRTL(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
      return false;
    }
    Configuration config = context.getResources().getConfiguration();
    return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
  }

  interface InternalListCallback {

    boolean onItemSelected(
        MaterialDialog dialog,
        View itemView,
        int position,
        @Nullable CharSequence text,
        boolean longPress);
  }

  static class DefaultVH extends RecyclerView.ViewHolder
      implements View.OnClickListener, View.OnLongClickListener {

    final CompoundButton control;
    final TextView title;
    final DefaultRvAdapter adapter;

    DefaultVH(View itemView, DefaultRvAdapter adapter) {
      super(itemView);
      control = itemView.findViewById(R.id.md_control);
      title = itemView.findViewById(R.id.md_title);
      this.adapter = adapter;
      itemView.setOnClickListener(this);
      if (adapter.dialog.builder.listLongCallback != null) {
        itemView.setOnLongClickListener(this);
      }
    }

    @Override
    public void onClick(View view) {
      if (adapter.callback != null && getAdapterPosition() != RecyclerView.NO_POSITION) {
        CharSequence text = null;
        if (adapter.dialog.builder.items != null
            && getAdapterPosition() < adapter.dialog.builder.items.size()) {
          text = adapter.dialog.builder.items.get(getAdapterPosition());
        }
        adapter.callback.onItemSelected(adapter.dialog, view, getAdapterPosition(), text, false);
      }
    }

    @Override
    public boolean onLongClick(View view) {
      if (adapter.callback != null && getAdapterPosition() != RecyclerView.NO_POSITION) {
        CharSequence text = null;
        if (adapter.dialog.builder.items != null
            && getAdapterPosition() < adapter.dialog.builder.items.size()) {
          text = adapter.dialog.builder.items.get(getAdapterPosition());
        }
        return adapter.callback.onItemSelected(
            adapter.dialog, view, getAdapterPosition(), text, true);
      }
      return false;
    }
  }
}