text:
require 'json'
require 'socket'
require 'net/http'

module Pingity
  # == Submodules ===========================================================

  autoload(:ApiMethods, 'pingity/api_methods')
  autoload(:Config, 'pingity/config')
  autoload(:Exceptions, 'pingity/exceptions')

  # == Constants ============================================================

  VERSION = File.read(File.expand_path(File.join('..', 'VERSION'), File.dirname(__FILE__))).chomp
  API_VERSION = '1.0'.freeze
  API_VERSION_FOR_URI = "v-#{API_VERSION.sub('.', '-')}".freeze

  # == Module Methods =======================================================

  def self.config(options = nil)
    @config = nil if (options)

    @config ||= Pingity::Config.new(options)

    yield(@config) if (block_given?)

    @config
  end
  class << self
    alias_method :configure, :config
  end

  def self.configured?
    self.config.valid?
  end

  def self.version
    VERSION
  end

  def self.api_version
    API_VERSION
  end

  def self.api_method?(method)
    ApiMethods.instance_methods.include?(method)
  end

  extend Pingity::ApiMethods

protected
  def self.api_call(method, options)
    payload = JSON.dump(options.merge(:api_key => Pingity.config.api_key))
    uri = URI("http://#{Pingity.config.api}/api/#{API_VERSION_FOR_URI}/#{method}.json")

    response = nil

    if (Pingity.config.verbose)
      puts "Request:\n\t#{payload}"
    end

    case (Pingity.config.transport)
    when :curb
    else
      Net::HTTP.start(uri.host, uri.port) do |http|
        http_response = http.post(
          uri.path,
          payload,
          'Content-Type' => 'application/json'
        )

        begin
          response = JSON.load(http_response.body)
        end
      end
    end

    puts response.inspect if (Pingity.config.verbose)

    response

  rescue SocketError => e
    case (e.to_s)
    when /nodename nor servname provided/
      raise Pingity::Exceptions::NetworkError, "Hostname #{Pingity.config.api.inspect} could not be resolved, adjust 'api' configuration parameter or check DNS."
    else
      raise Pingity::Exceptions::NetworkError, "#{e}"
    end
  end
end

redpajama_set_name: RedPajamaGithub


text:
var message = '';

if(players[5] == null) {
    message = 'No Data Available';
    document.write(message);
}
else {

    var playerName = "Player 4"
    var playerHand = players[5].hand;
    // alert(playerHand[0])
    var cardNum = ["1", "2", "3", "4", "5"];
    var handSize = playerHand.length;

    message = '
'  + playerName + '

' + players[5].bet + '

' + '

' + players[5].status  + '
';

    for (i = 0; i < handSize; i++) {

            message = message + '';
    }

    document.getElementById("p6").innerHTML = message;

}


text:
from cef_parser import *
import sys
import schema
import file_util

#
# settings
#
indent = '    '

#
# Common
#
def get_func_parts(func, slot, is_global = False):
    virtual = isinstance(func, obj_function_virtual)
    capi_parts = func.get_capi_parts()

    csn_name = capi_parts['name']
    if not virtual:
        if is_global:
            if csn_name[0:4] == 'cef_':
                csn_name = csn_name[4:]
        else:
            csn_name = get_capi_name(func.get_name(), False, None)
            prefix = func.parent.get_capi_name()
            if prefix[-2:] == '_t':
                prefix = prefix[:-2]
            if prefix[0:3] == 'cef':
                subprefix = prefix[3:]
                pos = csn_name.find(subprefix)
                if pos >= 0:
                    csn_name = csn_name[0:pos]

    csn_args = []
    for carg in capi_parts['args']:
        type = schema.c2cs_type( carg[:carg.rindex(' ')] )
        name = schema.quote_name( carg[carg.rindex(' ')+1:] )
        csn_args.append({'name' : name, 'type' : type})

    iname = ''
    if virtual:
        iname = schema.get_iname(func.parent)

    result = {
        'basefunc': False,
        'virtual': virtual,
        'obj': func,
        'slot': '%x' % slot,
        'name': func.get_name(),
        'field_name': '_' + func.get_capi_name(),
        'delegate_type': func.get_capi_name() + '_delegate',
        'delegate_slot': '_ds%x' % slot,

        'capi_name': capi_parts['name'],
        'capi_retval': capi_parts['retval'],
        'capi_args': capi_parts['args'],

        'csn_name': csn_name,
        'csn_retval': schema.c2cs_type( capi_parts['retval'] ),
        'csn_args': csn_args,
        'csn_entrypoint': capi_parts['name'],

        'csn_args_proto': ', '.join(map(lambda x: '%s %s' % (x['type'], x['name']), csn_args)),

        'iname': iname,
        }
    return result

def get_base_func(cls, slot, name, cname):
    cretval = ''
    if name == 'AddRef':
        cretval = 'void'
    elif name == 'Release':
        cretval = 'int'
    elif name == 'HasOneRef':
        cretval = 'int'
    return {
            'basefunc': True,
            'virtual': True,
            'obj': None,
            'slot': '%x' % slot,
            'name': name,
            'field_name': '_base._%s' % cname,
            'delegate_type': '%s_delegate' % cname,
            'delegate_slot': '_ds%x' % slot,
            'capi_name': cname,
            'capi_retval': cretval,
            'capi_args': ['%s* self' % cls.get_capi_name()],

            'csn_name': cname,
            'csn_retval': cretval,
            'csn_args': [ { 'type': '%s*' % cls.get_capi_name(), 'name': 'self' } ],

            'csn_args_proto': '%s* self' % cls.get_capi_name(),

            'iname': schema.get_iname(cls),
        }

def get_base_funcs(cls):
    return [
        get_base_func(cls, 0, 'AddRef', 'add_ref'),
        get_base_func(cls, 1, 'Release', 'release'),
        get_base_func(cls, 2, 'HasOneRef', 'has_one_ref'),
        ]

def make_file_header():
    return """//
// DO NOT MODIFY! THIS IS AUTOGENERATED FILE!
//
""";

def append_dllimport(result, func):
    result.append('// %(name)s' % func)
    result.append('[DllImport(%(nm_class)s.DllName, EntryPoint = "%(entrypoint)s", CallingConvention = %(nm_class)s.CEF_CALL)]' % { 'nm_class': schema.nm_class, 'entrypoint': func['csn_entrypoint'] })
    result.append('public static extern %(csn_retval)s %(csn_name)s(%(csn_args_proto)s);' % func)
    result.append('')

#
# Generating Introp/Classes.X/*.g.cs
#
def make_struct_file(cls):
    body = []
    body.append('using System;')
    body.append('using System.Diagnostics.CodeAnalysis;')
    body.append('using System.Runtime.InteropServices;')
    body.append('using System.Security;')
    body.append('');

    body.append('[StructLayout(LayoutKind.Sequential, Pack = %s)]' % schema.CEF_ALIGN)
    body.append('[SuppressMessage("Microsoft.Design", "CA1049:TypesThatOwnNativeResourcesShouldBeDisposable")]')
    body.append('internal unsafe struct %s' % schema.get_iname(cls))
    body.append('{')
    body.append( indent + ('\n' + indent + indent).join( make_struct_members(cls) ) )
    body.append('}')

    return make_file_header() + \
"""namespace %(namespace)s
{
%(body)s
}
""" % {
        'namespace': schema.interop_namespace,
        'body': indent + ('\n'+indent).join(body)
      }

def get_funcs(cls, base = True):
    funcs = []

    if base:
        for func in get_base_funcs(cls):
            funcs.append( func )

    i = 3
    for func in cls.get_virtual_funcs():
        funcs.append( get_func_parts(func, i) )
        i += 1

    return funcs

def make_struct_members(cls):
    result = []

    static_funcs = []
    funcs = get_funcs(cls)

    delegate_visibility = "internal"
    if schema.is_proxy(cls):
        delegate_visibility = "private"

    for func in cls.get_static_funcs():
        static_funcs.append( get_func_parts(func, 0) )

    result.append('internal cef_base_t _base;')
    for func in funcs:
        if not func['basefunc']:
            result.append('internal IntPtr %(field_name)s;' % func)
    result.append('')

    for func in static_funcs:
        append_dllimport(result, func)

    for func in funcs:
        postfixs = schema.get_platform_retval_postfixs(func['csn_retval'])
        for px in postfixs:
            func['px'] = px
            result.append('[UnmanagedFunctionPointer(%s)]' % schema.CEF_CALLBACK)
            result.append('#if !DEBUG')
            result.append('[SuppressUnmanagedCodeSecurity]')
            result.append('#endif')
            result.append(delegate_visibility + ' delegate %(csn_retval)s%(px)s %(delegate_type)s%(px)s(%(csn_args_proto)s);' % func)
            result.append('')

    for func in funcs:
        if schema.is_proxy(cls):
            postfixs = schema.get_platform_retval_postfixs(func['csn_retval'])
            for px in postfixs:
                func['px'] = px
                result.append('// %(name)s' % func)
                result.append('private static IntPtr _p%(slot)s%(px)s;' % func)
                result.append('private static %(delegate_type)s%(px)s _d%(slot)s%(px)s;' % func)
                result.append('')
                result.append('public static %(csn_retval)s%(px)s %(csn_name)s%(px)s(%(csn_args_proto)s)' % func)
                result.append('{')
                result.append('    %(delegate_type)s%(px)s d;' % func)
                result.append('    var p = self->%(field_name)s;' % func)
                result.append('    if (p == _p%(slot)s%(px)s) { d = _d%(slot)s%(px)s; }' % func)
                result.append('    else')
                result.append('    {')
                result.append('        d = (%(delegate_type)s%(px)s)Marshal.GetDelegateForFunctionPointer(p, typeof(%(delegate_type)s%(px)s));' % func)
                result.append('        if (_p%(slot)s%(px)s == IntPtr.Zero) { _d%(slot)s%(px)s = d; _p%(slot)s%(px)s = p; }' % func)
                result.append('    }')
                args = ', '.join(map(lambda x: x['name'], func['csn_args']))
                if func['csn_retval'] == 'void':
                    result.append('    d(%s);' % args)
                else:
                    result.append('    return d(%s);' % args)
                result.append('}')
                result.append('')

    if schema.is_handler(cls):
        iname = schema.get_iname(cls)
        result.append('private static int _sizeof;')
        result.append('')
        result.append('static %s()' % iname)
        result.append('{')
        result.append(indent + '_sizeof = Marshal.SizeOf(typeof(%s));' % iname)
        result.append('}')
        result.append('')

        result.append('internal static %s* Alloc()' % iname)
        result.append('{')
        result.append(indent + 'var ptr = (%s*)Marshal.AllocHGlobal(_sizeof);' % iname)
        result.append(indent + '*ptr = new %s();' % iname)
        result.append(indent + 'ptr->_base._size = (UIntPtr)_sizeof;')
        result.append(indent + 'return ptr;')
        result.append('}')
        result.append('')

        result.append('internal static void Free(%s* ptr)' % iname)
        result.append('{')
        result.append(indent + 'Marshal.FreeHGlobal((IntPtr)ptr);')
        result.append('}')
        result.append('')

    return result

#
# Generating Introp/libcef.g.cs
#
def make_libcef_file(header):
    result = []

    for func in header.get_funcs():
        append_dllimport(result, get_func_parts(func, 0, True))

    body = []
    body.append('using System;')
    body.append('using System.Runtime.InteropServices;')
    body.append('using System.Diagnostics.CodeAnalysis;')
    body.append('');

    body.append('internal static unsafe partial class %s' % schema.nm_class)
    body.append('{')
    body.append( indent + ('\n' + indent + indent).join( result ) )
    body.append('}')

    return make_file_header() + \
