text:
require "politokens/version"
require "securerandom"

module Politokens
  class << self
    def politoke(token_range = 9999, delimiter = "-")
      seed = random_seed

      build(seed, token_range, delimiter)
    end

    private

    def build(seed, token_range, delimiter)
      sections = [
        adjectives[seed % adjectives.length],
        nouns[seed % nouns.length],
        token(token_range)
      ]

      sections.compact.join(delimiter)
    end

    def random_seed
      SecureRandom.random_number(4096)
    end

    def token(range)
      SecureRandom.random_number(range) if range > 0
    end

    def adjectives
      %w(
        adaptable adventurous affable affectionate agreeable
        ambitious amiable amicable amusing brave bright
        broad-minded calm careful charming communicative
        compassionate conscientious considerate convivial
        courageous courteous creative decisive determined
        diligent diplomatic discreet dynamic easygoing
        emotional energetic enthusiastic exuberant fair-minded
        faithful fearless forceful frank friendly funny
        generous gentle good gregarious hard-working helpful
        honest humorous imaginative impartial independent
        intellectual intelligent intuitive inventive kind
        loving loyal modest neat nice optimistic passionate
        patient persistent pioneering philosophical placid
        plucky polite powerful practical pro-active
        quick-witted quiet rational reliable reserved
        resourceful romantic self-confident self-disciplined
        sensible sensitive shy sincere sociable straightforward
        sympathetic thoughtful tidy tough unassuming
        understanding versatile warmhearted willing witty
      )
    end

    def nouns
      %w(
        afghanistan aland-islands albania algeria american-samoa
        andorra angola anguilla antarctica antigua-and-barbuda
        argentina armenia aruba australia austria azerbaijan bahamas
        bahrain bangladesh barbados belarus belgium belize benin
        bermuda bhutan bolivia bosnia-and-herzegovina botswana
        bouvet-island brazil british-indian-ocean-territory
        brunei-darussalam bulgaria burkina-faso burundi cambodia
        cameroon canada cape-verde cayman-islands
        central-african-republic chad chile china christmas-island
        cocos-islands colombia comoros congo dr-congo cook-islands
        costa-rica cote-d'ivoire croatia cuba cyprus czech-republic
        denmark djibouti dominica dominican-republic ecuador egypt
        el-salvador equatorial-guinea eritrea estonia ethiopia
        falkland-islands-(malvinas) faroe-islands fiji finland
        france french-guiana french-polynesia
        french-southern-territories gabon gambia georgia germany
        ghana gibraltar greece greenland grenada guadeloupe guam
        guatemala guernsey guinea guinea-bissau guyana haiti
        heard-island-and-mcdonald-islands holy-see honduras
        hong-kong hungary iceland india indonesia iran iraq
        ireland isle-of-man israel italy jamaica japan jersey
        jordan kazakhstan kenya kiribati north-korea south-korea
        kuwait kyrgyzstan laos latvia lebanon lesotho liberia
        libya liechtenstein lithuania luxembourg macao macedonia
        madagascar malawi malaysia maldives mali malta
        marshall-islands martinique mauritania mauritius mayotte
        mexico micronesia moldova monaco mongolia montenegro
        montserrat morocco mozambique myanmar namibia nauru nepal
        netherlands netherlands-antilles new-caledonia new-zealand
        nicaragua niger nigeria niue norfolk-island
        northern-mariana-islands norway oman pakistan palau
        palestine panama papua-new-guinea paraguay peru philippines
        pitcairn poland portugal puerto-rico qatar reunion romania
        russia rwanda saint-helena saint-kitts-and-nevis saint-lucia
        saint-pierre-and-miquelon saint-vincent-and-the-grenadines
        samoa san-marino sao-tome-and-principe saudi-arabia senegal
        serbia seychelles sierra-leone singapore slovakia slovenia
        solomon-islands somalia south-africa spain sri-lanka sudan
        suriname swaziland sweden switzerland syria taiwan
        tajikistan tanzania thailand timor-leste togo tokelau tonga
        trinidad-and-tobago tunisia turkey turkmenistan
        turks-and-caicos-islands tuvalu uganda ukraine
        united-arab-emirates united-kingdom united-states uruguay
        uzbekistan vanuatu venezuela viet-nam virgin-islands
        wallis-and-futuna western-sahara yemen zambia zimbabwe
      )
    end
  end
