text:
import six

from nose.util import isclass

def hide(obj):
    """
    Mark object as private.
    """
    obj._spec__is_private = True
    return obj

def is_public_class(name, value):
    return isclass(value) and not name.startswith('_')

def class_members(obj):
    return [x for x in six.iteritems(vars(obj)) if is_public_class(*x)]

def my_getattr(self, name):
    if not self._parent_inst:
        parent = self._parent()
        parent.setup()
        self._parent_inst = parent
    return getattr(self._parent_inst, name)

def flag_inner_classes(obj):
    """
    Mutates any attributes on ``obj`` which are classes, with link to ``obj``.

    Adds a convenience accessor which instantiates ``obj`` and then calls its
    ``setup`` method.

    Recurses on those objects as well.
    """
    for tup in class_members(obj):
        tup[1]._parent = obj
        tup[1]._parent_inst = None
        tup[1].__getattr__ = my_getattr
        flag_inner_classes(tup[1])

def autohide(obj):
    """
    Automatically hide setup() and teardown() methods, recursively.
    """
    # Members on obj
    for name, item in six.iteritems(vars(obj)):
        if callable(item) and name in ('setup', 'teardown'):
            item = hide(item)
    # Recurse into class members
    for name, subclass in class_members(obj):
        autohide(subclass)

class InnerClassParser(type):
    """
    Metaclass that tags inner classes with a link to the parent class.

    Allows test loading machinery to determine if a given test is part of an
    inner class or a top level one.
    """
    def __new__(cls, name, bases, attrs):
        new_class = type.__new__(cls, name, bases, attrs)
        flag_inner_classes(new_class)
        autohide(new_class)
        return new_class

redpajama_set_name: RedPajamaGithub


text:
#ifndef css_select_properties_helpers_h_
#define css_select_properties_helpers_h_

uint32_t generic_destroy_color(void *bytecode);
uint32_t generic_destroy_uri(void *bytecode);
uint32_t generic_destroy_length(void *bytecode);
uint32_t generic_destroy_number(void *bytecode);

css_unit css__to_css_unit(uint32_t u);

css_error css__cascade_bg_border_color(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_color));
css_error css__cascade_uri_none(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t,
				lwc_string *));
css_error css__cascade_border_style(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t));
css_error css__cascade_border_width(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
				css_unit));
css_error css__cascade_length_auto(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
				css_unit));
css_error css__cascade_length_normal(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
				css_unit));
css_error css__cascade_length_none(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
				css_unit));
css_error css__cascade_length(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_fixed,
				css_unit));
css_error css__cascade_number(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t, css_fixed));
css_error css__cascade_page_break_after_before_inside(uint32_t opv,
		css_style *style, css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t));
css_error css__cascade_break_after_before_inside(uint32_t opv,
		css_style *style, css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t));
css_error css__cascade_counter_increment_reset(uint32_t opv, css_style *style,
		css_select_state *state,
		css_error (*fun)(css_computed_style *, uint8_t,
				css_computed_counter *));

#endif


text:
package com.vmware.vim25;

/**
* @author Steve Jin (http://www.doublecloud.org)
* @version 5.1
*/

@SuppressWarnings("all")
public class InvalidProperty extends MethodFault {
  public String name;

  public String getName() {
    return this.name;
  }

  public void setName(String name) {
    this.name=name;
  }
}


text:
This app will tie into facebook through facebook's api allowing the user to login, logout, and post to their feed.  This will also pull in the allowed user information.

