text:
/* iscannum.h */
/* Interface to Ghostscript number scanner */

/* Scan a number.  If the number consumes the entire string, return 0; */
/* if not, set *psp to the first character beyond the number and return 1. */
int scan_number(P5(const byte *sp, const byte *end, int sign, ref *pref,
  const byte **psp));


text:
(function($, Granite) {
    "use strict";

    function hexToRgb(hex) {
        return [
            parseInt(hex[1] + hex[2], 16),
            parseInt(hex[3] + hex[4], 16),
            parseInt(hex[5] + hex[6], 16)
        ];
    }

    $(window).adaptTo("foundation-registry").register("foundation.validation.validator", {
        selector: "[data-validation~='cqgems.customizingfield.color.grayscale']",
        validate: function(el) {
            var value = el.val();

            if (!value) {
                return;
            }

            var rgb = hexToRgb(value);

            if (rgb[0] !== rgb[1] || rgb[1] !== rgb[2]) {
                return Granite.I18n.get("The color needs to be grayscale, where R, G, B components have the same values.");
            }
        }
    });

})(Granite.$, Granite);

redpajama_set_name: RedPajamaGithub


text:
package net.happybrackets.device.config.template;

/**
 * This class provides a static function to generate a valid interfaces files with the provided ssid and psk
 *
 * This is a bit of a hack to give us some basic functionality we need without adopting a full blown templating library.
 *
 * In the future we might consider palming this off to a jvm based scripting language.
 *
 */
public class NetworkInterfaces {

    public static String newConfig(String ssid, String psk) {
        //Java, why can't I use multi-line strings? and what about heredocs!
        return "auto lo\n" +
                "\n" +
                "iface lo inet loopback\n" +
                "iface eth0 inet dhcp\n" +
                "\n" +
                "allow-hotplug wlan0\n" +
                "auto wlan0\n" +
                "\n" +
                "iface wlan0 inet dhcp\n" +
                "        wpa-ssid \"" + ssid + "\"\n" +
                "        wpa-psk \"" + psk + "\"";
    }
}


text:
namespace WebApi.HALight.UnitTests
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Newtonsoft.Json;
    using NUnit.Framework;
    using WebApi.HALight.Converters;

    [TestFixture]
    public class ResourceConverterFixture
    {
        public class UserResource : Resource
        {
            public string FirstName { get; set; }
            public List<string> Values { get; set; }
        }

        public class MetaResource : Resource
        {
            public string Meta { get; set; }
        }

        public class UserCollectionResource : CollectionResource<UserResource>
        {
            public MetaResource Meta { get; set; }

            public int MaximumCapacity { get; set; }
        }

        [TestCase]
        public void VerifyRoundtrip()
        {
            // Arrange
            var userResource = new UserResource()
            {
                FirstName = "Hans",
                Values = new List<string>()
                {
                    "One",
                    "Two"
                }
            };
            var userCollectionResource = new UserCollectionResource()
            {
                Meta = new MetaResource() { Meta = "MetaInfo" },
                MaximumCapacity = 10
            };

            userCollectionResource.Items.Add(userResource);

            userResource.Relations.Add(Link.CreateSelfLink("http://locahost/users/1"));

            userCollectionResource.Relations.Add(Link.CreateSelfLink("http://localhost/users"));
            userCollectionResource.Relations.Add(Link.CreateLink("admins", "http://locahost/users/admins"));
            userCollectionResource.Relations.Add(Link.CreateLink("user", "http://locahost/users/1"));

            // Act
            var serializedResources = JsonConvert.SerializeObject(userCollectionResource, new RelationsConverter(), new ResourceConverter());
            var deserializedResources = JsonConvert.DeserializeObject<UserCollectionResource>(serializedResources, new RelationsConverter(), new ResourceConverter());
            var serializedDeserializedResources = JsonConvert.SerializeObject(deserializedResources, new RelationsConverter(), new ResourceConverter());

            // Assert
            Assert.AreEqual(userCollectionResource.Relations, deserializedResources.Relations);
            Assert.AreEqual(userCollectionResource.Items.ElementAt(0).Relations, deserializedResources.Items.ElementAt(0).Relations);
            Assert.AreEqual(serializedResources, serializedDeserializedResources);
        }
    }
}


