text:
import userFilterVM from '../../../src/vms/user-filter-vm';

describe('admin.userFilterVM', function() {
  var vm = userFilterVM;

  describe("deactivated_at.toFilter", function() {
    it("should parse string inputs to json objects to send filter", function() {
      vm.deactivated_at('null');
      expect(vm.deactivated_at.toFilter()).toEqual(null);
    });
  });

  describe("full_text_index.toFilter", function() {
    it("should remove all diacritics to send filter", function() {
      vm.full_text_index('rémoção dos acêntüs');
      expect(vm.full_text_index.toFilter()).toEqual('remocao dos acentus');
    });
  });
});


text:
package test.testSpark

import org.junit._
import Assert._

@Test
class AppTest {

    @Test
    def testOK() = assertTrue(true)

//    @Test
//    def testKO() = assertTrue(false)

}

redpajama_set_name: RedPajamaGithub


text:
module Api
  module V2
    module Footnotes
      class FootnoteTypeSerializer
        include JSONAPI::Serializer

        set_type :footnote_type

        set_id :footnote_type_id

        attributes :footnote_type_id, :description
      end
    end
  end
end


text:
package org.apache.hadoop.chukwa.extraction.demux.processor.mapper;

import java.io.IOException;
import java.util.Hashtable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
import org.apache.hadoop.chukwa.extraction.engine.Record;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
import org.apache.log4j.Logger;

public class Log4jJobHistoryProcessor extends AbstractProcessor {
  static Logger log = Logger.getLogger(Log4jJobHistoryProcessor.class);

  private static final String recordType = "JobLogHistory";
  private static String internalRegex = null;
  private static Pattern ip = null;

  private Matcher internalMatcher = null;

  public Log4jJobHistoryProcessor() {
    internalRegex = "(.*?)=\"(.*?)\"(.*)([\\n])?";
    ip = Pattern.compile(internalRegex);
    internalMatcher = ip.matcher("-");
  }

  @Override
  protected void parse(String recordEntry,
      OutputCollector<ChukwaRecordKey, ChukwaRecord> output, Reporter reporter)
      throws Throwable {

    // log.info("JobLogHistoryProcessor record: [" + recordEntry + "] type["
    // + chunk.getDataType() + "]");

    try {

      // String dStr = recordEntry.substring(0, 23);
      int start = 24;
      int idx = recordEntry.indexOf(' ', start);
      // String level = recordEntry.substring(start, idx);
      start = idx + 1;
      idx = recordEntry.indexOf(' ', start);
      // String className = recordEntry.substring(start, idx-1);
      String body = recordEntry.substring(idx + 1);

      Hashtable<String, String> keys = new Hashtable<String, String>();
      ChukwaRecord record = null;

      int firstSep = body.indexOf(" ");
      keys.put("RECORD_TYPE", body.substring(0, firstSep));
      // log.info("JobLogHistoryProcessor Add field: [RECORD_TYPE]["
      // + keys.get("RECORD_TYPE") + "]");

      body = body.substring(firstSep);

      internalMatcher.reset(body);

      // String fieldName = null;
      // String fieldValue = null;

      while (internalMatcher.matches()) {

        keys.put(internalMatcher.group(1).trim(), internalMatcher.group(2)
            .trim());

        // TODO Remove debug info before production
        // fieldName = internalMatcher.group(1).trim();
        // fieldValue = internalMatcher.group(2).trim();
        // log.info("JobLogHistoryProcessor Add field: [" + fieldName +
        // "][" + fieldValue +"]" );
        // log.info("EOL : [" + internalMatcher.group(3) + "]" );
        internalMatcher.reset(internalMatcher.group(3));
      }

      if (!keys.containsKey("JOBID")) {
        // Extract JobID from taskID
        // JOBID = "job_200804210403_0005"
        // TASKID = "tip_200804210403_0005_m_000018"
        String jobId = keys.get("TASKID");
        int idx1 = jobId.indexOf('_', 0);
        int idx2 = jobId.indexOf('_', idx1 + 1);
        idx2 = jobId.indexOf('_', idx2 + 1);
        keys.put("JOBID", "job" + jobId.substring(idx1, idx2));
        // log.info("JobLogHistoryProcessor Add field: [JOBID]["
        // + keys.get("JOBID") + "]");
      }

      // if (keys.get("RECORD_TYPE").equalsIgnoreCase("Job") &&
      // keys.containsKey("SUBMIT_TIME"))
      // {
      // // Job JOBID="job_200804210403_0005" JOBNAME="MY_JOB"
      // USER="userxxx"
      // // SUBMIT_TIME="1208760436751"
      // JOBCONF="/mapredsystem/xxx.yyy.com/job_200804210403_0005/job.xml"
      //
      //
      // }
      // else if (keys.get("RECORD_TYPE").equalsIgnoreCase("Job") &&
      // keys.containsKey("LAUNCH_TIME"))
      // {
      // // Job JOBID="job_200804210403_0005" LAUNCH_TIME="1208760437110"
      // TOTAL_MAPS="5912" TOTAL_REDUCES="739"
      //
      // }
      // else if (keys.get("RECORD_TYPE").equalsIgnoreCase("Job") &&
      // keys.containsKey("FINISH_TIME"))
      // {
      // // Job JOBID="job_200804210403_0005" FINISH_TIME="1208760906816"
      // JOB_STATUS="SUCCESS" FINISHED_MAPS="5912" FINISHED_REDUCES="739"
      // FAILED_MAPS="0" FAILED_REDUCES="0"
      // // COUNTERS="File Systems.Local bytes read:1735053407244,File
      // Systems.Local bytes written:2610106384012,File Systems.HDFS bytes
      // read:801605644910,File Systems.HDFS bytes written:44135800,
      // // Job Counters .Launched map tasks:5912,Job Counters .Launched
      // reduce tasks:739,Job Counters .Data-local map tasks:5573,Job
      // Counters .Rack-local map tasks:316,Map-Reduce Framework.
      // // Map input records:9410696067,Map-Reduce Framework.Map output
      // records:9410696067,Map-Reduce Framework.Map input
      // bytes:801599188816,Map-Reduce Framework.Map output
      // bytes:784427968116,
      // // Map-Reduce Framework.Combine input records:0,Map-Reduce
      // Framework.Combine output records:0,Map-Reduce Framework.Reduce
      // input groups:477265,Map-Reduce Framework.Reduce input
      // records:739000,
      // // Map-Reduce Framework.Reduce output records:739000"
      //
      // }
      // else
      if (keys.get("RECORD_TYPE").equalsIgnoreCase("MapAttempt")
          && keys.containsKey("START_TIME")) {
        // MapAttempt TASK_TYPE="MAP"
        // TASKID="tip_200804210403_0005_m_000018"
        // TASK_ATTEMPT_ID="task_200804210403_0005_m_000018_0"
        // START_TIME="1208760437531"
        // HOSTNAME="tracker_xxx.yyy.com:xxx.yyy.com/xxx.xxx.xxx.xxx:53734"

        key = new ChukwaRecordKey();
        key.setKey("JobLogHist/Map/" + keys.get("JOBID") + "/"
            + keys.get("START_TIME"));
        key.setReduceType("JobLogHistoryReduceProcessor");
        record = new ChukwaRecord();
        record.setTime(Long.parseLong(keys.get("START_TIME")));
        record.add("JOBID", keys.get("JOBID"));
        record.add("START_TIME", keys.get("START_TIME"));
        record.add(Record.tagsField, chunk.getTags());
        // log.info("JobLogHist/Map/S");
        output.collect(key, record);

      } else if (keys.get("RECORD_TYPE").equalsIgnoreCase("MapAttempt")
          && keys.containsKey("FINISH_TIME")) {
        // MapAttempt TASK_TYPE="MAP"
        // TASKID="tip_200804210403_0005_m_005494"
        // TASK_ATTEMPT_ID="task_200804210403_0005_m_005494_0"
        // TASK_STATUS="SUCCESS"
        // FINISH_TIME="1208760624124"
        // HOSTNAME="tracker_xxxx.yyyy.com:xxx.yyy.com/xxx.xxx.xxx.xxx:55491"

        key = new ChukwaRecordKey();
        key.setKey("JobLogHist/Map/" + keys.get("JOBID") + "/"
            + keys.get("FINISH_TIME"));
        key.setReduceType("JobLogHistoryReduceProcessor");
        record = new ChukwaRecord();
        record.setTime(Long.parseLong(keys.get("FINISH_TIME")));
        record.add("JOBID", keys.get("JOBID"));
        record.add("FINISH_TIME", keys.get("FINISH_TIME"));
        record.add(Record.tagsField, chunk.getTags());
        // log.info("JobLogHist/Map/E");
        output.collect(key, record);
      }

      else if (keys.get("RECORD_TYPE").equalsIgnoreCase("ReduceAttempt")
          && keys.containsKey("START_TIME")) {
        // ReduceAttempt TASK_TYPE="REDUCE"
        // TASKID="tip_200804210403_0005_r_000138"
        // TASK_ATTEMPT_ID="task_200804210403_0005_r_000138_0"
        // START_TIME="1208760454885"
        // HOSTNAME="tracker_xxxx.yyyy.com:xxx.yyy.com/xxx.xxx.xxx.xxx:51947"

        key = new ChukwaRecordKey();
        key.setKey("JobLogHist/SHUFFLE/" + keys.get("JOBID") + "/"
            + keys.get("START_TIME"));
        key.setReduceType("JobLogHistoryReduceProcessor");
        record = new ChukwaRecord();
        record.setTime(Long.parseLong(keys.get("START_TIME")));
        record.add("JOBID", keys.get("JOBID"));
        record.add("START_TIME", keys.get("START_TIME"));
        record.add(Record.tagsField, chunk.getTags());
        // log.info("JobLogHist/SHUFFLE/S");
        output.collect(key, record);

      } else if (keys.get("RECORD_TYPE").equalsIgnoreCase("ReduceAttempt")
          && keys.containsKey("FINISH_TIME")) {
        // ReduceAttempt TASK_TYPE="REDUCE"
        // TASKID="tip_200804210403_0005_r_000138"
        // TASK_ATTEMPT_ID="task_200804210403_0005_r_000138_0"
        // TASK_STATUS="SUCCESS" SHUFFLE_FINISHED="1208760787167"
        // SORT_FINISHED="1208760787354" FINISH_TIME="1208760802395"
        // HOSTNAME="tracker__xxxx.yyyy.com:xxx.yyy.com/xxx.xxx.xxx.xxx:51947"

        key = new ChukwaRecordKey();
        key.setKey("JobLogHist/SHUFFLE/" + keys.get("JOBID") + "/"
            + keys.get("SHUFFLE_FINISHED"));
        key.setReduceType("JobLogHistoryReduceProcessor");
        record = new ChukwaRecord();
        record.setTime(Long.parseLong(keys.get("SHUFFLE_FINISHED")));
        record.add("JOBID", keys.get("JOBID"));
        record.add("SHUFFLE_FINISHED", keys.get("SHUFFLE_FINISHED"));
        record.add(Record.tagsField, chunk.getTags());
        // log.info("JobLogHist/SHUFFLE/E");
        output.collect(key, record);

        // SORT
        key = new ChukwaRecordKey();
        key.setKey("JobLogHist/SORT/" + keys.get("JOBID") + "/"
            + keys.get("SHUFFLE_FINISHED"));
        key.setReduceType("JobLogHistoryReduceProcessor");
        record = new ChukwaRecord();
        record.setTime(Long.parseLong(keys.get("SHUFFLE_FINISHED")));
        record.add("JOBID", keys.get("JOBID"));
        record.add("START_TIME", keys.get("SHUFFLE_FINISHED"));
        record.add(Record.tagsField, chunk.getTags());
        // log.info("JobLogHist/SORT/S");
        output.collect(key, record);

        key = new ChukwaRecordKey();
        key.setKey("JobLogHist/SORT/" + keys.get("JOBID") + "/"
            + keys.get("SORT_FINISHED"));
        key.setReduceType("JobLogHistoryReduceProcessor");
        record = new ChukwaRecord();
        record.setTime(Long.parseLong(keys.get("SORT_FINISHED")));
        record.add("JOBID", keys.get("JOBID"));
        record.add("SORT_FINISHED", keys.get("SORT_FINISHED"));
        record.add(Record.tagsField, chunk.getTags());
        // log.info("JobLogHist/SORT/E");
        output.collect(key, record);

        // Reduce
        key = new ChukwaRecordKey();
        key.setKey("JobLogHist/REDUCE/" + keys.get("JOBID") + "/"
            + keys.get("SORT_FINISHED"));
        key.setReduceType("JobLogHistoryReduceProcessor");
        record = new ChukwaRecord();
        record.setTime(Long.parseLong(keys.get("SORT_FINISHED")));
        record.add("JOBID", keys.get("JOBID"));
        record.add("START_TIME", keys.get("SORT_FINISHED"));
        record.add(Record.tagsField, chunk.getTags());
        // log.info("JobLogHist/REDUCE/S");
        output.collect(key, record);

        key = new ChukwaRecordKey();
        key.setKey("JobLogHist/REDUCE/" + keys.get("JOBID") + "/"
            + keys.get("FINISH_TIME"));
        key.setReduceType("JobLogHistoryReduceProcessor");
        record = new ChukwaRecord();
        record.setTime(Long.parseLong(keys.get("SORT_FINISHED")));
        record.add("JOBID", keys.get("JOBID"));
        record.add("FINISH_TIME", keys.get("SORT_FINISHED"));
        record.add(Record.tagsField, chunk.getTags());
        // log.info("JobLogHist/REDUCE/E");
        output.collect(key, record);

      } else if (keys.get("RECORD_TYPE").equalsIgnoreCase("Job")
          && keys.containsKey("COUNTERS")) {
        // Job JOBID="job_200804210403_0005" FINISH_TIME="1208760906816"
        // JOB_STATUS="SUCCESS" FINISHED_MAPS="5912"
        // FINISHED_REDUCES="739" FAILED_MAPS="0" FAILED_REDUCES="0"
        // COUNTERS="File Systems.Local bytes read:1735053407244,File
        // Systems.Local bytes written:2610106384012,File Systems.HDFS
        // bytes read:801605644910,File Systems.HDFS bytes
        // written:44135800,
        // Job Counters .Launched map tasks:5912,Job Counters .Launched
        // reduce tasks:739,Job Counters .Data-local map tasks:5573,Job
        // Counters .Rack-local map tasks:316,Map-Reduce Framework.
        // Map input records:9410696067,Map-Reduce Framework.Map output
        // records:9410696067,Map-Reduce Framework.Map input
        // bytes:801599188816,Map-Reduce Framework.Map output
        // bytes:784427968116,
        // Map-Reduce Framework.Combine input records:0,Map-Reduce
        // Framework.Combine output records:0,Map-Reduce
        // Framework.Reduce input groups:477265,Map-Reduce
        // Framework.Reduce input records:739000,
        // Map-Reduce Framework.Reduce output records:739000"

        record = new ChukwaRecord();
        key = new ChukwaRecordKey();
        buildGenericRecord(record, null, Long
            .parseLong(keys.get("FINISH_TIME")), "MRJobCounters");
        extractCounters(record, keys.get("COUNTERS"));

        String jobId = keys.get("JOBID").replace("_", "").substring(3);
        record.add("JobId", "" + jobId);

        // FIXME validate this when HodId will be available
        if (keys.containsKey("HODID")) {
          record.add("HodId", keys.get("HODID"));
        }

        // log.info("MRJobCounters +1");
        output.collect(key, record);
      }

      if (keys.containsKey("TASK_TYPE")
          && keys.containsKey("COUNTERS")
          && (keys.get("TASK_TYPE").equalsIgnoreCase("REDUCE") || keys.get(
              "TASK_TYPE").equalsIgnoreCase("MAP"))) {
        // MAP
        // Task TASKID="tip_200804210403_0005_m_000154" TASK_TYPE="MAP"
        // TASK_STATUS="SUCCESS" FINISH_TIME="1208760463883"
        // COUNTERS="File Systems.Local bytes read:159265655,File
        // Systems.Local bytes written:318531310,
        // File Systems.HDFS bytes read:145882417,Map-Reduce
        // Framework.Map input records:1706604,
        // Map-Reduce Framework.Map output records:1706604,Map-Reduce
        // Framework.Map input bytes:145882057,
        // Map-Reduce Framework.Map output bytes:142763253,Map-Reduce
        // Framework.Combine input records:0,Map-Reduce
        // Framework.Combine output records:0"

        // REDUCE
        // Task TASKID="tip_200804210403_0005_r_000524"
        // TASK_TYPE="REDUCE" TASK_STATUS="SUCCESS"
        // FINISH_TIME="1208760877072"
        // COUNTERS="File Systems.Local bytes read:1179319677,File
        // Systems.Local bytes written:1184474889,File Systems.HDFS
        // bytes written:59021,
        // Map-Reduce Framework.Reduce input groups:684,Map-Reduce
        // Framework.Reduce input records:1000,Map-Reduce
        // Framework.Reduce output records:1000"

        record = new ChukwaRecord();
        key = new ChukwaRecordKey();
        buildGenericRecord(record, null, Long
            .parseLong(keys.get("FINISH_TIME")), "SizeVsFinishTime");
        extractCounters(record, keys.get("COUNTERS"));
        record.add("JOBID", keys.get("JOBID"));
        record.add("TASKID", keys.get("TASKID"));
        record.add("TASK_TYPE", keys.get("TASK_TYPE"));

        // log.info("MR_Graph +1");
        output.collect(key, record);

      }
    } catch (IOException e) {
      log.warn("Unable to collect output in JobLogHistoryProcessor ["
          + recordEntry + "]", e);
      e.printStackTrace();
      throw e;
    }

  }

