Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 447 448 [449] 450 451 ... 795

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 804687 times)

karhell

  • Bay Watcher
  • [IS_A_MOLPY]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6720 on: November 26, 2014, 08:21:35 am »

rm is the normal bash file deletion command right? I'm not just having a brain-fart right?

Code: [Select]
Alexanders-iMac:src alexander$ rm lua.o
override rw-r--r--  root/staff for lua.o?
<snip>

That second line is simply rm asking whether you want to override the security settings for lua.o (which is, as others pointed out, writeable [and therefore deletable] only with the root account).
Should you answer yes, you'll be prompted for the root account's password, and then (provided you have the password) the file will be deleted.
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6721 on: November 26, 2014, 07:42:06 pm »

huh? Thief didn't say anything of the kind he was clearly talking about deleting lua.o. What he described was what that line of output actually meant. It's a printout of the user permissions attached to the file you tried to delete, lua.o. Thief explained what all of it meant, and what it signified - you can only "write" to that file if you're using the "root" account, which is like Administrator in Windows. "write" privileges include deleting the file.

root is the sysadmin account, staff is the group the file is attached to. that's what root/staff is saying, and the r's and w's (and x's but not here) stand for read, write and execute permissions for 3 levels of users - root, usergroup (which here is named "staff") and strangers. So it's security settings basically to stop idiots deleting system files.

It sounds like you don't know anything about UNIX file permissions and the chmod command. Without knowing how that works, you are basically stuffed for doing anything with files in UNIX or Linux environments.

Thief suggested you try the delete command again but put "sudo" before it. sudo = "superuser do", i.e. "Run as Administrator" in Windows.

I understand the basics (I do know what the "r's and w's" stand for), but I have never seen that message come up before, whenever I have tried to delete things without permission it has just told me "permission denied" before. What confused me was the fact that those are the only files in that folder (in Documents) that came up like that, for no apparent reason, and I have been able to delete them before using rm without issue other times I have ran the make file (I have deleted and rebuilt them several times now), and I can remove the other .o files without issue. I was also able to delete the files fine in finder (which I assume shouldn't be able to delete files with those permissions).

I apologige Thief, for the misunderstanding. Your advice was quite correct.

I am still curious as to how these files might have gotten those permissions in the first place.
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6722 on: November 27, 2014, 02:33:20 am »

MacOS would seem to have some additional protection on your user's home directory, allowing you to override the permissions of files there. That's quite cool!

Generally a file ends up with "root" as the user if it was created by a command run using "sudo" (though there are other ways). Its no coincidence that's also the easiest way to delete them!
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6723 on: November 27, 2014, 03:13:40 am »

Still, builders are spawned before harvesters. No idea why that is.
Maybe the game can only spawn one thing at a time, and the "spawn" call actually queues up a spawn action in another class. So, calling spawn twice in a row might overwrite the first action, and only spawn the second one you ask for. The fix would be to change the 2nd "if" to "else if".

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6724 on: November 27, 2014, 04:52:36 am »

Seems to be that way. I actually know only one can be spawned at a time.
I just reversed the order from lowest to highest priority and it now works as expected.
Logged
Taste my Paci-Fist

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6725 on: November 27, 2014, 05:02:27 am »

You probably should add the "else if" anyway, because just because something works right sometimes doesn't mean it always works that way, especially with command timing issues, different amounts of processor load or timing across threads could actually cause it do something unexpected, e.g. if the spawn.spawning flag happens to be set quicker than your second function call one out of 10 times then it won't have predictable results.

There's also a fair bit of overhead in doing both function calls, and in a game where you get limited CPU you should use conditional branching effectively to minimize the CPU hit so you can cram more logic in, especially since this is interpreted JavaScript with no optimization:

Slower:
Code: [Select]
    if ( !spawn.spawning && harvesters < 3 ) {
        spawn.createCreep ( [ Game.CARRY, Game.WORK, Game.WORK, Game.MOVE, Game.MOVE ], 'harvester' + Game.time , { role : 'harvester' } );
    }
   
    if ( !spawn.spawning && builders < 3 ) {
        spawn.createCreep ( [ Game.CARRY, Game.CARRY, Game.WORK, Game.WORK, Game.MOVE ], 'builder' + Game.time , { role : 'builder' } );
    }

Faster
Code: [Select]
    if ( !spawn.spawning )
    {
        if (harvesters < 3 )
            spawn.createCreep ( [ Game.CARRY, Game.WORK, Game.WORK, Game.MOVE, Game.MOVE ], 'harvester' + Game.time , { role : 'harvester' });
        else if (builders < 3 )
            spawn.createCreep ( [ Game.CARRY, Game.CARRY, Game.WORK, Game.WORK, Game.MOVE ], 'builder' + Game.time , { role : 'builder' } );
    }

This is faster because you only check spawn.spawning once per cycle, not twice, and if it spawns a harvester, you skip the check for builders altogether.

Worst-case scenario in the old version was 4 comparisons, two function calls (complete with pushing all the parameters to the stack), whereas worst-case now is 3 comparisions, and 1 function call. Function calls are where almost all the overhead are, because it has to save local state, then push the parameters, run the function then restore local state when the function returns.

Best-case scenario before was 2 comparisons, and in the new version it's one comparison.
« Last Edit: November 27, 2014, 05:15:42 am by Reelya »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6726 on: November 27, 2014, 05:41:52 am »

Oh, right, I forgot. Microsoft open-sourced (!!) the .NET Core two weeks ago. It was put on Github instead of Codeplex because, and I quote, "everyone uses GitHub and it's great".

Weird weird weird weird.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6727 on: November 27, 2014, 06:08:13 am »

It's mainly because they've realized that middle-ware is their future since they've accepted utter defeat selling Windows Phone. Desktop apps are moving to the cloud, and the future is diverse platforms, not a single monolithic platform controlled by one huge company like the Windows heyday.

Open source .NET means .NET support on virtually any new platform that becomes popular. If they can get .NET ported to every platform, then they can sell .NET apps to everyone and the company's future is more secure. People working on the .NET code for free is basically slave labor now in getting Microsoft tech working on 3rd party hardware / OS platforms. Think about it, an army of volunteers ports .NET to e.g. the latest Kindle, then Microsoft can come around and use that to sell MS Office to Kindle users without having to spend any money targetting the platform themselves. If one particular platform fails, then Microsoft is no worse off, and if it succeeds, that's more customers for their software packages. So this move effectively reduces the financial risk to Microsoft of porting .NET to new systems.
« Last Edit: November 27, 2014, 06:15:37 am by Reelya »
Logged

Sergarr

  • Bay Watcher
  • (9) airheaded baka (9)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6728 on: November 27, 2014, 09:24:47 am »

Oh, right, I forgot. Microsoft open-sourced (!!) the .NET Core two weeks ago. It was put on Github instead of Codeplex because, and I quote, "everyone uses GitHub and it's great".

Weird weird weird weird.
Does that mean that thousands of useful programs written on .NET framework are now going to be avaliable on all platforms?
Logged
._.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6729 on: November 27, 2014, 11:43:40 am »

Oh, right, I forgot. Microsoft open-sourced (!!) the .NET Core two weeks ago. It was put on Github instead of Codeplex because, and I quote, "everyone uses GitHub and it's great".

Weird weird weird weird.
GitHub is pretty cool but there's also a bunch of weird things about it. (like the fact that you can spoof their email system to reply as anybody and they don't give a fuck)
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6730 on: November 29, 2014, 11:47:04 am »