text:
'use strict';

define(['app'], function (app) {

    var injectParams = ['$http', '$q'];

    var customersFactory = function ($http, $q) {
        var serviceBase = '/api/dataservice/',
            factory = {};

        factory.getCustomers = function (pageIndex, pageSize) {
            return getPagedResource('customers', pageIndex, pageSize);
        };

        factory.getCustomersSummary = function (pageIndex, pageSize) {
            return getPagedResource('customersSummary', pageIndex, pageSize);
        };

        factory.getStates = function () {
            return $http.get(serviceBase + 'states').then(
                function (results) {
                    return results.data;
                });
        };

        factory.checkUniqueValue = function (id, property, value) {
            if (!id) id = 0;
            return $http.get(serviceBase + 'checkUnique/' + id + '?property=' + property + '&value=' + escape(value)).then(
                function (results) {
                    return results.data.status;
                });
        };

        factory.insertCustomer = function (customer) {
            return $http.post(serviceBase + 'postCustomer', customer).then(function (results) {
                customer.id = results.data.id;
                return results.data;
            });
        };

        factory.newCustomer = function () {
            return $q.when({ id: 0 });
        };

        factory.updateCustomer = function (customer) {
            return $http.put(serviceBase + 'putCustomer/' + customer.id, customer).then(function (status) {
                return status.data;
            });
        };

        factory.deleteCustomer = function (id) {
            return $http.delete(serviceBase + 'deleteCustomer/' + id).then(function (status) {
                return status.data;
            });
        };

        factory.getCustomer = function (id) {
            //then does not unwrap data so must go through .data property
            //success unwraps data automatically (no need to call .data property)
            return $http.get(serviceBase + 'customerById/' + id).then(function (results) {
                extendCustomers([results.data]);
                return results.data;
            });
        };

        function extendCustomers(customers) {
            var custsLen = customers.length;
            //Iterate through customers
            for (var i = 0; i < custsLen; i++) {
                var cust = customers[i];
                if (!cust.orders) continue;

                var ordersLen = cust.orders.length;
                for (var j = 0; j < ordersLen; j++) {
                    var order = cust.orders[j];
                    order.orderTotal = order.quantity * order.price;
                }
                cust.ordersTotal = ordersTotal(cust);
            }
        }

        function getPagedResource(baseResource, pageIndex, pageSize) {
            var resource = baseResource;
            resource += (arguments.length == 3) ? buildPagingUri(pageIndex, pageSize) : '';
            return $http.get(serviceBase + resource).then(function (response) {
                var custs = response.data;
                extendCustomers(custs);
                return {
                    totalRecords: parseInt(response.headers('X-InlineCount')),
                    results: custs
                };
            });
        }

        function buildPagingUri(pageIndex, pageSize) {
            var uri = '?$top=' + pageSize + '&$skip=' + (pageIndex * pageSize);
            return uri;
        }

        // is this still used???
        function orderTotal(order) {
            return order.quantity * order.price;
        };

        function ordersTotal(customer) {
            var total = 0;
            var orders = customer.orders;
            var count = orders.length;

            for (var i = 0; i < count; i++) {
                total += orders[i].orderTotal;
            }
            return total;
        };

        return factory;
    };

    customersFactory.$inject = injectParams;

    app.factory('customersService', customersFactory);

});


text: Simple, data-driven chat app using the EDMEAN.js framework.


text:
<!DOCTYPE html>