end


text:
#include "jsb_socketio.h"
#include "jsb_helper.h"
#include "cocos2d.h"
#include "network/WebSocket.h"
#include "network/SocketIO.h"
#include "spidermonkey_specifics.h"
#include "ScriptingCore.h"
#include "cocos2d_specifics.hpp"

using namespace cocos2d::network;

class JSB_SIOEvent : public cocos2d::Object {
public:
    JSB_SIOEvent();
    virtual ~JSB_SIOEvent();
    void setJSCallbackFunc(jsval obj);
    const jsval& getJSCallbackFunc() const;

private:
    JS::Heap<jsval> _jsCallback;
    JS::Heap<jsval> _extraData;

};

JSB_SIOEvent::JSB_SIOEvent()
: _jsCallback(JSVAL_VOID), _extraData(JSVAL_VOID)
{

}

JSB_SIOEvent::~JSB_SIOEvent()
{
    JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
    JS::RemoveValueRoot(cx, &_jsCallback);
}

void JSB_SIOEvent::setJSCallbackFunc(jsval func) {
    _jsCallback = func;
    JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
    // Root the callback function.
    JS::AddNamedValueRoot(cx, &_jsCallback, "JSB_SIOEvent_callback_func");
}

const jsval& JSB_SIOEvent::getJSCallbackFunc() const
{
    return _jsCallback;
}

//c++11 map to callbacks
typedef std::unordered_map<std::string, JSB_SIOEvent> JSB_SIOEventRegistry;

class JSB_SocketIODelegate : public SocketIO::SIODelegate {
public:

    JSB_SocketIODelegate() {
        JSB_SIOEvent tmp;
        std::string s = "default";
        _eventRegistry[s] = tmp;
    }

    virtual void onConnect(SIOClient* client) {
        CCLOG("JSB SocketIO::SIODelegate->onConnect method called from native");

        this->fireEventToScript(client, "connect", "");

    }

    virtual void onMessage(SIOClient* client, const std::string& data) {
        CCLOG("JSB SocketIO::SIODelegate->onMessage method called from native with data: %s", data.c_str());

        this->fireEventToScript(client, "message", data);

    }

    virtual void onClose(SIOClient* client) {
        CCLOG("JSB SocketIO::SIODelegate->onClose method called from native");

        this->fireEventToScript(client, "disconnect", "");

    }

    virtual void onError(SIOClient* client, const std::string& data) {
        CCLOG("JSB SocketIO::SIODelegate->onError method called from native with data: %s", data.c_str());

        this->fireEventToScript(client, "error", data);

    }

    virtual void fireEventToScript(SIOClient* client, const std::string& eventName, const std::string& data) {
        CCLOG("JSB SocketIO::SIODelegate->fireEventToScript method called from native with name '%s' data: %s", eventName.c_str(), data.c_str());

        js_proxy_t * p = jsb_get_native_proxy(client);
        if (!p) return;

        JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();

        jsval args;
        if(data == "") {
            args = JSVAL_NULL;
        } else {
            args = std_string_to_jsval(cx, data);
        }

        //ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), eventName.c_str(), 1, &args);

        JSB_SIOEventRegistry::iterator it = _eventRegistry.find(eventName);

        if(it != _eventRegistry.end()) {
            JSB_SIOEvent e = it->second;
            JS::RootedValue rval(cx);
            ScriptingCore::getInstance()->executeJSFunctionWithThisObj(JS::RootedValue(cx, OBJECT_TO_JSVAL(p->obj)), JS::RootedValue(cx, e.getJSCallbackFunc()), JS::HandleValueArray::fromMarkedLocation(1, &args), &rval);
        }

    }