Used [angular-seed](https://github.com/angular/angular-seed) as basis and [ng-facebook](https://github.com/GoDisco/ngFacebook) for facebook integration.


text:
var merc = require('mercator-projection');

module.exports = function pointToLL(location) {
  var ll = merc.fromPointToLatLng({x: location[ 0 ], y: location[ 1 ]});

  return [
    ll.lat,
    ll.lng
  ];
};


text:
package com.vmware.vim25;

/**
* @author Steve Jin (http://www.doublecloud.org)
* @version 5.1
*/

@SuppressWarnings("all")
public class EVCAdmissionFailedHostSoftware extends EVCAdmissionFailed {
}


text:
package org.drools.mvelcompiler.bigdecimal;

import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.Optional;

import com.github.javaparser.ast.expr.AssignExpr;
import org.drools.mvelcompiler.ast.AssignExprT;
import org.drools.mvelcompiler.ast.MethodCallExprT;
import org.drools.mvelcompiler.ast.TypedExpression;

import static java.util.Collections.singletonList;
import static java.util.Optional.of;

public abstract class BigDecimalConversion {
    TypedExpression rhs;

    BigDecimalConversion(TypedExpression rhs) {
        this.rhs = rhs;
    }

    public static BigDecimalConversion shouldConvertPlusEqualsOperatorBigDecimal(AssignExpr n, Optional<TypedExpression> optRHS) {
        if(!optRHS.isPresent() || (!optRHS.get().getType().isPresent())) {
            return new DoNotConvert(null);
        }

        TypedExpression rhs = optRHS.get();
        Optional<Type> optRHSType = rhs.getType();
        if(!optRHSType.isPresent()) {
            return new DoNotConvert(null);
        }

        Type rhsType = optRHSType.get();

        boolean isBigDecimal = BigDecimal.class.equals(rhsType);
        if(isBigDecimal) {
            if(AssignExpr.Operator.PLUS.equals(n.getOperator())) {
                return new ConvertPlus(rhs);
            } else if(AssignExpr.Operator.MINUS.equals(n.getOperator())) {
                return new ConvertMinus(rhs);
            } else {
                return new DoNotConvert(rhs);
            }
        }
        return new DoNotConvert(null);
    }

    public abstract boolean shouldConvert();

    protected abstract TypedExpression convertPlusEqualsOperatorBigDecimal(TypedExpression target);

    public TypedExpression convertExpression(TypedExpression target) {
        TypedExpression arithmeticExpression = convertPlusEqualsOperatorBigDecimal(target);
        return new AssignExprT(AssignExpr.Operator.ASSIGN, target, arithmeticExpression);
    }

    static class ConvertPlus extends BigDecimalConversion {

        ConvertPlus(TypedExpression rhs) {
            super(rhs);
        }

        @Override
        public boolean shouldConvert() {
            return true;
        }

        @Override
        public TypedExpression convertPlusEqualsOperatorBigDecimal(TypedExpression target) {
            return new MethodCallExprT("add", of(target), singletonList(rhs), of(BigDecimal.class));
        }
    }

    static class ConvertMinus extends BigDecimalConversion {

        ConvertMinus(TypedExpression rhs) {
            super(rhs);
        }

        @Override
        public boolean shouldConvert() {
            return true;
        }

        @Override
        public TypedExpression convertPlusEqualsOperatorBigDecimal(TypedExpression target) {
            return new MethodCallExprT("subtract", of(target), singletonList(rhs), of(BigDecimal.class));
        }
    }

    static class DoNotConvert extends BigDecimalConversion {

        DoNotConvert(TypedExpression rhs) {
            super(rhs);
        }

        @Override
        public boolean shouldConvert() {
            return false;
        }

        @Override
        public TypedExpression convertPlusEqualsOperatorBigDecimal(TypedExpression target) {
            throw new UnsupportedOperationException();
        }
    }
}


text:
<?php

require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';


text:
<?php

namespace imanager;

use imanager\iManagerAPI;
use pocketmine\event\player\PlayerChatEvent;
use pocketmine\event\player\PlayerCommandPreprocessEvent;
use pocketmine\event\player\PlayerPreLoginEvent;
use pocketmine\event\Listener;

class iManagerListener implements Listener{

    public function __construct(iManagerAPI $plugin){
        $this->plugin = $plugin;
    }
    public function getPlugin(){
        return $this->plugin;
    }
    public function onPlayerChat(PlayerChatEvent $event){
    	if($this->plugin->settings->getNested("enable.save-chat") === true){
    	    $this->plugin->chat->set($event->getPlayer()->getName().": ".$event->getMessage());
    	    $this->plugin->chat->save();
    	}
    }
    public function onPlayerCommandPreprocess(PlayerCommandPreprocessEvent $event){
    	if($this->plugin->settings->getNested("enable.log-commands") === true){
    	    if($event->getMessage()[0] === "/"){
    	    	$this->plugin->getServer()->getLogger()->notice($event->getPlayer()->getName()." issued command: ".$event->getMessage());
    	    }
    	}
    }
    public function onPlayerPreLogin(PlayerPreLoginEvent $event){
    	if($this->plugin->settings->getNested("enable.ip-whitelist") === true){
    	    if($this->plugin->ip->exists(strtolower($event->getPlayer()->getAddress()))){
    	    }
    	    else{
    	    	$event->setCancelled(true);
    	    }
    	}
    }
}


text:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text;
using ICSharpCode.SharpZipLib.Zip;
using NPOI.OpenXml4Net.Util;
using NPOI.SS.Formula.Udf;
using NPOI.SS.UserModel;
using NPOI.Util;
using NPOI.XSSF.Model;
using NPOI.XSSF.UserModel;

namespace NPOI.XSSF.Streaming
{
    /// <summary>
    /// Streaming version of the XSSFWorkbook, originally implemented in the "BigGridDemo".
    /// </summary>
    public class SXSSFWorkbook : IWorkbook
    {
        private static readonly POILogger logger = POILogFactory.GetLogger(typeof(SXSSFWorkbook));

        public const int DEFAULT_WINDOW_SIZE = 100;

        public XSSFWorkbook XssfWorkbook;

        private Dictionary<SXSSFSheet, XSSFSheet> _sxFromXHash = new Dictionary<SXSSFSheet, XSSFSheet>();
        private Dictionary<XSSFSheet, SXSSFSheet> _xFromSxHash = new Dictionary<XSSFSheet, SXSSFSheet>();

        private int _randomAccessWindowSize = DEFAULT_WINDOW_SIZE;

        public int RandomAccessWindowSize
        {
            get { return _randomAccessWindowSize; }
            set
            {
                if (value <= 0)
                {
                    throw new ArgumentException("rowAccessWindowSize must be greater than 0 or -1");
                }
                _randomAccessWindowSize = value;
            }

        }

        /// <summary>
        /// whether temp file should be compresss.
        /// </summary>
        private bool _compressTmpFiles = false;

        /// <summary>
        /// shared string table - a cache of strings in this workbook.
        /// </summary>
        private SharedStringsTable _sharedStringSource;

        public int ActiveSheetIndex
        {
            get { return XssfWorkbook.ActiveSheetIndex; }
        }

        public int FirstVisibleTab
        {
            get { return XssfWorkbook.FirstVisibleTab; }

            set { XssfWorkbook.FirstVisibleTab = value; }
        }

        public int NumberOfSheets
        {
            get { return XssfWorkbook.NumberOfSheets; }
        }

        public short NumberOfFonts
        {
            get { return XssfWorkbook.NumberOfFonts; }
        }

        public short NumCellStyles
        {
            get { return XssfWorkbook.NumCellStyles; }
        }

        public int NumberOfNames
        {
            get { return XssfWorkbook.NumberOfNames; }
        }

        public MissingCellPolicy MissingCellPolicy
        {
            get { return XssfWorkbook.MissingCellPolicy; }

            set { XssfWorkbook.MissingCellPolicy = value; }
        }

        public bool IsHidden
        {
            get { return XssfWorkbook.IsHidden; }

            set { XssfWorkbook.IsHidden = value; }
        }

        #region Constructors

        public SXSSFWorkbook() : this(null)
        {

        }

        public SXSSFWorkbook(XSSFWorkbook workbook) : this(workbook, DEFAULT_WINDOW_SIZE)
        {

        }

        public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize)
            : this(workbook, rowAccessWindowSize, false)
        {

        }

        public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize, bool compressTmpFiles)
            : this(workbook, rowAccessWindowSize, compressTmpFiles, false)
        {

        }

        /// <summary>
        /// Currently only supports writing not reading. E.g. the number of rows returned from a worksheet will be wrong etc.
        /// </summary>
        /// <param name="workbook"></param>
        /// <param name="rowAccessWindowSize"></param>
        /// <param name="compressTmpFiles"></param>
        /// <param name="useSharedStringsTable"></param>
        public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize, bool compressTmpFiles, bool useSharedStringsTable)
        {
            RandomAccessWindowSize = rowAccessWindowSize;

            _compressTmpFiles = compressTmpFiles;

            if (workbook == null)
            {
                XssfWorkbook = new XSSFWorkbook();
                _sharedStringSource = useSharedStringsTable ? XssfWorkbook.GetSharedStringSource() : null;
            }
            else
            {
                XssfWorkbook = workbook;
                _sharedStringSource = useSharedStringsTable ? XssfWorkbook.GetSharedStringSource() : null;
                var numberOfSheets = XssfWorkbook.NumberOfSheets;
                for (int i = 0; i < numberOfSheets; i++)
                {
                    XSSFSheet sheet = (XSSFSheet)XssfWorkbook.GetSheetAt(i);
                    CreateAndRegisterSXSSFSheet(sheet);
                }
            }
        }

        #endregion

        private SXSSFSheet CreateAndRegisterSXSSFSheet(ISheet xSheet)
        {
            SXSSFSheet sxSheet;
            try
            {
                sxSheet = new SXSSFSheet(this, (XSSFSheet)xSheet);
            }
            catch (IOException ioe)
            {
                throw new RuntimeException(ioe);
            }
            RegisterSheetMapping(sxSheet, (XSSFSheet)xSheet);
            return sxSheet;
        }

        private void RegisterSheetMapping(SXSSFSheet sxSheet, XSSFSheet xSheet)
        {
            _sxFromXHash.Add(sxSheet, xSheet);
            _xFromSxHash.Add(xSheet, sxSheet);
        }

        private void DeregisterSheetMapping(XSSFSheet xSheet)
        {
            SXSSFSheet sxSheet = GetSXSSFSheet(xSheet);

            try
            {
                sxSheet._writer.Close();
            }
            catch (IOException e)
            {
                // ignore exception here
            }

            _sxFromXHash.Remove(sxSheet);

            _xFromSxHash.Remove(xSheet);
        }

        private XSSFSheet GetXSSFSheet(SXSSFSheet sheet)
        {
            return _sxFromXHash[sheet];
        }

        private SXSSFSheet GetSXSSFSheet(XSSFSheet sheet)
        {
            return _xFromSxHash[sheet];
        }

        public SheetDataWriter CreateSheetDataWriter()
        {
            if (_compressTmpFiles)
            {
                return new GZIPSheetDataWriter(_sharedStringSource);
            }

            return new SheetDataWriter(_sharedStringSource);
        }

        private XSSFSheet GetSheetFromZipEntryName(string sheetRef)
        {
            foreach (XSSFSheet sheet in _sxFromXHash.Values)
            {
                if (sheetRef.Equals(sheet.GetPackagePart().PartName.Name.Substring(1))) return sheet;
            }
            return null;
        }

        private void InjectData(ZipEntrySource zipEntrySource, Stream outStream)
        {
            try
            {
                ZipOutputStream zos = new ZipOutputStream(outStream);
                try
                {
                    var en = zipEntrySource.Entries;
                    while (en.MoveNext())
                    {
                        var ze = (ZipEntry)en.Current;
                        zos.PutNextEntry(new ZipEntry(ze.Name));
                        var inputStream = zipEntrySource.GetInputStream(ze);
                        XSSFSheet xSheet = GetSheetFromZipEntryName(ze.Name);
                        if (xSheet != null)
                        {
                            SXSSFSheet sxSheet = GetSXSSFSheet(xSheet);
                            var xis = sxSheet.getWorksheetXMLInputStream();
                            try
                            {
                                CopyStreamAndInjectWorksheet(inputStream, zos, xis);
                            }
                            finally
                            {
                                xis.Close();
                            }
                        }
                        else
                        {
                            CopyStream(inputStream, zos);
                        }
                        inputStream.Close();
                    }
                }
                finally
                {
                    zos.Close();
                }
            }
            finally
            {
                zipEntrySource.Close();
            }
        }

        private static void CopyStream(Stream inputStream, Stream outputStream)
        {
            var chunk = new byte[1024];
            int count;

            while ((count = inputStream.Read(chunk, 0, chunk.Length)) > 0)
            {
                outputStream.Write(chunk, 0, count);
            }
        }

        private static void CopyStreamAndInjectWorksheet(Stream inputStream, Stream outputStream, Stream worksheetData)
        {
            StreamReader inReader = new StreamReader(inputStream, Encoding.UTF8);
            StreamWriter outWriter = new StreamWriter(outputStream, Encoding.UTF8);
            bool needsStartTag = true;
            int c;
            int pos = 0;
            String s = "<sheetData";

            StringBuilder sb = new StringBuilder();
            int n = s.Length;
            //Copy from "in" to "out" up to the string "<sheetData/>" or "</sheetData>" (excluding).
            while (((c = inReader.Read()) != -1))
            {
                if ((char)c == (char)s[pos])
                {
                    pos++;
                    if (pos == n)
                    {
                        if ("<sheetData".Equals(s))
                        {
                            c = inReader.Read();
                            if (c == -1)
                            {
                                outWriter.Write(s);
                                sb.Append(s);
                                break;
                            }
                            if ((char)c == '>')
                            {
                                // Found <sheetData>
                                outWriter.Write(s);
                                sb.Append(s);
                                outWriter.Write((char)c);
                                sb.Append((char) c);
                                s = "</sheetData>";
                                n = s.Length;
                                pos = 0;
                                needsStartTag = false;
                                continue;
                            }
                            if ((char)c == '/')
                            {
                                // Found <sheetData/
                                c = inReader.Read();
                                if (c == -1)
                                {
                                    outWriter.Write(s);
                                    sb.Append(s);
                                    break;
                                }
                                if ((char)c == '>')
                                {
                                    // Found <sheetData/>
                                    break;
                                }

                                outWriter.Write(s);
                                sb.Append(s);
                                outWriter.Write('/');
                                sb.Append('/');
                                outWriter.Write((char)c);
                                sb.Append((char) c);
                                pos = 0;
                                continue;
                            }

                            outWriter.Write(s);
                            sb.Append(s);
                            outWriter.Write('/');
                            sb.Append('/');
                            outWriter.Write((char)c);
                            sb.Append((char)c);
                            pos = 0;
                            continue;
                        }
                        else
                        {
                            // Found </sheetData>
                            break;
                        }
                    }
                }
                else
                {
                    if (pos > 0)
                    {
                        outWriter.Write(s.Substring(0,pos));
                        sb.Append(s, 0, pos);
                    }
                    if (c == s[0])
                    {
                        pos = 1;
                    }
                    else
                    {
                        outWriter.Write((char)c);
                        sb.Append((char) c);
                        pos = 0;
                    }
                }
            }
            outWriter.Flush();
            if (needsStartTag)
            {
                outWriter.Write("<sheetData>\n");
                sb.Append("<sheetData>\n");
                outWriter.Flush();
            }
            //Copy the worksheet data to "out".
            CopyStream(worksheetData, outputStream);
            outWriter.Write("</sheetData>");
            outWriter.Flush();
            //Copy the rest of "in" to "out".
            while (((c = inReader.Read()) != -1))
            {
                outWriter.Write((char) c);
                sb.Append((char)c);
            }
            outWriter.Flush();

        }

        public void SetSheetOrder(string sheetname, int pos)
        {
            XssfWorkbook.SetSheetOrder(sheetname, pos);
        }

        public void SetSelectedTab(int index)
        {
            XssfWorkbook.SetSelectedTab(index);
        }

        public void SetActiveSheet(int sheetIndex)
        {
            XssfWorkbook.SetActiveSheet(sheetIndex);
        }

        public string GetSheetName(int sheet)
        {
            return XssfWorkbook.GetSheetName(sheet);
        }

        public void SetSheetName(int sheet, string name)
        {
            XssfWorkbook.SetSheetName(sheet, name);
        }

        public int GetSheetIndex(string name)
        {
            return XssfWorkbook.GetSheetIndex(name);
        }

        public int GetSheetIndex(ISheet sheet)
        {
            return XssfWorkbook.GetSheetIndex(GetXSSFSheet((SXSSFSheet)sheet));
        }

        public ISheet CreateSheet()
        {
            return CreateAndRegisterSXSSFSheet(XssfWorkbook.CreateSheet());
        }

        public ISheet CreateSheet(string sheetname)
        {
            return CreateAndRegisterSXSSFSheet(XssfWorkbook.CreateSheet(sheetname));
        }

        public ISheet CloneSheet(int sheetNum)
        {
            throw new NotImplementedException();
        }

        public ISheet GetSheetAt(int index)
        {
            return GetSXSSFSheet((XSSFSheet)XssfWorkbook.GetSheetAt(index));
        }

        public ISheet GetSheet(string name)
        {
            return GetSXSSFSheet((XSSFSheet)XssfWorkbook.GetSheet(name));
        }

        public void RemoveSheetAt(int index)
        {
            // Get the sheet to be removed
            var xSheet = (XSSFSheet)XssfWorkbook.GetSheetAt(index);
            var sxSheet = GetSXSSFSheet(xSheet);

            // De-register it
            XssfWorkbook.RemoveSheetAt(index);
            DeregisterSheetMapping(xSheet);

            // Clean up temporary resources
            try
            {
                sxSheet.dispose();
            }
            catch (IOException e)
            {
                logger.Log(POILogger.WARN, e);
            }
        }

        public IEnumerator GetEnumerator()
        {
            throw new NotImplementedException();
        }

        public void SetRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)
        {
            throw new NotImplementedException();
        }

        public IFont CreateFont()
        {
            return XssfWorkbook.CreateFont();
        }

        [Obsolete("deprecated in poi 3.16")]
        public IFont FindFont(short boldWeight, short color, short fontHeight, string name, bool italic, bool strikeout, FontSuperScript typeOffset, FontUnderlineType underline)
        {
            return XssfWorkbook.FindFont(boldWeight, color, fontHeight, name, italic, strikeout, typeOffset, underline);
        }

        public IFont GetFontAt(short idx)
        {
            return XssfWorkbook.GetFontAt(idx);
        }

        public ICellStyle CreateCellStyle()
        {
            return XssfWorkbook.CreateCellStyle();
        }

        public ICellStyle GetCellStyleAt(short idx)
        {
            return XssfWorkbook.GetCellStyleAt(idx);
        }

        public void Write(Stream stream)
        {
            FlushSheets();

            //Save the template
            var tmplFile = TempFile.CreateTempFile("poi-sxssf-template", ".xlsx");
            try
            {
                var os = new FileStream(tmplFile.FullName, FileMode.Open, FileAccess.ReadWrite);
                try
                {
                    XssfWorkbook.Write(os);
                }
                finally
                {
                    os.Close();
                }

                //Substitute the template entries with the generated sheet data files
                ZipEntrySource source = new ZipFileZipEntrySource(new ZipFile(tmplFile.FullName));
                InjectData(source, stream);
            }
            finally
            {
                tmplFile.Delete();
                if (File.Exists(tmplFile.FullName))
                {
                    throw new IOException("Could not delete temporary file after processing: " + tmplFile);
                }
            }
        }

        private void FlushSheets()
        {
            foreach (SXSSFSheet sheet in _xFromSxHash.Values)
            {
                sheet.flushRows();
            }
        }

        /**
        * Dispose of temporary files backing this workbook on disk.
        * Calling this method will render the workbook unusable.
        * @return true if all temporary files were deleted successfully.
        */
        public bool Dispose()
        {
            var success = true;
            foreach (SXSSFSheet sheet in _sxFromXHash.Keys)
            {
                try
                {
                    success = sheet.dispose() && success;
                }
                catch (IOException e)
                {
                    logger.Log(POILogger.WARN, e);
                    success = false;
                }
            }
            return success;
        }

        public IName GetName(string name)
        {
            return XssfWorkbook.GetName(name);
        }
        [Obsolete("Deprecated in 3.16 throws an error.")]
        public IName GetNameAt(int nameIndex)
        {
            return XssfWorkbook.GetNameAt(nameIndex);
        }

        public IName CreateName()
        {
            return XssfWorkbook.CreateName();
        }

        [Obsolete("deprecated in 3.16 New projects should avoid accessing named ranges by index. GetName(String)} instead.")]
        public int GetNameIndex(string name)
        {
            return XssfWorkbook.GetNameIndex(name);
        }

        [Obsolete("deprecated in 3.16 New projects should use RemoveName(Name)")]
        public void RemoveName(int index)
        {
            XssfWorkbook.RemoveName(index);
        }

        [Obsolete("deprecated in 3.16 New projects should use RemoveName(IName Name)")]
        public void RemoveName(string name)
        {
            XssfWorkbook.RemoveName(name);
        }

        public int LinkExternalWorkbook(string name, IWorkbook workbook)
        {
            throw new NotImplementedException();
        }

        public void SetPrintArea(int sheetIndex, string reference)
        {
            XssfWorkbook.SetPrintArea(sheetIndex, reference);
        }

        public void SetPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)
        {
            XssfWorkbook.SetPrintArea(sheetIndex, startColumn, endColumn, startRow, endRow);
        }

        public string GetPrintArea(int sheetIndex)
        {
            return XssfWorkbook.GetPrintArea(sheetIndex);
        }

        public void RemovePrintArea(int sheetIndex)
        {
            XssfWorkbook.RemovePrintArea(sheetIndex);
        }

        public IDataFormat CreateDataFormat()
        {
            return XssfWorkbook.CreateDataFormat();
        }

        public int AddPicture(byte[] pictureData, PictureType format)
        {
            return XssfWorkbook.AddPicture(pictureData, format);
        }

        public IList GetAllPictures()
        {
            return XssfWorkbook.GetAllPictures();
        }

        public ICreationHelper GetCreationHelper()
        {
            return new SXSSFCreationHelper(this);
        }

        public bool IsSheetHidden(int sheetIx)
        {
            return XssfWorkbook.IsSheetHidden(sheetIx);
        }

        public bool IsSheetVeryHidden(int sheetIx)
        {
            return XssfWorkbook.IsSheetVeryHidden(sheetIx);
        }

        public void SetSheetHidden(int sheetIx, SheetState hidden)
        {
            XssfWorkbook.SetSheetHidden(sheetIx, hidden);
        }

        public void SetSheetHidden(int sheetIx, int hidden)
        {
            XssfWorkbook.SetSheetHidden(sheetIx, hidden);
        }

        public void AddToolPack(UDFFinder toopack)
        {
            XssfWorkbook.AddToolPack(toopack);
        }

        public void Close()
        {
            // ensure that any lingering writer is closed
            foreach (SXSSFSheet sheet in _xFromSxHash.Values)
            {
                try
                {
                    sheet._writer.Close();
                }
                catch (IOException e)
                {
                    logger.Log(POILogger.WARN,
                            "An exception occurred while closing sheet data writer for sheet "
                            + sheet.SheetName + ".", e);
                }
            }

            // Tell the base workbook to close, does nothing if
            //  it's a newly created one
            XssfWorkbook.Close();
        }

        //TODO: missing methods from POI 3.16 setForceFormulaRecalculation, GetForceFormulaRecalulation, GetSpreadsheetVersion
        //TODO: missing method isDate1904, isHidden, setHidden
    }
}


