text:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Assets.Scripts.Content;
using UnityEngine;
using ValkyrieTools;

///
/// This class reads and stores all of the content for a base game and expansions.
public class ContentData {

    public HashSet<string> loadedPacks;
    public List<ContentPack> allPacks;
    public Dictionary<string, StringKey> packSymbol;

    private Dictionary<Type, Dictionary<string, IContent>> Content = new Dictionary<Type, Dictionary<string, IContent>>();

    protected Dictionary<string, IContent> ContentOfType<T>() where T : IContent
    {
        Content.TryGetValue(typeof(T), out Dictionary<string, IContent> content);
        if (content == null)
        {
            content = new Dictionary<string, IContent>();
            Content[typeof(T)] = content;
        }
        return content;
    }

    public void AddOrReplace<T>(string name, T content) where T : IContent
    {
        ContentOfType<T>()[name] = content;
    }

    public bool TryGet<T>(string name, out T value) where T : IContent
    {
        var contains = ContentOfType<T>().TryGetValue(name, out IContent obj);
        value = (T) obj;
        return contains;
    }

    public T Get<T>(string name) where T : IContent
    {
        return (T) ContentOfType<T>()[name];
    }
    public IEnumerable<string> Keys<T>() where T : IContent
    {
        return ContentOfType<T>().Keys.AsEnumerable();
    }

    public IEnumerable<T> Values<T>() where T : IContent
    {
        return ContentOfType<T>().Values.Cast<T>().AsEnumerable();
    }

    public bool ContainsKey<T>(string key) where T : IContent
    {
        return ContentOfType<T>().ContainsKey(key);
    }

    public IEnumerable<KeyValuePair<string, T>> GetAll<T>() where T : IContent
    {
        return ContentOfType<T>().AsEnumerable()
            .Select(t => new KeyValuePair<string, T>(t.Key, (T)t.Value));
    }

    public int Count<T>() where T : IContent
    {
        return ContentOfType<T>().Count;
    }

    // textureCache is used to store previously loaded textures so they are faster next time
    // For the editor all defined images are loaded, requires ~1GB RAM
    // For quests only used tiles/tokens will be loaded
    public static Dictionary<string, Texture2D> textureCache;

    ///
    /// Get the path where game content is defined.
    /// <returns>
    /// The path as a string with a trailing '/'.</returns>
    public static string ContentPath()
    {
        if (Application.platform == RuntimePlatform.Android)
        {
            return Application.persistentDataPath + "/assets/content/";
        }
        return Application.streamingAssetsPath + "/content/";
    }

    // Return a list of id for all enbaled content packs
    public List<string> GetLoadedPackIDs()
    {
        return new List<string>(loadedPacks);
    }

    ///
    /// Get the path where ffg app content is imported.
    /// <returns>
    /// The path as a string without a trailing '/'.</returns>
    public static string ImportPath()
    {
        return GameTypePath + Path.DirectorySeparatorChar + "import";
    }

    ///
    /// Get download directory without trailing '/'
    ///
    /// <returns>location to save / load packages</returns>
    public static string DownloadPath()
    {
        return Game.AppData() + Path.DirectorySeparatorChar + "Download";
    }

    public static string TempPath
    {
        get
        {
            if (Application.platform == RuntimePlatform.Android)
            {
                return Path.Combine(Game.AppData(), "temp");
            }
            return Path.GetTempPath();
        }
    }

    public static string TempValyriePath
    {
        get
        {
            return Path.Combine(TempPath, "Valkyrie");
        }
    }

    public static string GameTypePath
    {
        get
        {
            return Path.Combine(Game.AppData() , Game.Get().gameType.TypeName());
        }
    }

    public static string ValkyrieLoadPath
    {
        get
        {
            return Path.Combine(TempValyriePath, "Load");
        }
    }

    public static string ValkyriePreloadPath
    {
        get
        {
            return Path.Combine(TempValyriePath, "Preload");
        }
    }

    public static string ValkyrieLoadQuestPath
    {
        get
        {
            return Path.Combine(ValkyrieLoadPath, "quest");
        }
    }

    ///
    /// Seach the provided path for all content packs and read meta data.
    /// <param name="path">Path to search for content packs.</param>
    public ContentData(string path)
    {
        // This is pack type for sorting packs
        loadedPacks = new HashSet<string>();

        // This is pack symbol list
        packSymbol = new Dictionary<string, StringKey>();

        //This has the game game and all expansions, general info
        allPacks = new List<ContentPack>();

        // Search each directory in the path (one should be base game, others expansion.  Names don't matter
        string[] contentFiles = Directory.GetFiles(path, "content_pack.ini", SearchOption.AllDirectories);
        foreach (string p in contentFiles)
        {
            PopulatePackList(Path.GetDirectoryName(p));
        }
    }

