text:
define(['lib/news_special/bootstrap', 'module/controller/controller', 'lib/news_special/share_tools/controller'], function (news, controller, shareTools) {

    return {
        init: function () {

            news.pubsub.emit('istats', ['app-initiated', 'newsspec-interaction', true]);

            // setTimeout(function () {
            //     news.pubsub.emit('istats', ['panel-clicked', 'newsspec-interaction', 3]);
            // }, 500);
            // setTimeout(function () {
            //     news.pubsub.emit('istats', ['quiz-end', 'newsspec-interaction', true]);
            // }, 2000);

            shareTools.init('.tempShareToolsHolder', {
                storyPageUrl: 'http://bbc.co.uk/nhswinter',
                header:       'Share this',
                message:      'How well does YOUR hospital perform? Enter your postcode to see',
                hashtag:      'nhswinter',
                image:        'http://news.bbcimg.co.uk/news/special/2014/newsspec_9501/content/english/img/nhs_winter.png',
                template:     'default'
            });
            //shareTools template key value can be 'default' or 'dropdown'

            // news.setStaticIframeHeight(2000);

            // news.hostPageSetup(function () {
            //     window.alert('sending instructions to the host page');
            //     document.body.style.background = 'red';
            // });
            controller.init();

            news.sendMessageToremoveLoadingImage();
        }
    };

});

redpajama_set_name: RedPajamaGithub


text:
package models.data

import main.ParsedAppScanSourceXmlData

import com.mongodb.casbah.commons.{MongoDBObjectBuilder, MongoDBListBuilder, MongoDBList, MongoDBObject}
import scala.collection.mutable
import com.mongodb.casbah.Imports._

class DataCompilation( operatingSystem : String )
{
 /**
   * Creates the finding record to be uploaded to the mongodb system
   *
   * @param siteStrings The set of site identifiers mapped to strings
   * @param finding The finding records, not containing string data yet
   * @param files The list of files in this application
   * @param strings The list of strings for this assessment
   * @param parsedData The object storing all of the data parsed fromt he assessment file
   * @return MongoDBObject
   */
  def createFindingRecord( siteStrings : mutable.ListMap[ String, Map[ String, String ] ], finding : Map[ String, String ],
                                   files :  mutable.ListMap[ String, String ], strings : mutable.ListMap[ String, String ],
                                   parsedData : ParsedAppScanSourceXmlData ) : MongoDBObject =
  {
    var findingRecord = new MongoDBObjectBuilder
    //matchers for windows and linux, case insensitive
    val windows = """(?i)windows""".r
    val linux = """(?i)linux""".r

    //Lookup table for the confidence parameter
    val conf = finding.get( "conf" ).getOrElse( null ) match
    {
      case "1" => "Vulnerability"
      case "2" => "Type 1"
      case "3" => "Type 2"
      case _ => null
    }

    //Lookup table for the severity parameter
    val sev = finding.get( "sev" ).getOrElse( null ) match
    {
      case "0" => "High"
      case "1" => "Medium"
      case "2" => "Low"
      case "3" => "Informational"
      case _ => null
    }

    //Get the site record for this finding
    val site = parsedData.getSiteStrings.get( finding.get( "site_id" ).getOrElse( null ) ).getOrElse( null )
    //Get the findingId
    val findingId = finding.get( "id" ).getOrElse( null )

    //Adding the action object record, not sure what it maps to at this point
    findingRecord += ( "ao_id" -> finding.get( "ao_id" ).getOrElse( null ) )
    //Appending the confidence rating for the vulnerability
    findingRecord += ( "conf" -> conf )
    //Appending the finding identifier
    findingRecord += ( "finding_id" -> findingId )
    //Appending the project name to the finding record
    findingRecord += ( "project_name" -> strings.get( finding.get( "project_name" ).getOrElse( null ) ).getOrElse( null ) )
    //Appending the set of property identifiers, currently unused
    //TODO: Create a lookup table for property identifiers if they are useful
    findingRecord += ( "prop_ids" -> finding.get( "prop_ids" ).getOrElse( null ) )
    //Append the record identifier for the finding, currently unused
    findingRecord += ( "rec_id" -> finding.get( "rec_id" ).getOrElse( null ) )
    //Append the severity of the vulnerability
    findingRecord += ( "sev" -> sev )
    //Append the site id value, used as a manual check of the success of the conversion and upload
    findingRecord += ( "site_id" -> finding.get( "site_id" ).getOrElse( null ) )
    //Append the vulnerability type string
    findingRecord += ( "vtype" -> strings.get( finding.get( "vtype" ).getOrElse( null ) ).getOrElse( null ) )
    //Append the vulnerability type API call
    findingRecord += ( "method" -> site.get( "method" ).getOrElse( null ).toString )
    //Append the context data from the site
    findingRecord += ( "ctx" -> site.get( "ctx" ).getOrElse( null ) )
    //Append the column number
    findingRecord += ( "cn" -> site.get( "cn" ).getOrElse( null ) )
    //append the signature of the vulnerability, appears to be deprecated, currently unused
    findingRecord += ( "sig" -> site.get( "sig" ).getOrElse( null ) )
    //append the ordinal value of the vulnerability, currently unused
    findingRecord += ( "ord" -> site.get( "ord" ).getOrElse( null ) )
    //append the caller name
    findingRecord += ( "caller" -> site.get( "caller" ).getOrElse( null ) )
    //append the line number
    findingRecord += ( "ln" -> site.get( "ln" ).getOrElse( null ) )

    //Get the file record for this finding
    val file = site.get( "file" ).getOrElse( null )
    //normalize the file path to use / rather than \
    val fullPath = operatingSystem match
    {
      case windows() => parsedData.getCodeLocation + file.replaceAllLiterally( "/", "\\" )
      case linux() => parsedData.getCodeLocation + file
    }

    //add the file path to the record
    findingRecord += ( "file_path" -> file )
    //Get the line number of this finding
    val ln = site.get( "ln" ).getOrElse( null )

    val codeInFile = new GetCodeFromFile( fullPath )
    //grab the code for this finding record, assuming code exists
    val code = codeInFile.getCode( ln )

    codeInFile.closeFile

    //append the code to the finding record
    findingRecord += ( "code" -> code )

    //Get the list of taint traces organized by finding ID
    val taintsByFinding = parsedData.getTaintsByFinding
    //get the list of taints for this finding record
    val taints = taintsByFinding.get( findingId ).getOrElse( null )
    val appscanMatcher = new AppScanStringMatcher
    val taintStrings = appscanMatcher.createTaintStrings( parsedData )
    //create the taint trace itself, if one should exist
    var taintTrace = MongoDBList()
    if( taints != null )
    {
      taintTrace = createTaintTrace( taints, taintStrings, parsedData )
    }
    //Append the taint trace record to this finding
    findingRecord += ( "taint_trace" -> taintTrace )
    //Append the assessment name
    findingRecord += ( "application_name" -> parsedData.getAssessmentName )

    return findingRecord.result
  }