  protected void extractCounters(ChukwaRecord record, String input) {

    String[] data = null;
    String[] counters = input.split(",");

    for (String counter : counters) {
      data = counter.split(":");
      record.add(data[0].replaceAll(" ", "_").replaceAll("\\.", "_")
          .toUpperCase(), data[1]);
    }
  }

  public String getDataType() {
    return Log4jJobHistoryProcessor.recordType;
  }
}


text:
package bootstrap;

import java.util.Date;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.mongodb.core.MongoOperations;

import com.mongodb.MongoClient;

public class MongoHandler {

    private static MongoOperations mop = null;
    private static MongoClient client = null;

    private static MongoHandler instance = null;

    /**
     * Intantiate a connection to mongodb
     */

    public MongoHandler() {
        init();
    }

    public static MongoHandler getInstance(String dbName) {
        if(dbName!=null){
            ///ThreadLocalDbNameMongoDbFactory.clearDefaultNameForCurrentThread();
       //     ThreadLocalDbNameMongoDbFactory.setDefaultNameForCurrentThread(dbName);
        }

        return (instance == null ? instance = new MongoHandler() : instance);
    }
    public static MongoHandler getInstance() {

        //ThreadLocalDbNameMongoDbFactory.clearDefaultNameForCurrentThread();
        //ThreadLocalDbNameMongoDbFactory.setDefaultNameForCurrentThread(null);

        return (instance == null ? instance = new MongoHandler() : instance);
    }

    @SuppressWarnings("resource")
    public static void init(){

        ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class);
        if(mop == null){
            mop = (MongoOperations)ctx.getBean("mongoTemplate");

        }

    }

    /**
     * Gets the time from mongodb server
     * @return the time from the machine hosting the mongodb server
     */
    public static Date getServerTime(){
        try{
            return ((Date) SpringMongoConfig.mongoInfo.getServerStatus().get("localTime"));
        }catch(Exception e){
            return new Date();
        }
    }

    public MongoOperations getMongo(){
        return mop;
    }

    public MongoClient getClient(){
        return client;
    }

}