text:
from __future__ import unicode_literals

from django.db import migrations

class Migration(migrations.Migration):

    dependencies = [
        ('Buses', '0004_auto_20161013_1857'),
    ]

    operations = [
        migrations.RenameField(
            model_name='currentlocation',
            old_name='longitute',
            new_name='longitude',
        ),
        migrations.RenameField(
            model_name='locationhistory',
            old_name='longitute',
            new_name='longitude',
        ),
    ]


text:
/**
 * @file
 * @brief Define lane sequence predictor
 */

#ifndef MODULES_PREDICTION_PREDICTOR_LANE_SEQUENCE_LANE_SEQUENCE_PREDICTOR_H_
#define MODULES_PREDICTION_PREDICTOR_LANE_SEQUENCE_LANE_SEQUENCE_PREDICTOR_H_

#include <string>
#include <vector>

#include "modules/common/math/kalman_filter.h"
#include "modules/common/proto/pnc_point.pb.h"
#include "modules/prediction/predictor/sequence/sequence_predictor.h"
#include "modules/prediction/proto/lane_graph.pb.h"

namespace apollo {
namespace prediction {

class LaneSequencePredictor : public SequencePredictor {
 public:
  /**
   * @brief Constructor
   */
  LaneSequencePredictor() = default;

  /**
   * @brief Destructor
   */
  virtual ~LaneSequencePredictor() = default;

  /**
   * @brief Make prediction
   * @param Obstacle pointer
   */
  void Predict(Obstacle* obstacle) override;

 protected:
  /**
   * @brief Draw lane sequence trajectory points
   * @param Obstacle
   * @param Lane sequence
   * @param Total prediction time
   * @param Prediction period
   * @param A vector of generated trajectory points
   */
  void DrawLaneSequenceTrajectoryPoints(
      const Obstacle& obstacle, const LaneSequence& lane_sequence,
      const double total_time, const double period,
      std::vector<apollo::common::TrajectoryPoint>* points);
};

}  // namespace prediction
}  // namespace apollo

#endif  // MODULES_PREDICTION_PREDICTOR_VEHICLE_LANE_SEQUENCE_PREDICTOR_H_


text:
#ifndef InspectorOverlay_h
#define InspectorOverlay_h

#include "core/InspectorTypeBuilder.h"
#include "platform/Timer.h"
#include "platform/geometry/FloatQuad.h"
#include "platform/geometry/LayoutRect.h"
#include "platform/graphics/Color.h"
#include "platform/heap/Handle.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/RefPtr.h"
#include "wtf/text/WTFString.h"

namespace blink {

class Color;
class EmptyChromeClient;
class GraphicsContext;
class InspectorClient;
class InspectorOverlayHost;
class JSONValue;
class Node;
class Page;
class PlatformGestureEvent;
class PlatformKeyboardEvent;
class PlatformMouseEvent;
class PlatformTouchEvent;

struct HighlightConfig {
    WTF_MAKE_FAST_ALLOCATED;
public:
    Color content;
    Color contentOutline;
    Color padding;
    Color border;
    Color margin;
    Color eventTarget;
    Color shape;
    Color shapeMargin;

    bool showInfo;
    bool showRulers;
    bool showExtensionLines;
};

class InspectorOverlay final : public NoBaseWillBeGarbageCollectedFinalized<InspectorOverlay> {
    WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
public:
    static PassOwnPtrWillBeRawPtr<InspectorOverlay> create(Page* page, InspectorClient* client)
    {
        return adoptPtrWillBeNoop(new InspectorOverlay(page, client));
    }

    ~InspectorOverlay();
    void trace(Visitor*);

    void update();
    void hide();
    void paint(GraphicsContext&);
    void drawOutline(GraphicsContext*, const LayoutRect&, const Color&);
    bool handleGestureEvent(const PlatformGestureEvent&);
    bool handleMouseEvent(const PlatformMouseEvent&);
    bool handleTouchEvent(const PlatformTouchEvent&);
    bool handleKeyboardEvent(const PlatformKeyboardEvent&);

    void setPausedInDebuggerMessage(const String*);
    void setInspectModeEnabled(bool);

    void hideHighlight();
    void highlightNode(Node*, Node* eventTarget, const HighlightConfig&, bool omitTooltip);
    void highlightQuad(PassOwnPtr<FloatQuad>, const HighlightConfig&);
    void showAndHideViewSize(bool showGrid);

    Node* highlightedNode() const;
    bool getBoxModel(Node*, RefPtr<TypeBuilder::DOM::BoxModel>&);
    PassRefPtr<JSONObject> highlightJSONForNode(Node*);

    void freePage();

    InspectorOverlayHost* overlayHost() const { return m_overlayHost.get(); }

    void startedRecordingProfile();
    void finishedRecordingProfile() { m_activeProfilerCount--; }

    // Methods supporting underlying overlay page.
    void invalidate();
private:
    InspectorOverlay(Page*, InspectorClient*);

    bool isEmpty();

    void drawNodeHighlight();
    void drawQuadHighlight();
    void drawPausedInDebuggerMessage();
    void drawViewSize();

    Page* overlayPage();
    void reset(const IntSize& viewportSize, int scrollX, int scrollY);
    void evaluateInOverlay(const String& method, const String& argument);
    void evaluateInOverlay(const String& method, PassRefPtr<JSONValue> argument);
    void onTimer(Timer<InspectorOverlay>*);