"""namespace %(namespace)s
{
%(body)s
}
""" % {
        'namespace': schema.interop_namespace,
        'body': indent + ('\n'+indent).join(body)
      }

#
# Generating C# wrappers
#
def make_wrapper_g_file(cls):
    body = []

    body.append('using System;')
    body.append('using System.Collections.Generic;')
    body.append('using System.Diagnostics;')
    body.append('using System.Runtime.InteropServices;')
    # body.append('using System.Diagnostics.CodeAnalysis;')
    body.append('using %s;' % schema.interop_namespace)
    body.append('')

    for line in schema.get_overview(cls):
        body.append('// %s' % line)

    if schema.is_proxy(cls):
        body.append('public sealed unsafe partial class %s : IDisposable' % schema.cpp2csname(cls.get_name()))
        body.append('{')
        body.append( indent + ('\n' + indent + indent).join( make_proxy_g_body(cls) ) )
        body.append('}')

    if schema.is_handler(cls):
        body.append('public abstract unsafe partial class %s' % schema.cpp2csname(cls.get_name()))
        body.append('{')
        body.append( indent + ('\n' + indent + indent).join( make_handler_g_body(cls) ) )
        body.append('}')

    return make_file_header() + \
"""namespace %(namespace)s
{
%(body)s
}
""" % {
        'namespace': schema.namespace,
        'body': indent + ('\n'+indent).join(body)
      }

#
# make proxy body
#
def make_proxy_g_body(cls):
    csname = schema.cpp2csname(cls.get_name())
    iname = schema.get_iname(cls)

    result = []

    # result.append('#if DEBUG')
    # result.append('private static int _objCt;')
    # result.append('internal static int ObjCt { get { return _objCt; } }')
    # result.append('#endif')
    # result.append('')

    # static methods
    result.append('internal static %(csname)s FromNative(%(iname)s* ptr)' % { 'csname' : csname, 'iname' : iname })
    result.append('{')
    result.append(indent + 'return new %s(ptr);' % csname)
    result.append('}')
    result.append('')

    result.append('internal static %(csname)s FromNativeOrNull(%(iname)s* ptr)' % { 'csname' : csname, 'iname' : iname })
    result.append('{')
    result.append(indent + 'if (ptr == null) return null;')
    result.append(indent + 'return new %s(ptr);' % csname)
    result.append('}')
    result.append('')

    # private fields
    result.append('private %s* _self;' % iname)
    result.append('')

    # ctor
    result.append('private %(csname)s(%(iname)s* ptr)' % { 'csname' : csname, 'iname' : iname })
    result.append('{')
    result.append(indent + 'if (ptr == null) throw new ArgumentNullException("ptr");')
    result.append(indent + '_self = ptr;')
    #
    # todo: diagnostics code: Interlocked.Increment(ref _objCt);
    #
    result.append('}')
    result.append('')

    # disposable
    result.append('~%s()' % csname)
    result.append('{')
    result.append(indent + 'if (_self != null)')
    result.append(indent + '{')
    result.append(indent + indent + 'Release();')
    result.append(indent + indent + '_self = null;')
    result.append(indent + '}')
    result.append('}')
    result.append('')

    result.append('public void Dispose()')
    result.append('{')
    result.append(indent + 'if (_self != null)')
    result.append(indent + '{')
    result.append(indent + indent + 'Release();')
    result.append(indent + indent + '_self = null;')
    result.append(indent + '}')
    result.append(indent + 'GC.SuppressFinalize(this);')
    result.append('}')
    result.append('')

    result.append('internal void AddRef()')
    result.append('{')
    result.append(indent + '%(iname)s.add_ref(_self);' % { 'iname': iname })
    result.append('}')
    result.append('')

    result.append('internal bool Release()')
    result.append('{')
    result.append(indent + 'return %(iname)s.release(_self) != 0;' % { 'iname': iname })
    result.append('}')
    result.append('')

    result.append('internal bool HasOneRef')
    result.append('{')
    result.append(indent + 'get { return %(iname)s.has_one_ref(_self) != 0; }' % { 'iname': iname })
    result.append('}')
    result.append('')

    # TODO: use it only if it is really necessary!
    # result.append('internal %(iname)s* Pointer' % { 'iname' : iname })
    # result.append('{')
    # result.append(indent + 'get { return _self; }')
    # result.append('}')
    # result.append('')

    result.append('internal %(iname)s* ToNative()' % { 'iname' : iname })
    result.append('{')
    result.append(indent + 'AddRef();')
    result.append(indent + 'return _self;')
    result.append('}')

    return result

#
# make handler body
#
def make_handler_g_body(cls):
    csname = schema.cpp2csname(cls.get_name())
    iname = schema.get_iname(cls)

    funcs = get_funcs(cls)

    result = []

    # this dictionary used to keep object alive even when we doesn't reference object directly, but it can be referenced only from native side
    result.append('private static Dictionary<IntPtr, %(csname)s> _roots = new Dictionary<IntPtr, %(csname)s>();' % { 'csname' : csname })
    result.append('')

    result.append('private int _refct;')
    result.append('private %s* _self;' % iname)
    # result.append('private bool _disposed;')
    result.append('')

    result.append('protected object SyncRoot { get { return this; } }')
    result.append('')

    if schema.is_reversible(cls):
        result.append('internal static %s FromNativeOrNull(%s* ptr)' % (csname, iname))
        result.append('{')
        result.append(indent + '%s value = null;' % csname)
        result.append(indent + 'bool found;')
        result.append(indent + 'lock (_roots)')
        result.append(indent + '{')
        result.append(indent + indent + 'found = _roots.TryGetValue((IntPtr)ptr, out value);')
        result.append(indent + '}')
        result.append(indent + 'return found ? value : null;')
        result.append('}')
        result.append('')

        result.append('internal static %s FromNative(%s* ptr)' % (csname, iname))
        result.append('{')
        result.append(indent + 'var value = FromNativeOrNull(ptr);')
        result.append(indent + 'if (value == null) throw ExceptionBuilder.ObjectNotFound();')
        result.append(indent + 'return value;')
        result.append('}')
        result.append('')

    for func in funcs:
        result.append('private %(iname)s.%(delegate_type)s %(delegate_slot)s;' % func)
    result.append('')

    # ctor
    result.append('protected %s()' % csname)
    result.append('{')
    result.append(indent + '_self = %s.Alloc();' % iname)
    result.append('');
    for func in funcs:
        result.append(indent + '%(delegate_slot)s = new %(iname)s.%(delegate_type)s(%(csn_name)s);' % func)
        result.append(indent + '_self->%(field_name)s = Marshal.GetFunctionPointerForDelegate(%(delegate_slot)s);' % func)
    result.append('}')
    result.append('')

    # finalizer & dispose
    result.append('~%s()' % csname)
    result.append('{')
    result.append(indent + 'Dispose(false);')
    result.append('}')
    result.append('')

    if schema.is_autodispose(cls):
        result.append('private void Dispose()')
        result.append('{')
        result.append(indent + 'Dispose(true);')
        result.append(indent + 'GC.SuppressFinalize(this);')
        result.append('}')
        result.append('')

    result.append('protected virtual void Dispose(bool disposing)')
    result.append('{')
    # result.append(indent + '_disposed = true;')
    result.append(indent + 'if (_self != null)')
    result.append(indent + '{')
    result.append(indent + indent + '%s.Free(_self);' % iname)
    result.append(indent + indent + '_self = null;')
    result.append(indent + '}')
    result.append('}')
    result.append('')

    # todo: this methods must throw exception if object already disposed
    # todo: verify self pointer in debug
    result.append('private void add_ref(%s* self)' % iname)
    result.append('{')
    result.append(indent + 'lock (SyncRoot)')
    result.append(indent + '{')
    result.append(indent + indent + 'var result = ++_refct;')
    result.append(indent + indent + 'if (result == 1)')
    result.append(indent + indent + '{')
    result.append(indent + indent + indent + 'lock (_roots) { _roots.Add((IntPtr)_self, this); }')
    result.append(indent + indent + '}')
    result.append(indent + '}')
    result.append('}')
    result.append('')

    result.append('private int release(%s* self)' % iname)
    result.append('{')
    result.append(indent + 'lock (SyncRoot)')
    result.append(indent + '{')
    result.append(indent + indent + 'var result = --_refct;')
    result.append(indent + indent + 'if (result == 0)')
    result.append(indent + indent + '{')
    result.append(indent + indent + indent + 'lock (_roots) { _roots.Remove((IntPtr)_self); }')
    if schema.is_autodispose(cls):
        result.append(indent + indent + indent + 'Dispose();')
    result.append(indent + indent + indent + 'return 1;')
    result.append(indent + indent + '}')
    result.append(indent + indent + 'return 0;')
    result.append(indent + '}')
    result.append('}')
    result.append('')

    result.append('private int has_one_ref(%s* self)' % iname)
    result.append('{')
    result.append(indent + 'lock (SyncRoot) { return _refct == 1 ? 1 : 0; }')
    result.append('}')
    result.append('')

    result.append('internal %s* ToNative()' % iname)
    result.append('{')
    result.append(indent + 'add_ref(_self);')
    result.append(indent + 'return _self;')
    result.append('}')
    result.append('')

    result.append('[Conditional("DEBUG")]')
    result.append('private void CheckSelf(%s* self)' % iname)
    result.append('{')
    result.append(indent + 'if (_self != self) throw ExceptionBuilder.InvalidSelfReference();')
    result.append('}')
    result.append('')

    return result

#
# Generating impl templates
#
def make_impl_tmpl_file(cls):
    body = []

    body.append('using System;')
    body.append('using System.Collections.Generic;')
    body.append('using System.Diagnostics;')
    body.append('using System.Runtime.InteropServices;')
    # body.append('using System.Diagnostics.CodeAnalysis;')
    body.append('using %s;' % schema.interop_namespace)
    body.append('')

    append_xmldoc(body, cls.get_comment())

    if schema.is_proxy(cls):
        body.append('public sealed unsafe partial class %s' % schema.cpp2csname(cls.get_name()))
        body.append('{')
        body.append( indent + ('\n' + indent + indent).join( make_proxy_impl_tmpl_body(cls) ) )
        body.append('}')

    if schema.is_handler(cls):
        body.append('public abstract unsafe partial class %s' % schema.cpp2csname(cls.get_name()))
        body.append('{')
        body.append( indent + ('\n' + indent + indent).join( make_handler_impl_tmpl_body(cls) ) )
        body.append('}')

    return \
"""namespace %(namespace)s
{
%(body)s
}
""" % {
        'namespace': schema.namespace,
        'body': indent + ('\n'+indent).join(body)
      }

#
# make proxy impl tmpl body
#
def make_proxy_impl_tmpl_body(cls):
    csname = schema.cpp2csname(cls.get_name())
    iname = schema.get_iname(cls)
    funcs = get_funcs(cls, False)
    static_funcs = []
    for func in cls.get_static_funcs():
        static_funcs.append( get_func_parts(func, 0) )

    result = []

    for func in static_funcs:
        append_xmldoc(result, func['obj'].get_comment())
        result.append('public static %(csn_retval)s %(name)s(%(csn_args_proto)s)' % func)
        result.append('{')
        result.append('    throw new NotImplementedException(); // TODO: %(csname)s.%(name)s' % { 'csname': csname, 'name' : func['name'] })
        result.append('}')
        result.append('')

    for func in funcs:
        name = func['name']
        retval = func['csn_retval']
        args = func['csn_args_proto']
        if func['csn_args'][0]['name'] == 'self':
            args = ', '.join(map(lambda x: '%s %s' % (x['type'], x['name']), func['csn_args'][1:]))

        append_xmldoc(result, func['obj'].get_comment())

        result.append('public %s %s(%s)' % (retval, name, args))
        result.append('{')
        result.append('    throw new NotImplementedException(); // TODO: %(csname)s.%(name)s' % { 'csname': csname, 'name' : func['name'] })
        result.append('}')
        result.append('')

    return result