    // Read a content pack for list of files and meta data
    public void PopulatePackList(string path)
    {
        // All packs must have a content_pack.ini, otherwise ignore
        if (File.Exists(path + Path.DirectorySeparatorChar + "content_pack.ini"))
        {
            ContentPack pack = new ContentPack();

            // Get all data from the file
            IniData d = IniRead.ReadFromIni(path + Path.DirectorySeparatorChar + "content_pack.ini");
            // Todo: better error handling
            if (d == null)
            {
                ValkyrieDebug.Log("Failed to get any data out of " + path + Path.DirectorySeparatorChar + "content_pack.ini!");
                Application.Quit();
            }

            pack.name = d.Get("ContentPack", "name");
            if (pack.name.Equals(""))
            {
                ValkyrieDebug.Log("Failed to get name data out of " + path + Path.DirectorySeparatorChar + "content_pack.ini!");
                Application.Quit();
            }

            // id can be empty/missing
            pack.id = d.Get("ContentPack", "id");

            // If this is invalid we will just handle it later, not fatal
            if (d.Get("ContentPack", "image").IndexOf("{import}") == 0)
            {
                pack.image = ImportPath() + d.Get("ContentPack", "image").Substring(8);
            }
            else
            {
                pack.image = path + Path.DirectorySeparatorChar + d.Get("ContentPack", "image");
            }

            // Black description isn't fatal
            pack.description = d.Get("ContentPack", "description");

            // Some packs have a type
            pack.type = d.Get("ContentPack", "type");

            // Get cloned packs
            string cloneString = d.Get("ContentPack", "clone");
            pack.clone = new List<string>();
            foreach (string s in cloneString.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
            {
                pack.clone.Add(s);
            }

            // Get all the other ini files in the pack
            List<string> files = new List<string>();
            // content_pack file is included
            files.Add(path + Path.DirectorySeparatorChar + "content_pack.ini");

            // No extra files is valid
            if (d.Get("ContentPackData") != null)
            {
                foreach (string file in d.Get("ContentPackData").Keys)
                {
                    files.Add(path + Path.DirectorySeparatorChar + file);
                }
            }
            // Save list of files
            pack.iniFiles = files;

            // Get all the other ini files in the pack
            Dictionary<string, List<string>> dictFiles = new Dictionary<string, List<string>>();
            // No extra files is valid
            if (d.Get("LanguageData") != null)
            {
                foreach (string s in d.Get("LanguageData").Keys)
                {
                    int firstSpace = s.IndexOf(' ');
                    string id = s.Substring(0, firstSpace);
                    string file = s.Substring(firstSpace + 1);
                    if (!dictFiles.ContainsKey(id))
                    {
                        dictFiles.Add(id, new List<string>());
                    }
                    dictFiles[id].Add(path + Path.DirectorySeparatorChar + file);
                }
            }
            // Save list of files
            pack.localizationFiles = dictFiles;

            // Add content pack
            allPacks.Add(pack);

            // Add symbol
            packSymbol.Add(pack.id, new StringKey("val", pack.id + "_SYMBOL"));

            // We finish without actually loading the content, this is done later (content optional)
        }
    }

    // Return a list of names for all found content packs
    public List<string> GetPacks()
    {
        List<string> names = new List<string>();
        allPacks.ForEach(cp => names.Add(cp.name));
        return names;
    }

    public string GetContentName(string id)
    {
        foreach (ContentPack cp in allPacks)
        {
            if (cp.id.Equals(id))
            {
                return new StringKey(cp.name).Translate();
            }
        }
        return "";
    }

    public string GetContentAcronym(string id)
    {
        foreach (ContentPack cp in allPacks)
        {
            if (cp.id.Equals(id))
            {
                return new StringKey("val", cp.id).Translate();
            }
        }
        return "";
    }

    public string GetContentSymbol(string id)
    {
        foreach (ContentPack cp in allPacks)
        {
            if (cp.id.Equals(id))
            {
                return new StringKey("val", cp.id+"_SYMBOL").Translate();
            }
        }
        return "";
    }

    internal bool AddContent<T>(string name, T d) where T : IContent
    {
        bool added = false;
        // If we don't already have one or it's lower priority then add this
        if (!TryGet(name, out T existingPackData)
            || existingPackData.Priority < d.Priority)
        {
            AddOrReplace(name, d);
            return true;
        }
        // items of the same priority belong to multiple packs
        else if (existingPackData.Priority == d.Priority)
        {
            existingPackData.Sets.AddRange(d.Sets);
            return false;
        }

        return false;
    }

    // Holding class for contentpack data
    public class ContentPack
    {
        public string name;
        public string image;
        public string description;
        public string id;
        public string type;
        public List<string> iniFiles;
        public Dictionary<string, List<string>> localizationFiles;
        public List<string> clone;
    }

    ///
    /// This will resove the asset name to a matching file and return the full file path including the file extension or null, if the file can't be resolved.
    ///
    public static string ResolveTextureFile(string name)
    {
        if (name == null) throw new ArgumentNullException("name");
        if (File.Exists(name))
        {
            return name;
        }

        // Check all possible extensions
        foreach (string extension in new[] { ".dds", ".pvr", ".png", ".jpg", ".jpeg" })
        {
            string file = name + extension;
            if (File.Exists(file))
            {
                return file;
            }
        }
        return null;
    }

    // Get a unity texture from a file (dds or other unity supported format)
    public static Texture2D FileToTexture(string file)
    {
        if (file == null) throw new ArgumentNullException("file");
        return FileToTexture(file, Vector2.zero, Vector2.zero);
    }

    // Get a unity texture from a file (dds, svr or other unity supported format)
    // Crop to pos and size in pixels
    public static Texture2D FileToTexture(string file, Vector2 pos, Vector2 size)
    {
        if (file == null) throw new ArgumentNullException("file");
        var resolvedFile = ResolveTextureFile(file);
        // return if file could not be resolved
        if (resolvedFile == null)
        {
            ValkyrieDebug.Log("Could not resolve file: '" + file + "'");
            return null;
        }
        file = resolvedFile;

        Texture2D texture = null;

        if (textureCache == null)
        {
            textureCache = new Dictionary<string, Texture2D>();
        }

        if (textureCache.ContainsKey(file))
        {
            texture = textureCache[file];
        }
        else
        {
            string ext = Path.GetExtension(file);
            if (ext.Equals(".dds", StringComparison.InvariantCultureIgnoreCase))
            {
                texture = DdsToTexture(file);
            }
            else if (ext.Equals(".pvr", StringComparison.InvariantCultureIgnoreCase))
            {
                texture = PvrToTexture(file);
            }
            else // If the image isn't one of the formats above, just use unity file load
            {
                texture = ImageToTexture(file);
            }
            if (!file.Contains(TempPath))
            {
                textureCache.Add(file, texture);
            }
        }
        // Get whole image
        if (size.x == 0) return texture;

        // Get part of the image
        // Array of pixels from image
        Color[] pix = texture.GetPixels(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.y), Mathf.RoundToInt(size.x), Mathf.RoundToInt(size.y));
        // Empty texture
        var subTexture = new Texture2D(Mathf.RoundToInt(size.x), Mathf.RoundToInt(size.y));
        // Set pixels
        subTexture.SetPixels(pix);
        subTexture.Apply();
        return subTexture;
    }

    private static Texture2D DdsToTexture(string file)
    {
        if (file == null) throw new ArgumentNullException("file");
        // Unity doesn't support dds directly, have to do hackery
        // Read the data
        byte[] ddsBytes = null;
        try
        {
            ddsBytes = File.ReadAllBytes(file);
        }
        catch (Exception ex)
        {
            if (!File.Exists(file))
                ValkyrieDebug.Log("Warning: DDS Image missing: '" + file + "'");
            else
                ValkyrieDebug.Log("Warning: DDS Image loading of file '" + file + "' failed with " + ex.GetType().Name + " message: " + ex.Message);
            return null;
        }
        // Check for valid header
        byte ddsSizeCheck = ddsBytes[4];
        if (ddsSizeCheck != 124)
        {
            ValkyrieDebug.Log("Warning: Image invalid: '" + file + "'");
            return null;
        }

        // Extract dimensions
        int height = ddsBytes[13] * 256 + ddsBytes[12];
        int width = ddsBytes[17] * 256 + ddsBytes[16];

        /*20-23 pit
         * 24-27 dep
         * 28-31 mm
         * 32-35 al
         * 36-39 res
         * 40-43 sur
         * 44-51 over
         * 52-59 des
         * 60-67 sov
         * 68-75 sblt
         * 76-79 size
         * 80-83 flags
         * 84-87 fourCC
         * 88-91 bpp
         * 92-95 red
         */

        char[] type = new char[4];
        type[0] = (char)ddsBytes[84];
        type[1] = (char)ddsBytes[85];
        type[2] = (char)ddsBytes[86];
        type[3] = (char)ddsBytes[87];

        // Copy image data (skip header)
        const int DDS_HEADER_SIZE = 128;
        byte[] dxtBytes = new byte[ddsBytes.Length - DDS_HEADER_SIZE];
        Buffer.BlockCopy(ddsBytes, DDS_HEADER_SIZE, dxtBytes, 0, ddsBytes.Length - DDS_HEADER_SIZE);

        Texture2D texture = null;

        if (ddsBytes[87] == '5')
        {
            texture = new Texture2D(width, height, TextureFormat.DXT5, false);
        }
        else if (ddsBytes[87] == '1')
        {
            texture = new Texture2D(width, height, TextureFormat.DXT1, false);
        }
        else if (ddsBytes[88] == 32)
        {
            if (ddsBytes[92] == 0)
            {
                texture = new Texture2D(width, height, TextureFormat.BGRA32, false);
            }
            else
            {
                texture = new Texture2D(width, height, TextureFormat.RGBA32, false);
            }
        }
        else if (ddsBytes[88] == 24)
        {
            texture = new Texture2D(width, height, TextureFormat.RGB24, false);
        }
        else
        {
            ValkyrieDebug.Log("Warning: Image invalid: '" + file + "'");
        }
        texture.LoadRawTextureData(dxtBytes);
        texture.Apply();
        return texture;
    }