text:
{-# LANGUAGE BangPatterns, EmptyDataDecls, ScopedTypeVariables #-}

-- |
-- Module      : Data.Text.ICU.Regex.Pure
-- Copyright   : (c) 2010 Bryan O'Sullivan
--
-- License     : BSD-style
-- Maintainer  : bos@serpentine.com
-- Stability   : experimental
-- Portability : GHC
--
-- Regular expression support for Unicode, implemented as bindings to
-- the International Components for Unicode (ICU) libraries.
--
-- The functions in this module are pure and hence thread safe, but
-- may not be as fast or as flexible as those in the
-- "Data.Text.ICU.Regex" module.
--
-- The syntax and behaviour of ICU regular expressions are Perl-like.
-- For complete details, see the ICU User Guide entry at
-- <http://userguide.icu-project.org/strings/regexp>.

module Data.Text.ICU.Regex.Pure
    (
    -- * Types
      MatchOption(..)
    , ParseError(errError, errLine, errOffset)
    , Match
    , Regex
    , Regular
    -- * Functions
    -- ** Construction
    , regex
    , regex'
    -- ** Inspection
    , pattern
    -- ** Searching
    , find
    , findAll
    -- ** Match groups
    -- $group
    , groupCount
    , unfold
    , span
    , group
    , prefix
    , suffix
    ) where

import qualified Control.Exception as E
import Data.String (IsString(..))
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Foreign as T
import Data.Text.ICU.Error.Internal (ParseError(..), handleError)
import qualified Data.Text.ICU.Regex as IO
import Data.Text.ICU.Regex.Internal hiding (Regex(..), regex)
import qualified Data.Text.ICU.Regex.Internal as Internal
import Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
import Foreign.Marshal.Alloc (alloca)
import Foreign.Marshal.Array (advancePtr)
import Foreign.Storable (peek)
import Prelude hiding (span)
import System.IO.Unsafe (unsafeInterleaveIO, unsafePerformIO)

-- | A compiled regular expression.
--
-- 'Regex' values are usually constructed using the 'regex' or
-- 'regex'' functions.  This type is also an instance of 'IsString',
-- so if you have the @OverloadedStrings@ language extension enabled,
-- you can construct a 'Regex' by simply writing the pattern in
-- quotes (though this does not allow you to specify any 'Option's).
newtype Regex = Regex {
      reRe :: Internal.Regex
    }

instance Show Regex where
    show re = "Regex " ++ show (pattern re)

instance IsString Regex where
    fromString = regex [] . T.pack

-- | A match for a regular expression.
data Match = Match {
      matchRe :: Internal.Regex
    , _matchPrev :: T.I16
    }

instance Show Match where
    show m = "Match " ++ show (unfold group m)

-- | A typeclass for functions common to both 'Match' and 'Regex'
-- types.
class Regular r where
    regRe :: r -> Internal.Regex

    regFp :: r -> ForeignPtr URegularExpression
    regFp = Internal.reRe . regRe
    {-# INLINE regFp #-}

instance Regular Match where
    regRe = matchRe

instance Regular Regex where
    regRe = reRe

-- | Compile a regular expression with the given options.  This
-- function throws a 'ParseError' if the pattern is invalid, so it is
-- best for use when the pattern is statically known.
regex :: [MatchOption] -> Text -> Regex
regex opts pat = Regex . unsafePerformIO $ IO.regex opts pat

-- | Compile a regular expression with the given options.  This is
-- safest to use when the pattern is constructed at run time.
regex' :: [MatchOption] -> Text -> Either ParseError Regex
regex' opts pat = unsafePerformIO $
  ((Right . Regex) `fmap` Internal.regex opts pat) `E.catch`
  \(err::ParseError) -> return (Left err)

-- | Return the source form of the pattern used to construct this
-- regular expression or match.
pattern :: Regular r => r -> Text
pattern r = unsafePerformIO . withForeignPtr (regFp r) $ \rePtr ->
  alloca $ \lenPtr -> do
    textPtr <- handleError $ uregex_pattern rePtr lenPtr
    (T.fromPtr textPtr . fromIntegral) =<< peek lenPtr

-- | Find the first match for the regular expression in the given text.
find :: Regex -> Text -> Maybe Match
find re0 haystack = unsafePerformIO .
  matching re0 haystack $ \re -> do
    m <- IO.findNext re
    return $! if m then Just (Match re 0) else Nothing

-- | Lazily find all matches for the regular expression in the given
-- text.
findAll :: Regex -> Text -> [Match]
findAll re0 haystack = unsafePerformIO . unsafeInterleaveIO $ go 0
  where
    len = fromIntegral . T.lengthWord16 $ haystack
    go !n | n >= len  = return []
          | otherwise = matching re0 haystack $ \re -> do
      found <- IO.find re n
      if found
        then do
          n' <- IO.end_ re 0
          (Match re n:) `fmap` go n'
        else return []

matching :: Regex -> Text -> (IO.Regex -> IO a) -> IO a
matching (Regex re0) haystack act = do
  re <- IO.clone re0
  IO.setText re haystack
  act re

-- $group
--
-- Capturing groups are numbered starting from zero.  Group zero is
-- always the entire matching text.  Groups greater than zero contain
-- the text matching each capturing group in a regular expression.

-- | Return the number of capturing groups in this regular
-- expression or match's pattern.
groupCount :: Regular r => r -> Int
groupCount = unsafePerformIO . IO.groupCount . regRe
{-# INLINE groupCount #-}

-- | A combinator for returning a list of all capturing groups on a
-- 'Match'.
unfold :: (Int -> Match -> Maybe Text) -> Match -> [Text]
unfold f m = go 0
  where go !n = case f n m of
                  Nothing -> []
                  Just z  -> z : go (n+1)

-- | Return the /n/th capturing group in a match, or 'Nothing' if /n/
-- is out of bounds.
group :: Int -> Match -> Maybe Text
group n m = grouping n m $ \re -> do
  let n' = fromIntegral n
  start <- fromIntegral `fmap` IO.start_ re n'
  end <- fromIntegral `fmap` IO.end_ re n'
  (fp,_) <- IO.getText re
  withForeignPtr fp $ \ptr ->
    T.fromPtr (ptr `advancePtr` fromIntegral start) (end - start)

-- | Return the prefix of the /n/th capturing group in a match (the
-- text from the start of the string to the start of the match), or
-- 'Nothing' if /n/ is out of bounds.
prefix :: Int -> Match -> Maybe Text
prefix n m = grouping n m $ \re -> do
  start <- fromIntegral `fmap` IO.start_ re n
  (fp,_) <- IO.getText re
  withForeignPtr fp (`T.fromPtr` start)

-- | Return the span of text between the end of the previous match and
-- the beginning of the current match.
span :: Match -> Text
span (Match re p) = unsafePerformIO $ do
  start <- IO.start_ re 0
  (fp,_) <- IO.getText re
  withForeignPtr fp $ \ptr ->
    T.fromPtr (ptr `advancePtr` fromIntegral p) (start - p)

-- | Return the suffix of the /n/th capturing group in a match (the
-- text from the end of the match to the end of the string), or
-- 'Nothing' if /n/ is out of bounds.
suffix :: Int -> Match -> Maybe Text
suffix n m = grouping n m $ \re -> do
  end <- fromIntegral `fmap` IO.end_ re n
  (fp,len) <- IO.getText re
  withForeignPtr fp $ \ptr -> do
    T.fromPtr (ptr `advancePtr` fromIntegral end) (len - end)

grouping :: Int -> Match -> (Internal.Regex -> IO a) -> Maybe a
grouping n (Match m _) act = unsafePerformIO $ do
  count <- IO.groupCount m
  let n' = fromIntegral n
  if n' == 0 || (n' >= 0 && n' <= count)
    then Just `fmap` act m
    else return Nothing


text:
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.editor.ex;

import com.intellij.openapi.editor.FoldRegion;
import org.jetbrains.annotations.NotNull;

/**
 * Defines common contract for clients interested in folding processing.
 *
 * @author Denis Zhdanov
 */
public interface FoldingListener {

  /**
   * Informs that {@code 'collapsed'} state of given fold region is just changed, or that the given fold region has just been created.
   *

   * Note: listener should delay fold region state processing until {@link #onFoldProcessingEnd()} is called.
   * I.e. folding model may return inconsistent data between current moment and {@link #onFoldProcessingEnd()}.
   *
   * @param region    fold region that is just collapsed or expanded
   */
  default void onFoldRegionStateChange(@NotNull FoldRegion region) {
  }

  /**
   * Informs that the given fold region is about to be removed.
   */
  default void beforeFoldRegionRemoved(@NotNull FoldRegion region) {
  }

  /**
   * Informs that fold processing is done.
   */
  default void onFoldProcessingEnd() {
  }
}


text:
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <parameters>
        <parameter key="htcpcp_server.coffeepot.class">Htcpcp\ServerBundle\Service\CoffeePotService</parameter>
    </parameters>

    <services>
        <service id="htcpcp_server.coffeepot" class="%htcpcp_server.coffeepot.class%">
            <argument type="service" id="request_stack" />
        </service>
    </services>
</container>


text:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:ns1="urn:oasis:names:tc:xliff:document:1.2">
    <!-- From: file:/C:/Users/Jon/Dropbox/My%20Documents/android/Notey2_2/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.1.1/res/values-ja/values.xml -->
    <eat-comment/>
    <string msgid="4600421777120114993" name="abc_action_bar_home_description">"ホームへ移動"</string>
    <string msgid="1594238315039666878" name="abc_action_bar_up_description">"上へ移動"</string>
    <string msgid="3588849162933574182" name="abc_action_menu_overflow_description">"その他のオプション"</string>
    <string msgid="4076576682505996667" name="abc_action_mode_done">"完了"</string>
    <string msgid="7468859129482906941" name="abc_activity_chooser_view_see_all">"すべて表示"</string>
    <string msgid="2031811694353399454" name="abc_activitychooserview_choose_application">"アプリの選択"</string>
    <string msgid="3691816814315814921" name="abc_searchview_description_clear">"検索キーワードを削除"</string>
    <string msgid="2550479030709304392" name="abc_searchview_description_query">"検索キーワード"</string>
    <string msgid="8264924765203268293" name="abc_searchview_description_search">"検索"</string>
    <string msgid="8928215447528550784" name="abc_searchview_description_submit">"検索キーワードを送信"</string>
    <string msgid="893419373245838918" name="abc_searchview_description_voice">"音声検索"</string>
    <string msgid="3421042268587513524" name="abc_shareactionprovider_share_with">"共有"</string>
    <string msgid="7165123711973476752" name="abc_shareactionprovider_share_with_application">"%sと共有"</string>
    <!-- From: file:/C:/Users/Jon/Dropbox/My%20Documents/android/Notey2_2/app/build/intermediates/exploded-aar/com.github.flavienlaurent.datetimepicker/library/0.0.2/res/values-ja/values.xml -->
    <eat-comment/>
    <string msgid="3968620852217927702" name="day_picker_description">"日グリッド(月別)"</string>
    <string msgid="6908431551612331381" name="deleted_key">"<ns1:g id="KEY">%1$s</ns1:g>を削除しました"</string>
    <string msgid="7007948707597430919" name="done_label">"完了"</string>
    <string msgid="7586639618712934060" name="hour_picker_description">"円形スライダー(時)"</string>
    <string msgid="2674929164900463786" name="item_is_selected">"<ns1:g id="ITEM">%1$s</ns1:g>を選択しました"</string>
    <string msgid="6024811202872705251" name="minute_picker_description">"円形スライダー(分)"</string>
    <!-- From: file:/C:/Users/Jon/Dropbox/My%20Documents/android/Notey2_2/app/build/intermediates/exploded-aar/de.psdev.licensesdialog/licensesdialog/1.7.0/res/values-ja/strings.xml -->
    <eat-comment/>
    <string name="notices_close">閉じる</string>
    <string name="notices_title">オープンソースライセンス</string>
    <!-- From: file:/C:/Users/Jon/Dropbox/My%20Documents/android/Notey2_2/app/build/intermediates/exploded-aar/com.github.flavienlaurent.datetimepicker/library/0.0.2/res/values-ja/values.xml -->
    <eat-comment/>
    <string msgid="3973338219107019769" name="select_day">"月と日を選択"</string>
    <string msgid="7651068754188418859" name="select_hours">"時間を選択"</string>
    <string msgid="8327182090226828481" name="select_minutes">"分を選択"</string>
    <string msgid="2603330600102539372" name="select_year">"年を選択"</string>
    <string msgid="6963340404644587098" name="year_picker_description">"年リスト"</string>
</resources>


text:
'''
Take normal chart CHANGELOG entries and build ArtifactHub changelog annotations.
Only outputs the annotations for the latest release in the CHANGELOG.

e.g from:

New Features
""""""""""""

- Add resources for `cleanup` and `createuser` jobs (#19263)

to:

- kind: added
  description: Add resources for `cleanup` and `createuser` jobs
  links:
    - name: "#19263"
      url: https://github.com/apache/airflow/pull/19263
'''

import re
from typing import Dict, List, Optional, Tuple, Union

import yaml

TYPE_MAPPING = {
    # CHANGELOG: (ArtifactHub kind, prefix for description)
    # ArtifactHub kind must be one of: added, changed, deprecated, removed, fixed or security
    "New Features": ("added", None),
    "Improvements": ("changed", None),
    "Bug Fixes": ("fixed", None),
    "Doc only changes": ("changed", "Docs"),
    "Misc": ("changed", "Misc"),
}

PREFIXES_TO_STRIP = [
    # case insensitive
    "Chart:",
    "Chart Docs:",
]

def parse_line(line: str) -> Tuple[Optional[str], Optional[int]]:
    match = re.search(r'^- (.*?)(?:\(#(\d+)\)){0,1}$', line)
    if not match:
        return None, None
    desc, pr_number = match.groups()
    return desc.strip(), int(pr_number)

def print_entry(section: str, description: str, pr_number: Optional[int]):
    for unwanted_prefix in PREFIXES_TO_STRIP:
        if description.lower().startswith(unwanted_prefix.lower()):
            description = description[len(unwanted_prefix) :].strip()

    kind, prefix = TYPE_MAPPING[section]
    if prefix:
        description = f"{prefix}: {description}"
    entry: Dict[str, Union[str, List]] = {"kind": kind, "description": description}
    if pr_number:
        entry["links"] = [
            {"name": f"#{pr_number}", "url": f"https://github.com/apache/airflow/pull/{pr_number}"}
        ]
    print(yaml.dump([entry]))

in_first_release = False
section = ""
with open("chart/CHANGELOG.txt") as f:
    for line in f:
        line = line.strip()
        if not line:
            continue
        if line.startswith("Airflow Helm Chart"):
            # We only want to get annotations for the "latest" release
            if in_first_release:
                break
            in_first_release = True
            continue
        if line.startswith('"""') or line.startswith('----'):
            continue
        if not line.startswith('- '):
            section = line
            continue

        description, pr = parse_line(line)
        if description:
            print_entry(section, description, pr)


text:
\documentclass[20pt,landscape,a4paper,footrule]{foils}
\usepackage{zencurity-slides}

%\externaldocument{unix-audit-security-oevelser}
\externaldocument{\jobname-exercises}

% Kl 18 - 21

% Jul med Kramshøj - Netværkssikkerhed, gløgg og juleøl!

% Vi afholder julearrangement med fokus på netværkssikkerhed. Foredraget kommer til at indeholde uddrag fra pentest, hacking, historik og en hurtig gennemgang op til idag hvor vi har Metasploit og Armitage som state-of-the-art værktøjer. Vi bryder ind i computere og viser hvordan pentest værktøjer kan medvirke til både at spare tid og verificere opsætningen af netværksudstyr, som firewalls.

% Der vil være kort Kali introduktion, og ellers berøres følgende emner:

% * Portscanning med Nmap, IPv4 og IPv6

% * Script scanning med Nmap, eksempler som nmap -p 443 --script

% * ssl-heartbleed <target>

% * Hvor kommer det fra! Fra SATAN til Armitage og åbne exploit databaser i dag

% * Hvordan sikrer vi os bedst!? Henriks bud på sikring af hjem og firma,

%  hint: VLAN all teh things

% * Advarsel omkring hvordan vi sikrer os imod at komme i problemer, med ref til CSC hackersagen Og så kan vi passende henover gløgg og æbleskiver diskutere om sådanne værktøjer skal være frit tilgængelige!

% Basic things that we need are below
\begin{document}
\selectlanguage{danish}

\mytitlepage{Netværkssikkerhed

 Jul med Kramshøj Hacking Seminar}

\slide{Formålet }

\vskip 2 cm

\hlkimage{5cm}{dont-panic.png}
\centerline{\color{titlecolor}\LARGE Don't Panic!}

\begin{list1}
\item pentest, hacking, historik og en hurtig gennemgang op til idag hvor vi har Metasploit og Armitage som state-of-the-art værktøjer
\item Vi bryder ind i computere og viser hvordan pentest værktøjer kan medvirke til både at spare tid og verificere opsætningen af netværksudstyr, som firewalls
\end{list1}

\vskip 1cm
\centerline{Jeg bruger Kali 2.0 Linux hackerplatformen som eksempel}

\slide{Metasploit and Armitage Still rocking the internet}

\hlkimage{14cm}{metasploit-about.png}

\begin{list1}
\item Udviklingsværktøjerne til exploits er i dag meget raffinerede!
\item \link{http://www.metasploit.com/}
\item Armitage GUI fast and easy hacking for Metasploit\\
\link{http://www.fastandeasyhacking.com/}
\item Kursus Metasploit Unleashed\\
\link{http://www.offensive-security.com/metasploit-unleashed/Main_Page}
\item Bog: Metasploit: The Penetration Tester's Guide, No Starch Press\\
ISBN-10: 159327288X
\end{list1}

\slide{Demo: Metasploit Armitage }

\hlkimage{16cm}{armitage-overview.png}

\slide{Agenda}

\begin{list1}
\item Hvor kommer det fra! Fra SATAN til Armitage og åbne exploit databaser i dag

\item Kali introduktion

\item Portscanning med Nmap, IPv4 og IPv6

\item Script scanning med Nmap, eksempler som\\
\verb+nmap -p 443 --script ssl-heartbleed <target>+

\item Hvordan sikrer vi os bedst!? Henriks bud på sikring af hjem og firma

\end{list1}

\vskip 2cm

\centerline{Forventer løst format, afslappet, spørgsmål og afstikkere \smiley}

\slide{Aftale om test af netværk}

{\bfseries Straffelovens paragraf 263 Stk. 2. Med bøde eller fængsel
  indtil 6 måneder
straffes den, som uberettiget skaffer sig adgang til en andens
oplysninger eller programmer, der er bestemt til at bruges i et anlæg
til elektronisk databehandling.}

Hacking kan betyde:
\begin{list2}
\item At man skal betale erstatning til personer eller virksomheder
\item At man får konfiskeret sit udstyr af politiet
\item At man, hvis man er over 15 år og bliver dømt for hacking, kan
  få en bøde - eller fængselsstraf i alvorlige tilfælde
\item At man, hvis man er over 15 år og bliver dømt for hacking, får
en plettet straffeattest. Det kan give problemer, hvis man skal finde
et job eller hvis man skal rejse til visse lande, fx USA og
Australien
\item Frit efter: \link{http://www.stophacking.dk} Det
  Kriminalpræventive Råd, siden er væk
\item Frygten for terror har forstærket ovenstående - så lad være!
\end{list2}

\slide{Internet idag}

\hlkimage{14cm}{images/server-client.pdf}

\begin{list1}
\item Klienter og servere
\item Rødder i akademiske miljøer
\item Protokoller hvor nogle er mere end 20 år gamle
\item Meget lidt kryptering, mest på http til brug ved e-handel
\end{list1}

\slide{Trinity breaking in}

\hlkimage{20cm}{trinity-nmapscreen-hd-cropscale-418x250.jpg}
\link{http://nmap.org/movies.html}\\
Meget realistisk \link{http://www.youtube.com/watch?v=51lGCTgqE_w}

\slide{Hackerværktøjer}

\begin{list1}
\item \emph{Improving the Security of Your Site by Breaking Into it} af
Dan Farmer og Wietse Venema i 1993
\item De udgav i 1995 så en softwarepakke med navnet SATAN
\emph{Security Administrator Tool for Analyzing Networks}
\item De forårsagede en del panik og furore, alle kan hacke, verden bryder sammen

\vskip 1cm
\begin{quote}
We realize that SATAN is a two-edged sword -- like
many tools, it can be used for good and for evil
purposes. We also realize that intruders (including
wannabees) have much more capable (read intrusive)
tools than offered with SATAN.
\end{quote}
\end{list1}

\vskip 1cm
Kilde:
\link{http://www.fish2.com/security/admin-guide-to-cracking.html}

\slide{Hackerværktøjer}
\hlkimage{3cm}{hackers_JOLIE+1995.jpg}

\begin{list2}
\item Nmap, Nping - tester porte, godt til firewall admins \link{http://nmap.org}
\item Metasploit Framework gratis på \link{http://www.metasploit.com/}
\item Wireshark avanceret netværkssniffer - \link{http://http://www.wireshark.org/}
\item Burpsuite \link{http://portswigger.net/burp/}
\item OpenBSD operativsystem med fokus
  på sikkerhed  \link{http://www.openbsd.org}
\end{list2}

Kilde: billedet er Angelina Jolie fra Hackers 1995

\centerline{Kræver en mere struktureret tilgang end de viser på film \smiley}

\slide{OSI og Internet modellerne}

\hlkimage{14cm,angle=90}{images/compare-osi-ip.pdf}

\slide{The Internet Worm 2. nov 1988}

\begin{list1}
\item Udnyttede følgende sårbarheder
\begin{list2}
\item buffer overflow i fingerd - VAX kode, Sendmail - DEBUG, Tillid mellem systemer: rsh, rexec, ...
\item dårlige passwords
\end{list2}
\item Avanceret + camouflage!
\begin{list2}
\item Programnavnet sat til 'sh', Brugte fork() til at skifte PID jævnligt
\item Fandt systemer i /etc/hosts.equiv, .rhosts, .forward, netstat ...
\item Password cracking med intern liste med 432 ord og /usr/dict/words
\end{list2}
\item Lavet af Robert T. Morris, Jr.
\item Medførte dannelsen af CERT, \link{http://www.cert.org}
\end{list1}

\centerline{1980'erne - det er vel fixet så?}

\slide{2016 botnets Internet of things (IoT)}

\begin{quote}
  This is bad news for cybersecurity as the IoT devices market heats up as people buy into the smart, automated systems. Gartner Inc. projects connected devices to rise to 6.4 billion worldwide in 2016 with almost 5.5 million devices being connected daily.
\end{quote}

\begin{list1}
\item 2016: Mirai Botnet Internet of things (IoT), 60 common factory default usernames and passwords\\
"Mirai was used in the DDoS attack on 20 September 2016 on the Krebs on Security site which reached 620 Gbps."

\item 2016: Currently, "Bashlight" is creating an army of a million IoT devices.\\
Eeen million enheder!

\end{list1}

Sources: \link{https://en.wikipedia.org/wiki/Mirai_(malware)}\\
{\footnotesize\link{http://heavy.com/tech/2016/10/mirai-iot-botnet-internet-of-things-ddos-attacks-internet-outage-blackout-why-is-internet-down/}}

\slide{Security Breaches: Ashley Madison}

\begin{quote}
When hackers swiped an estimated 36 million accounts associated with AshleyMadison.com, a site which helps married people cheat on their partners, there was a rush to find out what had been stolen.
\end{quote}

\begin{list2}
\item Ashley Madison, inkl password hacking
\item Popular passwords
123456,
,password
,12345
,qwerty
,12345678,football
\item Also hacking kills? Suicides and family break-ups?
\item accidental outing of gays/ Gay persecution, death?
\end{list2}

Source:\\
{\footnotesize\link{http://www.zdnet.com/article/these-are-the-worst-passwords-from-the-ashley-madison-hack/}}

\slide{Security Breaches: Top 20 Ashley Madison Passwords}

\begin{quote}
Previously thought to be impossible thanks to the slow pace and high stress it puts on a computer's CPU, the CynoSure Prime group managed to crack over 11 million passwords from the total of 36 million, mainly due to a programming error in how the passwords were hashed.
\end{quote}

\begin{list2}
\item Main passwords hashed with slow (good) bcrypt  algoritm, but hackers found tokens hashed with MD5\\
\link{http://cynosureprime.blogspot.dk/2015/09/how-we-cracked-millions-of-ashley.html}
\item Also check out Twitter Mark Burnett @m8urnett and his 10 million password dump\\
\link{http://wpengine.com/unmasked/}
\item Systems exist which can try 135 billion MD5 hashes PER SECOND with 8 GPUs
\end{list2}

Source: Catalin Cimpanu, Softpedia 15 September 2015\\
{\footnotesize\link{http://news.softpedia.com/news/top-20-ashely-madison-passwords-491799.shtml}}

\slide{Release of vuln information without patch}

\begin{list1}
\item Google project Zero
\item Follow a
"90-day disclosure deadline statement... which in this instance has passed."
\item Released Zero-day information about Microsoft and Apple OS X vulnerabilities
\item MS patched some in \emph{first Patch Tuesday of 2015, which came out on Jan. 13.}
\end{list1}

Sources:\\
{\tiny
\link{http://googleonlinesecurity.blogspot.fr/2014/07/announcing-project-zero.html}\\
\link{http://searchsecurity.techtarget.com/news/2240238448/Googles-Project-Zero-reveals-another-Windows-zero-day-vulnerability}\\
\link{http://www.engadget.com/2015/01/02/google-posts-unpatched-microsoft-bug/}\\
\link{http://www.eweek.com/security/google-project-zero-continues-its-microsoft-zero-day-assault.html}\\
\link{http://www.zdnet.com/article/googles-project-zero-reveals-three-apple-os-x-zero-day-vulnerabilities/}
}

Trend with more vulnerabilities per day, and\\
even big vendors cannot react quickly enough

\slide{Samba remote code execution}

\begin{alltt}\small
  ===========================================================
  == Subject:     Unexpected code execution in smbd.
  ==
  == CVE ID#:     CVE-2015-0240
  ==
  == Versions:    Samba 3.5.0 to 4.2.0rc4
  ==
  == Summary:     Unauthenticated code execution attack on
  ==		smbd file services.
  ==
  ===========================================================
\end{alltt}

\centerline{Great, even our old tools still has multiple bugs}

Source:\\
\link{https://www.samba.org/samba/security/CVE-2015-0240}

\slide{Sceneskift - Hacking er magi}

\hlkimage{7cm}{wizard_in_blue_hat.png}

\vskip 1 cm

\centerline{Hacking ligner indimellem  magi}

\slide{Hacking er ikke magi}

\hlkimage{17cm}{ninjas.png}

\vskip 1 cm
\centerline{Hacking kræver blot lidt ninja-træning}

\slide{Movie:Kryptonite lock - old}

\hlkimage{16cm}{youtube-bic-lock.png}

\begin{list1}
\item Just search for: kryptonite lock bic pen
\item \link{https://www.youtube.com/watch?v=LahDQ2ZQ3e0}
\end{list1}

\slide{Teknisk hvad er hacking}

\hlkimage{17cm}{buffer-overflow-3.pdf}

\slide{Hacking eksempel - det er ikke magi}

\begin{list1}
\item MAC filtrering på trådløse netværk
\item Alle netkort har en MAC adresse - BRÆNDT ind i kortet fra fabrikken
\item Mange trådløse Access Points kan filtrere MAC adresser
\item Kun kort som er på listen over godkendte adresser tillades adgang til netværket
\pause
\item Det virker dog ikke \smiley
\item De fleste netkort tillader at man overskriver denne adresse midlertidigt
\item Derudover har der ofte været fejl i implementeringen af MAC filtrering
\end{list1}

\slide{MAC filtrering}

\hlkimage{15cm}{stupid-security.jpg}

\slide{Buffer overflows et C problem}

\begin{list1}
\item {\bfseries Et buffer overflow}
er det der sker når man skriver flere data end der er afsat plads til
i en buffer, et dataområde. Typisk vil programmet gå ned, men i visse
tilfælde kan en angriber overskrive returadresser for funktionskald og
overtage kontrollen.
\item {\bfseries Stack protection}
er et udtryk for de systemer der ved hjælp af operativsystemer,
programbiblioteker og lign. beskytter stakken med returadresser og
andre variable mod overskrivning gennem buffer overflows. StackGuard
og Propolice er nogle af de mest kendte.
\end{list1}

\slide{Buffer og stacks}

\hlkimage{20cm}{buffer-overflow-1.pdf}

\begin{alltt}
main(int argc, char **argv)
\{      char buf[200];
        strcpy(buf, argv[1]);
        printf("%s\textbackslash{}n",buf);
\}
\end{alltt}

\slide{Overflow -- segmentation fault}

\hlkimage{20cm}{buffer-overflow-2.pdf}

\begin{list1}
\item Bad function overwrites return value!
\item Control return address
\item Run shellcode from buffer, or from other place
\end{list1}

\slide{Exploits -- udnyttelse af sårbarheder}

\begin{list2}
\item Exploit/exploitprogram er udnytter en sårbarhed rettet mod et specifikt system.
\item Kan være 5 linier eller flere sider ofte Perl, Python eller et C program
\end{list2}

Eksempel demo i Perl, uddrag:
\begin{alltt}\footnotesize
$buffer = "";
$null = "\textbackslash{}x00";
$nop = "\textbackslash{}x90";

$nopsize = 1;
$len = 201; // what is needed to overflow, maybe 201, maybe more!
$the_shell_pointer = 0x01101d48; // address where shellcode is
# Fill buffer
for ($i = 1; $i < $len;$i += $nopsize) \{
    $buffer .= $nop;
\}
$address = pack('l', $the_shell_pointer);
$buffer .= $address;
exec "$program", "$buffer";
\end{alltt}

\slide{Hvordan finder man buffer overflow, og andre fejl}

\begin{list1}
\item Black box testing
\item Closed source reverse engineering
\item White box testing
\item Open source betyder man kan læse og analysere koden
\item Source code review -- automatisk eller manuelt
\item Fejl kan findes ved at prøve sig frem -- fuzzing
\item Exploits virker typisk mod specifikke versioner af software
\end{list1}

\slide{Hvad skal der ske?}

\begin{list1}
\item Tænk som en hacker
\item Rekognoscering
\begin{list2}
\item ping sweep, port scan
\item OS detection -- TCP/IP eller banner grab
\item Servicescan -- rpcinfo, netbios, ...
\item telnet/netcat interaktion med services
\end{list2}
\item Udnyttelse/afprøvning: Metasploit, Nikto, exploit programs
\item Oprydning/hærdning vises måske ikke, men I bør i praksis:
\begin{list2}
\item Lav en rapport
\item Ændre, forbedre og hærde systemer
\item Gennemgå rapporten, registrer ændringer
\item Opdater programmer, konfigurationer, arkitektur, osv.
\end{list2}
\item I skal jo også VISE andre at I gør noget ved sikkerheden.
\end{list1}

\slide{Hackerlab opsætning}

\hlkimage{10cm}{hacklab-1.png}

\begin{list2}
\item Tænk som en hacker, rekognoscering, angreb, udnyt
\item Hardware: en moderne laptop med CPU der kan bruge virtualiseting\\
Husk at slå virtualisering til i BIOS
\item Software: Windows, Mac, Linux og virtualiseringssoftware: VMware, Virtual box, vælg selv
\item Hackersoftware: Kali Linux som en virtuel maskine
\item Soft targets: Metasploitable, Windows 2000, Windows Xp, ...
\end{list2}

\slide{Hackerværktøjer}
% måske til reference afsnit?
\hlkimage{3cm}{hackers_JOLIE+1995.jpg}

\begin{list2}
\item Alle bruger nogenlunde de samme værktøjer, se også \link{http://www.sectools.org/}
\item Portscanner Nmap, Nping -- tester porte, godt til firewall admins \link{https://nmap.org}
\item Generel sårbarhedsscanner Metasploit Framework \link{https://www.metasploit.com/}
\item Specialscannere, eksempelvis web sårbarhedsscanner -- eksempelvis Burp, Nikto, Skipfish
\item Specielle scannere -- wifi Aircrack-ng, web Burpsuite \link{http://portswigger.net/burp/}
\item Wireshark avanceret netværkssniffer -- \link{https://www.wireshark.org/}
\item og scripting, PowerShell, Unix shell, Perl, Python, Ruby, \ldots
\end{list2}

Billedet: Angelina Jolie fra Hackers 1995

\slide{Kali Linux the new backtrack}

\hlkimage{10cm}{kali-linux.png}

\begin{list1}
%\item BackTrack -- \link{http://www.backtrack-linux.org}
\item Kali -- \link{https://www.kali.org/} - den man bruger idag
\item Wireshark -- \link{https://www.wireshark.org} avanceret netværkssniffer
\item Meget nemt at starte med, og kommer nemt igang med mange tools
\item Brug hjemmesiderne for tools til tutorials og videoer
\item \verb+youtube.com: kali hack > 200.000 hits+
\item Start evt med de mest populære fra \link{http://sectools.org/}
\end{list1}

\slide{OSI og Internet modellerne}

\hlkimage{14cm,angle=90}{images/compare-osi-ip.pdf}

\slide{Wireshark - grafisk pakkesniffer}

\hlkimage{20cm}{images/wireshark-website.png}

\centerline{\link{http://www.wireshark.org}}
\vskip 5mm
\centerline{både til Windows og UNIX}

\slide{Wireshark usage}
\hlkimage{16cm}{wireshark-http.png}

Wireshark: Filters, hexdump, protocol dissection, overview, coloring, advanced features

\demo{Wireshark}

\slide{The Exploit Database -- dagens buffer overflow}

\hlkimage{20cm}{exploit-db.png}

\centerline{\link{http://www.exploit-db.com/}}

\slide{Heartbleed CVE-2014-0160}

\hlkimage{22cm}{heartbleed-com.png}

Source: \link{http://heartbleed.com/}

\slide{Heartbleed hacking}

\begin{alltt}\footnotesize
  06b0: 2D 63 61 63 68 65 0D 0A 43 61 63 68 65 2D 43 6F  -cache..Cache-Co
  06c0: 6E 74 72 6F 6C 3A 20 6E 6F 2D 63 61 63 68 65 0D  ntrol: no-cache.
  06d0: 0A 0D 0A 61 63 74 69 6F 6E 3D 67 63 5F 69 6E 73  ...action=gc_ins
  06e0: 65 72 74 5F 6F 72 64 65 72 26 62 69 6C 6C 6E 6F  ert_order&billno
  06f0: 3D 50 5A 4B 31 31 30 31 26 70 61 79 6D 65 6E 74  =PZK1101&payment
  0700: 5F 69 64 3D 31 26 63 61 72 64 5F 6E 75 6D 62 65  _id=1&{\bf card_numbe}
  0710: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX  {\bf r=4060xxxx413xxx}
  0720: 39 36 26 63 61 72 64 5F 65 78 70 5F 6D 6F 6E 74  {\bf 96&card_exp_mont}
  0730: 68 3D 30 32 26 63 61 72 64 5F 65 78 70 5F 79 65  {\bf h=02&card_exp_ye}
  0740: 61 72 3D 31 37 26 63 61 72 64 5F 63 76 6E 3D 31  {\bf ar=17&card_cvn=1}
  0750: 30 39 F8 6C 1B E5 72 CA 61 4D 06 4E B3 54 BC DA  {\bf 09}.l..r.aM.N.T..
\end{alltt}

\begin{list2}
\item Obtained using Heartbleed proof of concepts - Gave full credit card details
\item "can XXX be exploited" - yes, clearly! PoCs ARE needed\\
without PoCs even Akamai wouldn't have repaired completely!
\item \link{https://github.com/rapid7/metasploit-framework/blob/master/modules/auxiliary/scanner/ssl/openssl_heartbleed.rb}
\end{list2}

\slide{Network mapping}

\hlkimage{23cm}{images/network-example.pdf}

\begin{list1}
\item Ved brug af traceroute og tilsvarende programmer kan man ofte
  udlede topologien i det netværk man undersøger
\end{list1}

\slide{Portscan med Zenmap GUI}

\hlkimage{16cm}{nmap-zenmap.png}

\slide{Scan for Heartbleed and SSLv2/SSLv3}

\hlkimage{8cm}{nmap-sslv2.png}

\begin{list1}
\item \verb+nmap -p 443 --script ssl-heartbleed <target>+\\
\link{https://nmap.org/nsedoc/scripts/ssl-heartbleed.html}
\item \verb+masscan 0.0.0.0/0 -p0-65535  --heartbleed+\\
\link{https://github.com/robertdavidgraham/masscan}
\end{list1}

\centerline{Almost every new vulnerability will have Nmap recipe}

\slide{Hjemmearbejde: Kali øvelser}

Prøv selv at gentage det jeg viste hjemme
\begin{list2}
\item Wireshark
\item Wireshark med FTP
\item Nmap med Zenmap, script scan
\item Armitage og Metasploit, husk \verb+service postgresql start+
\item WEP/WPA cracking
\end{list2}

\slide{Beskyt dig selv, og dit netværk}

Nu skifter vi over til at beskytte os selv!

\slide{DNS attacks, February 2015 - ongoing for +10 years!}

\hlkimage{15cm}{krebs-lenovo-google-dns-hack.png}
\begin{list1}
%\item DNS is the Domain Name System, \link{https://en.wikipedia.org/wiki/Dns}
\item DNS insecurity has huge impact on your security!
\item Most are denial of service, by may create Mitm or confidentiality concerns
\item Select DNS providers with care
\end{list1}

Sources:\\
{\tiny
\link{https://krebsonsecurity.com/2015/02/webnic-registrar-blamed-for-hijack-of-lenovo-google-domains/}\\
\link{http://www.version2.dk/artikel/google-og-lenovo-defaced-som-foelge-af-overset-sikkerhedsproblemstilling-91295}}

\slide{Example, Using tools similar to PacketQ}

\hlkimage{20cm}{using-packetq.png}

Are you using your brain and existing tools? Building own specialised tools?\\
Discussion: bridging the gaps between Devops and Security? Good thing, easy?

{\footnotesize
\link{http://securityblog.switch.ch/2013/01/22/using-packetq/}\\
\link{http://jpmens.net/2013/05/27/server-agnostic-logging-of-dns-queries-responses/}
}

\slide{Storing query logs, old school or needed?}

\hlkimage{7cm}{bro-sample-ssl-scripts.png}

Looking at DNS PacketQ it was an Older link, but thinking the time is now for doing:

\begin{list2}
\item DNS query logs, keep it for at least a week? - with DSC and PacketQ
\item SSL/TLS full logs over sessions, certs, keys - with Bro/Suricata\\
\link{https://www.bro.org/sphinx-git/script-reference/scripts.html}
\item Log and search with Elasticsearch?\\
\link{https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html}
\item Even netflow session logging, full 1:1 - NFSen, Suricata Flow mode?
%\item Moloch \link{https://github.com/aol/moloch}
\end{list2}

%\centerline{Why go to this extreme, storing information about past sessions?}

\slide{February 2015: Finding infected sources}

\begin{quote}
"We were contacted by a client to help with their incident response in tracking down an
infection on a clients machine with the new CTB-Locker ransomware (Curve-Tor-Bitcoin Locker)
aka Critroni which had no signatures available at the time of infection for this variant.

LANGuardian includes a file share activity monitoring module which provided a very
detailed forensic analysis of the ransomware and the paths it had taken in order to
encrypt the clients system and also the fileserver in which it was connected to, the
initial infection came from the opening of an attachment in an e-mail."
\end{quote}

\vskip 1cm

\centerline{It has become critical to identify vulnerable or infected ASAP!}

Source:
{\tiny\link{https://www.netfort.com/support-team-stories-detecting-the-source-of-ransomware/}}

Dont forget Suricata \link{http://suricata-ids.org/} and Security Onion\\ {\small\link{https://github.com/Security-Onion-Solutions/security-onion/wiki/Installation}}

\slide{Kibana 4}

\hlkimage{14cm}{kibanascreenshothomepagebannerbigger.jpg}

\centerline{Highly recommended for a lot of data visualisation}

Non-programmers can create, save, and share dashboards

Source:
\link{https://www.elastic.co/products/kibana}

\slide{Brug hackerværktøjer!}

\hlkimage{12cm}{nfsen-udp-flood.png}

\centerline{An extra 100k packets per second from this netflow source (source is a router)}

\begin{list1}
\item Hackerværktøjer -- bruger I dem? -- efter dette kursus gør I
\item Portscannere kan afsløre huller i forsvaret
\item I vil kunne finde mange potentielle problemer proaktivt ved
  regelmæssig brug
\end{list1}

\centerline{Værktøjerne er på Kali Linux allerede}

\slide{Detecting DDoS example tool Nfsen}

\hlkimage{15cm}{nfsen-ddos-profile-1.png}

We created a DDoS profile with the common types.

We can ask RRDtools about max, average etc.
\begin{alltt}\small
rrdtool graph x -s -24h DEF:v=DDoS/mx-cph-01.rrd:packets:MAX
VDEF:vm=v,MAXIMUM PRINT:vm:%.lf
\end{alltt}

\slide{DDoS traffic before filtering}
\hlkimage{26cm}{ddos-before-filtering}

\centerline{Only two links shown, at least 3Gbit incoming for this single IP}

\slide{DDoS traffic after filtering}
\hlkimage{18cm}{ddos-after-filtering}
\centerline{Link toward server (next level firewall actually) about ~350Mbit outgoing}

\begin{list1}
\item Problem: We receive unauthenticated chaotic traffic

\item Solution: Discard early, discard on edge, reduce noise

\item Only use CPU resources for potentially real traffic
\end{list1}

\centerline{Single firewall layer typically cannot cope!}

\slide{Defense in depth - multiple layers of security}

\hlkimage{20cm}{network-layers-1.pdf}

% 802.1q
\slide{VLAN Virtual LAN}

\hlkimage{10cm}{vlan-portbased.pdf}

\begin{list1}
\item Nogle switche tillader at man opdeler portene
\item Denne opdeling kaldes VLAN og portbaseret er det mest simple
\item Port 1-4 er et LAN
\item De resterende er et andet LAN
\item Data skal omkring en firewall eller en router for at krydse fra VLAN1 til VLAN2
\end{list1}

\slide{IEEE 802.1q}

\hlkimage{19cm}{vlan-8021q.pdf}

\begin{list1}
\item Nogle switche tillader konfiguration med 802.1q VLAN tagging på Ethernet niveau
\item Data skal omkring en firewall eller en router for at krydse fra VLAN1 til VLAN2
\item VLAN trunking giver mulighed for at dele VLANs ud på flere switches
\end{list1}

\slide{Sample switch - less than 100 EUR ex VAT}

\hlkimage{18cm}{TP-link-SG3210.png}

\begin{list1}
\item Understøtter VLANs 802.1q
\item Port isolation, med forwarding list
\item IP ACLs!
\item SNMP, SSH
\end{list1}

\centerline{\bf This is JUST AN EXAMPLE, research and select switches yourself}

\slide{Port isolation}

\hlkimage{16cm}{port-isolation.png}

No subnetting, but individual ports cannot talk

Easier than subnetting and VLANs?  Quick and dirty? \smiley

\slide{VLANs i hjemmet }

Jeg arbejder selv med en ide om at lave VLANs i hjemmet til diverse "funktioner"
\begin{list1}

\item media-vlan til chromecast og underholdning osv.

\item game-vlan til den ene teenagedreng

\item husets-vlan til automatisering, køleskabe osv.

\item lab-vlan1,2,3 - jeg laver altid diverse ting :-D

\item Guest-VLAN - gæsterne skal da isoleres
\end{list1}

\vskip 2cm

\centerline{Hvilke mangler jeg?}

\slide{Security devops}

\begin{list1}
\item We need devops skillz in security
\item automate, security is also big data
\item integrate tools, transfer, sort, search, pattern matching, statistics, ...
\item tools, languages, databases, protocols, data formats
\item Example introductions:
\begin{list2}
\item Seven languages/database/web frameworks in Seven Weeks
\item Elasticsearch the definitive guide\\
\link{http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/index.html}
\item \link{http://www.elasticsearch.org/overview/kibana/}
\item \link{http://www.elasticsearch.org/overview/logstash/}
\end{list2}
\end{list1}

\centerline{We are all Devops now, even security people!}

\slide{Recommended Books: Get Started }

\begin{list1}

\item \emph{24 Deadly Sins of Software Security}
Michael Howard, David LeBlanc, John Viega 2. udgave, første hed 19 Deadly Sins
\hlkimage{3cm}{24-deadly.jpg}

\item \emph{Network Security Through Data Analysis: Building Situational Awareness}\\
By Michael Collins, O'Reilly Media, February 2014 Pages: 348
Low page count, but high value! Recommended.
\hlkimage{3cm}{network-security-through-data-analysis.png}
\end{list1}

\slide{Join Camps}

\hlkimage{14cm}{Chaos_Communication_Camp_2015_with_Thunderstorm.jpg}
\centerline{\bf Chaos Communication Camp 2015 It was Awesome!}

{\small Source Wikipedia and \link{https://www.flickr.com/photos/schwarzbrot/20447504269/}}\\
Bornhack 2016 \link{https://www.instagram.com/bornhax/}\\
Reserver 22. - 29. August 2017! \link{https://bornhack.dk/}

\slide{Focus for the near future}

\begin{list2}
\item Walk through your infrastructure\\
get a detailed view of data, flows, protocols, bandwidth, ports and services

\item Automate pushing of updates for both clients and servers, goal update everything in hours
\item Learn to run Nmap and Metasploit scripts - identify vulnerable servers
\end{list2}

\vskip 2cm
\centerline{consider the fact we have multiple overlapping critical security incidents now!}

\vskip 2cm
How many incidents can your organisation handle in parallel?

Can multiple people in your organisation initate updates?

\myquestionspage

\end{document}


text:
package com.giggs.heroquest.data;

import com.giggs.heroquest.activities.games.TutorialQuest;
import com.giggs.heroquest.data.characters.MonsterFactory;
import com.giggs.heroquest.data.dungeons.DecorationFactory;
import com.giggs.heroquest.data.items.ItemFactory;
import com.giggs.heroquest.models.Quest;
import com.giggs.heroquest.models.Reward;

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

/**
 * Created by guillaume ON 10/6/14.
 */
public class QuestFactory {

    public static List<Quest> getAll() {
        List<Quest> lst = new ArrayList<>();
        lst.add(buildTutorial());
        lst.add(buildMaze());
        lst.add(buildTrial());
        lst.add(buildWarlord());
        lst.add(buildMagnus());
        lst.add(buildLegacy());
        lst.add(buildStone());
        lst.add(buildSpirit());
        lst.add(buildBarak());
        return lst;
    }

    public static Quest buildTutorial() {
        Quest quest = new Quest.Builder(0, "tutorial", "tutorial")
                .setAvailable(true)
                .setBoss(MonsterFactory.buildGoblin())
                .setRelic(DecorationFactory.buildSmallChest(new Reward("tr_gold", null, null, 10)))
                .setActivityClass(TutorialQuest.class)
                .build();
        return quest;
    }

    public static Quest buildMaze() {
        Quest quest = new Quest.Builder(1, "maze_quest", "maze")
                .setAvailable(true)
                .setIntro("maze_quest_intro")
                .setOutro("maze_quest_outro")
                .build();
        return quest;
    }

    public static Quest buildTrial() {
        Quest quest = new Quest.Builder(2, "trial_quest", "trial")
                .setAvailable(true)
                .setIntro("trial_quest_intro")
                .setOutro("trial_quest_outro")
                .setBoss(MonsterFactory.buildVerag())
                .build();
        return quest;
    }

    public static Quest buildWarlord() {
        Quest quest = new Quest.Builder(3, "warlord_quest", "warlord")
                .setIntro("warlord_quest_intro")
                .setOutro("warlord_quest_outro")
                .setReward(new Reward(null, null, null, 100))
                .setBoss(MonsterFactory.buildUlag())
                .setRelic(DecorationFactory.buildSmallChest(new Reward("tr_gold", null, null, 150)))
                .build();
        return quest;
    }

    public static Quest buildMagnus() {
        Quest quest = new Quest.Builder(4, "magnus_quest", "magnus")
                .setIntro("magnus_quest_intro")
                .setOutro("magnus_quest_outro")
                .setReward(new Reward(null, null, null, 200))
                .setBoss(MonsterFactory.buildGulthor())
                .build();
        return quest;
    }

    public static Quest buildLegacy() {
        Quest quest = new Quest.Builder(5, "legacy_quest", "legacy")
                .setIntro("legacy_quest_intro")
                .setOutro("legacy_quest_outro")
                .setBoss(MonsterFactory.buildGrak())
                .build();
        return quest;
    }

    public static Quest buildStone() {
        Quest quest = new Quest.Builder(6, "stone_quest", "stone")
                .setIntro("stone_quest_intro")
                .setOutro("stone_quest_outro")
                .setBoss(MonsterFactory.buildKarlen())
                .setRelic(DecorationFactory.buildBookcase(new Reward("protection_talisman", null, ItemFactory.buildProtectionTalisman(), 0)))
                .build();
        return quest;
    }

    public static Quest buildSpirit() {
        Quest quest = new Quest.Builder(7, "spirit_quest", "spirit")
                .setIntro("spirit_quest_intro")
                .setOutro("spirit_quest_outro")
                .setRelic(DecorationFactory.buildStatue(new Reward("spirit_blade", null, ItemFactory.buildSpiritBlade(), 0)))
                .build();
        return quest;
    }

    public static Quest buildBarak() {
        Quest quest = new Quest.Builder(8, "barak_quest", "barak")
                .setIntro("barak_quest_intro")
                .setOutro("barak_quest_outro")
                .setBoss(MonsterFactory.buildWitchLord())
                .build();
        return quest;
    }

}


text:
@interface MWMFollowController : MWMMapController

@end


text:
<!DOCTYPE html>

    <meta charset="UTF-8">
    <title>React getDOMNode</title>


text:
<?php

namespace Sylius\Bundle\ApiBundle\DependencyInjection;

use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
use Sylius\Component\Resource\Factory\Factory;
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Sylius\Bundle\ApiBundle\Model\Client;
use Sylius\Bundle\ApiBundle\Model\ClientInterface;
use Sylius\Bundle\ApiBundle\Form\Type\ClientType;
use Sylius\Bundle\ApiBundle\Model\AccessToken;
use Sylius\Bundle\ApiBundle\Model\AccessTokenInterface;
use Sylius\Bundle\ApiBundle\Model\RefreshToken;
use Sylius\Bundle\ApiBundle\Model\RefreshTokenInterface;
use Sylius\Bundle\ApiBundle\Model\AuthCode;
use Sylius\Bundle\ApiBundle\Model\AuthCodeInterface;

/**
 * This class contains the configuration information for the bundle.
 *
 * This information is solely responsible for how the different configuration
 * sections are normalized, and merged.
 *
 * @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
 */
class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritdoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('sylius_api');

        $rootNode
            ->children()
                ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
            ->end()
        ;

        $this->addResourcesSection($rootNode);

        return $treeBuilder;
    }
    /**
     * @param ArrayNodeDefinition $node
     */
    private function addResourcesSection(ArrayNodeDefinition $node)
    {
        $node
            ->children()
                ->arrayNode('resources')
                    ->addDefaultsIfNotSet()
                    ->children()
                        ->arrayNode('api_user')
                            ->addDefaultsIfNotSet()
                            ->children()
                                ->variableNode('options')->end()
                                ->arrayNode('classes')
                                    ->addDefaultsIfNotSet()
                                    ->children()
                                        ->scalarNode('model')->isRequired()->cannotBeEmpty()->end()
                                    ->end()
                                ->end()
                            ->end()
                        ->end()
                        ->arrayNode('api_client')
                            ->addDefaultsIfNotSet()
                            ->children()
                                ->variableNode('options')->end()
                                ->arrayNode('classes')
                                    ->addDefaultsIfNotSet()
                                    ->children()
                                        ->scalarNode('model')->defaultValue(Client::class)->cannotBeEmpty()->end()
                                        ->scalarNode('interface')->defaultValue(ClientInterface::class)->cannotBeEmpty()->end()
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
                                        ->scalarNode('repository')->cannotBeEmpty()->end()
                                        ->scalarNode('factory')->defaultValue(Factory::class)->end()
                                        ->arrayNode('form')
                                            ->addDefaultsIfNotSet()
                                            ->children()
                                                ->scalarNode('default')->defaultValue(ClientType::class)->cannotBeEmpty()->end()
                                            ->end()
                                        ->end()
                                    ->end()
                                ->end()
                                ->arrayNode('validation_groups')
                                    ->addDefaultsIfNotSet()
                                    ->children()
                                        ->arrayNode('default')
                                            ->prototype('scalar')->end()
                                            ->defaultValue(array('sylius'))
                                        ->end()
                                    ->end()
                                ->end()
                            ->end()
                        ->end()
                        ->arrayNode('api_access_token')
                            ->addDefaultsIfNotSet()
                            ->children()
                                ->variableNode('options')->end()
                                ->arrayNode('classes')
                                    ->addDefaultsIfNotSet()
                                    ->children()
                                        ->scalarNode('model')->defaultValue(AccessToken::class)->cannotBeEmpty()->end()
                                        ->scalarNode('interface')->defaultValue(AccessTokenInterface::class)->cannotBeEmpty()->end()
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
                                        ->scalarNode('repository')->cannotBeEmpty()->end()
                                        ->scalarNode('factory')->defaultValue(Factory::class)->end()
                                    ->end()
                                ->end()
                                ->arrayNode('validation_groups')
                                    ->addDefaultsIfNotSet()
                                    ->children()
                                        ->arrayNode('default')
                                            ->prototype('scalar')->end()
                                            ->defaultValue(array('sylius'))
                                        ->end()
                                    ->end()
                                ->end()
                            ->end()
                        ->end()
                        ->arrayNode('api_refresh_token')
                            ->addDefaultsIfNotSet()
                            ->children()
                                ->variableNode('options')->end()
                                ->arrayNode('classes')
                                    ->addDefaultsIfNotSet()
                                    ->children()
                                        ->scalarNode('model')->defaultValue(RefreshToken::class)->cannotBeEmpty()->end()
                                        ->scalarNode('interface')->defaultValue(RefreshTokenInterface::class)->cannotBeEmpty()->end()
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
                                        ->scalarNode('repository')->cannotBeEmpty()->end()
                                        ->scalarNode('factory')->defaultValue(Factory::class)->end()
                                    ->end()
                                ->end()
                                ->arrayNode('validation_groups')
                                    ->addDefaultsIfNotSet()
                                    ->children()
                                        ->arrayNode('default')
                                            ->prototype('scalar')->end()
                                            ->defaultValue(array('sylius'))
                                        ->end()
                                    ->end()
                                ->end()
                            ->end()
                        ->end()
                        ->arrayNode('api_auth_code')
                            ->addDefaultsIfNotSet()
                            ->children()
                                ->variableNode('options')->end()
                                ->arrayNode('classes')
                                    ->addDefaultsIfNotSet()
                                    ->children()
                                        ->scalarNode('model')->defaultValue(AuthCode::class)->cannotBeEmpty()->end()
                                        ->scalarNode('interface')->defaultValue(AuthCodeInterface::class)->cannotBeEmpty()->end()
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
                                        ->scalarNode('repository')->cannotBeEmpty()->end()
                                        ->scalarNode('factory')->defaultValue(Factory::class)->end()
                                    ->end()
                                ->end()
                                ->arrayNode('validation_groups')
                                    ->addDefaultsIfNotSet()
                                    ->children()
                                        ->arrayNode('default')
                                            ->prototype('scalar')->end()
                                            ->defaultValue(array('sylius'))
                                        ->end()
                                    ->end()
                                ->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
            ->end()
        ;
    }
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<Tokens version="1.0">
	<File path="Classes/DeleteError.html">

		<Token>
			<TokenIdentifier>//apple_ref/occ/cl/DeleteError</TokenIdentifier>
			<Abstract type="html">An error that occurred when deleting an object.</Abstract>
			<DeclaredIn>DeleteError.h</DeclaredIn>

			<NodeRef refid="251"/>
		</Token>

		<Token>
			<TokenIdentifier>//apple_ref/occ/instm/DeleteError/setKey:</TokenIdentifier>
			<Abstract type="html">Returns the key of the object that couldn't be deleted.</Abstract>
			<DeclaredIn>DeleteError.h</DeclaredIn>

			<Declaration>@property (nonatomic, retain) NSString *key</Declaration>

			<Anchor>//api/name/key</Anchor>
		</Token>

		<Token>
			<TokenIdentifier>//apple_ref/occ/instp/DeleteError/key</TokenIdentifier>
			<Abstract type="html">Returns the key of the object that couldn't be deleted.</Abstract>
			<DeclaredIn>DeleteError.h</DeclaredIn>

			<Declaration>@property (nonatomic, retain) NSString *key</Declaration>

			<Anchor>//api/name/key</Anchor>
		</Token>

		<Token>
			<TokenIdentifier>//apple_ref/occ/instm/DeleteError/setVersionId:</TokenIdentifier>
			<Abstract type="html">Returns the versionId of the object that couldn't be deleted.</Abstract>
			<DeclaredIn>DeleteError.h</DeclaredIn>

			<Declaration>@property (nonatomic, retain) NSString *versionId</Declaration>

			<Anchor>//api/name/versionId</Anchor>
		</Token>

		<Token>
			<TokenIdentifier>//apple_ref/occ/instp/DeleteError/versionId</TokenIdentifier>
			<Abstract type="html">Returns the versionId of the object that couldn't be deleted.</Abstract>
			<DeclaredIn>DeleteError.h</DeclaredIn>

			<Declaration>@property (nonatomic, retain) NSString *versionId</Declaration>

			<Anchor>//api/name/versionId</Anchor>
		</Token>

		<Token>
			<TokenIdentifier>//apple_ref/occ/instm/DeleteError/setCode:</TokenIdentifier>
			<Abstract type="html">Returns the status code for the failed delete.</Abstract>
			<DeclaredIn>DeleteError.h</DeclaredIn>

			<Declaration>@property (nonatomic, retain) NSString *code</Declaration>

			<Anchor>//api/name/code</Anchor>
		</Token>

		<Token>
			<TokenIdentifier>//apple_ref/occ/instp/DeleteError/code</TokenIdentifier>
			<Abstract type="html">Returns the status code for the failed delete.</Abstract>
			<DeclaredIn>DeleteError.h</DeclaredIn>

			<Declaration>@property (nonatomic, retain) NSString *code</Declaration>

			<Anchor>//api/name/code</Anchor>
		</Token>

		<Token>
			<TokenIdentifier>//apple_ref/occ/instm/DeleteError/setMessage:</TokenIdentifier>
			<Abstract type="html">Returns a description of the failure.</Abstract>
			<DeclaredIn>DeleteError.h</DeclaredIn>

			<Declaration>@property (nonatomic, retain) NSString *message</Declaration>

			<Anchor>//api/name/message</Anchor>
		</Token>

		<Token>
			<TokenIdentifier>//apple_ref/occ/instp/DeleteError/message</TokenIdentifier>
			<Abstract type="html">Returns a description of the failure.</Abstract>
			<DeclaredIn>DeleteError.h</DeclaredIn>

			<Declaration>@property (nonatomic, retain) NSString *message</Declaration>

			<Anchor>//api/name/message</Anchor>
		</Token>

	</File>
</Tokens>


text:
package voldemort.client.scheduler;

import java.util.Properties;
import java.util.concurrent.Callable;

import org.apache.log4j.Logger;

import voldemort.client.SystemStoreRepository;
import voldemort.store.InvalidMetadataException;
import voldemort.store.system.SystemStoreConstants;
import voldemort.utils.MetadataVersionStoreUtils;

/**
 * The AsyncMetadataVersionManager is used to track the Metadata version on the
 * cluster and if necessary Re-bootstrap the client.
 *
 * During initialization, it will retrieve the current version of the
 * cluster.xml and then periodically check whether this has been updated. During
 * init if the initial version turns out to be null, it means that no change has
 * been done to that store since it was created. In this case, we assume version
 * '0'.
 *
 * @author csoman
 *
 */

public class AsyncMetadataVersionManager implements Runnable {

    private String storesVersionKey = SystemStoreConstants.STORES_VERSION_KEY;

    private final Logger logger = Logger.getLogger(this.getClass());
    private Long currentClusterVersion;
    private Long currentStoreVersion;
    private final Callable<Void> storeClientThunk;
    private final SystemStoreRepository systemStoreRepository;
    public boolean isActive = false;

    public AsyncMetadataVersionManager(SystemStoreRepository sysRepository,
                                       Callable<Void> storeClientThunk,
                                       String storeName) {
        this.systemStoreRepository = sysRepository;

        if(storeName != null) {
            storesVersionKey = storeName;
        }

        // Get the properties object from the system store (containing versions)
        Properties versionProps = MetadataVersionStoreUtils.getProperties(this.systemStoreRepository.getMetadataVersionStore());

        // Initialize base cluster version to do all subsequent comparisons
        this.currentClusterVersion = initializeVersion(SystemStoreConstants.CLUSTER_VERSION_KEY,
                                                       versionProps);

        // Initialize base store version to do all subsequent comparisons
        this.currentStoreVersion = initializeVersion(storesVersionKey, versionProps);

        logger.debug("Initial cluster.xml version = " + this.currentClusterVersion);
        logger.debug("Initial store '" + storeName + "' version = " + this.currentClusterVersion);

        this.storeClientThunk = storeClientThunk;
        this.isActive = true;
    }

    private Long initializeVersion(String versionKey, Properties versionProps) {
        Long baseVersion = null;
        try {
            baseVersion = getCurrentVersion(versionKey, versionProps);
        } catch(Exception e) {
            logger.error("Exception while getting version for key : " + versionKey
                         + " Exception : " + e);
        }

        if(baseVersion == null) {
            baseVersion = new Long(0);
        }
        return baseVersion;
    }

    public Long getCurrentVersion(String versionKey, Properties versionProps) {
        Long versionValue = null;

        if (versionProps != null && versionProps.getProperty(versionKey) != null) {
            versionValue = Long.parseLong(versionProps.getProperty(versionKey));
        }

        logger.debug("*********** For key : " + versionKey + " received value = " + versionValue);
        return versionValue;
    }

    /*
     * This method checks for any update in the version for 'versionKey'. If
     * there is any change, it returns the new version. Otherwise it will return
     * a null.
     */
    public Long fetchNewVersion(String versionKey, Long curVersion, Properties versionProps) {
        try {
            Long newVersion = getCurrentVersion(versionKey, versionProps);

            // If version obtained is null, the store is untouched. Continue
            if(newVersion != null) {
                logger.debug("MetadataVersion check => Obtained " + versionKey + " version : "
                             + newVersion);

                /*
                 * Check if the new version is greater than the current one. We
                 * should not re-bootstrap on a stale version.
                 */
                if(curVersion == null || newVersion > curVersion) {
                    return newVersion;
                }
            } else {
                logger.debug("Metadata unchanged after creation ...");
            }
        }

        // Swallow all exceptions here (we don't want to fail the client).
        catch(Exception e) {
            logger.debug("Could not retrieve Metadata Version. Exception : " + e);
        }

        return null;
    }

    public void run() {

        logger.debug("************* AsyncMetadataVersionManger running. Checking for "
                     + SystemStoreConstants.CLUSTER_VERSION_KEY + " and  " + storesVersionKey
                     + " *************");
        try {
            /*
             * Get the properties object from the system store (containing
             * versions)
             */
            Properties versionProps = MetadataVersionStoreUtils.getProperties(this.systemStoreRepository.getMetadataVersionStore());

            Long newClusterVersion = fetchNewVersion(SystemStoreConstants.CLUSTER_VERSION_KEY,
                                                     this.currentClusterVersion,
                                                     versionProps);
            Long newStoreVersion = fetchNewVersion(storesVersionKey,
                                                   this.currentStoreVersion,
                                                   versionProps);

            // Check if something has been updated
            if((newClusterVersion != null) || (newStoreVersion != null)) {
                logger.info("Metadata version mismatch detected. Re-bootstrapping!");
                try {
                    if(newClusterVersion != null) {
                        logger.info("Updating cluster version");
                        currentClusterVersion = newClusterVersion;
                    }

                    if(newStoreVersion != null) {
                        logger.info("Updating store : '" + storesVersionKey + "' version");
                        this.currentStoreVersion = newStoreVersion;
                    }

                    this.storeClientThunk.call();

                } catch(Exception e) {
                    logger.error("Exception occurred while invoking the rebootstrap callback.", e);
                }
            }

        } catch(InvalidMetadataException e) {
            try {
                this.storeClientThunk.call();
            } catch(Exception e2) {
                logger.error("Exception occurred while invoking the rebootstrap callback.", e);
            }
        } catch(Exception e) {
            if(logger.isDebugEnabled()) {
                logger.debug("Could not retrieve metadata versions from the server.", e);
            }
        }

    }

    public Long getClusterMetadataVersion() {
        return this.currentClusterVersion;
    }

    public Long getStoreMetadataVersion() {
        return this.currentStoreVersion;
    }

    // Fetch the latest versions for cluster metadata
    public void updateMetadataVersions() {
        Properties versionProps = MetadataVersionStoreUtils.getProperties(this.systemStoreRepository.getMetadataVersionStore());
        Long newVersion = fetchNewVersion(SystemStoreConstants.CLUSTER_VERSION_KEY,
                                          null,
                                          versionProps);
        if(newVersion != null) {
            this.currentClusterVersion = newVersion;
        }
    }
}


text:
SELECT hll_set_max_sparse(256);
SELECT hll_set_defaults(10,4,128,0);

-- When defining a stored procedure the global statements don't take
-- effect.

CREATE OR REPLACE FUNCTION testfunc_azfwygmg() RETURNS void AS $$
BEGIN
PERFORM hll_set_max_sparse(-1);
PERFORM hll_set_defaults(11,5,-1,1);
END;
$$ LANGUAGE plpgsql;

SELECT hll_set_max_sparse(256);
SELECT hll_set_defaults(10,4,128,0);

-- When invoking a stored procedure they work.

SELECT testfunc_azfwygmg();

SELECT hll_set_max_sparse(256);
SELECT hll_set_defaults(10,4,128,0);


text:
Gmail Deliver
=============
A sample code for gmail send a e-mail

##Usage
```yaml

maildeliver:
  username: "sender gmail account"
  password: "password"
---
```

```java
//      create MailDeliver handler mail sender
      MailDeliver mailDeliver = MailDeliver.builder()
              .setHost(prop.getHost())
              .setPort(prop.getPort())
              .setUserName(prop.getUsername())
              .setPassword(prop.getPassword())
              .build();
//      setting mail address which is receiver address.
      mailDeliver.setRecipients(recipientsArray);
//      send mail (title , message)
      mailDeliver.send("[important]Check your account is current", "This message is fake.");
```