Jump to content

Mr_KoKa

Member
  • Posts

    703
  • Joined

  • Last visited

Reputation Activity

  1. Like
    Mr_KoKa got a reaction from Colonelramirez in Crispy 144Hz Gaming 2020   
    Very cool build Pan Ramirez 😎
  2. Like
    Mr_KoKa got a reaction from mackncheesiest in Remove debouncing/"keyboard chatter" issues with custom keypress proxy   
    It is called hook and I found this https://stackoverflow.com/questions/2067397/can-i-change-a-users-keyboard-input it looks like what you want to achieve.
  3. Agree
    Mr_KoKa got a reaction from mackncheesiest in Need guidance on making seek slider control audio.   
    As far as it is not android specific question then I think that array of strings with file names and the slider value would be an index of the array, just make sure to check if the value is not out of array's bounds. Then you get a file name from the array by index (value of slider) and play it, so no ifs.
  4. Informative
    Mr_KoKa got a reaction from daweakling in Need guidance on making seek slider control audio.   
    As far as it is not android specific question then I think that array of strings with file names and the slider value would be an index of the array, just make sure to check if the value is not out of array's bounds. Then you get a file name from the array by index (value of slider) and play it, so no ifs.
  5. Like
    Mr_KoKa got a reaction from vorticalbox in PHP need help with a few things   
    $s = '@badges=moderator/1;color=#008000;display-name=joveice;emotes=;id=5e290206-79cf-45cc-83da-8d49a26fc152;mod=1;room-id=170536778;sent-ts=1503421860968;subscriber=0;tmi-sent-ts=1503421858315;turbo=0;user-id=30332954;user-type=mod :joveice!joveice@joveice.tmi.twitch.tv PRIVMSG #digitalarcbot :dassa'; $spacePos = strpos($s, ' '); if($spacePos !== false){ $s = substr($s, 1, $spacePos - 1); // Skipping first character (@) and not including found space $vars = explode(';', $s); $keyValue = array(); foreach($vars as $var){ $parts = explode('=', $var); if(count($parts) == 2){ $keyValue[$parts[0]] = $parts[1]; } else { echo 'Invalid variable: '.$var; } } var_dump($keyValue); } else { echo 'Space not found.'; } I used strpos to find first space and then substr to skip @ and extract string to the position of the space found. then I just explode string by ; and then each by =
    Result is associative array. You can enclosure it into a function and instead of echoing errors return false or throw exceptions. Here is working example: https://repl.it/KUo7/0
  6. Like
    Mr_KoKa got a reaction from leodaniel in PHP need help with a few things   
    $s = '@badges=moderator/1;color=#008000;display-name=joveice;emotes=;id=5e290206-79cf-45cc-83da-8d49a26fc152;mod=1;room-id=170536778;sent-ts=1503421860968;subscriber=0;tmi-sent-ts=1503421858315;turbo=0;user-id=30332954;user-type=mod :joveice!joveice@joveice.tmi.twitch.tv PRIVMSG #digitalarcbot :dassa'; $spacePos = strpos($s, ' '); if($spacePos !== false){ $s = substr($s, 1, $spacePos - 1); // Skipping first character (@) and not including found space $vars = explode(';', $s); $keyValue = array(); foreach($vars as $var){ $parts = explode('=', $var); if(count($parts) == 2){ $keyValue[$parts[0]] = $parts[1]; } else { echo 'Invalid variable: '.$var; } } var_dump($keyValue); } else { echo 'Space not found.'; } I used strpos to find first space and then substr to skip @ and extract string to the position of the space found. then I just explode string by ; and then each by =
    Result is associative array. You can enclosure it into a function and instead of echoing errors return false or throw exceptions. Here is working example: https://repl.it/KUo7/0
  7. Informative
    Mr_KoKa got a reaction from Joveice in PHP need help with a few things   
    you read 128 bytes from socket, so even your example (295) will be fragmented and read after 3 fgets.
  8. Like
    Mr_KoKa got a reaction from Pachuca in C++ problems with end-of-file   
    Just be careful as if there is empty line at the end of your accounts file it will try to read it as it is not eof yet. It will fail to read it but will populate your array next index so if your array is made just to fit the data, then it will be written to the memory that is not your array, or that is not owned by your app, which will crash it.
     
    You can check if read operation succeeded by checking >> operator result like: 
    if(!static_cast<bool>(inf >> arrayA[index])){ cout << "Read account id operation failed, stopping reading."; return; } if(!static_cast<bool>(inf >> arrayB[index])){ cout << "Read balance operation failed, stopping reading."; return; }  
  9. Agree
    Mr_KoKa got a reaction from RUWO_builder in Relative paths in Java   
    Try to display yourself current working directory so you know where your app is looking for files. Maybe it is because the way you run your app.
  10. Informative
    Mr_KoKa got a reaction from CookieMaster in Need some help - C++   
    Your canvas is that string array, each string may be different length, so when you draw horizontal line you are changing only one line.
    You will need to check if starting X position is within existing string length, and as you drawing each character, you check if you need to swap or add a character.
     
    Examples:
    Original line: ######### 123456789 Draw line that will fit inside original string length: ###-----# 123456789 Draw line that will start inside original string length: #######----- 123456789012 000000000111 Draw line that will start after original string length: ######### ----- 12345678901234567 00000000011111111 When line fits inside original string then all you do is just changing characters.
    When it exceeds original string length at some point you append instead of swapping, you can see that at position 10 so only 2 characters were swapped and 3 were added
    When line starts beyond original string length you need to add space like in last example, where there 3 spaces were added and then line was drawn by appending line-character.
     
    Drawing vertical line would be as you would draw N * vertical lines of length of 1 character, you need to check for every row if you can just swap character or if you need just append it, or if you need to add space and then append it.
  11. Informative
    Mr_KoKa got a reaction from CookieMaster in Using cout to display an array in C++   
    getline function reads line from stream into string so putting it in while loop like this, you keep overwriting the previous line with the next line from your text file. You're ending up with img containing last line of your text file.
     
    To save every line in array you would need to enlarge the array after you read line. You could enlarge it by greater number then 1 so it wouldn't be enlarged every time you read new line, but it could take more memory then it needs to, you would then need to fit the array to elements count. So I will make example that will enlarge array one by one.
     
    #include <iostream> #include <fstream> using namespace std; int main(){ ifstream File("cookies.asc"); string img; string *array = nullptr; int arraySize = 0; while(getline(File, img)){ string *newArray = new string[arraySize + 1]; for(int i = 0; i < arraySize; i++){ newArray[i] = array[i]; } newArray[arraySize] = img; arraySize++; delete[] array; array = newArray; } for(int i = 0; i < arraySize; i++){ cout << array[i] << std::endl; } delete[] array; } You can see that inside a loop I create newArray of size arraySize + 1, so it is one element larger then it was. Then I copy old array values into new array and at the last array position I set value of newly read line. Then I increment the arraySize to keep its new size, I delete old array and assign newArray pointer to array. After this array is enlarged and keeps line that has been read. After reading I iterate over array to print its elements, then I delete it to free memory.
     
    I guess your assignment makes you to use arrays, but using stl containers would be easier and safer.
  12. Like
    Mr_KoKa got a reaction from DemonBF in Java: OOP "cannot be applied to given types"   
    You're probably confusing variable declaration with arguments. And, you don't need winner variable, you can return the winner (or tie) right away, without putting it to variable first. So if you would want to keep winner variable then you would need to do something like this:
    public String pickWinner(String userChoice, String cpuChoice){ String winner; //... rest of code Then you do what you already have, check choices and put string into winner variable.
     
    But as I said you don't need a variable.
    public String pickWinner(String userChoice, String cpuChoice) //Notice there is no winner and player name variables. { if ((cpuChoice.equals("Rock") && userChoice.equalsIgnoreCase("paper")) || (cpuChoice.equals("Paper") && userChoice.equalsIgnoreCase("Scissors")) || (cpuChoice.equals("Scissors") && userChoice.equalsIgnoreCase("rock"))) { //winner = "User"; return "User"; } //... and so one for Computer and Tie //return winner; <- this won't be needed too. BTW. If there is no winner, it is a tie, I guess there is no need for additional else if to check that. I would return "Tie" on else, so there would be no route that is not return
  13. Informative
    Mr_KoKa got a reaction from DemonBF in Java: OOP "cannot be applied to given types"   
    Yeah, be careful with that, use ctrl shift v to paste text without formatting, your code was invisible for me (on a dark forum skin) until selected.
    (If Beeeyeee wouldn't mention that I would never find out there was a line of code in your post : D)
  14. Like
    Mr_KoKa reacted to madknight3 in Syntax error near 'text'   
    Sounds like you have an error with your SQL statement. Make sure the string that's created is a valid query. You should be able to set a breakpoint and view the query string after it's assembled. 
     
    I also recommend parameterizing your queries to protect against SQL Injection and to have to worry less about the format of your values (don't have to manually deal with quotes and stuff).
    SqlCommand sc=new SqlCommand("insert into TabelaKlienci values(@Column1,@Column2,@Column3,@Column4,@Column5,@Column6)",con); // If you want to explicitly declare the data type sc.Parameters.Add("@Column1", SqlDbType.VarChar).Value = variableForColumn1; sc.Parameters.Add("@Column2", SqlDbType.Int).Value = variableForColumn2; //etc // or if you don't sc.Parameters.AddWithValue("@Column1", variableForColumn1); sc.Parameters.AddWithValue("@Column2", variableForColumn2); // etc // You can name the parameters anything you like, I just used @Column1, etc because I don't know what your columns are named  
    They are optional, although I think it's a better practice to use them.
  15. Informative
    Mr_KoKa got a reaction from Joveice in Regex PHP newline?   
    I have optimize capturing that number of dollars
    <b>(.*?)<\/b> wired <b>([\d\,]*)<\/b> Dollar.<\/td>\s+?<td>\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}<\/td> Instead of ((\d*|\,*)*) it is now ([\d\,]*)
    Square brackets creates characters group, and then * makes match for from zero to unlimited occurrence of character from that group.
  16. Informative
    Mr_KoKa got a reaction from Xenti3 in [Java] Need help writing an equals() method for a linked list   
    You're trying to compare userList to tempSeller instead of userList item, and you're doing same comparison userList.size()-times. So if there are 100 user on the list, you will compare same thing 100 times. Since it is a linked list it has pretty high complexity to get item on a n-index so getting item from a list by get(index) would be not reasonable, as you do it in sequence, you should use iterator.
     
    Other thing, are users unique by username? If so I would think about doing username:string => user:object map, so you could just check if user with that username exists in a map and then check if the password match, it will reduce complexity to be logarithmic. But that depends on if you really need linked list.
  17. Informative
    Mr_KoKa got a reaction from Xenti3 in [Java] Need help writing an equals() method for a linked list   
    import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class User { private String username; private String password; public User(String username, String password){ this.username = username; this.password = password; } public String getUsername(){ return this.username; } public String getPassword(){ return this.password; } @Override public boolean equals(Object other){ if(other instanceof User){ if(other == null || !(other instanceof User)){ return false; } if(other == this){ return true; } User otherUser = (User)other; return (this.username.equals(otherUser.username) && this.password.equals(otherUser.password)); } return false; } } class Main { public static void main (String[] args) throws java.lang.Exception { LinkedList<User> users = new LinkedList(); users.add(new User("A", "abc")); users.add(new User("B", "bcd")); users.add(new User("C", "cde")); users.add(new User("D", "def")); User userToCompare1 = new User("C", "cde"); User userToCompare2 = new User("B", "fgh"); if(users.contains(userToCompare1)){ System.out.println("User exists."); } else { System.out.println("User doesn't exist."); } if(users.contains(userToCompare2)){ System.out.println("User exists."); } else { System.out.println("User doesn't exist or wrong password."); } //There is a map example if you're curious Map<String, User> usersMap = new HashMap(); ListIterator<User> usersIterator = users.listIterator(); while(usersIterator.hasNext()){ User user = usersIterator.next(); usersMap.put(user.getUsername(), user); } if(usersMap.containsKey(userToCompare1.getUsername())){ User user = usersMap.get(userToCompare1.getUsername()); if(user.getPassword().equals(userToCompare1.getPassword())){ // or user.equals, but name is already equal. System.out.println("User exists."); } else { System.out.println("Wrong password."); } } else { System.out.println("User doesn't exist."); } if(usersMap.containsKey(userToCompare2.getUsername())){ User user = usersMap.get(userToCompare2.getUsername()); if(user.getPassword().equals(userToCompare2.getPassword())){ // or user.equals(userToCompare2), but name is already equal. System.out.println("User exists."); } else { System.out.println("Wrong password."); } } else { System.out.println("User doesn't exist."); } } } Runnable version: https://repl.it/Gb4v
     
    So there is an example how you override equal function of an object, so LinkedList contain will use it.
  18. Informative
    Mr_KoKa got a reaction from Xenti3 in [Java] Need help writing an equals() method for a linked list   
    it returns false because String is an object and should be compared with equal, other way you compare addresses.
  19. Like
    Mr_KoKa reacted to LtStaffel in COOKIES   
    Oh dear... let me type it actually into an editor. Next time please spare us the pictures and give us code we can copy and paste.
     
    Here's the code, you're welcome. (Scroll down, another of my posts here is probably the solution to your question)
     
  20. Like
    Mr_KoKa got a reaction from Pythons in "string indices must be integers"   
    I'm not judge your code, but the lack of use of code tags, look how much better it looks with code tags:
     
    import json Attack = 1 data = { "Attack": str(Attack) } jsonData = json.dumps(data) # Here is '{"Attack": "1"}' with open("savefile.json", 'w') as f: json.dump(jsonData, f) # And now it is '"{\"Attack\": \"1\"}"' with open('savefile.json', 'r') as f: data = json.load(f) # You decode it once and it becomes '{"Attack": "1"}' (a string) Attack = data["Attack"] # You're trying to get "Attack" indice of string which can be only indiced by integers from 0 to len(data)-1  
  21. Informative
    Mr_KoKa got a reaction from Pythons in "string indices must be integers"   
    The "saving it" part is wrong. Just ditch this line
    jsonData = json.dumps(data) # Here is '{"Attack": "1"}'  
    and change this line
    json.dump(jsonData, f) # And now it is '"{\"Attack\": \"1\"}"' to
    json.dump(data, f) # And now it is '"{\"Attack\": \"1\"}"'  
     
    So now you don't encode data to json and save it to jsonData and then encode it again and save to file, but now you just encode your data (dictionary) once right into the file. And then you load it from file as you did, decoding it once. Once encoded once decoded, it just works.
  22. Informative
    Mr_KoKa got a reaction from blizzardchris in C# store all strings between strings   
    As an Idea, you could try Regexp, but faster solution would be to parse file yourself like this:
    using System; using System.IO; namespace HelloWorld { class Hello { static void Main() { try { string text = File.ReadAllText("data.file"); int spos = -1; int epos; while((spos = text.IndexOf("point [", spos + 1)) != -1){ epos = text.IndexOf("]", spos); if(epos != -1){ Console.WriteLine("Found: " + text.Substring(spos, epos - spos + 1)); spos = epos + 1; } else { Console.WriteLine("No ending bracket found."); break; } } } catch(Exception e){ Console.WriteLine(e.Message); } } } } Try it here: https://repl.it/GRDS/2
     
    Code searches for "point [" and then from the position it found it (you could add +7 so it would skip that string it just found) it looks for "]"
    When it find "]" it gets substring from the posittion it found "point [" on to the position it found "]" on. And then loop starts again from the position it found "]" at.
     
    Thet being said, you would need to make sure yourself if parsed value is valid, if file would missing closing bracket of point it would parse until closest closing bracket, so the resulting data would be much more then bunch of numbers. Regex can skip such invalid point but it is probably better to know if such point exists and not try to parse file further. If the file is generated then possibility of it being invalid is small.
  23. Informative
    Mr_KoKa reacted to espurritado in How to remove last comma   
    you could consider printing the first number outside the loop, and then in the loop, coma and the next number.
     
    also PLEASE use code tags thanks
  24. Informative
    Mr_KoKa got a reaction from Beeeyeee in [Java] What Loop do I use?   
    You have semicolon after while's condition so the loop has no body and block under that is meant to be that loop's body is not, it just executes as it is outside the loop.
  25. Agree
    Mr_KoKa got a reaction from newgeneral10 in [Java] What Loop do I use?   
    You have semicolon after while's condition so the loop has no body and block under that is meant to be that loop's body is not, it just executes as it is outside the loop.
×