    RawPtrWillBeMember<Page> m_page;
    InspectorClient* m_client;
    String m_pausedInDebuggerMessage;
    bool m_inspectModeEnabled;
    RefPtrWillBeMember<Node> m_highlightNode;
    RefPtrWillBeMember<Node> m_eventTargetNode;
    HighlightConfig m_nodeHighlightConfig;
    OwnPtr<FloatQuad> m_highlightQuad;
    OwnPtrWillBeMember<Page> m_overlayPage;
    OwnPtr<EmptyChromeClient> m_overlayChromeClient;
    RefPtrWillBeMember<InspectorOverlayHost> m_overlayHost;
    HighlightConfig m_quadHighlightConfig;
    bool m_drawViewSize;
    bool m_drawViewSizeWithGrid;
    bool m_omitTooltip;
    Timer<InspectorOverlay> m_timer;
    int m_activeProfilerCount;
    bool m_updating;
};

} // namespace blink

#endif // InspectorOverlay_h


text:
sudo yum update -y
sudo yum groupinstall -y 'Development Tools'
sudo yum install -y git python curl pcre-devel libedit python-docutils \
    ncurses-devel graphviz readline-devel

# Clone and build source.
git clone https://github.com/varnishcache/varnish-cache
cd varnish-cache
./autogen.sh
./configure
make
make test
sudo make install


text:
package ftp.v4;

import java.io.IOException;
import java.net.URI;
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.AccessMode;
import java.nio.file.CopyOption;
import java.nio.file.DirectoryStream;
import java.nio.file.DirectoryStream.Filter;
import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.FileSystemAlreadyExistsException;
import java.nio.file.FileSystemNotFoundException;
import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.FileAttributeView;
import java.nio.file.spi.FileSystemProvider;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;

import ftp.MyFileAttributes;
import ftp.MyFileResource;

public class My4FileSystemProvider extends FileSystemProvider
{
  private final Map<URI, My4FileSystem> fileSystems = Collections.synchronizedMap(new WeakHashMap<URI, My4FileSystem>());
  private Long accountId;

  @Override
  public String getScheme()
  {
    // TODO Auto-generated method stub
    System.out.println("My4FileSystemProvider getScheme()");
    return "aws";
  }

  @Override
  public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException
  {
    System.out.println("My4FileSystemProvider newFileSystem(); uri=" + uri);
    //TODO 判斷uri的schema是不是一樣?
    if(fileSystems.containsKey(uri))
    {
      System.out.println("throw new FileSystemAlreadyExistsException()");
      throw new FileSystemAlreadyExistsException();
    }

    accountId = (Long)env.get("accountId");
    System.out.println("My4FileSystemProvider newFileSystem(); accountId=" + accountId);

    My4FileSystem fileSystem = new My4FileSystem(this);
    fileSystems.put(uri, fileSystem);
    return fileSystem;
  }

  @Override
  public FileSystem getFileSystem(URI uri)
  {
    // TODO Auto-generated method stub
    System.out.println("My4FileSystemProvider getFileSystem(); uri=" + uri);
    if(!fileSystems.containsKey(uri))
    {
      System.out.println("throw new FileSystemNotFoundException()");
      throw new FileSystemNotFoundException();
    }

    return fileSystems.get(uri);
  }

  @Override
  public Path getPath(URI uri)
  {
    // TODO Auto-generated method stub
    System.out.println("My4FileSystemProvider getPath(); uri=" + uri + " ; uri.getSchemeSpecificPart()=" + uri.getSchemeSpecificPart());
    return null;
  }

  @Override
  public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
  {
    // TODO Auto-generated method stub
    System.out.println("My4FileSystemProvider newByteChannel()");
    return null;
  }

  @Override
  public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException
  {
    System.out.println("My4FileSystemProvider newDirectoryStream(); dir=" + dir + " ; dir instanceof My4Path?" + (dir instanceof My4Path) + " ; filter=" + filter);
    return new My4DirectoryStream(this.accountId, dir);
  }

  @Override
  public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException
  {
    MyFileResource.INSTANCE.createDirectory(dir);
//    System.out.println("My4FileSystemProvider createDirectory();實際建立目錄後,取得屬性並設給該目錄物件; path=" + dir + "; attrs=" + attrs + "; attrs.length=" + attrs.length);
//    MyFileAttributes fileAttributes = new MyFileAttributes(FileTime.fromMillis(System.currentTimeMillis()),
//                                                             FileTime.fromMillis(System.currentTimeMillis()),
//                                                             FileTime.fromMillis(System.currentTimeMillis()),
//                                                             false,
//                                                             true,
//                                                             0L,
//                                                             EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE));
//    ((My4Path)dir).setFileAttributes(fileAttributes);
  }

  @Override
  public void delete(Path path) throws IOException
  {
    System.out.println("My4FileSystemProvider delete()");
    MyFileResource.INSTANCE.delete(path);
  }

  @Override
  public void copy(Path source, Path target, CopyOption... options) throws IOException
  {
    // TODO Auto-generated method stub
    System.out.println("My4FileSystemProvider copy()");
  }

  @Override
  public void move(Path source, Path target, CopyOption... options) throws IOException
  {
    System.out.println("My4FileSystemProvider move()");
    MyFileResource.INSTANCE.move(source, target);
  }

  @Override
  public boolean isSameFile(Path path, Path path2) throws IOException
  {
    // TODO Auto-generated method stub
    System.out.println("My4FileSystemProvider isSameFile()");
    return false;
  }

  @Override
  public boolean isHidden(Path path) throws IOException
  {
    // TODO Auto-generated method stub
    System.out.println("My4FileSystemProvider isHidden()");
    return false;
  }

  @Override
  public FileStore getFileStore(Path path) throws IOException
  {
    // TODO Auto-generated method stub
    System.out.println("My4FileSystemProvider getFileStore()");
    return null;
  }

  @Override
  public void checkAccess(Path path, AccessMode... modes) throws IOException
  {
    // TODO Auto-generated method stub
    System.out.println("My4FileSystemProvider checkAccess(); path=" + path);
    for(AccessMode mode : modes)
    {
      System.out.println("My4FileSystemProvider checkAccess(); AccessMode = " + mode.name());
    }
  }

  @Override
  public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options)
  {
    // TODO Auto-generated method stub
    System.out.println("My4FileSystemProvider getFileAttributeView()");
//    return (V)new My4BasicFileAttributeView();
    return null;
  }

  @Override
  public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException
  {
    System.out.println("My4FileSystemProvider readAttributes(Path path, Class<A> type, LinkOption... options); path=" + path + " ; type=" + type);
    for(LinkOption linkOption : options)
    {
      System.out.println("My4FileSystemProvider readAttributes(Path path, Class<A> type, LinkOption... options); link option=" + linkOption);
    }

    MyFileAttributes fileAttributes = MyFileResource.INSTANCE.readAttribute(path);
    if(fileAttributes == null)
    {
      throw new NoSuchFileException("Can't read attributes from " + path);
    }

    return (A)fileAttributes;
//    return (A)new My4FileAttributes();
//    return null;
//    throw new UnsupportedOperationException();
  }

  @Override
  public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException
  {
    System.out.println("My4FileSystemProvider readAttributes(Path path, String attributes, LinkOption... options); path=" + path + " ;attributes=" + attributes + "; options=" + options);
    MyFileAttributes fileAttributes = MyFileResource.INSTANCE.readAttribute(path);
    Map<String, Object> map = new HashMap<>();
    map.put("creationTime", fileAttributes.creationTime());
    map.put("lastAccessTime", fileAttributes.lastAccessTime());
    map.put("lastModifiedTime", fileAttributes.lastModifiedTime());
    map.put("isSymbolicLink", fileAttributes.isSymbolicLink());
    map.put("isOther", fileAttributes.isOther());
    map.put("size", fileAttributes.size());
    map.put("isDirectory", fileAttributes.isDirectory());
    map.put("isRegularFile", fileAttributes.isRegularFile());
    map.put("permissions", fileAttributes.permissions());
    map.put("owner", fileAttributes.owner());
    map.put("group", fileAttributes.group());
    return map;
  }

  @Override
  public void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException
  {
    System.out.println("My4FileSystemProvider setAttribute(); path=" + path + "; attribute=" + attribute + "; value=" + value);
  }

  @Override
  public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
  {
    System.out.println("My4FileSystemProvider newFileChannel(); path=" + path + "; options=" + options + "; attrs.length=" + attrs.length);
    for(FileAttribute attr : attrs)
    {
      System.out.println("My4FileSystemProvider newFileChannel(); attr=" + attr);
    }

    return MyFileResource.INSTANCE.newFileChannel(path, options);
//    My4Path my4Path = (My4Path)path;
//    if(my4Path.getFileAttributes() == null)//模擬新建檔案後,給個假的檔案屬性。
//    {
//      my4Path.setFileAttributes(my4Path.getFileSystem().createMy4FileAttributes(false, 0L));
//    }
//    return (FileChannel)Channels.newChannel(new FileOutputStream("z:/test.txt"));
//    return super.newFileChannel(path, options, attrs);
  }

}


text:
<a:doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xsdtesting particlesId004.xsd" xmlns:a="http://xsdtesting">
	<a:e1/>
</a:doc>


text:
Computes the CircleLoss

Inherits From: [`MetricLoss`](../../TFSimilarity/losses/MetricLoss.md)

```python
TFSimilarity.losses.CircleLoss(
    gamma: float = 80.0,
    margin: float = 0.4,
    name: str = CircleLoss,
    **kwargs
)
```

Circle Loss: A Unified Perspective of Pair Similarity Optimization
https://arxiv.org/abs/2002.10857

The original paper used cosine similarity while this loss has been
modified to work with a distance such as cosine or euclidean.

y_true must be  a 1-D integer Tensor of shape (batch_size,).
It's values represent the classes associated with the examples as
**integer  values**.

y_pred must be 2-D float Tensor  of L2 normalized embedding vectors.
you can use the layer tensorflow_similarity.layers.L2Embedding() as the
last layer of your model to ensure your model output is properly
normalized.

<colgroup><col width="214px"><col></colgroup>

Args

distance

Which distance function to use to compute the pairwise
distances between embeddings. The distance is expected to be
between [0, 2]. Defaults to 'cosine'.

gamma

Scaling term. Defaults to 80. Note: Large values cause the
LogSumExp to return the Max pair and reduces the weighted mixing
of all pairs. Should be hypertuned.

margin

Used to weight the distance. Below this distance, negatives
are up weighted and positives are down weighted. Similarly, above
this distance negatives are down weighted and positive are up
weighted. Defaults to 0.4.

name

Loss name. Defaults to CircleLoss.

## Methods

from_config

``python
@classmethod``

```python
from_config(
    config
)
```

Instantiates a Loss from its config (output of get_config()).

<colgroup><col width="214px"><col></colgroup>

Args

config

Output of get_config().

<colgroup><col width="214px"><col></colgroup>

Returns

A Loss instance.

get_config

View source

```python
get_config() -> Dict[str, Any]
```

Contains the loss configuration.

<colgroup><col width="214px"><col></colgroup>

Returns

A Python dict containing the configuration of the loss.

__call__

```python
__call__(
    y_true, y_pred, sample_weight=None
)
```

Invokes the Loss instance.

<colgroup><col width="214px"><col></colgroup>

Args

y_true