    void setJSDelegate(JSObject* pJSDelegate) {
        _JSDelegate = pJSDelegate;
    }

    void addEvent(const std::string& eventName, JSB_SIOEvent jsevent) {
        _eventRegistry[eventName] = jsevent;
    }

private:
    JS::Heap<JSObject*> _JSDelegate;

    JSB_SIOEventRegistry _eventRegistry;

};

JSClass  *js_cocos2dx_socketio_class;
JSObject *js_cocos2dx_socketio_prototype;

void js_cocos2dx_SocketIO_finalize(JSFreeOp *fop, JSObject *obj) {
    CCLOG("jsbindings: finalizing JS object %p (SocketIO)", obj);
}

bool js_cocos2dx_SocketIO_constructor(JSContext *cx, uint32_t argc, jsval *vp)
{
    JS_ReportError(cx, "SocketIO isn't meant to be instantiated, use SocketIO.connect() instead");

    return false;
}

bool js_cocos2dx_SocketIO_connect(JSContext* cx, uint32_t argc, jsval* vp){
    CCLOG("JSB SocketIO.connect method called");

    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);

    if (argc == 1 || argc == 2) {

        std::string url;

        do {
            bool ok = jsval_to_std_string(cx, args.get(0), &url);
            JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
        } while (0);

        JSB_SocketIODelegate* siodelegate = new JSB_SocketIODelegate();

        CCLOG("Calling native SocketIO.connect method");
        SIOClient* ret = SocketIO::connect(*siodelegate, url);

        jsval jsret;
        do{
            if (ret) {
                // link the native object with the javascript object
                js_proxy_t *p;
                HASH_FIND_PTR(_native_js_global_ht, &ret, p);
                if(!p) {
                    //previous connection not found, create a new one
                    JSObject *obj = JS_NewObject(cx, js_cocos2dx_socketio_class, JS::RootedObject(cx, js_cocos2dx_socketio_prototype), JS::NullPtr());
                    p = jsb_new_proxy(ret, obj);
                    JS::AddNamedObjectRoot(cx, &p->obj, "SocketIO");
                    siodelegate->setJSDelegate(p->obj);
                }

                jsret = OBJECT_TO_JSVAL(p->obj);

            }
            else{
                jsret = JSVAL_NULL;
            }
        } while(0);

        args.rval().set(jsret);

        return true;

    }

    JS_ReportError(cx, "JSB SocketIO.connect: Wrong number of arguments");
    return false;
}

bool js_cocos2dx_SocketIO_send(JSContext* cx, uint32_t argc, jsval* vp){
    CCLOG("JSB SocketIO.send method called");

    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    JSObject *obj = JS_THIS_OBJECT(cx, vp);
    js_proxy_t *proxy = jsb_get_js_proxy(obj);
    SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
    JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");

    if (argc == 1) {

        std::string payload;

        do {
            bool ok = jsval_to_std_string(cx, args.get(0), &payload);
            JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
        } while (0);

        CCLOG("JSB SocketIO send mesage: %s", payload.c_str());

        cobj->send(payload);

        return true;

    }

    JS_ReportError(cx, "Wrong number of arguments");
    return false;

}

bool js_cocos2dx_SocketIO_emit(JSContext* cx, uint32_t argc, jsval* vp){
    CCLOG("JSB SocketIO.emit method called");

    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    JSObject *obj = JS_THIS_OBJECT(cx, vp);
    js_proxy_t *proxy = jsb_get_js_proxy(obj);
    SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
    JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");

    if (argc == 2) {

        std::string eventName;

        do {
            bool ok = jsval_to_std_string(cx, args.get(0), &eventName);
            JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
        } while (0);

        std::string payload;

        do {
            bool ok = jsval_to_std_string(cx, args.get(1), &payload);
            JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
        } while (0);

        CCLOG("JSB SocketIO emit event '%s' with payload: %s", eventName.c_str(), payload.c_str());

        cobj->emit(eventName, payload);

        return true;

    }

    JS_ReportError(cx, "JSB SocketIO.emit: Wrong number of arguments");
    return false;

}