Pizza Guys Order Form

        <form id="myform">
            Name:

            <input type = "text" name = "name" placeholder = "your name" required>

            Address: #### Street Name...

            <input type = "text" name = "address" placeholder = "delivery address" size = 60 pattern = "[0-9]+\s[A-Za-z\s]+" required>

            Phone Number: 123-123-1234

            <input type = "text" name = "phoneNumber" placeholder = "123-123-1234" pattern="[1-9][0-9]{2}-[0-9]{3}-[0-9]{4}" required>

            Pizza Size

            <input type = "radio" name = "pizzasize" value = "large" checked>Large
            <input type = "radio" name = "pizzasize" value = "medium">Medium
            <input type = "radio" name = "pizzasize" value = "small">Small

            Pizza Toppings

            <input type = "checkbox" name = "toppings" value = "sausage">Sausage
            <input type = "checkbox" name = "toppings" value = "pepperoni">Pepperoni
            <input type = "checkbox" name = "toppings" value = "olives">Olives
            <input type = "checkbox" name = "toppings" value = "Onions">Onions

            <input type = "submit" value = "Place Order">
            <input type = "button" value = "clear" onclick = "clearAll()">

        </form>


text:
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <ros/ros.h>
#include <ros/package.h>
#include <ros/console.h>
#include <target_finder/target_locator.h>
#include <tf/transform_broadcaster.h>

using std::string;
using std::vector;

class callService
{
public:
  callService(ros::NodeHandle nh) : nh_(nh)
  {
    client_ = nh_.serviceClient<target_finder::target_locator>("TargetLocateService");
    ros::NodeHandle pnh("~");
    if (!pnh.getParam("roi_width", roi_width_))
    {
      roi_width_ = 1280;
    }
    if (!pnh.getParam("roi_height", roi_height_))
    {
      roi_height_ = 1024;
    }
    if (!pnh.getParam("optical_frame", optical_frame_))
    {
      optical_frame_ = "basler1_optical_frame";
    }
    setRequest();
  }
  bool callTheService();
  void copyResponseToRequest();
  void setRequest();

private:
  ros::NodeHandle nh_;
  ros::ServiceClient client_;
  target_finder::target_locator srv_;
  tf::TransformBroadcaster tf_broadcaster_;
  int roi_width_;
  int roi_height_;
  std::string optical_frame_;
};

void callService::copyResponseToRequest()
{
  setRequest();
  srv_.request.initial_pose.position.x = srv_.response.final_pose.position.x;
  srv_.request.initial_pose.position.y = srv_.response.final_pose.position.y;
  srv_.request.initial_pose.position.z = srv_.response.final_pose.position.z;
  srv_.request.initial_pose.orientation.x = srv_.response.final_pose.orientation.x;
  srv_.request.initial_pose.orientation.y = srv_.response.final_pose.orientation.y;
  srv_.request.initial_pose.orientation.z = srv_.response.final_pose.orientation.z;
  srv_.request.initial_pose.orientation.w = srv_.response.final_pose.orientation.w;
}
bool callService::callTheService()
{
  if (client_.call(srv_))
  {
    double x, y, z, qx, qy, qz, qw;
    x = srv_.response.final_pose.position.x;
    y = srv_.response.final_pose.position.y;
    z = srv_.response.final_pose.position.z;
    qx = srv_.response.final_pose.orientation.x;
    qy = srv_.response.final_pose.orientation.y;
    qz = srv_.response.final_pose.orientation.z;
    qw = srv_.response.final_pose.orientation.w;
    ROS_INFO("Pose: tx= %5.4lf  %5.4lf  %5.4lf quat= %5.3lf  %5.3lf  %5.3lf %5.3lf, cost= %5.3lf",
             srv_.response.final_pose.position.x, srv_.response.final_pose.position.y,
             srv_.response.final_pose.position.z, srv_.response.final_pose.orientation.x,
             srv_.response.final_pose.orientation.y, srv_.response.final_pose.orientation.z,
             srv_.response.final_pose.orientation.w, srv_.response.final_cost_per_observation);
    tf::Transform camera_to_target;
    tf::Quaternion quat(qx, qy, qz, qw);
    camera_to_target.setOrigin(tf::Vector3(x, y, z));
    camera_to_target.setRotation(quat);
    tf::StampedTransform stf(camera_to_target, ros::Time::now(), optical_frame_.c_str(), "target_frame");
    tf_broadcaster_.sendTransform(stf);
    return (true);
  }
  ROS_ERROR("Target Location Failure");
  return (false);
}
void callService::setRequest()
{
  srv_.request.roi.x_offset = 0;
  srv_.request.roi.y_offset = 0;
  srv_.request.roi.width = roi_width_;
  srv_.request.roi.height = roi_height_;
  srv_.request.initial_pose.position.x = 0.0;
  srv_.request.initial_pose.position.y = 0.1;
  srv_.request.initial_pose.position.z = 1.0;
  srv_.request.initial_pose.orientation.x = 1.0;
  srv_.request.initial_pose.orientation.y = 0.0;
  srv_.request.initial_pose.orientation.z = 0.0;
  srv_.request.initial_pose.orientation.w = 0.00000000001;
  srv_.request.allowable_cost_per_observation = 7.0;
}

