Jump to content

fiveworlds

Senior Members
  • Posts

    1897
  • Joined

  • Last visited

Posts posted by fiveworlds

  1. Has anyone here used Blazor and know if it is worthwhile learning? Blazor appears to be an attempt to replace JavaScript with .net core C#.

    https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor

  2. Quote

    There is slight difference between C++,

    There really isn't though c++ is more complicated with header files etc. Private variables are accessible by subclasses, protected variables/methods can only be called by classes in the same package or sub packages (folder).

    namespace second_space {
    	class Box {
    		private:
    			class B {
    				protected:
    					double length = 10;
    			};
    		public:
    			class Car : B {
    			public:
    				double dimensions() {
    					return B::length;
    				};
    			};
    			double height=4;
    			double getDimensions(void);
    		protected:
    			double breadth = 7;
    	};
    	double Box::getDimensions() {
    		Car car = Car();
    		return car.dimensions();
    	}
    	class ExtendedBox:Box {
    		public:
    			double test(void);
    	};
    	double ExtendedBox::test() {
    		return breadth;
    	}
    	class Bar {
    		double test(void);
    	};
    	double Bar::test(void) {
    		Box box = Box();
    		return box.height;
    		//return box.breadth; compile error
    	}
    }
    
    int main() {
    	// Calls function from first name space.
    	second_space::Box box;
    	cout << box.getDimensions() << endl;
    	second_space::ExtendedBox extendedBox;
    	cout << extendedBox.test() << endl;
    	Bar::ExtendedCar extendedCar;
    	cout << extendedCar.test() << endl;
    	return 0;
    }
    Quote

    Python does not support access protection as C++/Java/C# does. Everything is public.

    Everything is public in Java, C# etc via reflection... I don't see the difference they all use some form of obfuscation in their own proprietary way.

     

     

  3. Quote

    // protected methods can be called only from subclass of this class or from class itself

    Not correct it doesn't have to be a subclass, protected methods can only be called by classes in the same package or sub packages (folder).

    There you go nice python example

    # coding = "utf-8"
    class Npc(object):
    
        ##########################################
        #   Static Attributes
        #########################################
    
        # All instances of the Npc class will only ever have one instance of a Static variable
        static_npc_database = "game_npc_list"
        _max_walk_vertical = 12
        __max_walk_horizontal = 10
        max_run_vertical = 35
        max_run_horizontal = 30
    
        ##########################################
        #   Static Getters
        ##########################################
    
        @staticmethod
        def _get_max_walk_horizontal():
            """ static private methods can be called only from instances of this class
            :return the top secret of Npc """
            return Npc.__max_walk_horizontal
    
        @staticmethod
        def __get_max_walk_vertical():
            """ static protected methods can be called only from classes/subclasses in the same package/module
            :return the secret of Npc """
            return Npc._max_walk_vertical
    
        @staticmethod
        def get_max_run_horizontal():
            """ public static methods can be called from all classes
            :return the top secret of Npc """
            return Npc.max_run_horizontal
    
        @staticmethod
        def get_max_run_vertical():
            """ public static methods can be called from all classes
            :return the secret of Npc """
            return Npc.max_run_vertical
    
        ##########################################
        #   Static Setters
        ##########################################
    
        @staticmethod
        def _set_max_walk_horizontal(new_max_walk_horizontal):
            """ static private methods can be called only from instances of this class
            :except not string or null """
            if Npc.string_validator(new_max_walk_horizontal):
                Npc.__max_walk_horizontal = new_max_walk_horizontal
    
        @staticmethod
        def __set_max_walk_vertical(new_max_walk_vertical):
            """ static protected methods can be called only from classes/subclasses in the same package/module
            :except not string or null """
            if Npc.string_validator(new_max_walk_vertical):
                Npc._max_walk_vertical = new_max_walk_vertical
    
        @staticmethod
        def _set_max_run_horizontal(new_max_run_horizontal):
            """ static private methods can be called only from instances of this class
            :except not string or null """
            if Npc.string_validator(new_max_run_horizontal):
                Npc.__max_run_horizontal = new_max_run_horizontal
    
        @staticmethod
        def __set_max_run_vertical(new_max_run_vertical):
            """ static protected methods can be called only from classes/subclasses in the same package/module
            :except not string or null """
            if Npc.string_validator(new_max_run_vertical):
                Npc._max_run_vertical = new_max_run_vertical
    
        #########################################
        #  Static Methods
        ##########################################
    
        @staticmethod
        def string_validator(variable):
            """
                Validates that a variable is a string
                :param variable: The string
                :return: The result
                :except: Variable is not a string
            """
            if variable is None or type(variable) != str:
                raise Exception("Npc cannot have a null/(non string) variable")
            else:
                return True
    
        @staticmethod
        def int_validator(variable):
            """
                Validates that a variable is an int
                :param variable: The int
                :return: The result
                :except: Variable is not an int
            """
            if variable is None or type(variable) != int:
                raise Exception("Npc cannot have a null/(non int) variable")
            else:
                return True
    
        @staticmethod
        def _calculate_movement_value(value, max_value):
            if Npc.int_validator(value):
                if value < max_value:
                    return value
                elif value > 0:
                    return max_value
                else:
                    return -max_value
    
        #######################
        #  constructor
        #######################
    
        def __init__(self,
                     first_name: str = "Santa",
                     x_position: int = 100,
                     y_position: int = 100,
                     max_walk_vertical: int = None,
                     max_walk_horizontal: int = None,
                     max_run_vertical: int = None,
                     max_run_horizontal: int = None):
            """
                Npc Constructor (non static variables are defined here)
                :type first_name: str
                :param first_name: The Npc's first-name.
                :type x_position: int
                :param x_position: The Npc's x position.
                :type y_position: int
                :param y_position: The Npc's y position.
            """
            if Npc.string_validator(first_name):
                # this is public attribute/member of object/class
                self.firstName = first_name
            if Npc.int_validator(x_position):
                # this is protected attribute/member of object/class
                # (accessible from this class and subclasses of this class)
                self._x_position = x_position
            if Npc.int_validator(y_position):
                # this is private attribute/member of object/class
                # (accessible only from this class code: actually never in this example)
                self.__y_position = y_position
    
            if max_walk_vertical is not None and max_walk_vertical < Npc._max_walk_vertical:
                self.max_walk_vertical = max_walk_vertical
            else:
                self.walk_vertical = Npc._max_walk_vertical
            if max_walk_horizontal is not None and max_walk_horizontal < Npc.__max_walk_horizontal:
                self.max_walk_horizontal = max_walk_horizontal
            else:
                self.max_walk_horizontal = Npc.__max_walk_horizontal
    
            if max_run_vertical is not None and max_run_vertical < Npc.max_run_vertical:
                self.max_run_vertical = max_run_vertical
            else:
                self.max_run_vertical = Npc.max_run_vertical
    
            if max_run_horizontal is not None and max_run_horizontal < Npc.max_run_horizontal:
                self.max_run_horizontal = max_run_horizontal
            else:
                self.max_run_horizontal = Npc.max_run_horizontal
    
        #########################################
        #  Getters Methods
        ##########################################
    
        def get_first_name(self):
            """ yet another public method
            :return the first name of Npc """
            return self.firstName
    
        def _get_x_position(self):
            """ protected methods can be called only from classes/subclasses in the same package/module
                :return the secret of Npc """
            return self._x_position
    
        def __get_y_position(self):
            """ private methods can be called only from this class
            :return the top secret of Npc """
            return self.__y_position
    
        #########################################
        #  Setter Methods
        ##########################################
    
        def set_first_name(self, first_name: str):
            """ public method can be executed from anywhere (with special careful attention from separate thread,
                than the main thread!)
                :except not string """
            if Npc.string_validator(first_name):
                self.firstName = first_name
    
        def _set_x_position(self, new_x_position):
            """ protected methods can be called only from classes/subclasses in the same package/module
                :return the secret of Npc """
            if Npc.int_validator(new_x_position):
                self._x_position = new_x_position
    
        def __set_y_position(self, new_y_position):
            """ private methods can be called only from this class
            :return the top secret of Npc """
            if Npc.int_validator(new_y_position):
                self.__y_position = new_y_position
    
        #################################################
        #  Methods
        #################################################
    
        def walk(self, vertical=0, horizontal=0):
            """ An Npc should be able to walk
                :param vertical: The distance to walk vertical
                :param horizontal: The distance to walk horizontal """
    
            self.__set_y_position(
                self.__get_y_position() + self._calculate_movement_value(vertical, self.max_walk_vertical))
            self._set_x_position(
                self._get_x_position() + self._calculate_movement_value(horizontal, self.max_walk_horizontal))
    
        def run(self, vertical=0, horizontal=0):
            """ An Npc should be able to run
            :param vertical: The distance to run vertical
            :param horizontal: The distance to run horizontal """
            self.__set_y_position(
                self.__get_y_position() + self._calculate_movement_value(vertical, self.max_run_vertical))
            self._set_x_position(
                self._get_x_position() + self._calculate_movement_value(horizontal, self.max_run_horizontal))
    
    
    class Teacher(Npc):
        def foo(self):
            self._get_x_position()
    
        def bar(self):
            self.__get_y_position()
    
    
    if __name__ == "__main__":
        teacher = Teacher()
        print(teacher.firstName)
        print(teacher.bar())
        try:
            print(teacher.foo())
        except:
            print("cannot get y position here because it is private")
        teacher.run(10, 10)
        print(teacher.bar())

     

  4. Quote

    What are your thoughts?  Should this type of research be sanctioned in western nations

    Don't we have animal insulin etc already? If the animals aren't in pain then in the short term it is ok (in the hope we could eventually be able to grow custom organs in a lab eliminating the need for animals to be used at all.)

    Quote

    Or should it be prohibited for ethical reasons?

    What advances are we missing out on because we didn't make the attempt? It really depends, a lot of diseases can be traced back to animals and will it create a new epidemic?

  5. Quote

    What video stream source?

    WebRtc is the new standard for video capture from a users camera. So similar to like facebook video chat/ google hangouts. The gets streamed to a <video> element normally and video data can then be drawn to canvas. The problem would be that sometimes the canvas can prevent access to the pixels data due to CORS. So something like this

    only multiplayer.

  6. Well I wanted to make some multiplayer games that make use of motion capture by drawing a video stream to a canvas in html.  WebRtc is fairly new though so there isn't many tutorials on it. It also seems hard to do and might not work if CORS prevents me from getting the video stream pixel data.

  7. Quote

    If I have to process a lot of data, I am exporting CSV, making C/C++ parser which is processing them extremely fast, and then importing CSV back to OpenOffice/Excel.

    Yeah I have one of those already but there is huge amounts of data 

    This was the actual code that was causing an error

    
      If IsEmpty("F29") = False And Round(Range("F29").Value, 2) >= 0.05 Then
        content = content & vbCrLf & "- Display Time (Seconds) " & WorksheetFunction.Round(Range("'Chart Data'!P34") * 100, 0) & "% worse"
      End If
    

    where F29 = 0.121043590973107

  8. Quote

    This is not going to work

    I am not sure if you are right about that. It just isn't a conventional use case. There is some applications available on GitHub that do stuff similar to this for example https://github.com/gistrec/File-Broadcaster

     

    Quote


    In the second case, when entire file exists, 1st client could start downloading from 0 offset, 2nd client could start downloading from e.g. 1 MB offset, 3rd client could start downloading from e.g. 2 MB offset and so on, so on, as many clients you want. Then 2nd client could download missing the first block of data from 1st client, and 1st client missing block from 2nd client, without bothering server anymore. 

    It's pretty complicated though. Client can be static or dynamic IP, public or private IP, behind firewall/NAT or not etc. etc. Only clients which are public static IP could listen for connection from clients unable to open local ports and reveal them to the Internet ("active" or "passive" clients). Server would have to reveal IP of one client to other client, so they could connect p2p (if they can), which is potential privacy vulnerability (abused by anti-piracy organizations). There are also security issues. Modified client software could send something else than has been downloaded from server machine, so there is needed some authentication and verification of integrity of data, which passes through clients to other clients..

     

    You can assume that you have complete access to the client. For example you could start a service to listen for the download on all clients. As for lost packets surely the client can keep track of where it loses packets and ask the sender to resend? Or the sender can loop through the download several times.

     

  9. Quote

    are you writing software or using existing software?

    I would like to use existing software if possible. If not I could write it.

    Quote

    are you writing/using client or server machines?

    I am using windows server 2012 as the switch which will be connected to many machines (not necessarily windows) on the same network. 

    Quote

    It's (I think) only useful if several users are downloading the same file(s) simultaneously.

    There are no users. It is an automated process involving downloading a large (12GB) zip file containing windows driver tests to about 40 computers a process which normally would take several hours from the windows assessment services server rig.  Since the server is also the switch I would like to try using 

    https://en.wikipedia.org/wiki/Broadcasting_(networking)

    or https://en.wikipedia.org/wiki/Multicast

    But most usages of these tend to be for things other than downloading a file such as sms/video emergency broadcasting

     

  10. Quote

    If you have read it  -  what do you think?   If you haven't   -  I can't recommend it enough if you like fantasy fiction... if you can get through the first book.

    I liked the books written by Robert Jordan but thought that Brandon Sanderson's continuation was hard to follow. I can't help thinking what Jordan would have written.

     

  11. 3-Sat is basically a Boolean expression written as an and of 3 or statements.
     

    (a!bc) and (!a!bc) and (!ab!c) and (!cde) and (!bc!d) 
    
    010****
    110****
    101****
    **100**
    *010***
    
    (aaa) and (!a!a!a)
    0*******
    1*******

    It can be solved in deterministic polynomial time by performing a bitwise unique match on FALSE values stored in an array.

    For example (a or !b or c) is only false for (010).

    We add the false values to an ordered array so a,b,c etc and simply do a bitwise check to see if the opposite already exists in the array, so for 010 that would be 101. If the opposite already exists then the Boolean expression is unsatisfiable.

    This would need to iterate over O(n) values in the worst case on a Single Tape Deterministic Turing machine. The expression is also unsatisfiable if the length of the array is >= 2n/2. Therefore the worst case runtime can never reach the exponential 2n

    I am unsure whether there is any exceptions to the rule that would make this not work?

  12. Quote

    These claim to be the strongest domestic type... with a price to match. 

    They aren't cheap but then I must have bought at least 1 umbrella a month this year so if it lasts then it would pay for itself. If not... then it is a waste of money. All weather gear is always an option but I need it for my work commute and it is not always appropriate for an office job (I suppose I could change when I get to work)

  13. There are really strong winds where I am from and they tend to destroy basically every umbrella I have bought including some from amazon that were supposedly rated for 60mph winds. All the big supermarket umbrellas Tesco/Dunnes etc don't last me a day. Is there anywhere I can buy an exceptionally windproof umbrella? 

  14. I find a lot of people here tend to be older so see simple questions as trolling, before asking a question see if you can google it first. Also try not having a strong opinion on things and keep your answers relevant to the topic question and not just reply to somebody else's comment. 

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.