    private static Texture2D PvrToTexture(string file)
    {
        if (file == null) throw new ArgumentNullException("file");

        long pixelformat = -1;
        try
        {
            string imagePath = new Uri(file).AbsoluteUri;
            var www = new WWW(imagePath);

            // *** HEADER ****
            // int verison
            // int flags
            pixelformat = BitConverter.ToInt64(www.bytes, 8);
            // int color space
            // int channel type
            int height = BitConverter.ToInt32(www.bytes, 24);
            int width = BitConverter.ToInt32(www.bytes, 28);
            // int depth
            // int num surfaces
            // int num faces
            // int mip map count
            // int meta data size

            // *** IMAGE DATA ****
            const int PVR_HEADER_SIZE = 52;
            var image = new byte[www.bytesDownloaded - PVR_HEADER_SIZE];
            Buffer.BlockCopy(www.bytes, PVR_HEADER_SIZE, image, 0, www.bytesDownloaded - PVR_HEADER_SIZE);
            Texture2D texture = null;
            switch (pixelformat)
            {
                case 22: // ETC2_RGB4
                    texture = new Texture2D(width, height, TextureFormat.ETC2_RGB, false, true);
                    texture.LoadRawTextureData(image);
                    texture.Apply();
                    break;
                case 23:  // ETC2_RGB8
                    texture = new Texture2D(width, height, TextureFormat.ETC2_RGBA8, false, true);
                    texture.LoadRawTextureData(image);
                    texture.Apply();
                    break;
                default:
                    ValkyrieDebug.Log("Warning: PVR unknown pixelformat: '" + pixelformat + "' in file: '" + file + "'");
                    break;
            }
            return texture;
        }
        catch (Exception ex)
        {
            if (!File.Exists(file))
                ValkyrieDebug.Log("Warning: PVR Image missing: '" + file + "'");
            else
                ValkyrieDebug.Log("Warning: PVR Image loading of file '" + file + "' failed with " + ex.GetType().Name + " message: " + ex.Message + " pixelformat: '" + pixelformat + "'");
            return null;
        }
    }

    private static Texture2D ImageToTexture(string file)
    {
        if (file == null) throw new ArgumentNullException("file");
        try
        {
            string imagePath = new Uri(file).AbsoluteUri;
            var www = new WWW(imagePath);
            return www.texture;
        }
        catch (Exception ex)
        {
            if (!File.Exists(file))
                ValkyrieDebug.Log("Warning: Image missing: '" + file + "'");
            else
                ValkyrieDebug.Log("Warning: Image loading of file '" + file + "' failed with " + ex.GetType().Name + " message: " + ex.Message);
            return null;
        }
    }

}


text:
<?php
require_once('back/conn.php');
if (!isset($_SESSION)) {
 		 session_start();
	}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "long":
		$theValue = ($theValue != "") ? intval($theValue) : "NULL";
    	break;
	case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<!DOCTYPE HTML>

<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="img/tunnel.ico" />

<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />

<title>过江隧道监测系统</title>

 Tunnel Monitor System Tunnel Monitor System
			1.0
			

 tab1 

 资讯

 图片

 产品

 用户

						<?php echo @$_SESSION['username'];?>

修改密码

注销

退出

 新闻管理

 实时数据

 GIS地图

 报表

 数据管理

 传感器管理

 解调仪管理

 数据导出

					实时数据



关闭当前

关闭全部

redpajama_set_name: RedPajamaGithub


text:
<!DOCTYPE HTML>
<html>
<head>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script>

// Formatting of promises is done according to
// https://www.chromium.org/blink/serviceworker/testing#TOC-Layout-Tests-Style

promise_test(function() {
  return navigator.mediaDevices.getUserMedia({})
    .then(function(s) {
        assert_unreached('getUserMedia should have failed');
      })
    .catch(function(e) {
        assert_equals(e.name, 'SyntaxError');
      });
}, 'getUserMedia() without any media types should fail');

promise_test(function() {
  return navigator.mediaDevices.getUserMedia({'audio': true})
    .then(function(s) {
         // do nothing
      })
    .catch(function(e) {
        assert_unreached('getUserMedia should have succeeded');
      });
}, 'getUserMedia() with audio=true should succeed');

promise_test(function() {
  return navigator.mediaDevices.getUserMedia(
      {audio: {'mandatory': { 'valid_but_unsupported_1': 0}}})
    .then(function(s) {
        assert_unreached('getUserMedia should have failed');
      })
    .catch(function(e) {
        assert_equals(e.name, 'ConstraintNotSatisfiedError');
      });
}, 'getUserMedia() with unsupported mandatory constraint should fail');

// The next tests document existing behavior. They seem non-conformant
// with the specs.
promise_test(function() {
  return navigator.mediaDevices.getUserMedia({video: {}})
    .then(function(s) {
        assert_unreached('getUserMedia should have failed');
      })
    .catch(function(e) {
        assert_equals(e.name, 'Error');
      });
}, 'getUserMedia() with empty constraints (neither mandatory nor optional) should fail with Error');

// The following set of tests verify behavior when trying to use the
// dictionary form of constraints. The behaviors currently expected are:
// - Unknown names in dictionary: ignored - which means Error
// - Known names but illegal syntax for value: TypeError
// - Known names and legal syntax for value: Error (no handler yet).

function check_constraints(name, constraints, expected_error) {
  promise_test(function() {
    return navigator.mediaDevices.getUserMedia({'video': constraints})
      .then(function(s) {
          assert_unreached('getUserMedia should have failed');
        })
      .catch(function(e) {
          assert_equals(e.name, expected_error);
        });
  }, name);
}

check_constraints(
  'Constraint with unsupported name gets ignored',
  {'unsupported_name': 47}, 'Error');

check_constraints(
  'Constraint with exact Long value should be parsed',
  {'height': {exact: 47}}, 'Error');
check_constraints(
  'Constraint with naked value should fail with TypeError (until supported)',
  {height: 47}, 'TypeError');

check_constraints(
  'Constraint with boolean value should be parsed',
  {'echoCancellation': {exact: true}}, 'Error');
check_constraints(
  'Constraint with boolean value should fail on naked value (until supported)',
  {'echoCancellation': true}, 'TypeError');

check_constraints(
  'Constraint with string value should work on exact with array',
  {'facingMode': {exact: ['user']}}, 'Error');
check_constraints(
  'Constraint with exact string value should fail (until supported)',
  {'facingMode': {exact: 'user'}}, 'TypeError');
check_constraints(
  'Constraint with naked string value should fail (until supported)',
  {'facingMode': 'user'}, 'TypeError');
check_constraints(
  'Using both mandatory and height should give TypeError',
  {'mandatory': {'height': '270'}, 'height': '270'}, 'TypeError');

// Shows that the advanced element is not ignored.
check_constraints(
  'Advanced constraints with illegal content gives TypeError',
  {'advanced': [{'height': 270}]}, 'TypeError');

</script>
</body>
</html>


text:
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddIsadoptToQuestionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('questions', function (Blueprint $table) {
            $table->boolean('isadopt')->default(0);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('questions', function (Blueprint $table) {
            $table->dropColumn(['isadopt']);
        });
    }
}