int main(int argc, char** argv)
{
  ros::init(argc, argv, "call_service");
  ros::NodeHandle nh;
  callService call_service(nh);
  ros::Rate loop_rate(10);
  while (ros::ok())
  {
    if (call_service.callTheService())
    {
      call_service.copyResponseToRequest();
    }
    else
    {
      call_service.setRequest();
    }
    ros::spinOnce();
    loop_rate.sleep();
  }
}


text:
namespace autofill {

namespace risk_util {

namespace {

void PassRiskData(base::OnceCallback<void(const std::string&)> callback,
                  std::unique_ptr<risk::Fingerprint> fingerprint) {
  std::string proto_data, risk_data;
  fingerprint->SerializeToString(&proto_data);
  base::Base64Encode(proto_data, &risk_data);
  std::move(callback).Run(risk_data);
}

#if !defined(OS_ANDROID)
// Returns the containing window for the given |web_contents|. The containing
// window might be a browser window for a Chrome tab, or it might be an app
// window for a platform app.
ui::BaseWindow* GetBaseWindowForWebContents(
    content::WebContents* web_contents) {
  Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
  if (browser)
    return browser->window();

  gfx::NativeWindow native_window = web_contents->GetTopLevelNativeWindow();
  extensions::AppWindow* app_window =
      AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
          native_window);
  return app_window->GetBaseWindow();
}
#endif

}  // namespace

void LoadRiskData(uint64_t obfuscated_gaia_id,
                  content::WebContents* web_contents,
                  base::OnceCallback<void(const std::string&)> callback) {
  // No easy way to get window bounds on Android, and that signal isn't very
  // useful anyway (given that we're also including the bounds of the web
  // contents).
  gfx::Rect window_bounds;
#if !defined(OS_ANDROID)
  window_bounds = GetBaseWindowForWebContents(web_contents)->GetBounds();
#endif

  const PrefService* user_prefs =
      Profile::FromBrowserContext(web_contents->GetBrowserContext())
          ->GetPrefs();
  std::string charset = user_prefs->GetString(::prefs::kDefaultCharset);
  std::string accept_languages =
      user_prefs->GetString(::language::prefs::kAcceptLanguages);
  base::Time install_time = base::Time::FromTimeT(
      g_browser_process->metrics_service()->GetInstallDate());

  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  risk::GetFingerprint(
      obfuscated_gaia_id, window_bounds, web_contents,
      version_info::GetVersionNumber(), charset, accept_languages, install_time,
      g_browser_process->GetApplicationLocale(), GetUserAgent(),
      base::BindOnce(PassRiskData, std::move(callback)));
}

}  // namespace risk_util

}  // namespace autofill