Ground truth values. shape = [batch_size, d0, .. dN], except
sparse loss functions such as sparse categorical crossentropy where
shape = [batch_size, d0, .. dN-1]

y_pred

The predicted values. shape = [batch_size, d0, .. dN]

sample_weight

Optional sample_weight acts as a coefficient for the
loss. If a scalar is provided, then the loss is simply scaled by the
given value. If sample_weight is a tensor of size [batch_size], then
the total loss for each sample of the batch is rescaled by the
corresponding element in the sample_weight vector. If the shape of
sample_weight is [batch_size, d0, .. dN-1] (or can be broadcasted to
this shape), then each loss element of y_pred is scaled
by the corresponding value of sample_weight. (Note ondN-1: all loss
  functions reduce by 1 dimension, usually axis=-1.)

<colgroup><col width="214px"><col></colgroup>

Returns

Weighted loss float Tensor. If reduction is NONE, this has
shape [batch_size, d0, .. dN-1]; otherwise, it is scalar. (Note dN-1
because all loss functions reduce by 1 dimension, usually axis=-1.)

<colgroup><col width="214px"><col></colgroup>

Raises

ValueError

If the shape of sample_weight is invalid.


text:
function HasBindingFail({hidden, object}, property) {
  return [
    {name: "has", target: object, property: property, result: false},
  ];
}

function HasBindingSuccess({hidden, object}, property) {
  return [
    {name: "has", target: object, property: property, result: true},
    {name: "get", target: object, property: Symbol.unscopables, receiver: object, result: hidden[Symbol.unscopables]},
  ];
}

function GetBindingValueFail({hidden, object}, property) {
  return [
    {name: "has", target: object, property: property, result: false},
  ];
}

function GetBindingValueSuccess({hidden, object}, property) {
  return [
    {name: "has", target: object, property: property, result: true},
  ];
}

function GetValue({hidden, object}, property, value) {
  return [
    {name: "get", target: object, property: property, receiver: object, result: value},
  ];
}

function BindingNotIntercepted({hidden, object}, {hidden: blackListHidden, object: blackListObject}, property) {
  return [
    {name: "get", target: blackListObject, property: property, receiver: blackListObject, result: void 0},
  ];
}

function BindingIntercepted({hidden, object}, {hidden: blackListHidden, object: blackListObject}, property) {
  return [
    {name: "get", target: blackListObject, property: property, receiver: blackListObject, result: blackListHidden[property]},
  ];
}

function WithLookup(history, hidden, fn) {
  let object = Recorder.watch(hidden, history);
  try { fn(object); } finally { Recorder.unwatch(object); }
  return {hidden, object};
}


text:
module Log2mail

  class File

    require_relative 'file/parser'
    include Parser

    # FIXME: redundant
    def log(msg, sev = ::Logger::DEBUG)
      $logger.log sev, '%s: %s%s  [%s]' % [@path, msg, $/, caller.first]
    end

    def warn(msg)
      log(msg, ::Logger::WARN)
    end

    attr_reader :path, :patterns

    def initialize( path, patterns, maxbufsize = 65536 )
      @path = path
      self.patterns = patterns
      @maxbufsize = maxbufsize
      log "Maximum buffer size: #{@maxbufsize}"
      log "Patterns: #{patterns.inspect}"
    end

    def patterns=(patterns)
      @patterns = patterns.map(&:to_r)
    end

    # ----------------------------
    # - File management (public) -
    # ----------------------------

    def open
      @f = ::File.open(@path, 'r', :encoding => "BINARY")
      log "file opened"
      @ino = @f.stat.ino
      @size = 0
      @f
    rescue Errno::ENOENT
      warn "does not exist"
      false
    end

    def seek_to_end
      @f.seek(0, IO::SEEK_END)
      @size = @f.stat.size
      @f
    end

    def read_to_end
      return unless @f
      s = @f.gets(nil)
      @size += s.length if s
      s
    end

    def eof?
      !@f or @f.eof?
    end

    def rotated?
      if inum_changed?
        log "inode number changed"
        true
      elsif file_size_changed?
        log "file size changed; probably truncated"
        true
      else
        false
      end
    end

    private

    # -------------------
    # - File management -
    # -------------------

    def inum_changed?
      ::File.stat(@path).ino != @ino
    rescue Errno::ENOENT
      true
    end

    def file_size_changed?
      @f.stat.size != @size
    end

  end

end


text:
class UsersController < ApplicationController
  def new
    @user = User.new
  end

  def create
    @user = User.new(user_params)
    if @user.save
      session[:user_id] = @user.id
      redirect_to root_url, notice: "Thank you for signing up!"
    else
      render :new
    end
  end

  def update
    respond_to do |format|
      if current_user.update(user_params)
        format.html { redirect_to root_path, notice: 'User was successfully updated.' }
        format.json { render :show, status: :ok, location: root_path }
      else
        format.html { render :edit }
        format.json { render json: current_user.errors, status: :unprocessable_entity }
      end
    end
  end

  def send_mail(user, slug, tag)
    TagMailer.deliver_new_tag_alert(user, slug, tag)
  end

  private

  def user_params
    params.require(:user).permit(:name, :email, :password, :password_confirmation, :email_update)
  end
end


text:
'use strict';

var sax = require('sax');
var util = require('util');
var Transform = require('stream').Transform;
var Record = require('../marc/record');
var ControlField = require('../marc/control_field');
var DataField = require('../marc/data_field');
var Subfield = require('../marc/subfield');
var Leader = require('../marc/leader');

function MarcxmlParser (opts) {
    if (!(this instanceof MarcxmlParser)) return new MarcxmlParser(opts);
    opts = opts || {};
    opts.objectMode = true; // this has to be true. Emit only Record objects
    opts.highWaterMark = 16; // max. # of output records buffered
    Transform.call(this, opts);

    this.init();

    var strict = opts.strict || false;
    this.resume_saxerror = opts.resume_saxerror || false;

    // See https://github.com/isaacs/sax-js for more info
    this.stream = sax.createStream(strict /* strict mode - no by default */, {lowercase: true, xmlns: true });
    this.stream.on('error', this.handleSaxError.bind(this));
    //this.stream.on('processinginstruction', this.handleProcessingInstruction.bind(this));
    this.stream.on('opentag', this.handleOpenTag.bind(this));
    this.stream.on('closetag',this.handleCloseTag.bind(this));
    this.stream.on('text', this.handleText.bind(this));
    this.stream.on('cdata', this.handleText.bind(this));
    this.stream.once('end', this.handleEnd.bind(this));
}
util.inherits(MarcxmlParser, Transform);

MarcxmlParser.prototype.init = function (){
    this.stack = [];
};

MarcxmlParser.prototype.handleEnd = function (){
    this.stream.removeListener('error', this.handleSaxError.bind(this));
    this.stream.removeListener('opentag', this.handleOpenTag.bind(this));
    this.stream.removeListener('closetag',this.handleCloseTag.bind(this));
    this.stream.removeListener('text', this.handleText.bind(this));
    this.stream.removeListener('cdata', this.handleText.bind(this));
    this.push(null);
};

MarcxmlParser.prototype.handleSaxError = function (e) {
    this.emit('error', e);
    if (this.resume_saxerror) {
        if (this.stream._parser) {
            this.stream._parser.error = null;
            this.stream._parser.resume();
        }
    }
};

MarcxmlParser.prototype.handleError = function (e){
    this.emit('error', e);
};

MarcxmlParser.prototype.handleOpenTag = function (node){
    var obj;
    switch (node.local) {
        case 'record':
            obj = new Record();
            break;
        case 'leader':
            obj = new Leader();
            break;
        case 'controlfield':
            obj = new ControlField();
            if (node.attributes.tag) {
                obj.tag = node.attributes.tag.value;
            } else {
                // TODO: throw an error
            }
            break;
        case 'datafield':
            obj = new DataField();
            if (node.attributes.tag) {
                obj.tag = node.attributes.tag.value;
            } else {
                // TODO: throw an error
            }
            if (node.attributes.ind1) {
                obj.indicator1 = node.attributes.ind1.value;
            } else {
                // TODO: throw an error
            }
            if (node.attributes.ind2) {
                obj.indicator2 = node.attributes.ind2.value;
            } else {
                // TODO: throw an error
            }
            break;
        case 'subfield':
            obj = new Subfield();
            if (node.attributes.code) {
                obj.code = node.attributes.code.value;
            } else {
                // TODO: throw an error
            }
            break;
        default:
            break;
    }
    if (typeof obj !== 'undefined') this.stack.push(obj);
};

MarcxmlParser.prototype.handleCloseTag = function (el){
    var obj = this.stack.pop();
    if (obj instanceof Subfield) {
        var field = this.stack.pop();
        field.addSubfield(obj);
        this.stack.push(field);
    } else if (obj instanceof ControlField || obj instanceof DataField) {
        var record = this.stack.pop();
        record.addVariableField(obj);
        this.stack.push(record);
    } else if (obj instanceof Leader) {
        var record = this.stack.pop();
        record.leader = obj;
        this.stack.push(record);
    } else if (obj instanceof Record) {
        this.push(obj);
    }
};

MarcxmlParser.prototype.handleText = function (text){
    var obj = this.stack.pop();
    if (obj instanceof Subfield || obj instanceof ControlField) {
        obj.data = text;
    } else if (obj instanceof Leader) {
        obj.unmarshal(text);
    }
    this.stack.push(obj);
};

// Naive Stream API
MarcxmlParser.prototype._transform = function (data, encoding, done) {
    try {
        this.stream.write(data);
        done();
    } catch (e) {
        done(e);
        this.push(null); // Manually trigger and end, since we can't reliably do any more parsing
    }
};

module.exports = MarcxmlParser;


text:
#ifndef PANGOLIN_TIMER_H
#define PANGOLIN_TIMER_H

#include "pangolin.h"

#ifdef _UNIX_
#include <sys/time.h>
#endif

#ifdef _WIN_
#include <windows.h>
#endif