text:
/*
 * @test
 * @bug 6287172
 * @summary SASL + Digest-MD5, charset quoted
 */

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Logger;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.sasl.RealmCallback;
import javax.security.sasl.Sasl;
import javax.security.sasl.SaslClient;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
import javax.security.auth.callback.CallbackHandler;
import com.sun.security.auth.callback.DialogCallbackHandler;
import com.sun.security.auth.callback.TextCallbackHandler;

/*
 * According to RFC 2831, DIGEST-MD5 servers must generate challenge strings
 * whose charset and algorithm values are not enclosed within quotes.
 * For example,
 *     challenge: realm="127.0.0.1",nonce="8GBOabRGeIqZB5BiaYJ1NDTuteV+D7n+qbSTH1fo",qop="auth",charset=utf-8,algorithm=md5-sess
 */
public class NoQuoteParams {

    private static Logger logger = Logger.getLogger("global");
    private static final String DIGEST_MD5 = "DIGEST-MD5";
    private static final byte[] EMPTY = new byte[0];

    private static CallbackHandler authCallbackHandler =
        new SampleCallbackHandler();

    public static void main(String[] args) throws Exception {

        Map<String, String> props = new TreeMap<String, String>();
        props.put(Sasl.QOP, "auth");

        // client
        SaslClient client = Sasl.createSaslClient(new String[]{ DIGEST_MD5 },
            "user1", "xmpp", "127.0.0.1", props, authCallbackHandler);
        if (client == null) {
            throw new Exception("Unable to find client implementation for: " +
                DIGEST_MD5);
        }

        byte[] response = client.hasInitialResponse()
            ? client.evaluateChallenge(EMPTY) : EMPTY;
        logger.info("initial: " + new String(response));

        // server
        byte[] challenge = null;
        SaslServer server = Sasl.createSaslServer(DIGEST_MD5, "xmpp",
          "127.0.0.1", props, authCallbackHandler);
        if (server == null) {
            throw new Exception("Unable to find server implementation for: " +
                DIGEST_MD5);
        }

        if (!client.isComplete() || !server.isComplete()) {
            challenge = server.evaluateResponse(response);

            logger.info("challenge: " + new String(challenge));

            if (challenge != null) {
                response = client.evaluateChallenge(challenge);
            }
        }

        String challengeString = new String(challenge, "UTF-8").toLowerCase();

        if (challengeString.indexOf("\"md5-sess\"") > 0 ||
            challengeString.indexOf("\"utf-8\"") > 0) {
            throw new Exception("The challenge string's charset and " +
                "algorithm values must not be enclosed within quotes");
        }

        client.dispose();
        server.dispose();
    }
}

class SampleCallbackHandler implements CallbackHandler {

    public void handle(Callback[] callbacks)
        throws java.io.IOException, UnsupportedCallbackException {
            for (int i = 0; i < callbacks.length; i++) {
                if (callbacks[i] instanceof NameCallback) {
                    NameCallback cb = (NameCallback)callbacks[i];
                    cb.setName(getInput(cb.getPrompt()));

                } else if (callbacks[i] instanceof PasswordCallback) {
                    PasswordCallback cb = (PasswordCallback)callbacks[i];

                    String pw = getInput(cb.getPrompt());
                    char[] passwd = new char[pw.length()];
                    pw.getChars(0, passwd.length, passwd, 0);

                    cb.setPassword(passwd);

                } else if (callbacks[i] instanceof RealmCallback) {
                    RealmCallback cb = (RealmCallback)callbacks[i];
                    cb.setText(getInput(cb.getPrompt()));

                } else {
                    throw new UnsupportedCallbackException(callbacks[i]);
                }
            }
    }

    /**
     * In real world apps, this would typically be a TextComponent or
     * similar widget.
     */
    private String getInput(String prompt) throws IOException {
        return "dummy-value";
    }
}


text:
cask 'devonthink-pro' do
  version '2.8.9'
  sha256 '7c4c0f9f1e4e49ce53ac4746ac18a888c450a46309a1b6534de51fe18ae3ee93'

  # amazonaws.com/DTWebsiteSupport was verified as official when first introduced to the cask
  url "https://s3.amazonaws.com/DTWebsiteSupport/download/devonthink/#{version}/DEVONthink_Pro.dmg.zip"
  appcast 'http://www.devon-technologies.com/fileadmin/templates/filemaker/sparkle.php?product=300030707&format=xml',
          checkpoint: 'fcdee99aeca17275a9f5d123830a7540ca9eccebf0f94f910bbf6d3c2630627a'
  name 'DEVONthink Pro'
  homepage 'http://www.devontechnologies.com/products/devonthink/devonthink-pro.html'
  license :commercial

  container nested: 'DEVONthink_Pro.dmg'

  app 'DEVONthink Pro.app'
end


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

#include "base/json/json_writer.h"

#include <cmath>

#include "base/format_macros.h"
#include "base/json/string_escape.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"