bool js_cocos2dx_SocketIO_disconnect(JSContext* cx, uint32_t argc, jsval* vp){
    CCLOG("JSB SocketIO.disconnect method called");

    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    JSObject *obj = JS_THIS_OBJECT(cx, vp);
    js_proxy_t *proxy = jsb_get_js_proxy(obj);
    SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
    JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");

    if(argc == 0) {

        cobj->disconnect();
        args.rval().setUndefined();
        return true;
    }

    JS_ReportError(cx, "JSB SocketIO.disconnect: Wrong number of arguments");
    return false;

}

bool js_cocos2dx_SocketIO_close(JSContext* cx, uint32_t argc, jsval* vp){
    CCLOG("JSB SocketIO.close method called");

    if(argc == 0) {

        //This method was previously implemented to take care of the HTTPClient instance not being destroyed properly
        //SocketIO::close();
        JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
        args.rval().setUndefined();
        return true;
    }

    JS_ReportError(cx, "JSB SocketIO.close: Wrong number of arguments");
    return false;

}

static bool _js_set_SIOClient_tag(JSContext* cx, uint32_t argc, jsval* vp)
{
    CCLOG("JSB SocketIO.setTag method called");
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    JSObject* jsobj = args.thisv().toObjectOrNull();
    js_proxy_t *proxy = jsb_get_js_proxy(jsobj);
    SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
    JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");

    if (cobj) {
        std::string out = "";

        jsval_to_std_string(cx, args.get(0), &out);
        cobj->setTag(out.c_str());
        return true;
    } else {
        JS_ReportError(cx, "Error: SocketIO instance is invalid.");
        return false;
    }

}

static bool _js_get_SIOClient_tag(JSContext* cx, uint32_t argc, jsval* vp)
{
    CCLOG("JSB SocketIO.getTag method called");
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    JSObject* jsobj = args.thisv().toObjectOrNull();
    js_proxy_t *proxy = jsb_get_js_proxy(jsobj);
    SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
    JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");

    if (cobj) {
        args.rval().set(std_string_to_jsval(cx, cobj->getTag()));
        return true;
    } else {
        JS_ReportError(cx, "Error: SocketIO instance is invalid.");
        return false;
    }

}

bool js_cocos2dx_SocketIO_on(JSContext* cx, uint32_t argc, jsval* vp){
    CCLOG("JSB SocketIO.on method called");

    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    JSObject *obj = JS_THIS_OBJECT(cx, vp);
    js_proxy_t *proxy = jsb_get_js_proxy(obj);
    SIOClient* cobj = (SIOClient *)(proxy ? proxy->ptr : NULL);
    JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");

    if(argc == 2) {

        std::string eventName;

        do {
            bool ok = jsval_to_std_string(cx, args.get(0), &eventName);
            JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
        } while (0);

        CCLOG("JSB SocketIO eventName to: '%s'", eventName.c_str());

        JSB_SIOEvent tmpCobj;
        tmpCobj.setJSCallbackFunc(args.get(1));

        ((JSB_SocketIODelegate *)cobj->getDelegate())->addEvent(eventName, tmpCobj);

        args.rval().set(OBJECT_TO_JSVAL(proxy->obj));

        JS_SetReservedSlot(proxy->obj, 0, args.get(1));

        return true;
    }

    JS_ReportError(cx, "JSB SocketIO.close: Wrong number of arguments");
    return false;

}