namespace pangolin
{

#ifdef _UNIX_
typedef timeval basetime;

inline basetime TimeNow()
{
    basetime t;
    gettimeofday(&t,NULL);
    return t;
}

inline double TimeNow_s()
{
    basetime tnow = TimeNow();
    return (double)tnow.tv_sec + 1E-6 * (double)tnow.tv_usec;
}

inline basetime TimeFromSeconds(double seconds)
{
    basetime t;
    t.tv_sec = (time_t)seconds;
    t.tv_usec = (useconds_t)((seconds - t.tv_sec) * 1E6);
    return t;
}

inline basetime TimeAdd(basetime t1, basetime t2)
{
    basetime t;
    t.tv_sec = t1.tv_sec + t2.tv_sec;
    t.tv_usec = t1.tv_usec + t2.tv_usec;
    if(t.tv_usec >= 1E6 )
    {
        t.tv_usec -= 1E6;
        t.tv_sec += 1;
    }

    return t;
}

inline double TimeDiff_s(basetime start, basetime end)
{
    return (double)(end.tv_sec - start.tv_sec) + (double)(end.tv_usec - start.tv_usec) * 1E-6;
}
#endif

#ifdef _WIN_
typedef LARGE_INTEGER basetime;

inline basetime TimeNow()
{
    basetime t;
    QueryPerformanceCounter(&t);
    return t;
}

inline double TimeNow_s()
{
    LARGE_INTEGER f;
    QueryPerformanceFrequency(&f);
    basetime tnow = TimeNow();
    return tnow.QuadPart / f.QuadPart;
}

inline double TimeDiff_s(basetime start, basetime end)
{
    LARGE_INTEGER f;
    QueryPerformanceFrequency(&f);
    return (end.QuadPart - start.QuadPart) / f.QuadPart;
}

inline basetime TimeFromSeconds(double seconds)
{
    LARGE_INTEGER f;
    QueryPerformanceFrequency(&f);
    basetime t;
    t.QuadPart = (seconds * f.QuadPart);
    return t;
}

inline basetime TimeAdd(basetime t1, basetime t2)
{
    basetime t;
    t.QuadPart = t1.QuadPart + t2.QuadPart;
    return t;
}
#endif

inline basetime WaitUntil(basetime t)
{
    // TODO: use smarter sleep!
    basetime currtime = TimeNow();
    while( TimeDiff_s(currtime,t) > 0 )
        currtime = TimeNow();
    return currtime;
}

struct Timer
{
    Timer() {
        Reset();
    }

    void Reset()
    {
        start = TimeNow();
    }

    double Elapsed_s()
    {
        basetime currtime = TimeNow();
        return TimeDiff_s(start,currtime);
    }

    basetime start;
};

}

#endif //PANGOLIN_TIMER_H


text:
package net.ejpm.conn.remote;

public interface RemoteJobHost {

    public String submitJob();

}


text:
// Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <iostream>
#include <string>

#include <geometry_test_common.hpp>

#include <boost/geometry/algorithms/detail/sections/sectionalize.hpp>
#include <boost/geometry/algorithms/detail/sections/range_by_section.hpp>
#include <boost/geometry/views/detail/range_type.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>

template <int DimensionCount, bool Reverse, typename Geometry>
void test_sectionalize(std::string const caseid, Geometry const& geometry, std::size_t section_count)
{
    typedef typename bg::point_type<Geometry>::type point;
    typedef bg::model::box<point> box;
    typedef bg::sections<box, DimensionCount> sections;

    sections s;
    bg::sectionalize<Reverse>(geometry, s);

    BOOST_CHECK_EQUAL(s.size(), section_count);

    typedef typename bg::closeable_view
        <
            typename bg::detail::range_type<Geometry>::type const,
            bg::closure<Geometry>::value
        >::type cview_type;
    typedef typename bg::reversible_view
        <
            cview_type const,
            Reverse ? bg::iterate_reverse : bg::iterate_forward
        >::type view_type;
    typedef typename boost::range_iterator
        <
            view_type const
        >::type range_iterator;

    BOOST_FOREACH(typename sections::value_type const& sec, s)
    {
        cview_type cview(bg::range_by_section(geometry, sec));
        view_type view(cview);
        range_iterator it1 = boost::begin(view) + sec.begin_index;
        range_iterator it2 = boost::begin(view) + sec.end_index;
        int count = 0;
        for (range_iterator it = it1; it != it2; ++it)
        {
            count++;
        }
        BOOST_CHECK_EQUAL(int(sec.count), count);
    }
}

template <typename Geometry, bool Reverse>
void test_sectionalize(std::string const& caseid, std::string const& wkt,
        std::size_t count1)
{
    Geometry geometry;
    bg::read_wkt(wkt, geometry);
    if (bg::closure<Geometry>::value == bg::open)
    {
        geometry.outer().resize(geometry.outer().size() - 1);
    }
    //bg::correct(geometry);
    test_sectionalize<1, Reverse>(caseid + "_d1", geometry, count1);
}

template <typename P>
void test_all()
{
    std::string const first = "polygon((2.0 1.3, 2.4 1.7, 2.8 1.8, 3.4 1.2, 3.7 1.6,3.4 2.0, 4.1 3.0, 5.3 2.6, 5.4 1.2, 4.9 0.8, 2.9 0.7,2.0 1.3))";
    test_sectionalize<bg::model::polygon<P>, false>("first", first, 4);

    test_sectionalize<bg::model::polygon<P, false>, true>("first_reverse",
        first, 4);

    test_sectionalize<bg::model::polygon<P, false, true>, false>("first_open",
        first, 4);

    test_sectionalize<bg::model::polygon<P, true, false>, true>("first_open_reverse",
        first, 4);
}

int test_main(int, char* [])
{
    test_all<bg::model::d2::point_xy<double> >();

    return 0;
}


text:
#import "PBSplashProvider.h"
#import "PBSystemUtilities.h"
#import "PBInstallerLocator.h"

@implementation PBSplashProvider

+ (PBSplashProvider *) defaultProvider
{
    static PBSplashProvider * sSplashProvider=nil;

    if (sSplashProvider==nil)
    {
        sSplashProvider=[[PBSplashProvider alloc] init];
    }

    return sSplashProvider;
}

- (id) init
{
    self=[super init];

    if (self!=nil)
    {
        NSString * tPath;

        tPath=[PBInstallerLocator pathForInstaller];

        if (tPath!=nil)
        {
            NSBundle * tBundle;

			// Check that this is the one we're looking for

            tBundle=[NSBundle bundleWithPath:tPath];

            tPath=nil;

            if (tBundle!=nil)
            {
                isTigrou_=([PBSystemUtilities systemMajorVersion]>=PBTiger);

                if (isTigrou_==NO)
                {
                    tPath=[[tBundle resourcePath] stringByAppendingPathComponent:@"Splash.bundle"];
                }
                else
                {
                    tPath=[[tBundle builtInPlugInsPath] stringByAppendingPathComponent:@"Introduction.bundle"];
                }

                if (tPath!=nil)
                {
                    bundle_=[[NSBundle bundleWithPath:tPath] retain];
                }
            }
        }
    }

    return self;
}

- (NSString *) pathWithLanguage:(NSString *) inEnglishName
{
    if (bundle_!=nil)
    {
        if (isTigrou_==NO)
        {
            return [bundle_ pathForResource:@"Splash"
                                     ofType:@"rtf"
                                inDirectory:nil
                            forLocalization:inEnglishName];
        }
        else
        {
             return [bundle_ pathForResource:@"Default"
                                     ofType:@"rtf"
                                inDirectory:nil
                            forLocalization:inEnglishName];
        }
    }

    return nil;
}

@end


text:
package com.rabbit.dao.idao.product;

import java.util.List;

import com.rabbit.dao.idao.IProductEnquiryDao;
import com.rabbit.dto.product.ProductVideo;

public interface IProductVideoEnquiryDao extends IProductEnquiryDao {

	public List<ProductVideo> getVideosBylistId(String clistingid);

	public List<ProductVideo> getVideoBylistingIds(List<String> listingIds);
}


text:
<?php

class site_theme_base
{

    public function set_last_modify()
    {
        return app::get('site')->setConf('site_theme_last_modify', time());
    }//End Function

    public function get_last_modify()
    {
        return app::get('site')->getConf('site_theme_last_modify');
    }//End Function

    public function set_default($theme){
        $theme_sytle = $this->get_theme_style($theme);
        if(empty($theme_sytle)){
            $this->set_theme_style($theme, '');
        }//todo:如果无样式或没有选择过样式,强制设置为空字符串
        app::get('site')->model('themes')->update(array('is_used'=>'false'), array());
        app::get('site')->model('themes')->update(array('is_used'=>'true'), array('theme'=>$theme));
        return app::get('site')->setConf('current_theme', $theme);
    }

    public function theme_exists()
    {
        return (is_null($this->get_default())) ? false : true;
    }//End Function

    public function get_default()
    {
        return app::get('site')->getConf('current_theme');
    }//End Function

    public function update_theme($aData)
    {
        return app::get('site')->model('themes')->save($aData);
    }//End Function

    public function set_theme_style($theme, $style)
    {
        return app::get('site')->setConf('theme_style.'.$theme, $style);
    }//End Function

    public function get_theme_style($theme)
    {
        return app::get('site')->getConf('theme_style.'.$theme);
    }//End Function

    public function set_theme_cache_version($theme)
    {
        return app::get('site')->setConf('theme_cache_version.'.$theme, time());
    }//End Function

    public function get_theme_cache_version($theme)
    {
        return app::get('site')->getConf('theme_cache_version.'.$theme);
    }//End Function

    public function get_view($theme)
    {
        return ecos_cactus('site','theme_get_view',$theme);
    }//End Function

    public function get_basic_config($theme){
        $basic_config='on';
        $path = THEME_DIR.'/'.$theme;
        if(!is_dir($path)&&!ECAE_MODE)  return array();
        $workdir = getcwd();
        chdir($path);
        $xml = kernel::single('site_utility_xml');
        $content = kernel::single('site_theme_file')->get_theme_xml($theme, 'theme.xml');
        $config = $xml->xml2arrayValues($content);

        $basic_config = $config['theme']['basic_config']?$config['theme']['basic_config']['value']:$basic_config;
        chdir($workdir);
        return $basic_config;
    }

    /*old functions*/

    public function get_border_from_themes($theme){
        $wights_border=Array();
        $path = THEME_DIR.'/'.$theme;
        if(!is_dir($path))  return array();
        $workdir = getcwd();
        chdir($path);
        $xml = kernel::single('site_utility_xml');
        $content=file_get_contents('theme.xml');
        $config = $xml->xml2arrayValues($content);

        if(isset($config['theme']['borders']['set']['attr'])){
                $wights_border[$config['theme']['borders']['set']['attr']['tpl']]=file_get_contents($config['theme']['borders']['set']['attr']['tpl']);
        }elseif( is_array($config['theme']['borders']['set'] ) ) {
            foreach($config['theme']['borders']['set'] as $k=>$v){
                $wights_border[$v['attr']['tpl']]=file_get_contents($v['attr']['tpl']);
            }
        }
        chdir($workdir);
        return $wights_border;
    }

    public function get_theme_styles($theme)
    {
        $aConfig = app::get('site')->model('themes')->select()->columns(array('config'))->where('theme = ?', $theme)->instance()->fetch_one();
        if(is_array($aConfig['config'])){
            foreach($aConfig['config'] AS $key=>$value){
                //if($value['type'] != 'fullstyle')   continue;
                $styles[] = $value;
            }
        }
        return $styles;
    }//End Function

    public function get_theme_borders($theme){
        $aConfig = app::get('site')->model('themes')->select()->columns(array('config'))->where('theme = ?', $theme)->instance()->fetch_one();
        for($i=0;$i<count($aConfig['borders']);$i++){
            $aData[$aConfig['borders'][$i]['tpl']]=$aConfig['borders'][$i]['key'];
        }
        return $aData;
    }

    public function get_theme_info($theme)
    {
        return app::get('site')->model('themes')->select()->where('theme = ?', $theme)->instance()->fetch_row();
    }//End Function