  /**
   * Function used to create a list from the taint trace records from the findingData records parsed out earlier. Due
   * to the complexities in storing this data (site information), saving this mapping for creating the MongoDBList and
   * MongoDBObject values, which are much more forgiving of type than standard Scala objects
   *
   * @param taintList The taint trace record stored in the assessment's Finding element
   * @param taintStrings The full list of taints with strings, organized as a lookup table by taint id
   * @param parsedData The container object containing the parsed data from throughout this process
   * @return The trace list, ready for export into the MongoDB
   */
  protected def createTaintTrace( taintList : String, taintStrings : mutable.ListMap[ String, Map[ String, String ] ],
                                  parsedData : ParsedAppScanSourceXmlData ) : MongoDBList =
  {
    //Create an array out of the taintList, since each taint record is separated by commas
    val taintTrace = taintList.split( "," )

    //set of sites with String data included from the container object
    val siteStrings = parsedData.getSiteStrings

    //Various bits of data we need in order to create the taint trace records
    var taints = new MongoDBListBuilder
    val parentStack = new mutable.Stack[ String ]
    var taintPosition = 0

    //Iterate through each taint record from the taint trace array
    for( taint <- taintTrace )
    {
      //Push the new taint record into the parent stack, which we will use to create a full trace diagram.
      //The trace record is a depth-first search, so once popped off the stack, the previous record will no longer
      //be a parent record, thus we use a stack object to keep track
      parentStack.push( taint )

      //Each . in a taint record tells you how far up in the parent stack to return to, so count them
      val parentFinder = taint.count( _ == '.' )
      if( parentFinder > 0 )
      {
        //If we need to return to a previous parent, pop the stack until that parent is reached
        for( iter <- 1 to parentFinder  )
        {
          parentStack.pop()
        }
      }

      //Create a new record to populate a single taint record
      var newTaint = new MongoDBObjectBuilder
      //Store the taint's original position, for clarity
      newTaint += ( "position" -> taintPosition )
      //increment the position record for the next item
      taintPosition = taintPosition + 1
      //Grab just the taint_id from the record, the .'s have already been accounted for above
      val taintId = taint.split( """\.""" )( 0 )

      //Iterate through each key in the taint record
      for( taintKey <- taintStrings( taintId ).keys )
      {
        //This is the reason we don't convert directly: We need to create a MongoDBObject out of the site record, since
        //we do not care about the site_id itself
        if( taintKey.equals( "site_id" ) )
        {
          var site = new MongoDBObjectBuilder
          val siteString = siteStrings( taintStrings( taintId )( taintKey ) )
          for( siteKey <- siteString.keys )
          {
            site += ( siteKey -> siteString( siteKey ) )
          }
          //add a record to our new taint object, site : { site object }
          newTaint += ( "site" -> site.result )
        }
        else
        {
          //if it isn't site_id, add it directly to the taint record object
          newTaint += ( taintKey -> taintStrings( taintId )( taintKey ) )
        }
      }
      //If we need to return to a previous parent record, after this taint object, add it here
      if( parentStack.top != taintId )
      {
        newTaint += ( "parent_id" -> parentStack.top )
      }
      taints += newTaint.result
    }

    return taints.result
  }
}