namespace base {

#if defined(OS_WIN)
static const char kPrettyPrintLineEnding[] = "\r\n";
#else
static const char kPrettyPrintLineEnding[] = "\n";
#endif

/* static */
const char* JSONWriter::kEmptyArray = "[]";

/* static */
void JSONWriter::Write(const Value* const node, std::string* json) {
  WriteWithOptions(node, 0, json);
}

/* static */
void JSONWriter::WriteWithOptions(const Value* const node, int options,
                                  std::string* json) {
  json->clear();
  // Is there a better way to estimate the size of the output?
  json->reserve(1024);

  bool escape = !(options & OPTIONS_DO_NOT_ESCAPE);
  bool omit_binary_values = !!(options & OPTIONS_OMIT_BINARY_VALUES);
  bool omit_double_type_preservation =
      !!(options & OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION);
  bool pretty_print = !!(options & OPTIONS_PRETTY_PRINT);

  JSONWriter writer(escape, omit_binary_values, omit_double_type_preservation,
                    pretty_print, json);
  writer.BuildJSONString(node, 0);

  if (pretty_print)
    json->append(kPrettyPrintLineEnding);
}

JSONWriter::JSONWriter(bool escape, bool omit_binary_values,
                       bool omit_double_type_preservation, bool pretty_print,
                       std::string* json)
    : escape_(escape),
      omit_binary_values_(omit_binary_values),
      omit_double_type_preservation_(omit_double_type_preservation),
      pretty_print_(pretty_print),
      json_string_(json) {
  DCHECK(json);
}

void JSONWriter::BuildJSONString(const Value* const node, int depth) {
  switch (node->GetType()) {
    case Value::TYPE_NULL:
      json_string_->append("null");
      break;

    case Value::TYPE_BOOLEAN:
      {
        bool value;
        bool result = node->GetAsBoolean(&value);
        DCHECK(result);
        json_string_->append(value ? "true" : "false");
        break;
      }

    case Value::TYPE_INTEGER:
      {
        int value;
        bool result = node->GetAsInteger(&value);
        DCHECK(result);
        base::StringAppendF(json_string_, "%d", value);
        break;
      }

    case Value::TYPE_INT64:
      {
        int64 value;
        bool result = node->GetAsInt64(&value);
        DCHECK(result);
        base::StringAppendF(json_string_, "%"PRId64, value);
        break;
      }

    case Value::TYPE_DOUBLE:
      {
        double value;
        bool result = node->GetAsDouble(&value);
        DCHECK(result);
        if (omit_double_type_preservation_ &&
            value <= kint64max &&
            value >= kint64min &&
            std::floor(value) == value) {
          json_string_->append(Int64ToString(static_cast<int64>(value)));
          break;
        }
        std::string real = DoubleToString(value);
        // Ensure that the number has a .0 if there's no decimal or 'e'.  This
        // makes sure that when we read the JSON back, it's interpreted as a
        // real rather than an int.
        if (real.find('.') == std::string::npos &&
            real.find('e') == std::string::npos &&
            real.find('E') == std::string::npos) {
          real.append(".0");
        }
        // The JSON spec requires that non-integer values in the range (-1,1)
        // have a zero before the decimal point - ".52" is not valid, "0.52" is.
        if (real[0] == '.') {
          real.insert(0, "0");
        } else if (real.length() > 1 && real[0] == '-' && real[1] == '.') {
          // "-.1" bad "-0.1" good
          real.insert(1, "0");
        }
        json_string_->append(real);
        break;
      }

    case Value::TYPE_STRING:
      {
        std::string value;
        bool result = node->GetAsString(&value);
        DCHECK(result);
        if (escape_) {
          JsonDoubleQuote(UTF8ToUTF16(value), true, json_string_);
        } else {
          JsonDoubleQuote(value, true, json_string_);
        }
        break;
      }

    case Value::TYPE_LIST:
      {
        json_string_->append("[");
        if (pretty_print_)
          json_string_->append(" ");

        const ListValue* list = static_cast<const ListValue*>(node);
        for (size_t i = 0; i < list->GetSize(); ++i) {
          const Value* value = NULL;
          bool result = list->Get(i, &value);
          DCHECK(result);

          if (omit_binary_values_ && value->GetType() == Value::TYPE_BINARY) {
            continue;
          }

          if (i != 0) {
            json_string_->append(",");
            if (pretty_print_)
              json_string_->append(" ");
          }

          BuildJSONString(value, depth);
        }

        if (pretty_print_)
          json_string_->append(" ");
        json_string_->append("]");
        break;
      }

    case Value::TYPE_DICTIONARY:
      {
        json_string_->append("{");
        if (pretty_print_)
          json_string_->append(kPrettyPrintLineEnding);

        const DictionaryValue* dict =
          static_cast<const DictionaryValue*>(node);
        bool first_entry = true;
        for (DictionaryValue::Iterator itr(*dict); !itr.IsAtEnd();
             itr.Advance(), first_entry = false) {
          if (omit_binary_values_ &&
              itr.value().GetType() == Value::TYPE_BINARY) {
            continue;
          }

          if (!first_entry) {
            json_string_->append(",");
            if (pretty_print_)
              json_string_->append(kPrettyPrintLineEnding);
          }

          if (pretty_print_)
            IndentLine(depth + 1);
          AppendQuotedString(itr.key());
          if (pretty_print_) {
            json_string_->append(": ");
          } else {
            json_string_->append(":");
          }
          BuildJSONString(&itr.value(), depth + 1);
        }

        if (pretty_print_) {
          json_string_->append(kPrettyPrintLineEnding);
          IndentLine(depth);
          json_string_->append("}");
        } else {
          json_string_->append("}");
        }
        break;
      }

    case Value::TYPE_BINARY:
      {
        if (!omit_binary_values_) {
          NOTREACHED() << "Cannot serialize binary value.";
        }
        break;
      }

    default:
      NOTREACHED() << "unknown json type";
  }
}

void JSONWriter::AppendQuotedString(const std::string& str) {
  // TODO(viettrungluu): |str| is UTF-8, not ASCII, so to properly escape it we
  // have to convert it to UTF-16. This round-trip is suboptimal.
  JsonDoubleQuote(UTF8ToUTF16(str), true, json_string_);
}

void JSONWriter::IndentLine(int depth) {
  // It may be faster to keep an indent string so we don't have to keep
  // reallocating.
  json_string_->append(std::string(depth * 3, ' '));
}

}  // namespace base


text:
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Pentacorn;
using System.Collections.Generic;
using Size = System.Drawing.Size;
using System;

namespace Pentacorn.Graphics
{
    class RenderableGrayCodeSweep : Renderable<GrayCodeSweep>
    {
        public RenderableGrayCodeSweep(RendererImpl rendererImpl)
        {
        }

        public override void Render(RendererImpl rendererImpl, IViewProject viewProject, GrayCodeSweep grayCodeSweep)
        {
            var black = grayCodeSweep.BlackColor;
            var white = grayCodeSweep.WhiteColor;

            var bws = grayCodeSweep.Sgc.BitsForStep(grayCodeSweep.Bit).Select(bw => bw ? white : black).ToArray();

            var whiteTexel = rendererImpl.WhiteTexel;
            var spriteBatch = rendererImpl.SpriteBatch;

            spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Opaque);
            if (grayCodeSweep.Dir == GrayCodeSweep.Direction.Horizontal)
                for (int i = 0; i < grayCodeSweep.Sgc.Count; ++i)
                    spriteBatch.Draw(whiteTexel, new Rectangle(i, 0, 1, grayCodeSweep.SweepLength), bws[i]);
            else if (grayCodeSweep.Dir == GrayCodeSweep.Direction.Vertical)
                for (int i = 0; i < grayCodeSweep.Sgc.Count; ++i)
                    spriteBatch.Draw(whiteTexel, new Rectangle(0, i, grayCodeSweep.SweepLength, 1), bws[i]);
            spriteBatch.End();
        }

        private IEnumerable<Texture2D> Patterns(RendererImpl rendererImpl, Size size)
        {
            var horizontal = new SafeGrayCode(size.Width);
            var vertical = new SafeGrayCode(size.Height);

            var
            tex = new Texture2D(rendererImpl.Device, 1, 1, false, SurfaceFormat.Color);
            tex.SetData(new Color[] { Color.Black });
            yield return tex;

            tex.Dispose();
            tex = new Texture2D(rendererImpl.Device, 1, 1, false, SurfaceFormat.Color);
            tex.SetData(new Color[] { new Color(0.5f, 0.5f, 0.5f, 1.0f) });
            yield return tex;

            tex.Dispose();
            tex = new Texture2D(rendererImpl.Device, 1, 1, false, SurfaceFormat.Color);
            tex.SetData(new Color[] { Color.White });
            yield return tex;

            for (int b = 0; b < horizontal.NumBits; ++b)
            {
                tex.Dispose();
                tex = new Texture2D(rendererImpl.Device, size.Width, 1, false, SurfaceFormat.Color);
                var data = horizontal.BitsForStep(b).Select(gray => gray ? Color.White : Color.Black).ToArray();
                tex.SetData(data);
                yield return tex;
            }

            for (int b = 0; b < vertical.NumBits; ++b)
            {
                tex.Dispose();
                tex = new Texture2D(rendererImpl.Device, size.Width, size.Height, false, SurfaceFormat.Color);
                var data = new Color[size.Area()];
                int y = 0;
                foreach (var gray in vertical.BitsForStep(b))
                {
                    for (int x = 0; x < size.Width; ++x)
                        data[y * size.Width + x] = gray ? Color.White : Color.Black;
                    ++y;
                }

                tex.SetData(data);
                yield return tex;
            }
        }
    }
}