text:
package org.apache.giraph.master;

import java.util.List;

import org.apache.giraph.aggregators.Aggregator;
import org.apache.giraph.bsp.CentralizedServiceMaster;
import org.apache.giraph.combiner.MessageCombiner;
import org.apache.giraph.conf.DefaultImmutableClassesGiraphConfigurable;
import org.apache.giraph.conf.MessageClasses;
import org.apache.giraph.graph.Computation;
import org.apache.giraph.graph.GraphState;
import org.apache.giraph.reducers.ReduceOperation;
import org.apache.giraph.worker.WorkerInfo;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.mapreduce.Mapper;

/**
 * Interface for defining a master vertex that can perform centralized
 * computation between supersteps. This class will be instantiated on the
 * master node and will run every superstep before the workers do.
 *
 * Communication with the workers should be performed via aggregators. The
 * values of the aggregators are broadcast to the workers before
 * vertex.compute() is called and collected by the master before
 * master.compute() is called. This means aggregator values used by the workers
 * are consistent with aggregator values from the master from the same
 * superstep and aggregator used by the master are consistent with aggregator
 * values from the workers from the previous superstep.
 */
public abstract class MasterCompute
    extends DefaultImmutableClassesGiraphConfigurable
    implements MasterAggregatorUsage, MasterGlobalCommUsage, Writable {
  /** If true, do not do anymore computation on this vertex. */
  private boolean halt = false;
  /** Master aggregator usage */
  private CentralizedServiceMaster serviceMaster;
  /** Graph state */
  private GraphState graphState;
  /**
   * Computation and MessageCombiner classes used, which can be
   * switched by master
   */
  private SuperstepClasses superstepClasses;

  /**
   * Must be defined by user to specify what the master has to do.
   */
  public abstract void compute();

  /**
   * Initialize the MasterCompute class, this is the place to register
   * aggregators.
   *
   * @throws InstantiationException
   * @throws IllegalAccessException
   */
  public abstract void initialize() throws InstantiationException,
    IllegalAccessException;

  /**
   * Retrieves the current superstep.
   *
   * @return Current superstep
   */
  public final long getSuperstep() {
    return graphState.getSuperstep();
  }

  /**
   * Get the total (all workers) number of vertices that
   * existed in the previous superstep.
   *
   * @return Total number of vertices (-1 if first superstep)
   */
  public final long getTotalNumVertices() {
    return graphState.getTotalNumVertices();
  }

  /**
   * Get the total (all workers) number of edges that
   * existed in the previous superstep.
   *
   * @return Total number of edges (-1 if first superstep)
   */
  public final long getTotalNumEdges() {
    return graphState.getTotalNumEdges();
  }

  /**
   * After this is called, the computation will stop, even if there are
   * still messages in the system or vertices that have not voted to halt.
   */
  public final void haltComputation() {
    halt = true;
  }

  /**
   * Has the master halted?
   *
   * @return True if halted, false otherwise.
   */
  public final boolean isHalted() {
    return halt;
  }

  /**
   * Get the mapper context
   *
   * @return Mapper context
   */
  public final Mapper.Context getContext() {
    return graphState.getContext();
  }

  /**
   * Get list of workers
   *
   * @return List of workers
   */
  public final List<WorkerInfo> getWorkerInfoList() {
    return serviceMaster.getWorkerInfoList();
  }

  /**
   * Set Computation class to be used
   *
   * @param computationClass Computation class
   */
  public final void setComputation(
      Class<? extends Computation> computationClass) {
    superstepClasses.setComputationClass(computationClass);
  }

  /**
   * Get Computation class to be used
   *
   * @return Computation class
   */
  public final Class<? extends Computation> getComputation() {
    // Might be called prior to classes being set, do not return NPE
    if (superstepClasses == null) {
      return null;
    }

    return superstepClasses.getComputationClass();
  }

  /**
   * Set MessageCombiner class to be used
   *
   * @param combinerClass MessageCombiner class
   */
  public final void setMessageCombiner(
      Class<? extends MessageCombiner> combinerClass) {
    superstepClasses.setMessageCombinerClass(combinerClass);
  }

  /**
   * Get MessageCombiner class to be used
   *
   * @return MessageCombiner class
   */
  public final Class<? extends MessageCombiner> getMessageCombiner() {
    // Might be called prior to classes being set, do not return NPE
    if (superstepClasses == null) {
      return null;
    }

    return superstepClasses.getMessageCombinerClass();
  }

  /**
   * Set incoming message class to be used
   *
   * @param incomingMessageClass incoming message class
   */
  @Deprecated
  public final void setIncomingMessage(
      Class<? extends Writable> incomingMessageClass) {
    superstepClasses.setIncomingMessageClass(incomingMessageClass);
  }

  /**
   * Set outgoing message class to be used
   *
   * @param outgoingMessageClass outgoing message class
   */
  public final void setOutgoingMessage(
      Class<? extends Writable> outgoingMessageClass) {
    superstepClasses.setOutgoingMessageClass(outgoingMessageClass);
  }

  /**
   * Set outgoing message classes to be used
   *
   * @param outgoingMessageClasses outgoing message classes
   */
  public void setOutgoingMessageClasses(
      MessageClasses<? extends WritableComparable, ? extends Writable>
        outgoingMessageClasses) {
    superstepClasses.setOutgoingMessageClasses(outgoingMessageClasses);
  }

  @Override
  public final <S, R extends Writable> void registerReducer(
      String name, ReduceOperation<S, R> reduceOp) {
    serviceMaster.getGlobalCommHandler().registerReducer(name, reduceOp);
  }

  @Override
  public final <S, R extends Writable> void registerReducer(
      String name, ReduceOperation<S, R> reduceOp, R globalInitialValue) {
    serviceMaster.getGlobalCommHandler().registerReducer(
        name, reduceOp, globalInitialValue);
  }

  @Override
  public final <T extends Writable> T getReduced(String name) {
    return serviceMaster.getGlobalCommHandler().getReduced(name);
  }

  @Override
  public final void broadcast(String name, Writable object) {
    serviceMaster.getGlobalCommHandler().broadcast(name, object);
  }

  @Override
  public final <A extends Writable> boolean registerAggregator(
    String name, Class<? extends Aggregator<A>> aggregatorClass)
    throws InstantiationException, IllegalAccessException {
    return serviceMaster.getAggregatorTranslationHandler().registerAggregator(
        name, aggregatorClass);
  }

  @Override
  public final <A extends Writable> boolean registerPersistentAggregator(
      String name,
      Class<? extends Aggregator<A>> aggregatorClass) throws
      InstantiationException, IllegalAccessException {
    return serviceMaster.getAggregatorTranslationHandler()
        .registerPersistentAggregator(name, aggregatorClass);
  }

  @Override
  public final <A extends Writable> A getAggregatedValue(String name) {
    return serviceMaster.getAggregatorTranslationHandler()
        .<A>getAggregatedValue(name);
  }

  @Override
  public final <A extends Writable> void setAggregatedValue(
      String name, A value) {
    serviceMaster.getAggregatorTranslationHandler()
        .setAggregatedValue(name, value);
  }

  /**
   * Call this to log a line to command line of the job. Use in moderation -
   * it's a synchronous call to Job client
   *
   * @param line Line to print
   */
  public void logToCommandLine(String line) {
    serviceMaster.getJobProgressTracker().logInfo(line);
  }

  public final void setGraphState(GraphState graphState) {
    this.graphState = graphState;
  }

  public final void setMasterService(CentralizedServiceMaster serviceMaster) {
    this.serviceMaster = serviceMaster;
  }

  public final void setSuperstepClasses(SuperstepClasses superstepClasses) {
    this.superstepClasses = superstepClasses;
  }
}