    public function install_theme_widgets($theme)
    {
        foreach(kernel::servicelist('site_theme_content_detector') AS $service){
            $service->update($theme);
            base_kvstore::instance('site_themes')->store('theme_last_modified'.get_class($service).$theme, $service->last_modified($theme));
        }
    }//End Function

    public function update_theme_widgets($theme, $force=false)
    {
        foreach(kernel::servicelist('site_theme_content_detector') AS $service){
            $last_modified = $service->last_modified($theme);
            if( $force
            || base_kvstore::instance('site_themes')->fetch('theme_last_modified'.get_class($service).$theme, $modified) === false
            || $last_modified != $modified ){
                logger::info('autofix theme widgets...');
                $service->update($theme);
                base_kvstore::instance('site_themes')->store('theme_last_modified'.get_class($service).$theme, $last_modified);
            }
        }
    }//End Function

    public function delete_theme_widgets($theme)
    {
        foreach(kernel::servicelist('site_theme_content_detector') AS $service){
            $service->clear_by_theme($theme);
            base_kvstore::instance('site_themes')->delete('theme_last_modified'.get_class($service).$theme);
        }
    }//End Function

    public function set_theme_views($theme, $views)
    {
        return app::get('site')->setConf('theme_views_' . $theme, $views);
    }//End Function

    public function get_theme_views($theme)
    {
        return app::get('site')->getConf('theme_views_' . $theme);
    }//End Function

    public function maintenance_theme_files($theme_dir=''){
        if (!$theme_dir) return;

        set_time_limit(0);
        cachemgr::init(false);
        header('Content-type: text/html;charset=utf-8');
        ignore_user_abort(false);
        ob_implicit_flush(1);
        ini_set('implicit_flush',true);
        kernel::$console_output = true;
        while(ob_get_level()){
            ob_end_flush();
        }
        echo str_repeat("\0",1024);
        echo '<pre>';
        echo '>update themes'."\n";

        if ($theme_dir==THEME_DIR){
            $dir = new DirectoryIterator($theme_dir);
            foreach($dir as $file)
            {
                $filename = $file->getFilename();
                if($filename{0}=='.'){
                    continue;
                }else{
                    $this->update_theme_widgets($filename);
                }
            }
        }
        else{
            $this->update_theme_widgets($theme_dir);
        }
        echo 'ok.</pre>';
    }

}//End Class


text:
// Auto generated by @moped/db-schema - do not edit by hand

export default interface DbRateLimitStates {
  /**
   * Primary Key
   */
  id: string;
  timestamp: number;
  value: number;
}


text:
 .. Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

 ..   http://www.apache.org/licenses/LICENSE-2.0

 .. Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

.. TODO: This section would be removed after we migrate to www_rbac completely.

Data Profiling
==============

Part of being productive with data is having the right weapons to
profile the data you are working with. Airflow provides a simple query
interface to write SQL and get results quickly, and a charting application
letting you visualize data.

Adhoc Queries
-------------
The adhoc query UI allows for simple SQL interactions with the database
connections registered in Airflow.

.. image:: img/adhoc.png

Charts
------
A simple UI built on top of flask-admin and highcharts allows building
data visualizations and charts easily. Fill in a form with a label, SQL,
chart type, pick a source database from your environment's connections,
select a few other options, and save it for later use.

You can even use the same templating and macros available when writing
airflow pipelines, parameterizing your queries and modifying parameters
directly in the URL.

These charts are basic, but they're easy to create, modify and share.

Chart Screenshot
................

.. image:: img/chart.png

-----

Chart Form Screenshot
.....................

.. image:: img/chart_form.png


text:
package auth

import (
	"context"
	"fmt"
	"time"

	"github.com/onsi/ginkgo/v2"
	v1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/util/wait"
	e2eauth "k8s.io/kubernetes/test/e2e/auth"
	"k8s.io/kubernetes/test/e2e/framework"
	e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
	"k8s.io/kubernetes/test/e2e/upgrades"
	imageutils "k8s.io/kubernetes/test/utils/image"
)

const (
	podBeforeMigrationName = "pod-before-migration"
	podAfterMigrationName  = "pod-after-migration"
)

// ServiceAccountAdmissionControllerMigrationTest test that a pod is functioning before and after
// a cluster upgrade.
type ServiceAccountAdmissionControllerMigrationTest struct {
	pod *v1.Pod
}

// Name returns the tracking name of the test.
func (ServiceAccountAdmissionControllerMigrationTest) Name() string {
	return "[sig-auth] serviceaccount-admission-controller-migration"
}

// Setup creates pod-before-migration which has legacy service account token.
func (t *ServiceAccountAdmissionControllerMigrationTest) Setup(f *framework.Framework) {
	t.pod = createPod(f, podBeforeMigrationName)
	inClusterClientMustWork(f, t.pod)
}

// Test waits for the upgrade to complete, and then verifies pod-before-migration
// and pod-after-migration are able to make requests using in cluster config.
func (t *ServiceAccountAdmissionControllerMigrationTest) Test(f *framework.Framework, done <-chan struct{}, upgrade upgrades.UpgradeType) {
	ginkgo.By("Waiting for upgrade to finish")
	<-done

	ginkgo.By("Starting post-upgrade check")
	ginkgo.By("Checking pod-before-migration makes successful requests using in cluster config")
	podBeforeMigration, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(context.TODO(), podBeforeMigrationName, metav1.GetOptions{})
	framework.ExpectNoError(err)
	if podBeforeMigration.GetUID() != t.pod.GetUID() {
		framework.Failf("Pod %q GetUID() = %q, want %q.", podBeforeMigration.Name, podBeforeMigration.GetUID(), t.pod.GetUID())
	}
	if podBeforeMigration.Status.ContainerStatuses[0].RestartCount != 0 {
		framework.Failf("Pod %q RestartCount = %d, want 0.", podBeforeMigration.Name, podBeforeMigration.Status.ContainerStatuses[0].RestartCount)
	}
	inClusterClientMustWork(f, podBeforeMigration)

	ginkgo.By("Checking pod-after-migration makes successful requests using in cluster config")
	podAfterMigration := createPod(f, podAfterMigrationName)
	if len(podAfterMigration.Spec.Volumes) != 1 || podAfterMigration.Spec.Volumes[0].Projected == nil {
		framework.Failf("Pod %q Volumes[0].Projected.Sources = nil, want non-nil.", podAfterMigration.Name)
	}
	inClusterClientMustWork(f, podAfterMigration)

	ginkgo.By("Finishing post-upgrade check")
}

// Teardown cleans up any remaining resources.
func (t *ServiceAccountAdmissionControllerMigrationTest) Teardown(f *framework.Framework) {
	// rely on the namespace deletion to clean up everything
}

func inClusterClientMustWork(f *framework.Framework, pod *v1.Pod) {
	var logs string
	since := time.Now()
	if err := wait.PollImmediate(15*time.Second, 5*time.Minute, func() (done bool, err error) {
		framework.Logf("Polling logs")
		logs, err = e2epod.GetPodLogsSince(f.ClientSet, pod.Namespace, pod.Name, "inclusterclient", since)
		if err != nil {
			framework.Logf("Error pulling logs: %v", err)
			return false, nil
		}
		numTokens, err := e2eauth.ParseInClusterClientLogs(logs)
		if err != nil {
			framework.Logf("Error parsing inclusterclient logs: %v", err)
			return false, fmt.Errorf("inclusterclient reported an error: %v", err)
		}
		if numTokens == 0 {
			framework.Logf("No authenticated API calls found")
			return false, nil
		}
		return true, nil
	}); err != nil {
		framework.Failf("Unexpected error: %v\n%s", err, logs)
	}
}

// createPod creates a pod.
func createPod(f *framework.Framework, podName string) *v1.Pod {
	pod := &v1.Pod{
		ObjectMeta: metav1.ObjectMeta{
			Name:      podName,
			Namespace: f.Namespace.Name,
		},
		Spec: v1.PodSpec{
			Containers: []v1.Container{{
				Name:  "inclusterclient",
				Image: imageutils.GetE2EImage(imageutils.Agnhost),
				Args:  []string{"inclusterclient", "--poll-interval=5"},
			}},
			RestartPolicy: v1.RestartPolicyNever,
		},
	}

	createdPod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
	framework.ExpectNoError(err)
	framework.Logf("Created pod %s", podName)

	if !e2epod.CheckPodsRunningReady(f.ClientSet, f.Namespace.Name, []string{pod.Name}, time.Minute) {
		framework.Failf("Pod %q/%q never became ready", createdPod.Namespace, createdPod.Name)
	}

	return createdPod
}


text:
package com.svetroid.hobbes.bot;

import net.dv8tion.jda.api.events.message.MessageReceivedEvent;

public class CommandInput {

    private final MessageReceivedEvent event;
    private String commandAlias;
    private String[] arguments;

    public CommandInput(MessageReceivedEvent event) {
        this.event = event;
    }

    public MessageReceivedEvent getEvent() {
        return event;
    }

    public void setCommandAlias(String commandAlias) {
        this.commandAlias = commandAlias;
    }

    public void setArguments(String[] arguments) {
        this.arguments = arguments;
    }

    public String getCommandAlias() {
        return commandAlias;
    }

    public String[] getArgs() {
        return arguments;
    }

    public String getArg(int i) {
        return arguments[i];
    }

    public String getArgString() {
        StringBuilder sb = new StringBuilder();
        for (String s : arguments) {
            sb.append(s).append(" ");
        }
        return sb.toString().trim();
    }

}


text:
layout: post
title: Stages in Serverless Framework
description: Stages in Serverless Framework can be configured using the "stage:" setting in serverless.yml. You can also deploy to a stage using the "--stage" option in the "serverless deploy" command. To configure environment variables for the different stages, use the custom variables in the serverless.yml.
date: 2018-04-06 00:00:00
comments_id: stages-in-serverless-framework/35
---

Serverless Framework allows you to create stages for your project to deploy to. Stages are useful for creating environments for testing and development. Typically you create a staging environment that is an independent clone of your production environment. This allows you to test and ensure that the version of code that you are about to deploy is good to go.

In this chapter we will take a look at how to configure stages in serverless. Let's first start by looking at how stages can be implemented.

### How Is Staging Implemented?

There are a couple of ways to set up stages for your project:

- Using the API Gateway built-in stages

  You can create multiple stages within a single API Gateway project. Stages within the same project share the same endpoint host, but have a different path. For example, say you have a stage called `prod` with the endpoint:

  ```txt
  https://abc12345.execute-api.us-east-1.amazonaws.com/prod
  ```

  If you were to add a stage called `dev` to the same API Gateway API, the new stage will have the endpoint:

  ```txt
  https://abc12345.execute-api.us-east-1.amazonaws.com/dev
  ```

  The downside is that both stages are part of the same project. You don't have the same level of flexibility to fine tune the IAM policies for stages of the same API, when compared to tuning different APIs. This leads to the next setup, each stage being its own API.