text:
/* $Id: timer-r0drv-os2.cpp $ */
/** @file
 * IPRT - Memory Allocation, Ring-0 Driver, OS/2.
 */

/*
 * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

/*******************************************************************************
*   Header Files                                                               *
*******************************************************************************/
#include "the-os2-kernel.h"

#include <iprt/timer.h>
#include <iprt/time.h>
#include <iprt/spinlock.h>
#include <iprt/err.h>
#include <iprt/asm.h>
#include <iprt/assert.h>
#include <iprt/alloc.h>

#include "internal/magics.h"

/*******************************************************************************
*   Structures and Typedefs                                                    *
*******************************************************************************/
/**
 * The internal representation of an OS/2 timer handle.
 */
typedef struct RTTIMER
{
    /** Magic.
     * This is RTTIMER_MAGIC, but changes to something else before the timer
     * is destroyed to indicate clearly that thread should exit. */
    uint32_t volatile       u32Magic;
    /** The next timer in the timer list. */
    PRTTIMER                pNext;
    /** Flag indicating the timer is suspended. */
    uint8_t volatile        fSuspended;
    /** Cleared at the start of timer processing, set when calling pfnTimer.
     * If any timer changes occurs while doing the callback this will be used to resume the cycle. */
    bool                    fDone;
    /** Callback. */
    PFNRTTIMER              pfnTimer;
    /** User argument. */
    void                   *pvUser;
    /** The timer interval. 0 if one-shot. */
    uint64_t                u64NanoInterval;
    /** The start of the current run.
     * This is used to calculate when the timer ought to fire the next time. */
    uint64_t volatile       u64StartTS;
    /** The start of the current run.
     * This is used to calculate when the timer ought to fire the next time. */
    uint64_t volatile       u64NextTS;
    /** The current tick number (since u64StartTS). */
    uint64_t volatile       iTick;
} RTTIMER;

/*******************************************************************************
*   Global Variables                                                           *
*******************************************************************************/
/** Spinlock protecting the timers. */
static RTSPINLOCK           g_Spinlock = NIL_RTSPINLOCK;
/** The timer head. */
static PRTTIMER volatile    g_pTimerHead = NULL;
/** The number of active timers. */
static uint32_t volatile    g_cActiveTimers = 0;
/** The number of active timers. */
static uint32_t volatile    g_cTimers = 0;
/** The change number.
 * This is used to detect list changes during the timer callback loop. */
static uint32_t volatile    g_u32ChangeNo;

/*******************************************************************************
*   Internal Functions                                                         *
*******************************************************************************/
RT_C_DECLS_BEGIN
DECLASM(void) rtTimerOs2Tick(void);
DECLASM(int) rtTimerOs2Arm(void);
DECLASM(int) rtTimerOs2Dearm(void);
RT_C_DECLS_END

RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, uint32_t fFlags, PFNRTTIMER pfnTimer, void *pvUser)
{
    *ppTimer = NULL;

    /*
     * We don't support the fancy MP features.
     */
    if (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC)
        return VERR_NOT_SUPPORTED;

    /*
     * Lazy initialize the spinlock.
     */
    if (g_Spinlock == NIL_RTSPINLOCK)
    {
        RTSPINLOCK Spinlock;
        int rc = RTSpinlockCreate(&Spinlock, RTSPINLOCK_FLAGS_INTERRUPT_SAFE, "RTTimerOS2");
        AssertRCReturn(rc, rc);
        //bool fRc;
        //ASMAtomicCmpXchgSize(&g_Spinlock, Spinlock, NIL_RTSPINLOCK, fRc);
        //if (!fRc)
        if (!ASMAtomicCmpXchgPtr((void * volatile *)&g_Spinlock, Spinlock, NIL_RTSPINLOCK))
            RTSpinlockDestroy(Spinlock);
    }

    /*
     * Allocate and initialize the timer handle.
     */
    PRTTIMER pTimer = (PRTTIMER)RTMemAlloc(sizeof(*pTimer));
    if (!pTimer)
        return VERR_NO_MEMORY;

    pTimer->u32Magic = RTTIMER_MAGIC;
    pTimer->pNext = NULL;
    pTimer->fSuspended = true;
    pTimer->pfnTimer = pfnTimer;
    pTimer->pvUser = pvUser;
    pTimer->u64NanoInterval = u64NanoInterval;
    pTimer->u64StartTS = 0;

    /*
     * Insert the timer into the list (LIFO atm).
     */
    RTSpinlockAcquire(g_Spinlock);
    g_u32ChangeNo++;
    pTimer->pNext = g_pTimerHead;
    g_pTimerHead = pTimer;
    g_cTimers++;
    RTSpinlockRelease(g_Spinlock);

    *ppTimer = pTimer;
    return VINF_SUCCESS;
}

/**
 * Validates the timer handle.
 *
 * @returns true if valid, false if invalid.
 * @param   pTimer  The handle.
 */
DECLINLINE(bool) rtTimerIsValid(PRTTIMER pTimer)
{
    AssertReturn(VALID_PTR(pTimer), false);
    AssertReturn(pTimer->u32Magic == RTTIMER_MAGIC, false);
    return true;
}

RTDECL(int) RTTimerDestroy(PRTTIMER pTimer)
{
    /* It's ok to pass NULL pointer. */
    if (pTimer == /*NIL_RTTIMER*/ NULL)
        return VINF_SUCCESS;
    if (!rtTimerIsValid(pTimer))
        return VERR_INVALID_HANDLE;

    /*
     * Remove it from the list.
     */
    RTSpinlockAcquire(g_Spinlock);
    g_u32ChangeNo++;
    if (g_pTimerHead == pTimer)
        g_pTimerHead = pTimer->pNext;
    else
    {
        PRTTIMER pPrev = g_pTimerHead;
        while (pPrev->pNext != pTimer)
        {
            pPrev = pPrev->pNext;
            if (RT_UNLIKELY(!pPrev))
            {
                RTSpinlockRelease(g_Spinlock);
                return VERR_INVALID_HANDLE;
            }
        }
        pPrev->pNext = pTimer->pNext;
    }
    Assert(g_cTimers > 0);
    g_cTimers--;
    if (!pTimer->fSuspended)
    {
        Assert(g_cActiveTimers > 0);
        g_cActiveTimers--;
        if (!g_cActiveTimers)
            rtTimerOs2Dearm();
    }
    RTSpinlockRelease(g_Spinlock);

    /*
     * Free the associated resources.
     */
    pTimer->u32Magic++;
    RTMemFree(pTimer);
    return VINF_SUCCESS;
}

RTDECL(int) RTTimerStart(PRTTIMER pTimer, uint64_t u64First)
{
    if (!rtTimerIsValid(pTimer))
        return VERR_INVALID_HANDLE;
    if (!pTimer->fSuspended)
        return VERR_TIMER_ACTIVE;

    /*
     * Calc when it should start firing and give the thread a kick so it get going.
     */
    u64First += RTTimeNanoTS();

    RTSpinlockAcquire(g_Spinlock);
    g_u32ChangeNo++;
    if (!g_cActiveTimers)
    {
        int rc = rtTimerOs2Arm();
        if (RT_FAILURE(rc))
        {
            RTSpinlockRelease(g_Spinlock);
            return rc;
        }
    }
    g_cActiveTimers++;
    pTimer->fSuspended = false;
    pTimer->fDone = true;               /* next tick, not current! */
    pTimer->iTick = 0;
    pTimer->u64StartTS = u64First;
    pTimer->u64NextTS = u64First;
    RTSpinlockRelease(g_Spinlock);

    return VINF_SUCCESS;
}

RTDECL(int) RTTimerStop(PRTTIMER pTimer)
{
    if (!rtTimerIsValid(pTimer))
        return VERR_INVALID_HANDLE;
    if (pTimer->fSuspended)
        return VERR_TIMER_SUSPENDED;

    /*
     * Suspend the timer.
     */
    RTSpinlockAcquire(g_Spinlock);
    g_u32ChangeNo++;
    pTimer->fSuspended = true;
    Assert(g_cActiveTimers > 0);
    g_cActiveTimers--;
    if (!g_cActiveTimers)
        rtTimerOs2Dearm();
    RTSpinlockRelease(g_Spinlock);

    return VINF_SUCCESS;
}