void register_jsb_socketio(JSContext *cx, JS::HandleObject global) {

    js_cocos2dx_socketio_class = (JSClass *)calloc(1, sizeof(JSClass));
    js_cocos2dx_socketio_class->name = "SocketIO";
    js_cocos2dx_socketio_class->addProperty = JS_PropertyStub;
    js_cocos2dx_socketio_class->delProperty = JS_DeletePropertyStub;
    js_cocos2dx_socketio_class->getProperty = JS_PropertyStub;
    js_cocos2dx_socketio_class->setProperty = JS_StrictPropertyStub;
    js_cocos2dx_socketio_class->enumerate = JS_EnumerateStub;
    js_cocos2dx_socketio_class->resolve = JS_ResolveStub;
    js_cocos2dx_socketio_class->convert = JS_ConvertStub;
    js_cocos2dx_socketio_class->finalize = js_cocos2dx_SocketIO_finalize;
    js_cocos2dx_socketio_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);

    static JSPropertySpec properties[] = {
        JS_PSGS("tag", _js_get_SIOClient_tag, _js_set_SIOClient_tag, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_PS_END
    };

    static JSFunctionSpec funcs[] = {
        JS_FN("send", js_cocos2dx_SocketIO_send, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("emit", js_cocos2dx_SocketIO_emit, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("disconnect", js_cocos2dx_SocketIO_disconnect, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("on", js_cocos2dx_SocketIO_on, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    static JSFunctionSpec st_funcs[] = {
        JS_FN("connect", js_cocos2dx_SocketIO_connect, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FN("close", js_cocos2dx_SocketIO_close, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
    };

    js_cocos2dx_socketio_prototype = JS_InitClass(
                                                cx, global,
                                                JS::NullPtr(),
                                                js_cocos2dx_socketio_class,
                                                js_cocos2dx_SocketIO_constructor, 0, // constructor
                                                nullptr,
                                                funcs,
                                                nullptr, // no static properties
                                                st_funcs);

    JSObject* jsclassObj = anonEvaluate(cx, global, "(function () { return SocketIO; })()").toObjectOrNull();

}

redpajama_set_name: RedPajamaGithub


text:
<?php
namespace TYPO3\CMS\Core\Resource\Rendering;

use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperInterface;
use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry;

/**
 * Vimeo renderer class
 */
class VimeoRenderer implements FileRendererInterface
{
    /**
     * @var OnlineMediaHelperInterface
     */
    protected $onlineMediaHelper;

    /**
     * Returns the priority of the renderer
     * This way it is possible to define/overrule a renderer
     * for a specific file type/context.
     * For example create a video renderer for a certain storage/driver type.
     * Should be between 1 and 100, 100 is more important than 1
     *
     * @return int
     */
    public function getPriority()
    {
        return 1;
    }

    /**
     * Check if given File(Reference) can be rendered
     *
     * @param FileInterface $file File of FileReference to render
     * @return bool
     */
    public function canRender(FileInterface $file)
    {
        return ($file->getMimeType() === 'video/vimeo' || $file->getExtension() === 'vimeo') && $this->getOnlineMediaHelper($file) !== false;
    }

    /**
     * Get online media helper
     *
     * @param FileInterface $file
     * @return bool|OnlineMediaHelperInterface
     */
    protected function getOnlineMediaHelper(FileInterface $file)
    {
        if ($this->onlineMediaHelper === null) {
            $orgFile = $file;
            if ($orgFile instanceof FileReference) {
                $orgFile = $orgFile->getOriginalFile();
            }
            if ($orgFile instanceof File) {
                $this->onlineMediaHelper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($orgFile);
            } else {
                $this->onlineMediaHelper = false;
            }
        }
        return $this->onlineMediaHelper;
    }

    /**
     * Render for given File(Reference) html output
     *
     * @param FileInterface $file
     * @param int|string $width TYPO3 known format; examples: 220, 200m or 200c
     * @param int|string $height TYPO3 known format; examples: 220, 200m or 200c
     * @param array $options
     * @param bool $usedPathsRelativeToCurrentScript See $file->getPublicUrl()
     * @return string
     */
    public function render(FileInterface $file, $width, $height, array $options = null, $usedPathsRelativeToCurrentScript = false)
    {
        // Check for an autoplay option at the file reference itself, if not overriden yet.
        if (!isset($options['autoplay']) && $file instanceof FileReference) {
            $autoplay = $file->getProperty('autoplay');
            if ($autoplay !== null) {
                $options['autoplay'] = $autoplay;
            }
        }

        $urlParams = [];
        if (!empty($options['autoplay'])) {
            $urlParams[] = 'autoplay=1';
        }
        if (!empty($options['loop'])) {
            $urlParams[] = 'loop=1';
        }
        $urlParams[] = 'title=' . (int)!empty($options['showinfo']);
        $urlParams[] = 'byline=' . (int)!empty($options['showinfo']);
        $urlParams[] = 'portrait=0';

        if ($file instanceof FileReference) {
            $orgFile = $file->getOriginalFile();
        } else {
            $orgFile = $file;
        }

        $videoId = $this->getOnlineMediaHelper($file)->getOnlineMediaId($orgFile);
        $src = sprintf('https://player.vimeo.com/video/%s?%s', $videoId, implode('&', $urlParams));

        $attributes = ['allowfullscreen'];
        if ((int)$width > 0) {
            $attributes[] = 'width="' . (int)$width . '"';
        }
        if ((int)$height > 0) {
            $attributes[] = 'height="' . (int)$height . '"';
        }
        if (is_object($GLOBALS['TSFE']) && $GLOBALS['TSFE']->config['config']['doctype'] !== 'html5') {
            $attributes[] = 'frameborder="0"';
        }
        foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick'] as $key) {
            if (!empty($options[$key])) {
                $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
            }
        }

        return sprintf(
            '<iframe src="%s"%s></iframe>',
            $src,
            empty($attributes) ? '' : ' ' . implode(' ', $attributes)
        );
    }
}


text:
<?php

class BxPostsUpdater extends BxDolStudioUpdater
{
    function __construct($aConfig)
    {
        parent::__construct($aConfig);
    }
}


text:
import VectorLegend from './legends/vector-legend';

export default {
  'vector-legend': VectorLegend
};


text:
/*************************************************************************/
/*  rw_lock_windows.cpp                                                  */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                      https://godotengine.org                          */
/*************************************************************************/
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.                 */
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)    */
/*                                                                       */
/* 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.                */
/*************************************************************************/

#if defined(WINDOWS_ENABLED)

#include "rw_lock_windows.h"

#include "error_macros.h"
#include "os/memory.h"
#include <stdio.h>

void RWLockWindows::read_lock() {

	AcquireSRWLockShared(&lock);
}

void RWLockWindows::read_unlock() {

	ReleaseSRWLockShared(&lock);
}

Error RWLockWindows::read_try_lock() {

	if (TryAcquireSRWLockShared(&lock) == 0) {
		return ERR_BUSY;
	} else {
		return OK;
	}
}

void RWLockWindows::write_lock() {

	AcquireSRWLockExclusive(&lock);
}

void RWLockWindows::write_unlock() {

	ReleaseSRWLockExclusive(&lock);
}

Error RWLockWindows::write_try_lock() {
	if (TryAcquireSRWLockExclusive(&lock) == 0) {
		return ERR_BUSY;
	} else {
		return OK;
	}
}

RWLock *RWLockWindows::create_func_windows() {

	return memnew(RWLockWindows);
}

void RWLockWindows::make_default() {

	create_func = create_func_windows;
}

RWLockWindows::RWLockWindows() {

	InitializeSRWLock(&lock);
}

RWLockWindows::~RWLockWindows() {
}

#endif


text:
/**
 * @file
 * @author Jernej Kovacic
 *
 * An internal header file, it should not be included directly.
 * @headername{QuaternionException.h}
 *
 * Declaration of the class QuaternionException.
 */

#ifndef _MATH_QUATERNIONEXCEPTION_HPP_
#define _MATH_QUATERNIONEXCEPTION_HPP_

#include <ostream>
#include "exception/IMathException.hpp"

namespace math
{

/**
 * An exception, typically thrown by functions of QuaternionGeneric
 */
struct QuaternionException : public IMathException
{
    /// Enum with possible error codes
    enum err_codes {
        DIVIDE_BY_ZERO              /// Attempt of division by zero
    };

    err_codes error;     /// Type of an error
    // Constructor
    QuaternionException(const QuaternionException::err_codes err);
    // Output a short description of the error
    void what(std::ostream& str = std::cerr) const;
};

} // namespace math

#endif  // _MATH_QUATERNIONEXCEPTION_HPP_


text:
Physics 2200 Final exam, Part I

One can approximate \pi as

\pi ~= n sin(a_n)

as n approaches infinity. We use the relationship:

sin(a\_{2n}) = \sqrt{1/2-\sqrt{1-sin^2(a\_n)}/2}

with the initial condition

sin(a_4) = 1/\sqrt{2}

to create a recursive function. However, the loss of precision causes a catastrophic failure at ~n = 2^15. We have updated this algorithm to use the following relationship:

sin(a\_{2n}) = \sqrt{2sin^2(a\_n) +2\sqrt{sin^4(a\_n)-sin^2(a\_n)}}

which does not not see the same failure, as shown by the following plot:

![](pi-poly-u.pdf)


text:
{-# LANGUAGE GeneralizedNewtypeDeriving, FlexibleInstances,
             MultiParamTypeClasses #-}
module Haste.Monad (
    JSGen, genJS, dependOn, getModName, addLocal, getCfg, continue, isolate,
    pushBind, popBind, getCurrentBinding, whenCfg, rename, getActualName
  ) where
import Control.Monad.State.Strict
import Haste.AST as AST hiding (modName)
import qualified Data.Set as S
import Control.Applicative
import qualified Data.Map as M

data GenState cfg = GenState {
    -- | Dependencies in current context.
    deps         :: ![Name],
    -- | Local variables in current context.
    locals       :: ![Name],
    -- | The current continuation. Code is generated by appending to this
    --   continuation.
    continuation :: !(Stm -> Stm),
    -- | The stack of nested lambdas we've traversed.
    bindStack    :: ![Var],
    -- | Name of the module being compiled.
    modName      :: !String,
    -- | Current compiler configuration.
    config       :: !cfg,
    -- | Mapping of variable renamings.
    renames      :: !(M.Map Var Var)
  }

initialState :: cfg -> GenState cfg
initialState cfg = GenState {
    deps         = [],
    locals       = [],
    continuation = id,
    bindStack    = [],
    modName      = "",
    config       = cfg,
    renames      = M.empty
  }

newtype JSGen cfg a =
  JSGen (State (GenState cfg) a)
  deriving (Monad, Functor, Applicative)

class Dependency a where
  -- | Add a dependency to the function currently being generated.
  dependOn :: a -> JSGen cfg ()
  -- | Mark a symbol as local, excluding it from the dependency graph.
  addLocal :: a -> JSGen cfg ()

instance Dependency AST.Name where
  {-# INLINE dependOn #-}
  dependOn v = JSGen $ do
    st <- get
    put st {deps = v : deps st}

  {-# INLINE addLocal #-}
  addLocal v = JSGen $ do
    st <- get
    put st {locals = v : locals st}

instance Dependency AST.Var where
  {-# INLINE dependOn #-}
  dependOn (Foreign _)      = return ()
  dependOn (Internal n _ _) = dependOn n

  {-# INLINE addLocal #-}
  addLocal (Foreign _)      = return ()
  addLocal (Internal n _ _) = addLocal n

instance Dependency a => Dependency [a] where
  dependOn = mapM_ dependOn
  addLocal = mapM_ addLocal

instance Dependency a => Dependency (S.Set a) where
  dependOn = dependOn . S.toList
  addLocal = addLocal . S.toList

genJS :: cfg         -- ^ Config to use for code generation.
      -> String      -- ^ Name of the module being compiled.
      -> JSGen cfg a -- ^ The code generation computation.
      -> (a, S.Set AST.Name, S.Set AST.Name, Stm -> Stm)
genJS cfg myModName (JSGen gen) =
  case runState gen (initialState cfg) {modName = myModName} of
    (a, GenState dependencies loc cont _ _ _ _) ->
      (a, S.fromList dependencies, S.fromList loc, cont)

getModName :: JSGen cfg String
getModName = JSGen $ modName <$> get

pushBind :: Var -> JSGen cfg ()
pushBind v = JSGen $ do
  st <- get
  put st {bindStack = v : bindStack st}

popBind :: JSGen cfg ()
popBind = JSGen $ do
  st <- get
  put st {bindStack = tail $ bindStack st}

getCurrentBinding :: JSGen cfg Var
getCurrentBinding = JSGen $ fmap (head . bindStack) get

-- | Add a new continuation onto the current one.
continue :: (Stm -> Stm) -> JSGen cfg ()
continue cont = JSGen $ do
  st <- get
  put st {continuation = continuation st . cont}

-- | Run a GenJS computation in isolation, returning its results rather than
--   writing them to the output stream. Dependencies and locals are still
--   updated, however, and any enclosing renames are still visible within
--   the isolated computation.
isolate :: JSGen cfg a -> JSGen cfg (a, Stm -> Stm)
isolate gen = do
  myMod <- getModName
  cfg <- getCfg
  b <- getCurrentBinding
  rns <- renames <$> JSGen get
  let (x, dep, loc, cont) = genJS cfg myMod $ do
        pushBind b
        JSGen $ do
          st <- get
          put st {renames = rns}
        gen
  dependOn dep
  addLocal loc
  return (x, cont)

getCfg :: JSGen cfg cfg
getCfg = JSGen $ fmap config get

whenCfg :: (cfg -> Bool) -> JSGen cfg () -> JSGen cfg ()
whenCfg p act = do
  cfg <- getCfg
  when (p cfg) act

-- | Run a computation with the given renaming added to its context.
rename :: Var -> Var -> JSGen cfg a -> JSGen cfg a
rename from to m = do
  st <- JSGen get
  JSGen $ put st {renames = M.insert from to $ renames st}
  x <- m
  st' <- JSGen get
  JSGen $ put st' {renames = renames st}
  return x

-- | Get the actual name of a variable, recursing through multiple renamings
--   if necessary.
getActualName :: Var -> JSGen cfg Var
getActualName v = do
  rns <- renames <$> JSGen get
  maybe (return v) getActualName $ M.lookup v rns


text:
package com.booking.ooziezombie.services;

import com.booking.ooziezombie.json.Job;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.net.URISyntaxException;

@Configuration
public class CoordinatorState {
    private static final Logger log = LoggerFactory.getLogger(CoordinatorState.class);

    @Value("${oozie.host}")
    private String oozieHost;

    public void change(final Job job, final String state) throws URISyntaxException {
        log.info("Changing "+job.getCoordJobName()+" ( "+job.getCoordJobId()+" ) to "+state);
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_XML);
        HttpEntity<String> entity = new HttpEntity<>("", headers);
        URI uri = new URI(oozieHost + "oozie/v1/job/" + job.getCoordJobId() + "?action="+state.toLowerCase());
        restTemplate.put(uri, entity);
    }
}


text:
@import UIKit;

@interface YYViewController : UIViewController

@end


text:
export interface Patient{
	id: string,
	name: string,
	phone: string,
	email: string
}


text:
<?php

use P87\PHMVCFCore\App\View;

class testView extends PHPUnit_Framework_TestCase
{
	public function testConstruct()
	{
		$view = new View();
		$this->assertInstanceOf('\P87\PHMVCFCore\App\View', $view);
		$this->assertAttributeEquals('template', 'template', $view);
	}

	public function testSetTemplate()
	{
		$view = new View();
		$view->setTemplate('foobar');
		$this->assertAttributeEquals('foobar', 'template', $view);
	}

	public function testSetAssignsVariable()
	{
		$expected = ['foo' => 'bar', 'bar' => 'foo'];
		$view = new View();
		$view->set('foo', 'bar');
		$view->set('bar', 'foo');
		$this->assertAttributeEquals($expected, 'vars', $view);
	}

	//TODO
	public function testView()
	{

	}

	//TODO
	public function testRender()
	{

	}
}