• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=khuba;42111795]Forgot to mention you don't put the leading dollar sign in. Just the name itself without the $.[/QUOTE] Ah, works now. Thanks for the help :)
For the curious I fixed my mergesort it is now: [CODE] using System; namespace MergeSort { class Program { static void Main(string[] args) { int[] input = { 1, 3, 33, 456, 3, 34, 3, 56, 3, 65, 3, 3, 76, 4, 5, 6, 7, 8, 45, 46, 44, 3 }; int[] output = MergeSort(input, 1, (input.Length)); Console.WriteLine("Test output for mergesort:"); foreach (int t in output) { Console.Write(t.ToString() + ", "); } Console.ReadLine(); } public static int[] Merge(int[] InputArray, int LowerBounds, int MidPoint, int UpperBounds) { int LeftTotal = MidPoint - LowerBounds+1; int RightTotal = UpperBounds - MidPoint; int[] LeftArray = new int[LeftTotal + 1]; int[] RightArray = new int[RightTotal + 1]; for (int i = 0; i < LeftTotal; ++i) { LeftArray[i] = InputArray[LowerBounds + i-1]; } for (int j = 0; j < RightTotal; ++j) { RightArray[j] = InputArray[MidPoint + j]; } LeftArray[LeftTotal] = int.MaxValue; RightArray[RightTotal] = int.MaxValue; int LeftCounter = 0, RightCounter = 0; for (int k = LowerBounds-1; k < UpperBounds; ++k) { if (LeftArray[LeftCounter] <= RightArray[RightCounter]) { InputArray[k] = LeftArray[LeftCounter]; ++LeftCounter; } else { InputArray[k] = RightArray[RightCounter]; ++RightCounter; } } return InputArray; } public static int[] MergeSort(int[] InputArray, int LowerBounds, int UpperBounds) { if (LowerBounds >= UpperBounds) { return InputArray; } int MidPoint = (UpperBounds + LowerBounds) / 2; InputArray = MergeSort(InputArray, LowerBounds, MidPoint); InputArray = MergeSort(InputArray, MidPoint + 1, UpperBounds); InputArray = Merge(InputArray, LowerBounds, MidPoint, UpperBounds); return InputArray; } } } [/CODE]
How would I go about making a Python script for simple chatting with Steam friends? Edit: I found [URL="https://github.com/GamingRobot/PySteam"]PySteam[/URL], which should give me exactly what I want. It seems to use Steam's mobile protocols. However, when running the example it always fails during login. [CODE] response = self.steamRequest("ISteamOAuth2", "GetTokenWithCredentials", {'client_id': self.oauth_client_id, 'grant_type': 'password', 'username': username, 'password': password, 'x_emailauthcode': email_auth_code, 'scope': 'read_profile write_profile read_client write_client'}, True)[/CODE] [CODE]def steamRequest(self, api, method, data, post=False): params = urllib.parse.urlencode(data) headers = {"Content-type": "application/x-www-form-urlencoded", "User-Agent": "Steam 1291812 / iPhone", "Accept-Language": "en-us", "Accept-Encoding": "gzip, deflate", "Accept": "*/*"} c = http.client.HTTPSConnection("api.steampowered.com:443") #c.set_debuglevel(1) if post: c.request("POST", "/" + api + "/" + method + "/v0001", params, headers) else: c.request("GET", "/" + api + "/" + method + "/v0001?" + params, None, headers) response = c.getresponse() print(response.status) if response.status == 200: data = response.read() #print(data) try: parjson = json.loads(data) except: return None if parjson != None: return parjson else: return {} else: return None[/CODE] After it requests "("GET", "/" + api + "/" + method + "/v0001?" + params, None, headers)" it responds with a 404. Is there another method I would be able to login with?
I'm having a api library return gibberish non-ascii letters. For example, a ä is turned into ä. Is there anyway where I can reparse these kinda letters so they are nice and unicodish. I'm coding in C# at the moment. I only really need support for å ä ö but others are nice too. Doing a string replace works, but its tedious to do with the whole utf8 character set.
[QUOTE=Donkie;42121663]I'm having a api library return gibberish non-ascii letters. For example, a ä is turned into ä. Is there anyway where I can reparse these kinda letters so they are nice and unicodish. I'm coding in C# at the moment. I only really need support for å ä ö but others are nice too. Doing a string replace works, but its tedious to do with the whole utf8 character set.[/QUOTE] What's the library? That's a Unicode issue and depending on the cause either your code is incorrect, which is easy enough to fix, or you would have to modify the library itself, which is a pain in the ass.
With C#'s Lists, is it more efficient to do [code] foreach (Type t in List) { t.DoShit(); } [/code] than [code] List.ForEach((t) => t.DoShit()); [/code] ?
[QUOTE=Funley;42122421]With C#'s Lists, is it more efficient to do [code] foreach (Type t in List) { t.DoShit(); } [/code] than [code] List.ForEach((t) => t.DoShit()); [/code] ?[/QUOTE] I'm pretty sure the foreach statement is faster.
[QUOTE=ECrownofFire;42122142]What's the library? That's a Unicode issue and depending on the cause either your code is incorrect, which is easy enough to fix, or you would have to modify the library itself, which is a pain in the ass.[/QUOTE] I was wrong with saying its a library, it isn't. I use GET to receive information, and I think its a problem on the servers end with the characters, which is something I don't have access to.
I'm using PHP and I'm getting a really weird bug, my code works fine on my local machine but it doesn't on my web server. The issues relates to parsing text and replacing multiple strings of characters with values from an array stored in an external file, when there's more than one string it needs to replace - it only does the 1st one on my web server but it does all of them when it's local. Sorry for not being able to go into a bit more detail. The difference between the two is that my local machine is running Apache + PHP 5.4.14 (Windows) whereas my web server is running Nginx + PHP 5.4.9-4ubuntu2.3 (Linux/Ubuntu).
[QUOTE=Funley;42122421]With C#'s Lists, is it more efficient to do [code] foreach (Type t in List) { t.DoShit(); } [/code] than [code] List.ForEach((t) => t.DoShit()); [/code] ?[/QUOTE] None are faster until you profile the code to know which one. And you'd do so as part of your entire program's profiling to make sure your results are accurate.
Think you guys could help me out with some super simple java? [cpp]import java.util.Scanner; public class Exercise2_6 { public static void main(String[] args) { int hundreds; //Use remainder to deal with the latter two digits in the number int remainder; int tens; int ones; int sum; System.out.print("Enter an integer between 0 and 1000: "); Scanner sc = new Scanner(System.in); int x = sc.nextInt(); //Assuming a 3 digit number, divide by 100 to get hundreds place digit. Do mod of that number and you get the tens and units places. Take that 2 digit number, //divide by ten and you'll have the 10's place, the mod of the 2 digit number divided by 10 will be the units place. hundreds = x/100; remainder = x % 100; tens = remainder/100; ones = remainder%10; sum = hundreds + tens + ones; System.out.println("The sum of all digits in " + x + " is " + sum); } } [/cpp] This should work, but for some reason the program my professor uses to grade this stuff is getting weird results. If it inputs 999 it's getting 18 instead of 27, and I don't know why because when I do it by hand, it works fine. When it inputs 11 it returns 1 instead of 2, and when it inputs 234, it returns 6. I did something wrong, apparently, but fuck if I know what it is. You don't need to import java.lang.Math for mod, do you? That should be default, I thought.
You're dividing the remainder by 100?
goddammit that's probably it [editline]8th September 2013[/editline] yep that was it thanks [editline]8th September 2013[/editline] when i wrote it i wrote it backwards like i tend to do without realizing it (remainder%10 = ones, etc) and I guess when I rewrote it I looked at the wrong line
[QUOTE=Funley;42122421]With C#'s Lists, is it more efficient to do [code] foreach (Type t in List) { t.DoShit(); } [/code] than [code] List.ForEach((t) => t.DoShit()); [/code] ?[/QUOTE] I don't think so, the lambda is small and doesn't catch any variables so it's possibly inlined during JIT. ForEach is most likely just a wrapper for foreach anyway, with an added type constraint of IEnumerable<T>. There [i]may[/i] be one additional boxing instruction, if the enumerator is a struct (which it almost never is) and [i]maybe[/i] a call becomes virtual due to the interface-use, but I doubt that's even measurable. [editline]8th September 2013[/editline] [QUOTE=Donkie;42122886]I was wrong with saying its a library, it isn't. I use GET to receive information, and I think its a problem on the servers end with the characters, which is something I don't have access to.[/QUOTE] Set the WebClients Encoding property to [System.Text.]Encoding.UTF8. If you GET binary data you have to set the encoding in the BinaryReader or use the UTF8Encoding's GetString method.
[QUOTE=Funley;42122421]With C#'s Lists, is it more efficient to do [code] foreach (Type t in List) { t.DoShit(); } [/code] than [code] List.ForEach((t) => t.DoShit()); [/code] ?[/QUOTE] They're probably both very similar (if not the same) in terms of performance, however, I find the loop to be cleaner and easier to follow, so I'd use the loop over the extension method. Generally, the only acceptable time to use the ForEach extension method is within a LINQ query IMO.
[QUOTE=robmaister12;42124103]They're probably both very similar (if not the same) in terms of performance, however, I find the loop to be cleaner and easier to follow, so I'd use the loop over the extension method. Generally, the only acceptable time to use the ForEach extension method is within a LINQ query IMO.[/QUOTE] Or calling an Action<T> delegate. LINQ queries (both lambda and query syntax) work fine in the foreach header though.
Don't know if this is the right place or not, but does anyone have some way to learn discrete math like a khan academy approach? I'm not finding anything...
How on earth are they able to destruction like this? (1:30) [media][URL]http://www.youtube.com/watch?v=R3b9e_KWO-I#t=90[/URL][/media] Is there something I can read about this? [editline]9th September 2013[/editline] My current hypothesis is model clipping + mesh deformation.
The deformation doesn't really look smooth. I'd guess it's a bit minecraft-y (the ships also look like it), but instead of placing blocks, they place sides. And they use object-local coordinate systems, so you can rotate stuff. The deformation might be pre-modeled (perhaps pre-computed) and it just cycles through the different stages of destruction, depending on the damage done, until it completely breaks, possibly causing objects to split in two (or more). [editline]9th September 2013[/editline] Although the deformation you can see at 1:49 does look like actual run-time calculated deformation because the sides are still connected. With a bit more complexer system, that looks what stuff is connected to it instead of just having one sequence of deformations, you could also get there. Maybe it's just not smooth, because it'd be too computationally intensive, so they just take bigger timesteps for that.
Although if the first part of destruction is precalculated, how would you take in account the angle from the damage source? It'd be a bit odd if you hit something from the outside and it'd dent towards the outside. [editline]9th September 2013[/editline] Although maybe that's something that can be overlooked?
Have you tried asking the devs?
[QUOTE=Asgard;42132004]How on earth are they able to destruction like this?[/QUOTE] Maybe the steps are because they do large destruction steps whenever the models intersect, so that rough-colliding cubes are taken out at once and adjacent ones damaged?
If i have a map with a string key and a pointer mapped value. I want to traverse it and delete the pointer. Will this work? [cpp]for(const auto & i:meshes){ delete i.second; }[/cpp]
[QUOTE=nuds;42119437]How would I go about making a Python script for simple chatting with Steam friends? Edit: I found [URL="https://github.com/GamingRobot/PySteam"]PySteam[/URL], which should give me exactly what I want. It seems to use Steam's mobile protocols. However, when running the example it always fails during login. [CODE]...[/CODE] After it requests "("GET", "/" + api + "/" + method + "/v0001?" + params, None, headers)" it responds with a 404. Is there another method I would be able to login with?[/QUOTE] If anyone is interested, I decided to use the same method as [URL="https://github.com/GamingRobot/WaterBot/blob/master/plugins/isteam/isteam.py"]GamingRobot's WaterBot[/URL] which uses IronPython to interact with SteamKit2. This allows me to easily use things from SteamKit2.dll in a Pythonic way like: [CODE]def sendChatMessage(self, chatid, msg): print(self.username + ": " + msg) steamid = SteamID(chatid) if self.IDtoLong(chatid) in self.chatrooms: self.steamFriends.SendChatRoomMessage(steamid, EChatEntryType.ChatMsg, str(msg)) else: self.steamFriends.SendChatMessage(steamid, EChatEntryType.ChatMsg, str(msg)) ... self.sendChatMessage(callback.Sender, "I can't handle Steam emoticons right now. They make me cry.")[/CODE]
I've got an email back from the Space Engineers developer on how he did it. I've asked if I'm allowed to publicise his email, and if I can I'll post it here later.
[QUOTE=WTF Nuke;42137565]If i have a map with a string key and a pointer mapped value. I want to traverse it and delete the pointer. Will this work? [cpp]for(const auto & i:meshes){ delete i.second; }[/cpp][/QUOTE] Yes. How about smart-pointers though?
[quote]Hi Frank, yes, you got it right. The whole ship is a grid made of block-like modules (which look like 3D models), and if there's a collision on some of block, the game calculated the level of damage and if it exceeds certain threshold, that block gets removed. If it's below a threshold, it just get deformed (by twisting vertexes and polygons). If your ship collides with an obstacle under low velocity, the damage would be small and it would only deform those blocks. The good thing is that deformation look smooth and believable. If we just removed the whole block, ships would look "block-y" after a collision - not very good looking. BTW, there's no documentation on this, we just did it because we needed it :-) But I may write about it on my blog sometime in future. I am glad you like it. Thanks! Best Regards, Marek Rosa[/quote]
[QUOTE=Asgard;42140370][/QUOTE] What a good guy.
I wonder what he's doing for deformation though. Would it just be complete randomization of the vertices, within a certain strength, or would it be influenced by something
[QUOTE=Asgard;42141153]I wonder what he's doing for deformation though. Would it just be complete randomization of the vertices, within a certain strength, or would it be influenced by something[/QUOTE] I would assume he bends them in the direction the ship that hit was going
Sorry, you need to Log In to post a reply to this thread.