RTDECL(int) RTTimerChangeInterval(PRTTIMER pTimer, uint64_t u64NanoInterval)
{
    if (!rtTimerIsValid(pTimer))
        return VERR_INVALID_HANDLE;

    return VERR_NOT_SUPPORTED;
}

DECLASM(void) rtTimerOs2Tick(void)
{
    /*
     * Query the current time and then take the lock.
     */
    const uint64_t u64NanoTS = RTTimeNanoTS();

    RTSpinlockAcquire(g_Spinlock);

    /*
     * Clear the fDone flag.
     */
    PRTTIMER pTimer;
    for (pTimer = g_pTimerHead; pTimer; pTimer = pTimer->pNext)
        pTimer->fDone = false;

    /*
     * Walk the timer list and do the callbacks for any active timer.
     */
    uint32_t u32CurChangeNo = g_u32ChangeNo;
    pTimer = g_pTimerHead;
    while (pTimer)
    {
        PRTTIMER pNext = pTimer->pNext;
        if (    !pTimer->fSuspended
            &&  !pTimer->fDone
            &&  pTimer->u64NextTS <= u64NanoTS)
        {
            pTimer->fDone = true;
            pTimer->iTick++;

            /* calculate the next timeout */
            if (!pTimer->u64NanoInterval)
                pTimer->fSuspended = true;
            else
            {
                pTimer->u64NextTS = pTimer->u64StartTS + pTimer->iTick * pTimer->u64NanoInterval;
                if (pTimer->u64NextTS < u64NanoTS)
                    pTimer->u64NextTS = u64NanoTS + RTTimerGetSystemGranularity() / 2;
            }

            /* do the callout */
            PFNRTTIMER  pfnTimer = pTimer->pfnTimer;
            void       *pvUser   = pTimer->pvUser;
            RTSpinlockRelease(g_Spinlock);
            pfnTimer(pTimer, pvUser, pTimer->iTick);

            RTSpinlockAcquire(g_Spinlock);

            /* check if anything changed. */
            if (u32CurChangeNo != g_u32ChangeNo)
            {
                u32CurChangeNo = g_u32ChangeNo;
                pNext = g_pTimerHead;
            }
        }

        /* next */
        pTimer = pNext;
    }

    RTSpinlockRelease(g_Spinlock);
}

RTDECL(uint32_t) RTTimerGetSystemGranularity(void)
{
    return 32000000; /* 32ms */
}

RTDECL(int) RTTimerRequestSystemGranularity(uint32_t u32Request, uint32_t *pu32Granted)
{
    return VERR_NOT_SUPPORTED;
}

RTDECL(int) RTTimerReleaseSystemGranularity(uint32_t u32Granted)
{
    return VERR_NOT_SUPPORTED;
}

RTDECL(bool) RTTimerCanDoHighResolution(void)
{
    return false;
}


text:
require 'spec_helper'
require 'sshjr/auth/password'

describe SSHJr::Auth::Password do
  describe '#authenticate' do
    it 'calls auth_password on the client' do
      client = double('client')
      client.should_receive(:auth_password).with('johndoe', 'secret')
      described_class.new('johndoe', 'secret').authenticate(client)
    end
  end
end


text:
module VagrantPlugins
  module ProviderIijGp
    module Action
      class IsCreated
        def initialize(app, env)
          @app = app
        end

        def call(env)
          env[:result] = env[:machine].state.id != :not_created
          @app.call(env)
        end
      end
    end
  end
end


text:
require 'spec_helper'

describe 'DataMapper::Validations::Rule::Generic', '#optional?' do
  def validator(opts = {})
    DataMapper::Validations::Rule::Length.new(:name, opts)
  end

  describe 'allowing blank' do
    subject do
      validator(
        :allow_blank => true
      )
    end

    it { subject.optional?("" ).should be }
    it { subject.optional?(nil).should be }
  end

  describe 'allowing nil' do
    subject do
      validator(
        :allow_nil => true
      )
    end

    it { subject.optional?("" ).should_not be }
    it { subject.optional?(nil).should be }
  end

  describe 'allowing blank, but now allowing nil' do
    subject do
      validator(
        :allow_blank => true,
        :allow_nil   => false
      )
    end

    it { subject.optional?("" ).should be }
    it { subject.optional?(nil).should_not be }
  end

  describe 'allowing nil, but now allowing blank' do
    subject do
      validator(
        :allow_blank => false,
        :allow_nil   => true
      )
    end

    it { subject.optional?("" ).should_not be }
    it { subject.optional?(nil).should be }
  end

end