<commit_before>﻿using System;
using System.Net.Sockets;
using System.Threading;
using UnityEngine;
using System.Linq;

public class KnobComponent : MonoBehaviour {

    const int numKnobs = 24;
    float[] knobs = new float[numKnobs];

    void Start()
    {
        Knobs.start(numKnobs);
    }

    void Update()
    {
        for (int i = 0; i < numKnobs; i++)
        {
            knobs[i] = Knobs.get(i);
            Shader.SetGlobalFloat("Knob" + i.ToString(), knobs[i]);
        }
    }

    void OnDestroy()
    {
        print(String.Join("\n", Enumerable.Range(0, numKnobs).Select(i => String.Format("{0}:\t{1}", i, Knobs.get(i))).ToArray()));
        Knobs.stop();
    }
}





public class Knobs
{
    private static int size;
    public static int[] knobs;

    private static Socket sock;

    private static Thread worker;
    private static bool running = false;

    public static void start(int numKnobs)
    {
        if (!running)
        {
            size = numKnobs;
            knobs = new int[size];

            try
            {
                sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                sock.Connect("localhost", 8008);

                worker = new Thread(new ThreadStart(readFromServer));
                worker.Start();

                running = true;
            }
            catch (SocketException e)
            {
                Console.WriteLine(e);
            }
        }
    }

    public static void stop()
    {
        if (running)
        {
            sock.Shutdown(SocketShutdown.Both);
            sock.Close();
            running = false;
        }
    }

    public static float get(int index)
    {
        return get(index, 0, 1);
    }

    public static float get(int index, float max)
    {
        return get(index, 0, max);
    }

    public static float get(int index, float min, float max)
    {
        float value = (float)knobs[index] / 127.0f;
        return (1 - value) * min + value * max;
    }


    private static void readFromServer()
    {
        byte[] sockBuffer = new byte[size];

        try
        {
            while (running)
            {
                if (sock.Receive(sockBuffer, size, SocketFlags.None) > 0)
                {
                    for (int i = 0; i < size; i++)
                    {
                        knobs[i] = sockBuffer[i];
                    }<commit_msg>Removes explicit private from function definition<commit_after>﻿using System;
using System.Net.Sockets;
using System.Threading;
using UnityEngine;
using System.Linq;

public class KnobComponent : MonoBehaviour {

    const int numKnobs = 24;
    float[] knobs = new float[numKnobs];

    void Start()
    {
        Knobs.start(numKnobs);
    }

    void Update()
    {
        for (int i = 0; i < numKnobs; i++)
        {
            knobs[i] = Knobs.get(i);
            Shader.SetGlobalFloat("Knob" + i.ToString(), knobs[i]);
        }
    }

    void OnDestroy()
    {
        print(String.Join("\n", Enumerable.Range(0, numKnobs).Select(i => String.Format("{0}:\t{1}", i, Knobs.get(i))).ToArray()));
        Knobs.stop();
    }
}





public class Knobs
{
    private static int size;
    public static int[] knobs;

    private static Socket sock;

    private static Thread worker;
    private static bool running = false;

    public static void start(int numKnobs)
    {
        if (!running)
        {
            size = numKnobs;
            knobs = new int[size];

            try
            {
                sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                sock.Connect("localhost", 8008);

                worker = new Thread(new ThreadStart(readFromServer));
                worker.Start();

                running = true;
            }
            catch (SocketException e)
            {
                Console.WriteLine(e);
            }
        }
    }

    public static void stop()
    {
        if (running)
        {
            sock.Shutdown(SocketShutdown.Both);
            sock.Close();
            running = false;
        }
    }

    public static float get(int index)
    {
        return get(index, 0, 1);
    }

    public static float get(int index, float max)
    {
        return get(index, 0, max);
    }

    public static float get(int index, float min, float max)
    {
        float value = (float)knobs[index] / 127.0f;
        return (1 - value) * min + value * max;
    }


    static void readFromServer()
    {
        byte[] sockBuffer = new byte[size];

        try
        {
            while (running)
            {
                if (sock.Receive(sockBuffer, size, SocketFlags.None) > 0)
                {
                    for (int i = 0; i < size; i++)
                    {
                        knobs[i] = sockBuffer[i];
                    }
{'fraction_non_alphanumeric': 0.11147540983606558, 'fraction_numerical': 0.00819672131147541, 'mean_word_length': 1.517276946879835, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2988167', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1384, 'n_words': 358}