#
# make handler impl tmpl body
#
def make_handler_impl_tmpl_body(cls):
    csname = schema.cpp2csname(cls.get_name())
    iname = schema.get_iname(cls)
    funcs = get_funcs(cls, False)
    static_funcs = []
    for func in cls.get_static_funcs():
        static_funcs.append( get_func_parts(func, 0) )

    result = []

    for func in static_funcs:
        append_xmldoc(result, func['obj'].get_comment())
        result.append('public static %(csn_retval)s %(name)s(%(csn_args_proto)s)' % func)
        result.append('{')
        result.append('    throw new NotImplementedException(); // TODO: %(csname)s.%(name)s' % { 'csname': csname, 'name' : func['name'] })
        result.append('}')
        result.append('')

    for func in funcs:
        result.append('private %s %s(%s)' % (func['csn_retval'], func['csn_name'], func['csn_args_proto']))
        result.append('{')
        result.append(indent + 'CheckSelf(self);')
        result.append(indent + 'throw new NotImplementedException(); // TODO: %(csname)s.%(name)s' % { 'csname': csname, 'name' : func['name'] })
        result.append('}')
        result.append('')

        name = func['name']
        retval = func['csn_retval']
        args = func['csn_args_proto']
        if func['csn_args'][0]['name'] == 'self':
            args = ', '.join(map(lambda x: '%s %s' % (x['type'], x['name']), func['csn_args'][1:]))

        append_xmldoc(result, func['obj'].get_comment())

        result.append('// protected abstract %s %s(%s);' % (retval, name, args))
        result.append('')

    return result

def append_xmldoc(result, lines):
    result.append('/// <summary>')
    for line in lines:
        if line != '/' and not (line is None):
            line = line.strip()
            if line != '':
                result.append('/// %s' % line.strip())
    result.append('/// </summary>')
    return

def make_version_cs(content):
    result = []

    result.append('public const string CEF_VERSION = %s;' % __get_version_constant(content, "CEF_VERSION"))
    result.append('public const int CEF_VERSION_MAJOR = %s;' % __get_version_constant(content, "CEF_VERSION_MAJOR"))
    result.append('public const int CEF_COMMIT_NUMBER = %s;' % __get_version_constant(content, "CEF_COMMIT_NUMBER"))
    result.append('public const string CEF_COMMIT_HASH = %s;' % __get_version_constant(content, "CEF_COMMIT_HASH"))
    result.append("");

    result.append('public const int CHROME_VERSION_MAJOR = %s;' % __get_version_constant(content, "CHROME_VERSION_MAJOR"))
    result.append('public const int CHROME_VERSION_MINOR = %s;' % __get_version_constant(content, "CHROME_VERSION_MINOR"))
    result.append('public const int CHROME_VERSION_BUILD = %s;' % __get_version_constant(content, "CHROME_VERSION_BUILD"))
    result.append('public const int CHROME_VERSION_PATCH = %s;' % __get_version_constant(content, "CHROME_VERSION_PATCH"))
    result.append("");

    result.append('public const string CEF_API_HASH_UNIVERSAL = %s;' % __get_version_constant(content, "CEF_API_HASH_UNIVERSAL"))
    result.append("");
    result.append('public const string CEF_API_HASH_PLATFORM_WIN = %s;' % __get_version_constant(content, "CEF_API_HASH_PLATFORM", "WIN"))
    result.append('public const string CEF_API_HASH_PLATFORM_MACOSX = %s;' % __get_version_constant(content, "CEF_API_HASH_PLATFORM", "MACOSX"))
    result.append('public const string CEF_API_HASH_PLATFORM_LINUX = %s;' % __get_version_constant(content, "CEF_API_HASH_PLATFORM", "LINUX"))

    body = []
    body.append('using System;')
    body.append('using System.Runtime.InteropServices;')
    body.append('using System.Diagnostics.CodeAnalysis;')
    body.append('');

    body.append('internal static unsafe partial class %s' % schema.nm_class)
    body.append('{')
    body.append( indent + ('\n' + indent + indent).join( result ) )
    body.append('}')

    return make_file_header() + \
"""namespace %(namespace)s
{
%(body)s
}
""" % {
        'namespace': schema.interop_namespace,
        'body': indent + ('\n'+indent).join(body)
      }

def __get_version_constant(content, name, platform = None):
    if platform is None:
        m = re.search('^#define\s+' + name + '\s+(.*?)\n', content, re.MULTILINE)
        if m is None:
            raise Exception('Could not find ' + name + ' constant.');
        value = m.group(1)
    else:
        m = re.search('\n#e?l?if defined\(OS_' + platform + '\)\n+#define\s+' + name + '\s+(.*?)\n', content, re.DOTALL)
        if m is None:
            raise Exception('Could not find ' + name + ' constant.');
        value = m.group(1)
    return value

#
# Main
#
def write_interop(header, filepath, backup, schema_name, cppheaderdir):
    writect = 0

    schema.load(schema_name, header)

    # validate: class role must be defined for all header classes
    for cls in header.get_classes():
        if not schema.is_handler(cls) and not schema.is_proxy(cls):
            msg = 'Class role must be defined. Class name %s.' % cls.get_name()
            sys.stdout.write('ERROR! %s\n' % msg)
            raise Exception(msg)

    # structs
    for cls in header.get_classes():
        content = make_struct_file(cls)
        writect += update_file(filepath + '/' + schema.struct_path, cls.get_capi_name() + ".g.cs", content, backup)

    # libcef.g.cs
    writect += update_file(filepath + '/' + schema.libcef_path, schema.libcef_filename, make_libcef_file(header), backup)

    # wrapper
    for cls in header.get_classes():
        content = make_wrapper_g_file(cls)
        writect += update_file(filepath + '/' + schema.wrapper_g_path, schema.cpp2csname(cls.get_name()) + ".g.cs", content, backup)

    # userdata
    userdatacls = obj_class(header, 'CefUserData', '', 'CefUserData', '', '', '', '', [])
    content = make_struct_file(userdatacls)
    writect += update_file(filepath + '/' + schema.struct_path, userdatacls.get_capi_name() + ".g.cs", content, backup)
    content = make_wrapper_g_file(userdatacls)
    writect += update_file(filepath + '/' + schema.wrapper_g_path, schema.cpp2csname(userdatacls.get_name()) + ".g.cs", content, backup)

    # impl template
    for cls in header.get_classes():
        content = make_impl_tmpl_file(cls)
        tmplpath = schema.handler_tmpl_path
        if schema.is_proxy(cls):
            tmplpath = schema.proxy_tmpl_path
        writect += update_file('./' + tmplpath, schema.cpp2csname(cls.get_name()) + ".tmpl.g.cs", content, backup)

    # process cef_version_h
    content = make_version_cs(read_file(cppheaderdir + '/' + 'cef_version.h'))
    writect += update_file(filepath + '/' + schema.libcef_path, schema.libcef_version_filename, content, backup)

    return writect

#
# Utils
#
def update_file(dir, filename, content, backup):
    if not os.path.isdir(dir):
        os.makedirs(dir)

    sys.stdout.write(filename + "... ")
    filename = dir + "/" + filename

    if path_exists(filename):
        oldcontent = read_file(filename)
    else:
        oldcontent = ''

    if content != oldcontent:
        if backup and oldcontent != '':
            backup_file(filename)
        write_file(filename, content)
        sys.stdout.write("updated.\n")
        return 1

    sys.stdout.write("up-to-date.\n")
    return 0


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

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

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