text:
Apache Kafka
=================
See our [web site](http://kafka.apache.org) for details on the project.

You need to have [gradle](http://www.gradle.org/installation) installed.

### First bootstrap and download the wrapper ###
    cd kafka_source_dir
    gradle

Now everything else will work

### Building a jar and running it ###
    ./gradlew jar

Follow instuctions in http://kafka.apache.org/documentation.html#quickstart

### Building source jar ###
    ./gradlew srcJar

### Building javadocs and scaladocs ###
    ./gradlew javadoc
    ./gradlew javadocJar # builds a jar from the javadocs
    ./gradlew scaladoc
    ./gradlew scaladocJar # builds a jar from the scaladocs
    ./gradlew docsJar # builds both javadoc and scaladoc jar

### Running unit tests ###
    ./gradlew test

### Forcing re-running unit tests w/o code change ###
    ./gradlew cleanTest test

### Running a particular unit test ###
    ./gradlew -Dtest.single=RequestResponseSerializationTest core:test

### Running a particular test method within a unit test ###
    ./gradlew core:test --tests kafka.api.ProducerFailureHandlingTest.testCannotSendToInternalTopic
    ./gradlew clients:test --tests org.apache.kafka.clients.MetadataTest.testMetadataUpdateWaitTime

### Running a particular unit test with log4j output ###
    change the log4j setting in either clients/src/test/resources/log4j.properties or core/src/test/resources/log4j.properties
    ./gradlew -i -Dtest.single=RequestResponseSerializationTest core:test

### Building a binary release gzipped tar ball ###
    ./gradlew clean
    ./gradlew releaseTarGz
    The above command will fail if you haven't set up the signing key. To bypass signing the artifact, you can run
    ./gradlew releaseTarGz -x signArchives

The release file can be found inside ./core/build/distributions/.

### Cleaning the build ###
    ./gradlew clean

### Running a task on a particular version of Scala (either 2.10.5 or 2.11.7) ###
#### (If building a jar with a version other than 2.10, need to set SCALA_BINARY_VERSION variable or change it in bin/kafka-run-class.sh to run quick start.) ####
    ./gradlew -PscalaVersion=2.11.7 jar
    ./gradlew -PscalaVersion=2.11.7 test
    ./gradlew -PscalaVersion=2.11.7 releaseTarGz

### Running a task for a specific project ###
This is for 'core', 'contrib:hadoop-consumer', 'contrib:hadoop-producer', 'examples' and 'clients'
    ./gradlew core:jar
    ./gradlew core:test

### Listing all gradle tasks ###
    ./gradlew tasks

### Building IDE project ####
    ./gradlew eclipse
    ./gradlew idea

### Building the jar for all scala versions and for all projects ###
    ./gradlew jarAll

### Running unit tests for all scala versions and for all projects ###
    ./gradlew testAll

### Building a binary release gzipped tar ball for all scala versions ###
    ./gradlew releaseTarGzAll

### Publishing the jar for all version of Scala and for all projects to maven ###
    ./gradlew uploadArchivesAll

Please note for this to work you should create/update `~/.gradle/gradle.properties` and assign the following variables

    mavenUrl=
    mavenUsername=
    mavenPassword=
    signing.keyId=
    signing.password=
    signing.secretKeyRingFile=

### Publishing the jars without signing to a local repository ###
    ./gradlew -Dorg.gradle.project.skipSigning=true -Dorg.gradle.project.mavenUrl=file://path/to/repo uploadArchivesAll

### Building the test jar ###
    ./gradlew testJar

### Determining how transitive dependencies are added ###
    ./gradlew core:dependencies --configuration runtime

### Running checkstyle on the java code ###
    ./gradlew checkstyleMain checkstyleTest

### Limit the number of processes for each task ###
    ./gradlew -Dorg.gradle.project.maxParallelForks=1 test

This will most commonly be useful for automated builds where the full resources of the host running the build and tests
may not be dedicated to Kafka's build.

### Running in Vagrant ###

See [vagrant/README.md](vagrant/README.md).

### Contribution ###

Apache Kafka is interested in building the community; we would welcome any thoughts or [patches](https://issues.apache.org/jira/browse/KAFKA). You can reach us [on the Apache mailing lists](http://kafka.apache.org/contact.html).

To contribute follow the instructions here:
 * http://kafka.apache.org/contributing.html

We also welcome patches for the website and documentation which can be found here:
 * https://svn.apache.org/repos/asf/kafka/site


text:
package com.apothesource.pillfill.datamodel.ndfrt;

import java.io.Serializable;

public class Concept implements Serializable {

    private static final long serialVersionUID = -1L;

    private String conceptName;

    private String conceptNui;

    private String conceptKind;

    /**
     * public getter
     *
     * @returns java.lang.String
     */
    public String getConceptName() {
        return this.conceptName;
    }

    /**
     * public setter
     *
     * @param java.lang.String
     */
    public void setConceptName(String conceptName) {
        this.conceptName = conceptName;
    }

    /**
     * public getter
     *
     * @returns java.lang.String
     */
    public String getConceptNui() {
        return this.conceptNui;
    }

    /**
     * public setter
     *
     * @param java.lang.String
     */
    public void setConceptNui(String conceptNui) {
        this.conceptNui = conceptNui;
    }

    /**
     * public getter
     *
     * @returns java.lang.String
     */
    public String getConceptKind() {
        return this.conceptKind;
    }

    /**
     * public setter
     *
     * @param java.lang.String
     */
    public void setConceptKind(String conceptKind) {
        this.conceptKind = conceptKind;
    }

}


text:
"""Utilities for preprocessing sequence data.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import numpy as np
import random
import json
from six.moves import range
import six

def pad_sequences(sequences, maxlen=None, dtype='int32',
                  padding='pre', truncating='pre', value=0.):
    """Pads sequences to the same length.

    This function transforms a list of
    `num_samples` sequences (lists of integers)
    into a 2D Numpy array of shape `(num_samples, num_timesteps)`.
    `num_timesteps` is either the `maxlen` argument if provided,
    or the length of the longest sequence otherwise.

    Sequences that are shorter than `num_timesteps`
    are padded with `value` at the end.

    Sequences longer than `num_timesteps` are truncated
    so that they fit the desired length.
    The position where padding or truncation happens is determined by
    the arguments `padding` and `truncating`, respectively.

    Pre-padding is the default.

    # Arguments
        sequences: List of lists, where each element is a sequence.
        maxlen: Int, maximum length of all sequences.
        dtype: Type of the output sequences.
            To pad sequences with variable length strings, you can use `object`.
        padding: String, 'pre' or 'post':
            pad either before or after each sequence.
        truncating: String, 'pre' or 'post':
            remove values from sequences larger than
            `maxlen`, either at the beginning or at the end of the sequences.
        value: Float or String, padding value.

    # Returns
        x: Numpy array with shape `(len(sequences), maxlen)`

    # Raises
        ValueError: In case of invalid values for `truncating` or `padding`,
            or in case of invalid shape for a `sequences` entry.
    """
    if not hasattr(sequences, '__len__'):
        raise ValueError('`sequences` must be iterable.')
    lengths = []
    for x in sequences:
        if not hasattr(x, '__len__'):
            raise ValueError('`sequences` must be a list of iterables. '
                             'Found non-iterable: ' + str(x))
        lengths.append(len(x))

    num_samples = len(sequences)
    if maxlen is None:
        maxlen = np.max(lengths)

    # take the sample shape from the first non empty sequence
    # checking for consistency in the main loop below.
    sample_shape = tuple()
    for s in sequences:
        if len(s) > 0:
            sample_shape = np.asarray(s).shape[1:]
            break

    is_dtype_str = np.issubdtype(dtype, np.str_) or np.issubdtype(dtype, np.unicode_)
    if isinstance(value, six.string_types) and dtype != object and not is_dtype_str:
        raise ValueError("`dtype` {} is not compatible with `value`'s type: {}\n"
                         "You should set `dtype=object` for variable length strings."
                         .format(dtype, type(value)))

    x = np.full((num_samples, maxlen) + sample_shape, value, dtype=dtype)
    for idx, s in enumerate(sequences):
        if not len(s):
            continue  # empty list/array was found
        if truncating == 'pre':
            trunc = s[-maxlen:]
        elif truncating == 'post':
            trunc = s[:maxlen]
        else:
            raise ValueError('Truncating type "%s" '
                             'not understood' % truncating)

        # check `trunc` has expected shape
        trunc = np.asarray(trunc, dtype=dtype)
        if trunc.shape[1:] != sample_shape:
            raise ValueError('Shape of sample %s of sequence at position %s '
                             'is different from expected shape %s' %
                             (trunc.shape[1:], idx, sample_shape))

        if padding == 'post':
            x[idx, :len(trunc)] = trunc
        elif padding == 'pre':
            x[idx, -len(trunc):] = trunc
        else:
            raise ValueError('Padding type "%s" not understood' % padding)
    return x

def make_sampling_table(size, sampling_factor=1e-5):
    """Generates a word rank-based probabilistic sampling table.

    Used for generating the `sampling_table` argument for `skipgrams`.
    `sampling_table[i]` is the probability of sampling
    the word i-th most common word in a dataset
    (more common words should be sampled less frequently, for balance).

    The sampling probabilities are generated according
    to the sampling distribution used in word2vec:

    ```
    p(word) = (min(1, sqrt(word_frequency / sampling_factor) /
        (word_frequency / sampling_factor)))
    ```

    We assume that the word frequencies follow Zipf's law (s=1) to derive
    a numerical approximation of frequency(rank):

    `frequency(rank) ~ 1/(rank * (log(rank) + gamma) + 1/2 - 1/(12*rank))`
    where `gamma` is the Euler-Mascheroni constant.

    # Arguments
        size: Int, number of possible words to sample.
        sampling_factor: The sampling factor in the word2vec formula.

    # Returns
        A 1D Numpy array of length `size` where the ith entry
        is the probability that a word of rank i should be sampled.
    """
    gamma = 0.577
    rank = np.arange(size)
    rank[0] = 1
    inv_fq = rank * (np.log(rank) + gamma) + 0.5 - 1. / (12. * rank)
    f = sampling_factor * inv_fq

    return np.minimum(1., f / np.sqrt(f))

def skipgrams(sequence, vocabulary_size,
              window_size=4, negative_samples=1., shuffle=True,
              categorical=False, sampling_table=None, seed=None):
    """Generates skipgram word pairs.

    This function transforms a sequence of word indexes (list of integers)
    into tuples of words of the form:

    - (word, word in the same window), with label 1 (positive samples).
    - (word, random word from the vocabulary), with label 0 (negative samples).

    Read more about Skipgram in this gnomic paper by Mikolov et al.:
    [Efficient Estimation of Word Representations in
    Vector Space](http://arxiv.org/pdf/1301.3781v3.pdf)

    # Arguments
        sequence: A word sequence (sentence), encoded as a list
            of word indices (integers). If using a `sampling_table`,
            word indices are expected to match the rank
            of the words in a reference dataset (e.g. 10 would encode
            the 10-th most frequently occurring token).
            Note that index 0 is expected to be a non-word and will be skipped.
        vocabulary_size: Int, maximum possible word index + 1
        window_size: Int, size of sampling windows (technically half-window).
            The window of a word `w_i` will be
            `[i - window_size, i + window_size+1]`.
        negative_samples: Float >= 0. 0 for no negative (i.e. random) samples.
            1 for same number as positive samples.
        shuffle: Whether to shuffle the word couples before returning them.
        categorical: bool. if False, labels will be
            integers (eg. `[0, 1, 1 .. ]`),
            if `True`, labels will be categorical, e.g.
            `[[1,0],[0,1],[0,1] .. ]`.
        sampling_table: 1D array of size `vocabulary_size` where the entry i
            encodes the probability to sample a word of rank i.
        seed: Random seed.

    # Returns
        couples, labels: where `couples` are int pairs and
            `labels` are either 0 or 1.

    # Note
        By convention, index 0 in the vocabulary is
        a non-word and will be skipped.
    """
    couples = []
    labels = []
    for i, wi in enumerate(sequence):
        if not wi:
            continue
        if sampling_table is not None:
            if sampling_table[wi] < random.random():
                continue

        window_start = max(0, i - window_size)
        window_end = min(len(sequence), i + window_size + 1)
        for j in range(window_start, window_end):
            if j != i:
                wj = sequence[j]
                if not wj:
                    continue
                couples.append([wi, wj])
                if categorical:
                    labels.append([0, 1])
                else:
                    labels.append(1)

    if negative_samples > 0:
        num_negative_samples = int(len(labels) * negative_samples)
        words = [c[0] for c in couples]
        random.shuffle(words)

        couples += [[words[i % len(words)],
                     random.randint(1, vocabulary_size - 1)]
                    for i in range(num_negative_samples)]
        if categorical:
            labels += [[1, 0]] * num_negative_samples
        else:
            labels += [0] * num_negative_samples

    if shuffle:
        if seed is None:
            seed = random.randint(0, 10e6)
        random.seed(seed)
        random.shuffle(couples)
        random.seed(seed)
        random.shuffle(labels)

    return couples, labels

def _remove_long_seq(maxlen, seq, label):
    """Removes sequences that exceed the maximum length.

    # Arguments
        maxlen: Int, maximum length of the output sequences.
        seq: List of lists, where each sublist is a sequence.
        label: List where each element is an integer.

    # Returns
        new_seq, new_label: shortened lists for `seq` and `label`.
    """
    new_seq, new_label = [], []
    for x, y in zip(seq, label):
        if len(x) < maxlen:
            new_seq.append(x)
            new_label.append(y)
    return new_seq, new_label

class TimeseriesGenerator(object):
    """Utility class for generating batches of temporal data.

    This class takes in a sequence of data-points gathered at
    equal intervals, along with time series parameters such as
    stride, length of history, etc., to produce batches for
    training/validation.

    # Arguments
        data: Indexable generator (such as list or Numpy array)
            containing consecutive data points (timesteps).
            The data should be at 2D, and axis 0 is expected
            to be the time dimension.
        targets: Targets corresponding to timesteps in `data`.
            It should have same length as `data`.
        length: Length of the output sequences (in number of timesteps).
        sampling_rate: Period between successive individual timesteps
            within sequences. For rate `r`, timesteps
            `data[i]`, `data[i-r]`, ... `data[i - length]`
            are used for create a sample sequence.
        stride: Period between successive output sequences.
            For stride `s`, consecutive output samples would
            be centered around `data[i]`, `data[i+s]`, `data[i+2*s]`, etc.
        start_index: Data points earlier than `start_index` will not be used
            in the output sequences. This is useful to reserve part of the
            data for test or validation.
        end_index: Data points later than `end_index` will not be used
            in the output sequences. This is useful to reserve part of the
            data for test or validation.
        shuffle: Whether to shuffle output samples,
            or instead draw them in chronological order.
        reverse: Boolean: if `true`, timesteps in each output sample will be
            in reverse chronological order.
        batch_size: Number of timeseries samples in each batch
            (except maybe the last one).

    # Returns
        A [Sequence](/utils/#sequence) instance.

    # Examples

    ```python
    from keras.preprocessing.sequence import TimeseriesGenerator
    import numpy as np

    data = np.array([[i] for i in range(50)])
    targets = np.array([[i] for i in range(50)])

    data_gen = TimeseriesGenerator(data, targets,
                                   length=10, sampling_rate=2,
                                   batch_size=2)
    assert len(data_gen) == 20

    batch_0 = data_gen[0]
    x, y = batch_0
    assert np.array_equal(x,
                          np.array([[[0], [2], [4], [6], [8]],
                                    [[1], [3], [5], [7], [9]]]))
    assert np.array_equal(y,
                          np.array([[10], [11]]))
    ```
    """

    def __init__(self, data, targets, length,
                 sampling_rate=1,
                 stride=1,
                 start_index=0,
                 end_index=None,
                 shuffle=False,
                 reverse=False,
                 batch_size=128):

        if len(data) != len(targets):
            raise ValueError('Data and targets have to be' +
                             ' of same length. '
                             'Data length is {}'.format(len(data)) +
                             ' while target length is {}'.format(len(targets)))

        self.data = data
        self.targets = targets
        self.length = length
        self.sampling_rate = sampling_rate
        self.stride = stride
        self.start_index = start_index + length
        if end_index is None:
            end_index = len(data) - 1
        self.end_index = end_index
        self.shuffle = shuffle
        self.reverse = reverse
        self.batch_size = batch_size

        if self.start_index > self.end_index:
            raise ValueError('`start_index+length=%i > end_index=%i` '
                             'is disallowed, as no part of the sequence '
                             'would be left to be used as current step.'
                             % (self.start_index, self.end_index))

    def __len__(self):
        return (self.end_index - self.start_index +
                self.batch_size * self.stride) // (self.batch_size * self.stride)

    def _empty_batch(self, num_rows):
        samples_shape = [num_rows, self.length // self.sampling_rate]
        samples_shape.extend(self.data.shape[1:])
        targets_shape = [num_rows]
        targets_shape.extend(self.targets.shape[1:])
        return np.empty(samples_shape), np.empty(targets_shape)

    def __getitem__(self, index):
        if self.shuffle:
            rows = np.random.randint(
                self.start_index, self.end_index + 1, size=self.batch_size)
        else:
            i = self.start_index + self.batch_size * self.stride * index
            rows = np.arange(i, min(i + self.batch_size *
                                    self.stride, self.end_index + 1), self.stride)

        samples, targets = self._empty_batch(len(rows))
        for j, row in enumerate(rows):
            indices = range(rows[j] - self.length, rows[j], self.sampling_rate)
            samples[j] = self.data[indices]
            targets[j] = self.targets[rows[j]]
        if self.reverse:
            return samples[:, ::-1, ...], targets
        return samples, targets

    def get_config(self):
        '''Returns the TimeseriesGenerator configuration as Python dictionary.

        # Returns
            A Python dictionary with the TimeseriesGenerator configuration.
        '''
        data = self.data
        if type(self.data).__module__ == np.__name__:
            data = self.data.tolist()
        try:
            json_data = json.dumps(data)
        except:
            raise TypeError('Data not JSON Serializable:', data)

        targets = self.targets
        if type(self.targets).__module__ == np.__name__:
            targets = self.targets.tolist()
        try:
            json_targets = json.dumps(targets)
        except:
            raise TypeError('Targets not JSON Serializable:', targets)

        return {
            'data': json_data,
            'targets': json_targets,
            'length': self.length,
            'sampling_rate': self.sampling_rate,
            'stride': self.stride,
            'start_index': self.start_index,
            'end_index': self.end_index,
            'shuffle': self.shuffle,
            'reverse': self.reverse,
            'batch_size': self.batch_size
        }

    def to_json(self, **kwargs):
        """Returns a JSON string containing the timeseries generator
        configuration. To load a generator from a JSON string, use
        `keras.preprocessing.sequence.timeseries_generator_from_json(json_string)`.

        # Arguments
            **kwargs: Additional keyword arguments
                to be passed to `json.dumps()`.

        # Returns
            A JSON string containing the tokenizer configuration.
        """
        config = self.get_config()
        timeseries_generator_config = {
            'class_name': self.__class__.__name__,
            'config': config
        }
        return json.dumps(timeseries_generator_config, **kwargs)

def timeseries_generator_from_json(json_string):
    """Parses a JSON timeseries generator configuration file and
    returns a timeseries generator instance.

    # Arguments
        json_string: JSON string encoding a timeseries
            generator configuration.

    # Returns
        A Keras TimeseriesGenerator instance
    """
    full_config = json.loads(json_string)
    config = full_config.get('config')

    data = json.loads(config.pop('data'))
    config['data'] = data
    targets = json.loads(config.pop('targets'))
    config['targets'] = targets

    return TimeseriesGenerator(**config)


text:
// ANTLR GENERATED CODE: DO NOT EDIT
package org.apache.lucene.expressions.js;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;

/**
 * This interface defines a complete generic visitor for a parse tree produced
 * by {@link JavascriptParser}.
 *
 * @param <T> The return type of the visit operation. Use {@link Void} for
 * operations with no return type.
 */
interface JavascriptVisitor<T> extends ParseTreeVisitor<T> {
  /**
   * Visit a parse tree produced by {@link JavascriptParser#compile}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitCompile(JavascriptParser.CompileContext ctx);
  /**
   * Visit a parse tree produced by the {@code numeric}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitNumeric(JavascriptParser.NumericContext ctx);
  /**
   * Visit a parse tree produced by the {@code precedence}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitPrecedence(JavascriptParser.PrecedenceContext ctx);
  /**
   * Visit a parse tree produced by the {@code external}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitExternal(JavascriptParser.ExternalContext ctx);
  /**
   * Visit a parse tree produced by the {@code bwshift}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitBwshift(JavascriptParser.BwshiftContext ctx);
  /**
   * Visit a parse tree produced by the {@code boolcomp}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitBoolcomp(JavascriptParser.BoolcompContext ctx);
  /**
   * Visit a parse tree produced by the {@code bwxor}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitBwxor(JavascriptParser.BwxorContext ctx);
  /**
   * Visit a parse tree produced by the {@code bwor}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitBwor(JavascriptParser.BworContext ctx);
  /**
   * Visit a parse tree produced by the {@code boolor}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitBoolor(JavascriptParser.BoolorContext ctx);
  /**
   * Visit a parse tree produced by the {@code bwand}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitBwand(JavascriptParser.BwandContext ctx);
  /**
   * Visit a parse tree produced by the {@code unary}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitUnary(JavascriptParser.UnaryContext ctx);
  /**
   * Visit a parse tree produced by the {@code booland}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitBooland(JavascriptParser.BoolandContext ctx);
  /**
   * Visit a parse tree produced by the {@code addsub}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitAddsub(JavascriptParser.AddsubContext ctx);
  /**
   * Visit a parse tree produced by the {@code booleqne}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitBooleqne(JavascriptParser.BooleqneContext ctx);
  /**
   * Visit a parse tree produced by the {@code conditional}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitConditional(JavascriptParser.ConditionalContext ctx);
  /**
   * Visit a parse tree produced by the {@code muldiv}
   * labeled alternative in {@link JavascriptParser#expression}.
   * @param ctx the parse tree
   * @return the visitor result
   */
  T visitMuldiv(JavascriptParser.MuldivContext ctx);
}