[snip]
Thanks!
I'll have a look through my code some time. Replaced some of it with a loop already (why does
Code: [Select]
for ( i in <list> )iterate over the indexes? Is it because lists are secretly maps and maps are iterated by key?)
which makes adding additional roles easier.
Logged
Taste my Paci-Fist

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6731 on: November 29, 2014, 05:06:43 pm »

It's just how the language is defined and there are alternatives they could have picked but didn't for some unknowable reason.  My guess is that it's because they wanted to keep the syntax simple but wanted to make it possible to access the keys in an array or object easily.  So, they could have made it:

Code: [Select]
for (var item in foo) {
}

But if they did that, how would you get the array or object keys if you needed them?  In PHP, they solve that with syntax like this:

Code: [Select]
foreach ($foo as $key => $value) {
}

Something similar could have been done in JavaScript, and indeed you can define functions that do this for you, like jQuery does.  It's just not part of the language for some reason.  You just have to take the long route for now, like this:

Code: [Select]
for (var key in foo) {
    var value = foo[key];
}
Logged
Through pain, I find wisdom.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6732 on: November 29, 2014, 06:04:43 pm »

If iterating over keys for arrays and lists wasn't implemented I'd do it like this (and it's kinda how I do it in Common Lisp, see below):
Code: [Select]
for ( i from 0 to (list.length - 1) ) {
}

I understand why you iterate over keys for a structure where they keys aren't generally enumerable (and it would be nice if Common Lisp did that with LOOP). It just seems off for iterating over a list or an array, where the keys aren't of interest in any way (of course assuming that all lists and arrays are indexed from a fixed number (like 0 in most cases)).

Code: (Iterating over the contents of a list in Common Lisp) [Select]
(loop for val in list ; if you've got an array to iterate over, use 'across' instead of 'in'
  do (foo val))
Code: (Iterating over a list while also having the correct index available) [Select]
(loop for val in list
  for i from 0
  do (bar val i))
Logged
Taste my Paci-Fist

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6733 on: November 29, 2014, 06:50:08 pm »

[snip]
Thanks!
I'll have a look through my code some time. Replaced some of it with a loop already (why does
Code: [Select]
for ( i in <list> )iterate over the indexes? Is it because lists are secretly maps and maps are iterated by key?)
which makes adding additional roles easier.
Much more likely is it's pulling from the same iteration theory background as is behind C++ STL: http://www.stlport.org/resources/StepanovUSA.html
Quote
In other words, I realized that a parallel reduction algorithm is associated with a semigroup structure type. That is the fundamental point: algorithms are defined on algebraic structures. It took me another couple of years to realize that you have to extend the notion of structure by adding complexity requirements to regular axioms. And than it took 15 years to make it work. (I am still not sure that I have been successful in getting the point across to anybody outside the small circle of my friends.) I believe that iterator theories are as central to Computer Science as theories of rings or Banach spaces are central to Mathematics. Every time I would look at an algorithm I would try to find a structure on which it is defined. So what I wanted to do was to describe algorithms generically. That's what I like to do. I can spend a month working on a well known algorithm trying to find its generic representation.

Which is implemented as the Iterator pattern: https://en.wikipedia.org/wiki/Iterator_pattern

Basic goal behind it is to be able to say "I have a foo holding a bunch of bars. I want to use algorithm X on this collection of bars. Now I have foo2 holding a bunch of bars in a different way. I want to use algorithm X on this collections of bars without rewriting it into some new algorithm Y." Not sure of all the implementation specifics, but its appearance is likely just a direct translation of the underlying pattern.
Logged

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6734 on: November 29, 2014, 07:17:15 pm »

Will read that.

For lists I think of indexes as secondary. Intuitively the iterator of a list for me is successive sublists (or rather the successive cons cells the list is made of).

I am just rambling. I don't think I have much of an idea what I am talking about anymore.
Logged
Taste my Paci-Fist
Pages: 1 ... 447 448 [449] 450 451 ... 795