Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 615 616 [617] 618 619 ... 796

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

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9240 on: March 18, 2016, 03:13:26 pm »

Code: [Select]
import sys
sys.stdout.write("Your favorite food is " + favfood + ", huh?")

Though it's debatable if you could say that's a "right way to do it" using any sense of the phrase.
Logged

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9241 on: March 18, 2016, 03:20:41 pm »

Hey, if it's stupid but works, it isn't stupid.

i would either be a really good engineer or a really bad one
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9242 on: March 18, 2016, 03:38:15 pm »

Hey, if it's stupid but works, it isn't stupid.
Maxim 43:  If it's stupid and it works, it's still stupid and you're lucky.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9243 on: March 18, 2016, 03:40:10 pm »

Code: [Select]
import sys
sys.stdout.write("Your favorite food is " + favfood + ", huh?")

Though it's debatable if you could say that's a "right way to do it" using any sense of the phrase.

Actually I'll support that method existing, because string concatenation is a thing you want in your scripting language. The + operator concatenates strings. Being able to pass through the result to any function that takes a string is an inevitable ability.

Sure, you can get rid of that way to do it, and promote the format-string method, but would you prefer to always have to concatenate strings by using printf-style formatters?
« Last Edit: March 18, 2016, 03:45:00 pm by Reelya »
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9244 on: March 18, 2016, 03:47:10 pm »

Code: [Select]
import sys
sys.stdout.write("Your favorite food is " + favfood + ", huh?")

Though it's debatable if you could say that's a "right way to do it" using any sense of the phrase.

Actually I'll support that method existing, because string concatenation is a thing you want in your scripting language. The + operator concatenates strings. Being able to pass through the result to any function that takes a string is an inevitable ability.

Let me rephrase.

Importing sys and writing to stdout is probably not the right thing to do if all you want can be handled by "print(stuff)", unless you're doing something special with print (say, logging output to somewhere other than stdout).
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9245 on: March 20, 2016, 12:43:27 pm »

I'm writing a Python script to periodically check my Facebook page in the background, for... reasons. I'm really not sure what the point of this project is.

I refuse to believe that Facebook is written by a sane human being. A typical post contains 20+ sub-elements, and that's without the like buttons and comment section and stuff like that. I don't much about HTML aside from what is required to use Selenium, but I'm sure there's got to be a simpler way to do that.

Unless it's actually an ingenious plan to keep script kiddies like myself from scraping posts, in which case it was a brilliant 100% success.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9246 on: March 20, 2016, 12:53:41 pm »

Unless it's actually an ingenious plan to keep script kiddies like myself from scraping posts, in which case it was a brilliant 100% success.
Sometimes you want to use the DOM selectors, and other times you want to use regex's to find the stuff. You can cut through a lot of junk by being clever that way.
« Last Edit: March 20, 2016, 12:55:26 pm by Reelya »
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9247 on: March 20, 2016, 12:54:40 pm »

How do you even GUI in Java?  Good grief...
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9248 on: March 20, 2016, 01:03:51 pm »

I'm writing a Python script to periodically check my Facebook page in the background, for... reasons. I'm really not sure what the point of this project is.

I refuse to believe that Facebook is written by a sane human being. A typical post contains 20+ sub-elements, and that's without the like buttons and comment section and stuff like that. I don't much about HTML aside from what is required to use Selenium, but I'm sure there's got to be a simpler way to do that.

Unless it's actually an ingenious plan to keep script kiddies like myself from scraping posts, in which case it was a brilliant 100% success.
Facebook is a lot like Google.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9249 on: March 20, 2016, 01:16:33 pm »

How do you even GUI in Java?  Good grief...

NetBeans comes with a GUI editor that supports Swing and the other one whose name I forget.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Vattic

  • Bay Watcher
  • bibo ergo sum
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9250 on: March 20, 2016, 09:48:46 pm »

I refuse to believe that Facebook is written by a sane human being. A typical post contains 20+ sub-elements, and that's without the like buttons and comment section and stuff like that. I don't much about HTML aside from what is required to use Selenium, but I'm sure there's got to be a simpler way to do that.
When in school we learned to use some website making software and the HTML produced was often odd like you describe.
Logged
6 out of 7 dwarves aren't Happy.
How To Generate Small Islands

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #9251 on: March 21, 2016, 12:01:10 am »

I'm writing a Python script to periodically check my Facebook page in the background, for... reasons. I'm really not sure what the point of this project is.

I refuse to believe that Facebook is written by a sane human being. A typical post contains 20+ sub-elements, and that's without the like buttons and comment section and stuff like that. I don't much about HTML aside from what is required to use Selenium, but I'm sure there's got to be a simpler way to do that.

Unless it's actually an ingenious plan to keep script kiddies like myself from scraping posts, in which case it was a brilliant 100% success.

That is a sign of generated code, yeah. The good part of generated code is most of the time the sub-elements will be in exactly the same order with the same classes and stuff. BeautifulSoup4 for python should help you make sense of the tags and extract data.

Also, I'd be surprised if Facebook dind't have an API, a la Twitter.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #9252 on: March 21, 2016, 12:04:46 am »

Facebook does have an API, but it's vile.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #9253 on: March 21, 2016, 12:05:44 am »

Okay, I understand what recursive methods are, and how they can be useful, but how can I make an iterative method into a recursive one? This new kind of logic is defeating me at the moment.

Here's an example.
Code: [Select]
public class printArray
{
// initializes values
public static void main ( String args[] )
{
int array[] = { 81, 22, 18, 34, 44, 21, 94 };

for ( int count = 0; count <= 6; count++ )
System.out.print( array[count] + " " );
}
}

This will output the contents of the array with spaces between them. How can I make that recursive?
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #9254 on: March 21, 2016, 12:26:37 am »

weeell... for one, that wouldn't be a very good algorithm to make recursive, but if you really wanted to...


public static void main ( String args[] ) {
  int array[] = { 81, 22, 18, 34, 44, 21, 94 };
      
  helper(array);
}

public static void helper( int[] array ) {
  helper(array, 0);
}

public static void helper( int[] array, int index ) {
  if (index == array.length) {
    return;
  }
  System.out.print( array[index] + " ");
  helper(array, index + 1);
}


The call stack would look like:

helper(array)
  helper(array, 0)
    helper(array, 1)
      helper(array, 2)
        helper(array, 3)
          helper(array, 4)
            helper(array, 5)
              helper(array, 6) <- exits here.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward
Pages: 1 ... 615 616 [617] 618 619 ... 796