- Separate APIs for each stage

  You create an API Gateway project for each stage. Let's take the same example, your `prod` stage has the endpoint:

  ```txt
  https://abc12345.execute-api.us-east-1.amazonaws.com/prod
  ```

  To create the `dev` stage, you create a new API Gateway project and add the `dev` stage to the new project. The new endpoint will look something like:

  ```txt
  https://xyz67890.execute-api.us-east-1.amazonaws.com/dev
  ```

  Note that the `dev` stage carries a different endpoint host since it belongs to a different project. This is the approach Serverless Framework takes when configuring stages for your Serverless project. We will look at this in detail below.

- Separate AWS account for each stage

  Just like how having each stage being separate APIs give us more flexibility to fine tune the IAM policy. We can take it a step further and create the API project in a different AWS account. Most companies don't keep their production infrastructure in the same account as their development infrastructure. This helps reduce any cases where developers accidentally edit/delete production resources. We go in to more detail on how to deploy to multiple AWS accounts using different AWS profiles in the [Configure Multiple AWS Profiles]({% link _chapters/configure-multiple-aws-profiles.md %}) chapter.

### Deploying to a Stage

Let's look at how the Serverless Framework helps us work with stages. As mentioned above, a new stage is a new API Gateway project. To deploy to a specific stage, you can either specify the stage in the `serverless.yml`.

```yml
service: service-name

provider:
  name: aws
  stage: dev
```

Or you can specify the stage by passing the `--stage` option to the `serverless deploy` command.

```bash
$ serverless deploy --stage dev
```

### Stage Variables in Serverless Framework

Deploying to stages can be pretty simple but now let's look at how to configure our environment variables so that they work with our various stages. We went over the concept of environment variables in the chapter on [Serverless Environment Variables]({% link _chapters/serverless-environment-variables.md %}). Let's extend that to specify variables based on the stage we are deploying to.

Let's take a look at a sample `serverless.yml` below.

```yml
service: service-name

custom:
  myStage: ${opt:stage, self:provider.stage}
  myEnvironment:
    MESSAGE:
      prod: "This is production environment"
      dev: "This is development environment"

provider:
  name: aws
  stage: dev
  environment:
    MESSAGE: ${self:custom.myEnvironment.MESSAGE.${self:custom.myStage}}
```

There are a couple of things happening here. We first defined the `custom.myStage` variable as `${opt:stage, self:provider.stage}`. This is telling Serverless Framework to use the `--stage` CLI option if it exists. And if it does not, then use the default stage specified by `provider.stage`. We also define the `custom.myEnvironment` section. This contains the value for `MESSAGE` defined for each stage. Finally, we set the environment variable `MESSAGE` as `${self:custom.myEnvironment.MESSAGE.${self:custom.myStage}}`. This sets the variable to pick the value of `self:custom.myEnvironment` depending on the current stage defined in `custom.myStage`.

You can easily extend this format to create separate sets of environment variables for the stages you are deploying to.

And we can access the `MESSAGE` in our Lambda functions via `process.env` object like so.

```js
export function main(event, context, callback) {
  callback(null, { body: process.env.MESSAGE });
}
```

Hopefully, this chapter gives you a quick idea on how to set up stages in your Serverless project.


text:
In this practical, we create a cluster of Raspberry Pis by stacking them up appropriately with some hardware support.
Then, we install [Kubernetes](kubernetes.io) to orchestrate the nodes in the cluster.

The first part of the practical details how to install the [HypriotOS](https://blog.hypriot.com) distribution on a Pi.
The second part explains how to stack-up Pis using to form the cluster.
In the last part, we deploy Kubernetes across the cluster and check that our installation is functional.

To build a cluster, you should group-up in teams of four students.
In what follows, it is assumed that you `git clone` the sources of this practical.

## 1. HypriotOS

Our first step is to install an operating system on a Raspberry Pi.
To this end, we use the *v1.7* version of *HypriotOS*, a Debian-flavored Linux for Raspberry Pi.
Below, we present an "headless" installation which does not require the use of a monitor but solely to connect the device to the network.
In terms of hardware, you will need a SD card and an ethernet cable to connect the Pi.

### 1.1 The flash software

To install an operating system on a Raspberry Pi, we follow a set of instructions based on the [flash](https://github.com/hypriot/flash) tool.

First of all, we need to download and install the tool.

	curl -O https://raw.githubusercontent.com/hypriot/flash/master/$(uname -s)/flash
	chmod +x flash

To configure the Pi with the `flash` tool, we first need to write a file named `occidentalis.txt`.
This file serves to define the network parameters.
In our case, it contains a single line of code defining the `hostname`.
To uniquely identiy the Pi in the network, you should pick an original name.
The theme is "sailing ships" because the Kubernetes software we use means "pilot" in greek.
For instance,

    hostname=laperouse

### 1.2 Installing the operating system

For the steps that follow, you will need `sudo` rights on the computer your are using.
Do not hesitate to sollicitate the help of other students or of the teaching assistant.

Plug the SD card in the computer using a USB adaptator.
Then, upload the operating system image on the SD card with the `flash` tool.
For insatnce, the command line is as follows with version `v1.7.1` of HypriotOS.

	./flash -c occidentalis.txt https://github.com/hypriot/image-builder-rpi/releases/download/v1.7.1/hypriotos-rpi-v1.7.1.img.zip

Once this is done, you may plug the SD card in the Raspberry Pi, then connect to it using `ssh`.
The default login is `pirate` and the password `hypriot`.
(Notice that you may edit `/etc/hosts` to register a specific IP address, e.g., `157.159.110.31	laperouse.local`.)

	ssh pirate@laperouse.local

To ease networking operations, we use the same SSH key everywhere.
The private and public parts of the key are respectively available [here](https://github.com/otrack/cloud-computing-hands-on/setup/pi) and [there](https://github.com/otrack/cloud-computing-hands-on/setup/pi.pub).
Install the public part on the Raspberry Pi and the private part on your computer.
Check that everything is working properly.

Once you manage to install a Pi, repeat the above operation for two additional ones.
Thus, in total, your team should have a total of three operational Pis.

## 2. Cluster

In what follows, we create the cluster of Raspberry Pis.

## 2.1 Base component

The first step to form the cluster is to stack-up two Pis.
To this end, you need
* two USB mini-A cables,
* two ARJ45 cables, and
* a multi-pi stackable Raspberry Pi case.

A schema to assemble the Pis is available [here](https://www.modmypi.com/blog/multi-pi-assembly-guide).
At the end, you should obtain something similar to the picture below.

## 2.2 Assembling and wiring

We form a cluster using three Raspberry Pis.
Two clusters are stacked-up in a _tower_.
A tower thus contains a total of six Pis
In a tower, we use one USB hub to power the Pis, and one ethernet hub to interconnect them.

Discuss with another student team to assemble a tower.
Stack-up the Raspberry Pis and the USB hub appropriately (this last component should be at the top).
Check that you manage to reach all the Raspberry Pis in your cluster.

## 3. Kubernetes

We now have to install the Kubernetes (k8s) software in the Raspberry Pi cluster.

The steps below take inspiration from the guildelines [here](https://blog.hypriot.com/post/setup-kubernetes-raspberry-pi-cluster) by the [hypriot](https://blog.hypriot.com) team, as well as the the official documentation [there](https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm).

## 3.1 Installation

The installation of k8s requries root privileges on each Pi.
You may retrieve them with

	sudo su -

To install Kubernetes and its dependencies, only a few commands are required.
First, trust the kubernetes APT key by adding the official APT Kubernetes repository on every node:

	curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
	echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list

To improve the speed of your installation, we advise to define a specific [mirror](http://www.raspbian.org/RaspbianMirrors).
This requires to comment out the `mirrordirector` line in `/etc/apt/sources.list`, then add a specific one.
For instance,

    # deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
	deb http://raspbian.42.fr/raspbian/ jessie main contrib non-free rpi

Then, install `kubeadm` on each node (in parallel) as follows:

	apt-get update && apt-get install -y kubeadm

## 3.2 Bootstrapping the cluster

## 3.2.1 Master node

To bootstrap the kubernetes cluster, we need to designate an initial master node.
Choose one of your Raspberry Pis, and run the following command.

	kubeadm init --pod-network-cidr 10.244.0.0/16 --token-ttl 0

This command takes a few minutes to execute.
At the end, you should obtain a log starting with:

    Your Kubernetes master has initialized successfully!
	...

Use the last command given in the log to connect the other nodes to the network.
This should be something of the form.

    kubeadm join --token 15c86d.c1f4b7190440deff 192.168.0.23:6443 --discovery-token-ca-cert-hash sha256:3a1ac385fd8b51e8620e768f6f8f8cc724766ebe9ada6cfe8e1e53bd37f9a768

After this command executes, you should obtain something of the form:

    Node join complete:
	...

## 3.2.2 Remote management

To manage the cluster remotely, we have to install the `kubectl` tool on your local machine.
Follow the instructions listed [here](https://kubernetes.io/docs/tasks/tools/install-kubectl) for your operating system.
Please make sure that shell autocompletion is working.

It remains to import the cluster configuration on your local machine.
To this end, copy the file `/etc/kubernetes/admin.conf` in `/home/pirate` on the master node.
Give read rights to the `pirate` user using `sudo`.
Then, on your own machine imports the kubernetes configuration as follows:

	mkdir -p $HOME/.kube
	scp -i pi pirate@laperouse.local:/home/pirate/admin.conf $HOME/.kube/config
	kubectl config set-context kubernetes

## 3.2.3 Virtual Network

It remains to create a network fabric to interconnect nodes.
To this end, we use [flannel](https://github.com/coreos/flannel) that offers a support for ARM (the CPU type of a Raspberry Pi).

	kubectl create -f ./kube-flannel.yml

After a minute, check that the nodes are ready by typing `kubectl get nodes`.
You should observe something of that form.

    NAME          STATUS    AGE       VERSION
    black-pearl   Ready     1h        v1.8.3
    fregate       Ready     1h        v1.8.3
    laperouse     Ready     1h        v1.8.3

To sidestep [this](https://github.com/coreos/flannel/issues/799) issue, we need to add manually a few iptable rules to each node.
To this end, you should do the following steps on each Pi.

    sudo apt install -y iptables-persistent # answer "yes" both times
    sudo iptables -P FORWARD ACCEPT
    sudo iptables -t nat -A POSTROUTING -s 10.244.0.0/16 ! -d 10.244.0.0/16 -j MASQUERADE
    sudo iptables -I FORWARD 1 -i cni0 -j ACCEPT -m comment --comment "flannel subnet"
    sudo iptables -I FORWARD 1 -o cni0 -j ACCEPT -m comment --comment "flannel subnet"
    sudo netfilter-persistent save  # save rules for next reboot.

## 3.2.3 Dashboard

Our last step is to create a convenient [dashboard](https://github.com/kubernetes/dashboard) to see the activity in the cluster.

     kubectl create -f kube-dashboard.yml

The dashboard should be operational shortly.
We access it by first proxying the API server locally, then connecting to it with our favorite browser.
(The authentification page can be skipped.)

     kubectl proxy
	 my-favorite-browser http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy

Your fleet is now ready, welcome on board, captain!