"""

from resource_management.libraries.functions import stack_select
from resource_management.libraries.functions import StackFeature
from resource_management.libraries.functions.stack_features import check_stack_feature
from resource_management.libraries.script import Script
from phoenix_service import phoenix_service
from hbase import hbase

# Note: Phoenix Query Server is only applicable to stack version supporting Phoenix.
class PhoenixQueryServer(Script):

  def install(self, env):
    import params
    env.set_params(params)
    self.install_packages(env)

  def configure(self, env):
    import params
    env.set_params(params)
    hbase(name='queryserver')

  def start(self, env, upgrade_type=None):
    import params
    env.set_params(params)
    self.configure(env)
    phoenix_service('start')

  def stop(self, env, upgrade_type=None):
    import params
    env.set_params(params)
    phoenix_service('stop')

  def pre_upgrade_restart(self, env, upgrade_type=None):
    import params
    env.set_params(params)

    if params.stack_version_formatted and check_stack_feature(StackFeature.PHOENIX, params.stack_version_formatted):
      stack_select.select_packages(params.version)

  def status(self, env):
    import status_params
    env.set_params(status_params)
    phoenix_service('status')

  def get_log_folder(self):
    import params
    return params.log_dir

  def get_user(self):
    import params
    return params.hbase_user

if __name__ == "__main__":
  PhoenixQueryServer().execute()


text:
angular.module('Wave.dataviewer.ctrl',[])

.controller('DataViewerController', ['$location', '$scope','$routeParams','$appUser','$sqlFiddle', '$dashboardService','$log', '$timeout','$window',
    function($location, $scope, $routeParams, $user, $sqlfiddle, $dashboard, $log, $timeout, $window) {
        $scope.user = $user.isLogined().user;
        $scope.tables = [];
        // $scope.editorOptions = {};
        $scope.isSqlstmt = true;
        $scope.editedItem = {};
        $scope.editedItem.query = "";
        $scope.errormsg = "";

        $scope.logout = function(){
            if($user.logout()){
                $location.path('/login');
            }
        }

        $scope.availOptions = {
            datatype : "local",
            height : 'auto',
            rowNum : 50,
            rowList : [30, 50,100],
            viewrecords : true,
            multiselect : false,
            autowidth : true
        };
        $scope.availcolnames = [];
        $scope.availcolmodel = [];
        var tables_p = $sqlfiddle.getTables();

        tables_p.then(function(data){
            $scope.availdata = data;
            if(data){
                var keys = Object.keys(data[0]);
                for(var i=0;i<keys.length;i++){
                    $scope.availcolnames.push(keys[i]);
                    $scope.availcolmodel.push({'name':keys[i], 'index':keys[i]})
                }
            }
        });

        $scope.resultOptions = {
            datatype : "local",
            height : 'auto',
            rowNum : 50,
            rowList : [30, 50,100],
            viewrecords : true,
            multiselect : false,
            autowidth : true
        };

        $scope.resultData = [];

        $scope.editorOptions = {
            onLoad : function(_editor){
                _editor.setSize('99.9%', '400px');
            $scope.editor = _editor;
            },
            operatorChars: /^[*+\-%<>!=]/,
            lineWrapping : true,
            smartIndent: true,
            autofocus: true,
            lineNumbers: true,
            tabMode: 'indent',
            matchBrackets: true,
            mode: 'text/x-mysql'

        };

        $scope.overrideOptions = {
        // define table layout
            "sDom" : "<'row-fluid dt-header'<'span6'f><'span6 hidden-phone'T>r>t<'row-fluid dt-footer'<'span6 visible-desktop'i><'span6'p>>",
            // add paging
            "sPaginationType" : "bootstrap",
            "oLanguage" : {
                "sLengthMenu" : "Showing: _MENU_",
                "sEmptyTable":  "You need to execute query"
            }
        }

        $scope.setTablename = function(tname){
            $scope.editor.setValue($scope.editor.getValue()  + " " + tname);

        }

        // $scope.tblDatas = data;
        $scope.runSQL = function(){
            $scope.tblcolnames = [];
            $scope.tblcolmodel = [];
            $scope.tbldata = [];
            $scope.editedItem.query = $scope.editor.getValue();
            q =  $scope.editedItem;
            var p = $sqlfiddle.executeQuery(q);

                p.then(function(data){
                    if(data.status == 'success'){
                        $scope.errormsg = ""
                        var keys = Object.keys(data.data[0]);
                        for(var i=0;i<keys.length;i++){
                            $scope.tblcolnames.push(keys[i]);
                            $scope.tblcolmodel.push({'name':keys[i], 'index':keys[i]})
                        }
                        $scope.tbldata = data.data;
                        console.log(JSON.stringify($scope.tblDatas));
                    }else if(data.status == 'error'){
                        $scope.errormsg = data.data;
                    }

                });

        }

    $scope.user = $user.isLogined().user;

    $scope.menus = [];
    $scope.leftMenus = function(){
        var promise = $dashboard.getMenus();
        promise.then(function(data){
            $scope.menus = JSON.parse(data[0].m1);
            $log.log('----$scope.printMenus-----');
            $timeout(function(){
                $window.initApp.SmartActions();
                $window.initApp.leftNav();
                $log.log($window.initApp);
            }, 300);
        });
    };
    $scope.leftMenus();
    $scope.leftMove = function(url){
        $log.log('move to >>' + url + '<<');
        $location.path(url);
    };

}])

;


text:
using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

	public Vector2 jumpForce = new Vector2(0,300);

	// Update is called once per frame
	void Update () {
		if(Input.touchCount > 0)
		{
			if(Input.GetTouch(0).phase == TouchPhase.Began)
			{
				rigidbody2D.velocity = Vector2.zero;
				rigidbody2D.AddForce(jumpForce);
			}
		}
		else if(Input.GetKeyUp("space"))
		{
			rigidbody2D.velocity = Vector2.zero;
			rigidbody2D.AddForce(jumpForce);
		}

		Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
		if(screenPosition.y > Screen.height || screenPosition.y < 0)
		{
			Die();
		}
	}

	void OnCollisionEnter2D(Collision2D other)
	{
		Die ();
	}

	void Die()
	{
		Application.LoadLevel(Application.loadedLevel);
	}
}


text:
package ma.glasnost.orika.converter.builtin;

import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Objects;

/**
 * DateToStringConverter provides custom conversion from String values to and
 * from Date instances, based on a provided date format pattern.

 *

 *
 * The format is applied based on the rules defined in
 * {@link java.text.SimpleDateFormat}.
 *
 * @author elaatifi@gmail.com
 *
 */
public class DateToStringConverter extends BidirectionalConverter<Date, String> {

    private final String pattern;
    private final Locale locale;
    private final ThreadLocal<SimpleDateFormat> dateFormats = new ThreadLocal<>();

    /**
     * @return a SimpleDateFormat instance safe for use in the current thread
     */
    private SimpleDateFormat getDateFormat() {
        SimpleDateFormat formatter = dateFormats.get();
        if (formatter == null) {
            formatter = new SimpleDateFormat(pattern, locale);
            dateFormats.set(formatter);
        }
        return formatter;
    }

    /**
     * Constructs a new instance of DateToStringConverter capable of parsing and
     * constructing Date strings according to the provided format.
     *
     * @param format
     *            the format descriptor, processed according to the rules
     *            defined in {@link java.text.SimpleDateFormat}
     */
    public DateToStringConverter(final String format) {
        this(format, Locale.getDefault());
    }

    /**
     * Constructs a new instance of DateToStringConverter with given locale
     */
    public DateToStringConverter(final String format, final Locale locale) {
        this.pattern = format;
        this.locale = locale;
    }

    @Override
    public String convertTo(Date source, Type<String> destinationType, MappingContext context) {
        return getDateFormat().format(source);
    }

    @Override
    public Date convertFrom(String source, Type<Date> destinationType, MappingContext context) {
        try {
            return getDateFormat().parse(source);
        } catch (ParseException e) {
            return null;
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        DateToStringConverter that = (DateToStringConverter) o;

        if (!Objects.equals(pattern, that.pattern)) return false;
        return Objects.equals(locale, that.locale);

    }

}


text:
package pl.opencaching.android.data.repository;

import javax.inject.Inject;

import io.realm.Realm;
import io.realm.RealmResults;
import pl.opencaching.android.data.models.okapi.Attribute;
import pl.opencaching.android.data.repository.base.RealmRepository;

public class AttributeRepository extends RealmRepository<Attribute> {

    @Inject
    public AttributeRepository(Realm realm) {
        super(realm);
    }

    public Attribute loadAttributeByCode(String acode) {
        return realm.where(Attribute.class)
                .equalTo("acode", acode)
                .findFirst();
    }

    public RealmResults<Attribute> loadAttributesIncludes(String[] includesCodes) {
        return realm.where(Attribute.class)
                .in("code", includesCodes)
                .findAll();
    }

}


text:
#ifndef AudioNodeInput_h
#define AudioNodeInput_h

#include "platform/audio/AudioBus.h"
#include "modules/webaudio/AudioNode.h"
#include "modules/webaudio/AudioSummingJunction.h"
#include "wtf/HashSet.h"

namespace blink {

class AudioNode;
class AudioNodeOutput;

// An AudioNodeInput represents an input to an AudioNode and can be connected from one or more AudioNodeOutputs.
// In the case of multiple connections, the input will act as a unity-gain summing junction, mixing all the outputs.
// The number of channels of the input's bus is the maximum of the number of channels of all its connections.

class AudioNodeInput FINAL : public AudioSummingJunction {
public:
    static PassOwnPtrWillBeRawPtr<AudioNodeInput> create(AudioNode&);

    // AudioSummingJunction
    virtual void trace(Visitor*) OVERRIDE;
    virtual bool canUpdateState() OVERRIDE { return !node().isDisposeCalled(); }
    virtual void didUpdate() OVERRIDE;

    // Can be called from any thread.
    AudioNode& node() const { return *m_node; }

    // Must be called with the context's graph lock.
    void connect(AudioNodeOutput&);
    void disconnect(AudioNodeOutput&);

    // disable() will take the output out of the active connections list and set aside in a disabled list.
    // enable() will put the output back into the active connections list.
    // Must be called with the context's graph lock.
    void enable(AudioNodeOutput&);
    void disable(AudioNodeOutput&);

    // pull() processes all of the AudioNodes connected to us.
    // In the case of multiple connections it sums the result into an internal summing bus.
    // In the single connection case, it allows in-place processing where possible using inPlaceBus.
    // It returns the bus which it rendered into, returning inPlaceBus if in-place processing was performed.
    // Called from context's audio thread.
    AudioBus* pull(AudioBus* inPlaceBus, size_t framesToProcess);

    // bus() contains the rendered audio after pull() has been called for each time quantum.
    // Called from context's audio thread.
    AudioBus* bus();

    // updateInternalBus() updates m_internalSummingBus appropriately for the number of channels.
    // This must be called when we own the context's graph lock in the audio thread at the very start or end of the render quantum.
    void updateInternalBus();

    // The number of channels of the connection with the largest number of channels.
    unsigned numberOfChannels() const;

private:
    explicit AudioNodeInput(AudioNode&);

    RawPtrWillBeMember<AudioNode> m_node;

    // m_disabledOutputs contains the AudioNodeOutputs which are disabled (will not be processed) by the audio graph rendering.
    // But, from JavaScript's perspective, these outputs are still connected to us.
    // Generally, these represent disabled connections from "notes" which have finished playing but are not yet garbage collected.
    // Oilpan: Since items are added to the hash set by the audio thread (not registered to Oilpan),
    // we cannot use a HeapHashSet.
    HashSet<AudioNodeOutput*> m_disabledOutputs;

    // Called from context's audio thread.
    AudioBus* internalSummingBus();
    void sumAllConnections(AudioBus* summingBus, size_t framesToProcess);

    RefPtr<AudioBus> m_internalSummingBus;
};

} // namespace blink

#endif // AudioNodeInput_h


text:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:padding="5dp" />

</RelativeLayout>


text:
namespace seec {

namespace cm {

class ProcessState;

namespace graph {

class ExpansionImpl;

/// \brief Stores information about a state that has been expanded for graphing.
///
class Expansion final {
  /// Internal implementation.
  std::unique_ptr<ExpansionImpl const> Impl;

  /// \brief Constructor.
  ///
  Expansion();

public:
  /// \brief Move constructor.
  ///
  Expansion(Expansion &&) = default;

  /// \brief Destructor.
  ///
  ~Expansion();

  /// \brief Create an \c Expansion for a \c seec::cm::ProcessState.
  ///
  static Expansion from(seec::cm::ProcessState const &State);

  /// \name Pointers.
  /// @{

  /// \brief Check if a \c Value is directly referenced by a pointer.
  ///
  bool isReferencedDirectly(Value const &Value) const;

  /// \brief Get all pointers that point directly into a memory area.
  ///
  std::vector<std::shared_ptr<ValueOfPointer const>>
  getReferencesOfArea(stateptr_ty Start, stateptr_ty End) const;

  /// \brief Check if any pointer points into a memory area.
  ///
  bool isAreaReferenced(stateptr_ty Start, stateptr_ty End) const;

  /// \brief Get all pointers.
  ///
  std::vector<std::shared_ptr<ValueOfPointer const>>
  getAllPointers() const;

  /// @} (Pointers.)
};

/// \brief Reduce a set of references to the most informative types.
///
void reduceReferences(std::vector<std::shared_ptr<ValueOfPointer const>> &Refs);

} // namespace graph (in cm in seec)

} // namespace cm (in seec)

} // namespace seec

#endif // SEEC_LIB_CLANG_GRAPHEXPANSION_HPP


text:
<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
    <dimen name="margin_medium">8dp</dimen>
    <dimen name="messagelayout_minwidth">40dp</dimen>
    <dimen name="timestamp_size">10sp</dimen>
    <dimen name="message_text_size">16sp</dimen>
    <dimen name="cmv_padding">10dp</dimen>
    <dimen name="cmv_corner_radius">15dp</dimen>
    <dimen name="message_layout_max_width">250dp</dimen>
    <dimen name="message_layout_margin">4dp</dimen>
    <dimen name="standard_content_padding">5dp</dimen>
    <dimen name="preview_layout_height">95dp</dimen>
    <dimen name="activity_landscape_width">300dp</dimen>
    <dimen name="button_width">250dp</dimen>

    <dimen name="margin_small">5dp</dimen>
    <dimen name="message_card_margin_small">4dp</dimen>
    <dimen name="message_card_margin_medium">6dp</dimen>
    <dimen name="padding_small">5dp</dimen>
    <dimen name="timestamp_layout_padding">8dp</dimen>
    <dimen name="piechart_layout_height">300dp</dimen>
    <dimen name="padding_large">10dp</dimen>
    <dimen name="webpreview_headline_height">32dp</dimen>
    <dimen name="webpreview_content_height">53dp</dimen>
    <dimen name="websearch_card_width">225dp</dimen>
    <dimen name="webpreview_layout_height">95dp</dimen>
    <dimen name="margin_very_small">2dp</dimen>
    <dimen name="margin_large">10dp</dimen>
    <dimen name="message_textview_bottom_padding">3dp</dimen>

</resources>


text:
{% extends "_layouts/dashboard.html" %}
{% set active_page = "admin" %}
{% set active_link = "categories" %}
{% import "_helpers/_general.html" as general_helpers %}
{% import "_helpers/_form.html" as form_helpers %}
{% import "_helpers/_card.html" as card_helpers %}
{% import "_helpers/_table.html" as table_helpers %}

{% block content %}
{{ general_helpers.render_title('Admin', 'Categories') }}

    {{ card_helpers.render_title('Add Category', 'Add a new project category') }}

        <form method="POST" action="{{ url_for('admin.categories') }}">
            {{ form.hidden_tag() }}
            {{ form_helpers.render_field(form.name, placeholder="Category name", class_="form-control", required="required") }}
            {{ form_helpers.render_field(form.description, placeholder="Category description", class_="form-control", required="required") }}

                <input id="reset" type="reset" value="Reset" class="btn btn-outline-secondary" role="button" />
                <input id="submit" type="submit" value="Add" class="btn btn-success" role="button" />

        </form>

    {{ card_helpers.render_title('Current Categories', 'Edit or delete current categories', search_table="#categories-table") }}

            {{ table_helpers.render_head(['ID', 'Title', 'Projects', 'Edit', 'Delete'], center_indexes=[3, 4, 5]) }}

                {% for c in categories %}

                {{ table_helpers.render_cell(c.id) }}
                {{ table_helpers.render_cell(c.name) }}
                {{ table_helpers.render_cell(n_projects_per_category[c.short_name], center=True) }}
                {{ table_helpers.render_cell('Edit', url=url_for('admin.update_category', id=c.id), btn=True, center=True) }}
                {{ table_helpers.render_cell('Delete', url=url_for('admin.del_category', id=c.id), btn=True, center=True) }}

                {% endfor %}
                {{ table_helpers.render_no_data_row(5) }}

{% endblock %}


text:
\section{Python for Big Data}\label{python-for-big-data}

\subsection{An Example with Pandas, NumPy and Matplotlib}\label{an-example-with-pandas-numpy-and-matplotlib}

In this example, we will download some traffic citation data for the
city of Bloomington, IN, load it into Python and generate a histogram.
In doing so, you will be exposed to important Python libraries for
working with big data such as \href{www.numpy.org}{numpy},
\href{pandas.pydata.org}{pandas} and \href{matplotlib.org}{matplotlib}.

\subsubsection{Set Up Directories and Get Test
Data}\label{set-up-directories-and-get-test-data}

Data.gov is a government portal for open data and the
\href{https://catalog.data.gov/dataset?organization_type=City+Government\&organization=city-of-bloomington\&_organization_limit=0}{city
  of Bloomington, Indiana makes available a number of datasets there}.

We will use traffic citations data for 2016.

To start, let's create a separate directory for this project and
download the CSV data:

\begin{lstlisting}{bash}
$ cd ~/projects/i524
$ mkdir btown-citations
$ cd btown-citations
$ wget https://data.bloomington.in.gov/dataset/c543f0c1-1e37-46ce-a0ba-e0a949bd248a/resource/24841976-fd35-4483-a2b4-573bd1e77cfb/download/2016-first-quarter-citations.csv
\end{lstlisting}

Depending on your directory organization, the above might be slightly
different for you.

If you go to the link to data.gov for Bloomington above, you will see
that the citations data is organized per quarter, so there are a total
of four files. Above, we downloaded the data for the first quarter. Go
ahead and download the remaining three files with \texttt{wget}.

In this example, we will use three modules, \texttt{numpy},
\texttt{pandas} and \texttt{matplotlib}. If you set up
\texttt{virtualenv} as described in the
Python tutorial \textless{}python\_intro\textgreater{}, the first two of
these are already installed for you. To install \texttt{matplotlib},
make sure you've activated your \texttt{virtualenv} and use
\texttt{pip}:

\begin{lstlisting}{bash}
$ source ~/ENV/bin/activate
$ pip install matplotlib
\end{lstlisting}

If you are using a different distribution of Python, you will need to
make sure that all three of these modules are installed.

\subsubsection{Load Data in Pandas}\label{load-data-in-pandas}

From the same directory where you saved the citations data, let's start
the Python interpreter and load the citations data for Q1 2016

\begin{lstlisting}
$ python
>>> from __future__ import division, print_function
>>> import numpy as np
>>> import pandas as pd
>>> import matplotlib.pyplot as plt
>>> data = pd.read_csv('2016-first-quarter-citations.csv')
\end{lstlisting}
% $

If the first \texttt{import} statement seems confusing, take a look at
the Python tutorial \textless{}python\_intro\textgreater{}. The next
three \texttt{import} statements load each of the modules we will use in
this example. The final line uses Pandas' \verb|read_csv| function to
load the data into a Pandas \texttt{DataFrame} data structure.

\subsubsection{Working with DataFrames}\label{working-with-dataframes}

You can verify that you are working with a \texttt{DataFrame} and use
some of its methods to take a look at the structure of the data as
follows:

\begin{lstlisting}
>>> type(data)
<class 'pandas.core.frame.DataFrame'>
>>> data.index
Int64Index([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
...
197, 198, 199, 200, 201, 202, 203, 204, 205, 206],
dtype='int64', length=200)
>>> data.columns
Index([u'Citation Number', u'Date Issued', u'Time Issued', u'Location ',
u'District', u'Cited Person Age', u'Cited Person Sex',
u'Cited Person Race', u'Offense Code', u'Offense Description',
u'Officer Age', u'Officer Sex', u'Officer Race'],
dtype='object')
>>> data.dtypes
Citation Number                object
Date Issued                    object
Time Issued                    object
Location                       object
District                       object
Cited Person Age              float64
Cited Person Sex               object
Cited Person Race              object
Offense Code                   object
Offense Description            object
Officer Age                   float64
Officer Sex                    object
Officer Race                   object
dtype: object
>>> data.shape
(200, 15)
\end{lstlisting}

As you can see from the \texttt{columns} field, when the CSV file was
read, the header line was used to populate the name of the columns in
the \texttt{DataFrame}. In addition, you will notice that
\verb|read_csv| correctly inferred the data type of some columns like
\emph{Age}, but not of others like \emph{Date Issued} and \emph{Time
Issued}. \verb|read_csv| is a very customizable function and in
general, you can correct issues like this using the \texttt{dtype} and
\texttt{converters} parameters. In this specific case, it makes more
sense to combine the \emph{Date Issued} and \emph{Time Issued} columns
into a new column containing a time stamp. We will see how to do this
shortly.

You can also look at the data itself with the \texttt{DataFrame}'s
\texttt{head()} and \texttt{tail()} methods:

\begin{lstlisting}
>>> data.head()
<Output omitted for brevity>
>>> data.tail()
<Output omitted for brevity>
\end{lstlisting}

In addition to letting you examine your data easily, \texttt{DataFrame}s
have methods that help you deal with missing values:

\begin{lstlisting}
>>> data = data.dropna(how='any')
>>> data.shape
\end{lstlisting}

Adding columns to the data is also easy. Here, we add two columns.
First, a
\href{https://docs.python.org/2/library/datetime.html}{datetime} column
that is a combination of the \texttt{Date\ Issued} and
\texttt{Time\ Issued} columns originally in the data. Second, a column
identifying what day of the week each citation was given. To understand
this example better, take a look at the Python docs for the
\texttt{strptime} and \texttt{strftime} functions in the
\texttt{datetime} module linked above.

\begin{lstlisting}
>>> from datetime import datetime
>>> data['DateTime Issued'] = data.apply(
...  lambda row: datetime.strptime(row['Date Issued'] + ':' + row['Time Issued'], '%m/%d/%y:%I:%M %p'), axis=1
... )
>>> data.columns
>>> data['Day of Week Issued'] = data.apply(
...  lambda row: datetime.strftime(row['DateTime Issued'], '%A'), axis=1
... )
\end{lstlisting}

\subsubsection{Plotting with Matplotlib and
NumPy}\label{plotting-with-matplotlib-and-numpy}

Let's say we want to see how many citations were given each day of the
week. We gather the data first:

\begin{lstlisting}
>>> days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
>>> dow_data = [days.index(dow) for dow in data['Day of Week Issued']]
>>> dow_data
<Output omitted for brevity>
\end{lstlisting}

Then we use \texttt{matplotlib} to plot it:

\begin{lstlisting}
>>> fig = plt.figure()
>>> ax = fig.add_subplot(1, 1, 1)
>>> plt.hist(dow_data, bins=len(days))
>>> plt.xticks(range(len(days)), days)
>>> plt.show()
\end{lstlisting}

You should see something like this on your screen:

\includegraphics[width=4.16667in]{dow.png}

\subsubsection{\texorpdfstring{More \emph{DataFrame} Manipulation and
Plotting}{More DataFrame Manipulation and Plotting}}\label{more-dataframe-manipulation-and-plotting}

\texttt{DataFrame}s and \texttt{numpy} give us other ways to manipulate
data. For example, we can plot a histogram of the ages of violators like
this:

\begin{lstlisting}
>>> ages = data['Cited Person Age'].astype(int)
>>> fig = plt.figure()
>>> ax = fig.add_subplot(1, 1, 1)
>>> plt.hist(ages, bins=np.max(ages) - np.min(ages))
>>> plt.show()
\end{lstlisting}

\includegraphics[width=4.16667in]{ages.png}

Surprisingly, we see some 116 year-old violators! This is probably an
error in the data, so we can remove these data points easily and plot
the histogram again:

\begin{lstlisting}
>>> ages = ages[ages < 100]
>>> fig = plt.figure()
>>> ax = fig.add_subplot(1, 1, 1)
>>> plt.hist(ages, bins=np.max(ages) - np.min(ages))
>>> plt.show()
\end{lstlisting}

\includegraphics[width=4.16667in]{ages-filtered.png}

\subsubsection{Saving Plots to PDF}\label{saving-plots-to-pdf}

Oftentimes, you will want to save your \texttt{matplotlib} graph as a
PDF or an SVG file instead of just viewing it on your screen. For both,
we need to create a \texttt{figure} and plot the histogram as before:

\begin{lstlisting}
>>> fig = plt.figure()
>>> ax = fig.add_subplot(1, 1, 1)
>>> plt.hist(ages, bins=np.max(ages) - np.min(ages))
\end{lstlisting}

Then, instead of calling \texttt{plt.show()} we can invoke
\texttt{plt.savefig()} to save as SVG:

\begin{lstlisting}
>>> plt.savefig('hist.svg')
\end{lstlisting}

If we want to save the figure as PDF instead, we need to use the
\texttt{PdfPages} module together with \texttt{savefig()}:

\begin{lstlisting}
>>> import matplotlib.patches as mpatches
>>> from matplotlib.backends.backend_pdf import PdfPages
>>> pp = PdfPages('hist.pdf')
>>> fig.savefig(pp, format='pdf')
>>> pp.close()
\end{lstlisting}

\subsubsection{Next Steps and Exercises}\label{next-steps-and-exercises}

There is a lot more to working with \texttt{pandas}, \texttt{numpy} and
\texttt{matplotlib} than we can show you here, but hopefully this
example has piqued your curiosity.

Don't worry if you don't understand everything in this example. For a
more detailed explanation on these modules and the examples we did,
please take a look at the tutorials below. The \texttt{numpy} and
\texttt{pandas} tutorials are mandatory if you want to be able to use
these modules, and the \texttt{matplotlib} gallery has many useful code
examples.

\subsection{Summary of Useful
Libraries}\label{summary-of-useful-libraries}

\subsubsection{Numpy}\label{s:numpy}

  \URL{http://www.numpy.org/}

According to the Numpy Web page ``NumPy is a package for scientific
computing with Python. It contains a powerful N-dimensional array
object, sophisticated (broadcasting) functions, tools for integrating
C/C++ and Fortran code, useful linear algebra, Fourier transform, and
random number capabilities''.

Tutorial:
\url{https://docs.scipy.org/doc/numpy-dev/user/quickstart.html}

\subsubsection{MatplotLib}\label{matplotlib}

  \URL{http://matplotlib.org/}

According the the Matplotlib Web page, ``matplotlib is a python 2D
plotting library which produces publication quality figures in a variety
of hardcopy formats and interactive environments across platforms.
matplotlib can be used in python scripts, the python and ipython shell
(ala MATLAB* or Mathematica), web application servers, and six
graphical user interface toolkits.''

Matplotlib Gallery: \url{http://matplotlib.org/gallery.html}

\subsubsection{Pandas}\label{pandas}

  \URL{http://pandas.pydata.org/}

According to the Pandas Web page, ``Pandas is a library library
providing high-performance, easy-to-use data structures and data
analysis tools for the Python programming language.''

In addition to access to charts via matplotlib it has elementary
functionality for conduction data analysis. Pandas may be very suitable
for your projects.

Tutorial: \url{http://pandas.pydata.org/pandas-docs/stable/10min.html}

Pandas Cheat Sheet:
\url{https://github.com/pandas-dev/pandas/blob/master/doc/cheatsheet/Pandas_Cheat_Sheet.pdf}

\subsection{Big Data Libraries}\label{other-useful-libraries}

\subsubsection{Scipy}\label{s:scipy}

  \URL{https://www.scipy.org/}

According to the Web page, SciPy (pronounced \textit{Sigh Pie}) is a
Python-based ecosystem of open-source software for mathematics, science,
and engineering. In particular, these are some of the core packages:

\begin{itemize}
\item NumPy
\item IPython
\item Pandas
\item Matplotlib
\item Sympy
\item SciPy library
\end{itemize}

It is thus an agglomeration of useful pacakes and will prbably sufice
for your projects in case you use Python.

\subsubsection{ggplot}\label{ggplot}

  \URL{http://ggplot.yhathq.com/}

According to the ggplot python Web page ggplot is a plotting system for
Python based on R's ggplot2. It allows to quickly generate some plots
quickly with little effort. Often it may be easier to use than
matplotlib directly.

\subsubsection{seaborn}\label{seaborn}

\URL{http://www.data-analysis-in-python.org/t_seaborn.html}

The good library for plotting is called seaborn which is build on top of
matplotlib. It provides high level templates for common statistical
plots.

\begin{itemize}
\item
  Gallery:
  \url{http://stanford.edu/~mwaskom/software/seaborn/examples/index.html}
\item
  Original Tutorial:
  \url{http://stanford.edu/~mwaskom/software/seaborn/tutorial.html}
\item
  Additional Tutorial:
  \url{https://stanford.edu/~mwaskom/software/seaborn/tutorial/distributions.html}
\end{itemize}

Here are some examples from a previous class:

\URL{https://github.com/bigdata-i523/hid231/blob/master/experiment/seaborn/seaborn-exercises.ipynb}
\URL{https://github.com/bigdata-i523/hid231/blob/master/experiment/learning-jupyter/learning_jupyter_notebook.ipynb}

\begin{exercise}\label{E:ipynb-export}
Take these examples and create sections in latex that can be added to
the book. Describe the process.

1. export the ipynb as rst
2. use pandoc to export it to tex
3. do some cleanup on the tex files

Can this be automated with a cmd5 script such as
\begin{lstlisting}{bash}
cms ipynb [url=URL | file=FILE] --output FILENAME
\end{lstlisting}
\end{exercise}

\subsubsection{Bokeh}\label{bokeh}

Bokeh is an interactive visualization library with focus on web browsers
for display. Its goal is to provide a similar experience as D3.js

\begin{itemize}
\item
  URL: \url{http://bokeh.pydata.org/}
\item
  Gallery: \url{http://bokeh.pydata.org/en/latest/docs/gallery.html}
\end{itemize}

\subsubsection{pygal}\label{pygal}

Pygal is a simple API to produce graphs that can be easily embedded into
your Web pages. It contains annotations when you hover over data points.
It also allows to present the data in a table.

\URL{http://pygal.org/}

\subsubsection{Network and Graphs}\label{network-and-graphs}

\begin{itemize}

\item
  igraph: \url{http://www.pythonforsocialscientists.org/t_igraph.html}
\item
  networkx: \url{https://networkx.github.io/}
\end{itemize}

\subsubsection{REST}\label{rest}

\begin{itemize}

\item
  django REST FRamework \url{http://www.django-rest-framework.org/}
\item
  flask
  \url{https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask}
\item
  requests
  \url{https://realpython.com/blog/python/api-integration-in-python/}
\item
  urllib2
  \url{http://rest.elkstein.org/2008/02/using-rest-in-python.html} (not
  recommended)
\item
  web
  \url{http://www.dreamsyssoft.com/python-scripting-tutorial/create-simple-rest-web-service-with-python.php}
  (not recommended)
\item
  bottle \url{http://bottlepy.org/docs/dev/index.html}
\item
  falcon \url{https://falconframework.org/}
\item
  eve \url{http://python-eve.org/}
\item
  \url{https://code.tutsplus.com/tutorials/building-rest-apis-using-eve--cms-22961}
\end{itemize}

\section{Parsing Data}

Being able to parse data is an important activity in the data analysis
process. Not all data may be following a specific format and the data
may need to be extracted.

\subsection{notebook.md Parser}

We are using a notebook.md to communicate what students have done
throughout the semester. We like to make a simple cmd5 command that
parses the notebook.md file and check it upon correctness.

An example for a notebook.md file is located here

\URL{https://raw.githubusercontent.com/bigdata-i523/sample-hid000/master/notebook.md}

The following code may inspire you

\URL{https://github.com/bigdata-i523/hid203/tree/master/experiment}

We like to implement the following functionality and use docopts to
document the command.

\begin{lstlisting}
cms class notebook [--git=GITREPONAME] --verify hid

    verifies the correctness of the notebook.md file

cms class notebook [--git=GITREPONAME] --log

    displays the log of the notebook.md

cms class notebook [--git=GITREPONAME] --history

    displays a true or false for each week since the first occurance
    of the notebook.md file in the git repository
\end{lstlisting}

\begin{exercise}\label{E:notebook-md.1}
  Write a notebook.md parser
\end{exercise}

\begin{exercise}\label{E:notebook-md.2}
  How can this command be generalized to provide not only information
  for a student but to provide information for the class. Example: can
  we identify preferred days of when the notebooks are checked in. Can
  we identify a list of students that have not updated the notebok for
  a week?  Can we identify the list of student s that have updated the
  notebook for a week?
\end{exercise}

\subsection{Video Length}

The Latex source of this class contains a macro to include videos.

Given a \LaTeX~file, can you create a table that includes the names of
all videos in that file and sums up the total viewing time. Previously
the document was stored in RST and the code from a previous student
may inspire you. Can you recreate it for \LaTeX?

\URL{https://github.com/bigdata-i523/hid107/blob/master/cloudmesh/bar/command/mycommand.py}

\begin{lstlisting}
cms class video list FILENAME --output=[tabular|longtable|csv|txt]

    prints the videolist in the given format. txt means it is just ASCII
\end{lstlisting}

\begin{comment}
The previous work even summarized the video length by chapter.

see: https://piazza.com/class/j5wll7vzylg25j?cid=325
\end{comment}

\begin{exercise}
Write a tool that extracts the information for video length.
\end{exercise}

\begin{exercise}
Write a tool that finds all youtube urls that are not in a video latex
macro.
\end{exercise}

\subsection{Dask}
\index{Dask}

Many times operations need to be done on data in parallel to utilize
modern processor architectures.

Dask provides a \textit{dynamic task scheduling} which is optimized for
computation. It is similar to other frameworks such as Airflow, Luigi,
Celery, or Make. However it is specializing in optimized interactive
computational workloads.

Furthermore, Dask targets Big Data \textit{collections} such as parallel
arrays, dataframes, and lists. These collections ar commonly found in
NumPy, Pandas, or Python iterators to larger-than-memory or
distributed environments. While using the Dask implementation we can
replace the original imports from the appropriate framework, replace
them with Dask imports and implicitly use parallel collections that
utilize internally the dynamic task schedulers.

More information can be found at:

\URL{https://dask.pydata.org}

\begin{exercise}
Conduct a performance study that showcases the difference of doing
parallel calculations in Dask, calculations in a framework such as
SciPy, and regular unthreaded python code.
\end{exercise}


text:
package statistics.db;

import java.util.ArrayList;
import java.util.List;
import statistics.model.shape.ShapeConfiguration;
import statistics.model.shape.ShapeLevel;
import statistics.model.shape.file.ShapefileConfiguration;
import statistics.model.shape.file.ShapefileLevel;
import statistics.store.shapes.IShapeConfigRepository;

/**
 *
 * @author Andre Matos
 */
public class ShapeConfigRepository implements IShapeConfigRepository {

    public ShapeConfigRepository(){}

    public ShapeConfiguration getShapeConfiguration(int sourceId, int indicatorId, String geoLevel) {

        List<ShapeLevel> levels = new ArrayList<ShapeLevel>();
        levels.add(new ShapefileLevel("NUTS1", "NUTS1\\nuts1.shp"));
        levels.add(new ShapefileLevel("NUTS2", "NUTS2\\nuts2.shp"));
        levels.add(new ShapefileLevel("NUTS3", "NUTS3\\nuts3.shp"));
        levels.add(new ShapefileLevel("District", "Distritos\\distritos.shp"));
        levels.add(new ShapefileLevel("Municipality", "Concelhos\\concelhos.shp"));
        levels.add(new ShapefileLevel("Parish", "Freguesias\\freguesias.shp"));

        return new ShapefileConfiguration(levels, "D:\\Dropbox\\My Dropbox\\Tese\\shapefiles\\processed");
    }
}


text:
(function() {
    function HomeCtrl(Message, Room, $uibModal) {
        HomeCtrl.activeRoom = null;
        this.activeRoomName = "Choose a Room";
        this.activeRoomMessages = [];
        this.roomList = Room.all;

        this.changeRoom = function(roomId, indexNum){
            this.activeRoom = this.roomList[indexNum];
            this.activeRoomName = this.activeRoom.$value;
            this.activeRoomId = roomId;
            this.activeRoomMessages = Message.getByRoomId(roomId);
        };

        this.showRoomModal = function() {
            var newRoomInstance = $uibModal.open({
                templateUrl: "/templates/createRoomTemp.html",
                controller: "CreateCtrl as createRoom",
                bindToController: true,
                size: 'lg'
            });
            newRoomInstance.result.then(function(){
                alert("New chat room created!");
            });
        };

        this.send = function(newMessage) {
            Message.send(newMessage);
        };
    }

    angular
        .module('blocChat')
        .controller('HomeCtrl', ['Message', 'Room', '$uibModal', HomeCtrl]);
})();


text:
package com.nway.platform.wform.component.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.nway.platform.wform.component.BaseComponent;
import com.nway.platform.wform.design.db.datatype.DataType;

@Component("textarea")
public class TextareaComponent implements BaseComponent {

	@Autowired
	private DataType dataType;

	@Override
	public Object getValue(Object value) {

		return value;
	}

	@Override
	public String getDataType(int capacity) {

		return dataType.getForString(capacity);
	}

}


text:
package im.actor.model.api.rpc;
/*
 *  Generated by the Actor API Scheme generator.  DO NOT EDIT!
 */

import im.actor.model.droidkit.bser.Bser;
import im.actor.model.droidkit.bser.BserParser;
import im.actor.model.droidkit.bser.BserObject;
import im.actor.model.droidkit.bser.BserValues;
import im.actor.model.droidkit.bser.BserWriter;
import im.actor.model.droidkit.bser.DataInput;
import im.actor.model.droidkit.bser.DataOutput;
import im.actor.model.droidkit.bser.util.SparseArray;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
import com.google.j2objc.annotations.ObjectiveCName;
import static im.actor.model.droidkit.bser.Utils.*;
import java.io.IOException;
import im.actor.model.network.parser.*;
import java.util.List;
import java.util.ArrayList;
import im.actor.model.api.*;

public class ResponseGetOAuth2Params extends Response {

    public static final int HEADER = 0xc3;
    public static ResponseGetOAuth2Params fromBytes(byte[] data) throws IOException {
        return Bser.parse(new ResponseGetOAuth2Params(), data);
    }

    private String authUrl;

    public ResponseGetOAuth2Params(@NotNull String authUrl) {
        this.authUrl = authUrl;
    }

    public ResponseGetOAuth2Params() {

    }

    @NotNull
    public String getAuthUrl() {
        return this.authUrl;
    }

    @Override
    public void parse(BserValues values) throws IOException {
        this.authUrl = values.getString(1);
    }

    @Override
    public void serialize(BserWriter writer) throws IOException {
        if (this.authUrl == null) {
            throw new IOException();
        }
        writer.writeString(1, this.authUrl);
    }

    @Override
    public String toString() {
        String res = "tuple GetOAuth2Params{";
        res += "}";
        return res;
    }

    @Override
    public int getHeaderKey() {
        return HEADER;
    }
}


text:
#include <rw_driver.h>

// If the following macro is defined, then new header provides
// an implementation for operator new [] & delete []; undef them here
// so that the test can provide its own implementation for these operators
#undef _RWSTD_NO_OPERATOR_NEW_ARRAY
#undef _RWSTD_NO_OPERATOR_DELETE_ARRAY

#if defined (__IBMCPP__) && !defined (_RWSTD_NO_IMPLICIT_INCLUSION)
  // disable implicit inclusion to work around
  // a limitation in IBM VisualAge 5.0.2.0 (PR #26959)

#  define _RWSTD_NO_IMPLICIT_INCLUSION
#endif

#if !defined (_MSC_VER) || _MSC_VER > 1300
   // prevent out-of-line template definitions in .cc files from being
   // explicitly #included during the processing of library headers (faster
   // compilation) assumes that the test doesn't instantiate those templates
   // on types other than those they were explcitly instantiated on (will
   // have no effect if explicit instantiation is disabled or unsupported)
#  define _RWSTD_NO_TEMPLATE_DEFINITIONS
#endif   // !defined (_MSC_VER) || _MSC_VER > 1300

struct LifetimeChecker
{
    LifetimeChecker ();

    ~LifetimeChecker ();

} lifetime_check;

#ifdef _WIN32
   // bring in <windows.h> as a compilation test to exercise
   // any potential collisions with our declarations
#  include <windows.h>
#endif

// include <iostream> *after* the definition of the global
// lifetime_checker object to exercise initialization and
// lifetime dependencies
#include <iostream>   // for cin, cout, ...
#include <cstdlib>    // for free(), malloc()

// make sure using declarations work (the test doesn't actually exploit
// the fact that the names are introduced into the global namespace)

_USING (std::cin);
_USING (std::cout);
_USING (std::cerr);
_USING (std::clog);

#ifndef _RWSTD_NO_WCHAR_T

_USING (std::wcin);
_USING (std::wcout);
_USING (std::wcerr);
_USING (std::wclog);

#endif   // _RWSTD_NO_WCHAR_T

/**************************************************************************/

int init_new_calls;    // number of calls to operator new during initialization
int init_delete_calls; // and operator delete
int new_calls;         // total number of calls to operator new
int delete_calls;      // and operator delete

int rw_opt_no_global_dtors;         // for --no-global-dtors
int rw_opt_no_replacement_new;      // for --no-replacement-new
int rw_opt_no_replacement_delete;   // for --no-replacement-delete

/**************************************************************************/

LifetimeChecker::LifetimeChecker ()
{
    // iostreams not yet initialized here
    // <iostream> must be included before the definition of any
    // global object whose ctor uses any of the standard objects
}

LifetimeChecker::~LifetimeChecker ()
{
    if (rw_opt_no_global_dtors) {
        rw_note (0, 0, __LINE__, "test of global dtors disabled");
    }
    else {
        // objects must not be destroyed during program lifetime
        // try to use them in the destructor of a global object...
        std::cout << "[output from the dtor of a global object]";

        std::cout << "[cout]";
        std::cerr << "[cerr]";
        std::clog << "[clog]";

#ifndef _RWSTD_NO_WCHAR_T

        std::wcout << "[wcout]";
        std::wcerr << "[wcerr]";
        std::wclog << "[wclog]";

#endif   // _RWSTD_NO_WCHAR_T

    }
}

/**************************************************************************/

template <class charT>
void do_test (charT)
{
    rw_info (0, 0, 0, "checking whether objects are initialized");

    // objects must exist
    rw_assert (   0 != &std::cin  && 0 != &std::cout
               && 0 != &std::cerr && 0 != &std::clog,
               0, __LINE__, "std::cin, cout, cerr, or clog address 0");

    rw_info (0, 0, __LINE__, "checking tied stream objects");

    int new_0 = new_calls;

    // exercise 27.3.1, p2
    rw_assert (&std::cout == std::cin.tie (&std::cout), 0, __LINE__,
               "&std::cout == std::cin.tie (&std::cout)");
    rw_assert (0 == std::cout.tie (), 0, __LINE__,
               "0 == std::cout.tie ()");
    rw_assert (0 == std::cerr.tie (), 0, __LINE__,
               "0 == std::cerr.tie ()");
    rw_assert (0 == std::clog.tie (), 0, __LINE__,
               "0 == std::clog.tie ()");

    rw_assert (0 == new_calls - new_0, 0, __LINE__,
               "unexpected dynamic memory allocation");

    rw_info (0, 0, __LINE__, "checking for std::ios_base::unitbuf in flags");

    new_0 = new_calls;

    // exercise 27.3.1, p3
    rw_assert (!(std::ios::unitbuf & std::cout.flags ()), 0, __LINE__,
               "std::ios::unitbuf & std::cout.flags ()");

    // exercise 27.3.1, p5
    rw_assert (!!(std::ios::unitbuf & std::cerr.flags ()), 0, __LINE__,
               "std::ios::unitbuf & std::cerr.flags ()");

    // exercise 27.3.1, p6
    rw_assert (!(std::ios::unitbuf & std::clog.flags ()), 0, __LINE__,
               "std::ios::unitbuf & std::clog.flags ()");

    rw_assert (0 == new_calls - new_0, 0, __LINE__,
               "unexpected dynamic memory allocation");

#ifndef _RWSTD_NO_WCHAR_T

    rw_assert (   0 != &std::wcin  && 0 != &std::wcout
               && 0 != &std::wcerr && 0 != &std::wclog,
               0, __LINE__, "std::wcin, wcout, wcerr, or wclog address 0");

    new_0 = new_calls;

    // exercise 27.3.2, p2
    rw_assert (&std::wcout == std::wcin.tie (&std::wcout), 0, __LINE__,
               "&std::wcout == std::wcin.tie (&std::wcout)");
    rw_assert (0 == std::wcout.tie (), 0, __LINE__,
               "0 == std::wcout.tie ()");
    rw_assert (0 == std::wcerr.tie (), 0, __LINE__,
               "0 == std::wcerr.tie ()");
    rw_assert (0 == std::wclog.tie (), 0, __LINE__,
               "0 == std::wclog.tie ()");

    rw_assert (0 == new_calls - new_0, 0, __LINE__,
               "unexpected dynamic memory allocation");

    new_0 = new_calls;

    // exercise 27.3.2, p3
    rw_assert (!(std::wios::unitbuf & std::wcout.flags ()), 0, __LINE__,
               "std::wios::unitbuf & std::wcout.flags ()");

    // exercise 27.3.2, p5
    rw_assert (!!(std::wios::unitbuf & std::wcerr.flags ()), 0, __LINE__,
               "std::wios::unitbuf & std::wcerr.flags ()");

    // exercise 27.3.2, p6
    rw_assert (!(std::wios::unitbuf & std::wclog.flags ()), 0, __LINE__,
               "std::wios::unitbuf & std::wclog.flags ()");

    rw_assert (0 == new_calls - new_0, 0, __LINE__,
               "unexpected dynamic memory allocation");

#endif   // _RWSTD_NO_WCHAR_T

    std::cout << 0.0;
    std::cerr << 0.0;
    std::clog << 0.0;

#ifndef _RWSTD_NO_WCHAR_T

    std::wcout << 0.0;
    std::wcerr << 0.0;
    std::wclog << 0.0;

#endif   // _RWSTD_NO_WCHAR_T

    std::cout << std::endl;

    rw_info (0, 0, __LINE__, "exercising the ability to tie each stream "
             "to itself without causing a deadlock");

    std::cout.tie (&std::cout);
    std::cout << std::cout.tie () << ' ';

    std::cerr.tie (&std::cerr);
    std::cerr << std::cerr.tie () << ' ';

    std::clog.tie (&std::clog);
    std::clog << std::clog.tie () << ' ';

#ifndef _RWSTD_NO_WCHAR_T

    std::wcout.tie (&std::wcout);
    std::wcout << std::wcout.tie () << ' ';

    std::wcerr.tie (&std::wcerr);
    std::wcerr << std::wcerr.tie () << ' ';

    std::wclog.tie (&std::wclog);
    std::wclog << std::wclog.tie () << ' ';

#endif   // _RWSTD_NO_WCHAR_T

    rw_info (0, 0, __LINE__, "exercising the ability to tie stream objects "
             "together without causing a deadlock");

    std::cout.tie (&std::cerr);
    std::cout << std::cout.tie () << ' ';

    std::cerr.tie (&std::cout);
    std::cerr << std::cerr.tie () << ' ';

    std::clog.tie (&std::cout);
    std::clog << std::clog.tie () << ' ';

    // untie all streams to free any memory dynamically
    // allocated by calling tie (p) with (p != 0)
    std::cin.tie (0);
    std::cout.tie (0);
    std::cerr.tie (0);
    std::clog.tie (0);

#ifndef _RWSTD_NO_WCHAR_T

    std::wcout.tie (&std::wcerr);
    std::wcout << std::wcout.tie () << ' ';

    std::wcerr.tie (&std::wcout);
    std::wcerr << std::wcerr.tie () << ' ';

    std::wclog.tie (&std::wcout);
    std::wclog << std::wclog.tie () << ' ';

    // untie all streams to free any memory dynamically
    // allocated by calling tie (p) with (p != 0)
    std::wcin.tie (0);
    std::wcout.tie (0);
    std::wcerr.tie (0);
    std::wclog.tie (0);

#endif   // _RWSTD_NO_WCHAR_T

    std::cout << std::endl;
}

/**************************************************************************/

static int
run_test (int, char*[])
{
    const int new_0    = new_calls;
    const int delete_0 = delete_calls;

    do_test (char ());

    const int new_1    = new_calls - new_0;
    const int delete_1 = delete_calls - delete_0;

    // verify that test doesn't leak any dynamically allocated storage
    rw_assert (0 == new_1 - delete_1, 0, __LINE__,
               "test leaked %d blocks of memory", new_1 - delete_1);
    rw_assert (0 == init_new_calls, 0, __LINE__,
               "iostream initialization called operator new() %d times, "
               "0 expected", init_new_calls);

#ifdef _RWSTD_NO_REPLACEABLE_NEW_DELETE

    rw_warn (0, 0, __LINE__,
                "replacement operators new and delete not tested: "
                "_RWSTD_NO_REPLACEABLE_NEW_DELETE #defined");

#endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE

    return 0;
}

/**************************************************************************/

#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE

#  include <new>

#  ifndef _RWSTD_BAD_ALLOC
     // #define if not #defined by <new> (SunPro #includes its
     // own <new> regardless of the preprocessor search path)
#    define _RWSTD_BAD_ALLOC _STD::bad_alloc
#  endif   // _RWSTD_BAD_ALLOC

void* operator new (std::size_t n) _THROWS ((_RWSTD_BAD_ALLOC))
{
    static int recursion;

    ++recursion;

    if (rw_opt_no_replacement_new) {
        static int noted;   // prevent multiple notes

        rw_note (noted++, 0, __LINE__,
                 "test of replacement operator new disabled");
    }
    else if (1 != recursion) {
        // avoid calling rw_warn() except when it has something
        // to warn about in case operator new() is being called
        // by the compiler's C++ runtime (e.g., HP aCC 6.16)
        // when the driver hasn't been initialized yet (otherwise
        // the driver aborts)
        rw_warn (1 == recursion, 0, __LINE__,
                 "recursive call to replacement operator new()");
    }
    else {
        // initialize iostreams (verifies that initialization
        // succeeds and is complete even if it occurs recursively)
        static std::ios_base::Init io_initializer;

        // use cout from within new to verify that the static local
        // ios_base::Init properly initializes iostream objects
        std::cout << "[replacement operator new (" << n << ")]\n";
    }

    ++new_calls;

    --recursion;

    void* const ptr = std::malloc (n);
    if (!ptr)
        _THROW (_RWSTD_BAD_ALLOC ());

    return ptr;
}

void operator delete (void *ptr) _THROWS (())
{
    static int recursion;

    ++recursion;

    if (rw_opt_no_replacement_delete) {
        static int noted;   // prevent multiple notes

        rw_note (noted++, 0, __LINE__,
                 "test of replacement operator delete disabled");
    }
    else if (rw_warn (1 == recursion, 0, __LINE__,
                      "recursive call to replacement operator delete()")) {
        std::cout << "[replacement operator delete (" << ptr << ")]\n";
    }

    --recursion;

    if (ptr)
        ++delete_calls;

    std::free (ptr);
}

void* operator new[] (std::size_t n) _THROWS ((_RWSTD_BAD_ALLOC))
{
    return operator new (n);
}

void operator delete[] (void *p) _THROWS (())
{
    operator delete (p);
}

#endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE

/**************************************************************************/

int main (int argc, char *argv[])
{
    init_new_calls = new_calls;
    init_delete_calls = delete_calls;

    return rw_test (argc, argv, __FILE__,
                    "lib.iostream.objects",
                    0,   // no comment
                    run_test,
                    "|-no-global-dtors# "
                    "|-no-replacement-new# "
                    "|-no-replacement-delete#",
                    &rw_opt_no_global_dtors,
                    &rw_opt_no_replacement_new,
                    &rw_opt_no_replacement_delete);
}


text:
import { Promise } from 'rsvp';
import { MirageError } from 'ember-cli-mirage/assert';
import Response from './response';
import FunctionHandler from './route-handlers/function';
import ObjectHandler from './route-handlers/object';
import GetShorthandHandler from './route-handlers/shorthands/get';
import PostShorthandHandler from './route-handlers/shorthands/post';
import PutShorthandHandler from './route-handlers/shorthands/put';
import DeleteShorthandHandler from './route-handlers/shorthands/delete';
import HeadShorthandHandler from './route-handlers/shorthands/head';

const DEFAULT_CODES = { get: 200, put: 204, post: 201, 'delete': 204 };

function createHandler({ verb, schema, serializerOrRegistry, path, rawHandler, options }) {
  let handler;
  let args = [schema, serializerOrRegistry, rawHandler, path, options];
  let type = typeof rawHandler;

  if (type === 'function') {
    handler = new FunctionHandler(...args);
  } else if (type === 'object' && rawHandler) {
    handler = new ObjectHandler(...args);
  } else if (verb === 'get') {
    handler = new GetShorthandHandler(...args);
  } else if (verb === 'post') {
    handler = new PostShorthandHandler(...args);
  } else if (verb === 'put' || verb === 'patch') {
    handler = new PutShorthandHandler(...args);
  } else if (verb === 'delete') {
    handler = new DeleteShorthandHandler(...args);
  } else if (verb === 'head') {
    handler = new HeadShorthandHandler(...args);
  }
  return handler;
}

/**
 * @hide
 */
export default class RouteHandler {

  constructor({ schema, verb, rawHandler, customizedCode, options, path, serializerOrRegistry }) {
    this.verb = verb;
    this.customizedCode = customizedCode;
    this.serializerOrRegistry = serializerOrRegistry;
    this.handler = createHandler({ verb, schema, path, serializerOrRegistry, rawHandler, options });
  }

  handle(request) {
    return this._getMirageResponseForRequest(request)
      .then(mirageResponse => this.serialize(mirageResponse, request))
      .then(serializedMirageResponse => {
        return serializedMirageResponse.toRackResponse();
      });
  }

  _getMirageResponseForRequest(request) {
    let result;
    try {
      /*
       We need to do this for the #serialize convenience method. Probably is
       a better way.
     */
      if (this.handler instanceof FunctionHandler) {
        this.handler.setRequest(request);
      }

      result = this.handler.handle(request);
    } catch(e) {
      if (e instanceof MirageError) {
        result = new Response(500, {}, e);

      } else {
        let message = e.message || e;

        result = new Response(500, {}, {
          message,
          stack: `Mirage: Your ${request.method} handler for the url ${request.url} threw an error:\n\n${e.stack || e}`
        });
      }
    }

    return this._toMirageResponse(result);
  }

  _toMirageResponse(result) {
    let mirageResponse;

    return new Promise((resolve, reject) => {
      Promise.resolve(result)
        .then(response => {
          if (response instanceof Response) {
            mirageResponse = result;
          } else {
            let code = this._getCodeForResponse(response);
            mirageResponse = new Response(code, {}, response);
          }
          resolve(mirageResponse);
        })
        .catch(reject);
    });
  }

  _getCodeForResponse(response) {
    let code;
    if (this.customizedCode) {
      code = this.customizedCode;
    } else {
      code = DEFAULT_CODES[this.verb];
      // Returning any data for a 204 is invalid
      if (code === 204 && response !== undefined && response !== '') {
        code = 200;
      }
    }
    return code;
  }

  serialize(mirageResponse, request) {
    mirageResponse.data = this.serializerOrRegistry.serialize(mirageResponse.data, request);

    return mirageResponse;
  }
}


text:
<project name="EYES Demonstrator" default="compile" basedir=".">
	<description>
        EYES Demonstrator build file.
    </description>
	<!-- set global properties for this build -->

  <property environment="env"/>
  <property name="classpath" value="${env.TOSROOT}/contrib/eyes/tools/java:${env.TOSROOT}/contrib/eyes/tools/java/tinyos_eyes.jar:${env.TOSROOT}/tools/java:${env.TOSROOT}/tools/java/tinyos.jar:${env.TOSROOT}/contrib/eyes/tools/java/de/tub/eyes/apps/demonstrator/lib/forms-1.0.4.jar:${env.TOSROOT}/contrib/eyes/tools/java/de/tub/eyes/apps/demonstrator/lib/l2fprod-common-all.jar:${env.TOSROOT}/contrib/eyes/tools/java/de/tub/eyes/apps/demonstrator/lib/looks-1.2.2.jar:${env.TOSROOT}/contrib/eyes/tools/java/de/tub/eyes/apps/demonstrator/lib/jep-2.3.0.jar:${env.TOSROOT}/tools/java/jars/log4j-1.2.11.jar"/>

	<!-- uncomment next line to display CLASSPATH -->
  <!--<echo message="Using CLASSPATH = ${classpath}"/>-->

	<property name="src" location="./../../../../../" />
	<property name="dist" location="dist" />
	<property name="docdir" value="docs" />
	<!-- change this value to the name of the application -->
	<property name="app.name" value="EYES_Demonstrator"/>
        <property name="main.class" value="de.tub.eyes.apps.demonstrator.Demonstrator"/>

	<target name="init">
		<!-- Create the time stamp -->
		<tstamp />
	</target>

	<target name="compile" depends="init" description="compile the source ">
		<!-- Compile the java code from ${src} into ${build} -->
		<javac classpath="${classpath}" srcdir="${src}" destdir="${src}"/>
	</target>

	<target name="dist" depends="compile" description="generate the distribution">
		<!-- Create the distribution directory -->
		<mkdir dir="${dist}" />
		<jar jarfile="${dist}/${app.name}-${DSTAMP}.jar" basedir="${src}">
			<fileset dir="${src}">
				<include name="img/*"/>
			</fileset>
			<manifest>
				 <attribute name="Main-Class" value="${main.class}"/>
				 <attribute name="Class-Path" value="${jar-classpath}"/>
			</manifest>
		</jar>
		<copy todir="${dist}">
			<fileset dir="${src}">
			 <include name="lib/*.jar"/>
			</fileset>
		</copy>
	</target>

	<target name="run" depends="compile" description="run the EYES Demonstrator">
		<java classname="${main.class}" fork="true">
			<classpath>
				<pathelement path="${classpath}"/>
			</classpath>
                        <!--<jvmarg value="-Xrunhprof:cpu=times,heap=sites"/>-->
		</java>
	</target>

	<target name="doc" description="build the Javadocs">
		<javadoc destdir="${docdir}" author="true" version="true" use="true" windowtitle="EYES Demonstrator JavaDoc" access="private">
			<classpath>
				<pathelement path="${classpath}"/>
			</classpath>
			<packageset dir="${src}">
				<include name="de/**" />
			</packageset>
			<link href="http://java.sun.com/j2se/1.4.2/docs/api/"/>
		</javadoc>
	</target>

	<target name="clean" description="clean up">
		<!-- Delete the ${build} and ${docdir} directory trees and all .class files-->
		<delete>
			<fileset dir="${src}" includes="**/*.class" />
		</delete>
		<delete dir="${dist}" />
		<delete dir="${docdir}" />
	</target>

        <target name="debug" depends="compile" description="Debug Project">
                <fail unless="netbeans.home">This target can only run inside the NetBeans IDE.</fail>
                <nbjpdastart name="${app.name}" addressproperty="jpda.address" transport="dt_socket">
                        <classpath path="${classpath}"/>
                    <!-- Optional - If source roots are properly declared in project, should
                                        work without setting source path.
                                            <sourcepath path="debug.sourcepath"/> -->
                </nbjpdastart>
                <java fork="true" classname="${main.class}">
                        <jvmarg value="-Xdebug"/>
                        <jvmarg value="-Xnoagent"/>
                        <jvmarg value="-Djava.compiler=none"/>
                        <jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
                        <classpath path="${classpath}"/>
                </java>
        </target>
</project>


text:
set -e
WORKDIR=`pwd`

CONTAINER="name-of-the-container-you-built"

# Directory inside the container which will contain the analysis code
C_ANADIR="/home/jupyter/analysis"

# Unclear why exactly you need to run the notebook with `sh -c`
# Found this solution from ipython/ipython#7062 and ipython/docker-notebook#6
container_id=`docker run -d -v $WORKDIR:$C_ANADIR -p 8888 $CONTAINER sh -c "ipython notebook --port=8888 --ip=0.0.0.0 --no-browser --notebook-dir=$C_ANADIR"`

if hash boot2docker 2>/dev/null; then
    connect_string=`docker port $container_id 8888 | sed -e 's/0.0.0.0/'$(boot2docker ip)'/'`
else
    connect_string=`docker port $container_id 8888`
fi

echo "Once you are done run the following two commands to clean up:"
echo
echo "    docker stop "$container_id
echo "    docker rm "$container_id
echo
echo "To get started point your browser at: "$connect_string