Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 678 679 [680] 681 682 ... 796

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

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10185 on: November 13, 2016, 12:27:36 pm »

Can't MAC adresses be spoofed fairly easily, though? Sure, a homebrew solution in a hotel might not care about that, but some ISPs have these open hotspots built in wherever they can (e.g. with all their customers), and I can't imagine those would like people spoofing the traffic of paying customers.
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.

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10186 on: November 13, 2016, 12:34:09 pm »

Can't MAC adresses be spoofed fairly easily, though? Sure, a homebrew solution in a hotel might not care about that, but some ISPs have these open hotspots built in wherever they can (e.g. with all their customers), and I can't imagine those would like people spoofing the traffic of paying customers.
Why would you want to though? Unless you change to an address that's already authenticated (in which case all sorts of things could go terribly wrong due to duplicate MAC addresses on the same network) then it's just going to mean that you are forced to redo authentication. This isn't a "blacklist" type of situation, it's a "whitelist" one; so by default you are automatically denied unless you've verified your address and are still using the MAC that you did that with.
« Last Edit: November 13, 2016, 12:35:50 pm by i2amroy »
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10187 on: November 13, 2016, 01:33:56 pm »

When you log in to public wi-fi, often there's a landing page with a button you have to press before it'll let you actually connect to the Internet. How is this done? I assume it's the local network serving its own page to a new user when it first requests something, but what is the more specific answer?

i2amroy covered some ways that this works, and redirects are how we handle it at work.  We use firewall redirects for all web traffic destined outside of our network if devices haven't gone through registration.

As for how it works on the client side, most devices have specific websites that they try to contact in order to determine if they have internet access.  If they make a request and get a response back that's different from what they expect, they assume that they're part of a captive network and will display the captive network assistant browser, which then hopefully loads the registration page.

The MAC address discussion is interesting.  You can spoof it, yeah, and we've actually had issues with people doing that on our networks before.  It ends up just making their internet not work though, so it doesn't really help.  Spoofing in those cases was actually done accidentally, because the users had some kind of weird network adapters that had configurable MAC addresses and they came preconfigured with the same MAC addresses.

Interestingly, even though MAC address is the (theoretically) unique identifier for a network adapter, we actually manage network access using IP addresses and firewall rules based on them.  The rules are just updated whenever DHCP leases change.
Logged
Through pain, I find wisdom.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10188 on: November 13, 2016, 02:01:41 pm »

Can't MAC adresses be spoofed fairly easily, though? Sure, a homebrew solution in a hotel might not care about that, but some ISPs have these open hotspots built in wherever they can (e.g. with all their customers), and I can't imagine those would like people spoofing the traffic of paying customers.
Why would you want to though? Unless you change to an address that's already authenticated (in which case all sorts of things could go terribly wrong due to duplicate MAC addresses on the same network) then it's just going to mean that you are forced to redo authentication. This isn't a "blacklist" type of situation, it's a "whitelist" one; so by default you are automatically denied unless you've verified your address and are still using the MAC that you did that with.
Fair enough, I didn't consider the consequences of having two devices using the same MAC address on the same network.
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.

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10189 on: November 13, 2016, 03:24:35 pm »

Can't MAC adresses be spoofed fairly easily, though? Sure, a homebrew solution in a hotel might not care about that, but some ISPs have these open hotspots built in wherever they can (e.g. with all their customers), and I can't imagine those would like people spoofing the traffic of paying customers.
Those ISPs give you an account you have to log into to use the hotspot.  And I believe once you disconnect to reconnect you need to log in again.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

Elephant Parade

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10190 on: November 21, 2016, 11:55:00 pm »

Anybody know how to get the Java scanner (the one included in java.util) to read an inputted string? I can't seem to get it to do so, and the official documentation isn't of any help.

Edit: Apparently == doesn't work properly with strings.
« Last Edit: November 22, 2016, 12:14:07 am by Elephant Parade »
Logged

DragonDePlatino

  • Bay Watcher
  • [HABIT:COLLECT_WEALTH]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10191 on: November 22, 2016, 12:16:41 am »

When getting input in Java, this is the general way I do it:

Code: [Select]
public void getInput()
{
Scanner console = new Scanner(System.in);
System.out.println("Type \"command1\", \"command2\" or \"exit\" to quit.");

boolean run = true;
while(run)
{
String input = console.nextLine();
switch(input)
{
case("command1"):
// Do stuff
break;
case("command2"):
// Do other stuff
break;
case("exit"):
run = false;
break;
default:
System.out.println("Invalid command: " + input)
break;
}
}
console.close();
}

You create a new Scanner and feed System.in (the command prompt) into it. When you want the user to input something, you call console.nextLine() and store the string. The program will freeze until it receives input, after which you can do a switch-statement on it to handle different commands.

EDIT:
Yes, the == operator does not work on strings. You need to use the String.compareTo() method for that. If you're using an IDE like Eclipse, you can type in the name of a string variable followed by a period. It will automatically suggest all of the methods you can use on that object, with input.compareTo() being an example of one.
« Last Edit: November 22, 2016, 12:20:21 am by DragonDePlatino »
Logged

DangerDwarf

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10192 on: November 22, 2016, 03:09:04 am »

Edit: Apparently == doesn't work properly with strings.

== works with strings, but maybe not exactly in the way you may think :)

In Java, for each variable that you declared, after allocating it (with the new operator) a reference to the memory location for that allocation is stored inside the variable. Then, whenever you use that variable in your code the program will know where in memory to get the data that you are trying to retrieve.

Example: Very simplified, but see it like this. Imagine you are reading two strings from input as follows:

Code: [Select]
Scanner scan = new Scanner(System.in);
String s1 = scan.nextLine();  //user types Hello
String s2 = scan.nextLine();  //user again types Hello

s1 references a location in memory where the physical bytes containing "Hello" is stored. s2 will similarly reference a different memory location containing "Hello".

Now here comes the interesting part. The == operator compares references to each other, and not the contents of these references. Basically s1 == s2 will check whether both s1 and s2 references the same memory location. In this case, the answer will be false.

String however has an "equals" function that will compare the contents of its memory with another String's contents. In this case s1.equals(s2) will return true, as "Hello" was contained in both of them.

Hope this makes sense. But watch out for the following:

Imagine you didn't read the strings from input but instead declared them as follows:

Code: [Select]
String s1 = "Hello";
String s2 = "Hello";

The result of s1.equals(s2) is obviously true, but surprisingly s1 == s2 also returns true? The reason is that Java was quite smart to see that the contents of s1 and s2 are both the same, and decided to hold this contents in the same memory location for both. Basically, both s1 and s2 will reference the same memory. This is possible because the strings were string constants and their values could be predetermined during compilation (in contrast to the previous example where the values were only available at runtime). So when you deal with string constants, keep the above in mind.




Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10193 on: November 22, 2016, 09:04:03 am »

Spoiler: Story (click to show/hide)

Long story short, Kroger (yes, the grocery chain) is actually a pretty neat place for a developer. Their latest projects revolve around ClickList and Amazon Echo.
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10194 on: November 22, 2016, 09:16:21 am »

Fuck all testing sites that don't allow you to look up docs without failing you
Uhm. This is a thing?
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10195 on: November 22, 2016, 09:27:37 am »

Fuck all testing sites that don't allow you to look up docs without failing you
Uhm. This is a thing?

I think it's an option in HackerRank. I've heard that some tests fail you if the tab loses focus.
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10196 on: November 22, 2016, 09:29:17 am »

Only the tab or also the browser? Because then you could switch to a different browser. If not, then I can't imagine how many people that thing failed because of some random Windows popup notice.
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10197 on: November 22, 2016, 09:39:18 am »

Only the tab or also the browser? Because then you could switch to a different browser. If not, then I can't imagine how many people that thing failed because of some random Windows popup notice.

Whatever is available in Javascript. With zero searching, it's probably able to tell if the current document has focus. That means no tabs, no switching windows (new browser or otherwise).

In all likelihood, it's a little lie to prevent people from cheating. I wasn't about to test that, though. I just used a separate computer.
Logged

DangerDwarf

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10198 on: November 22, 2016, 03:43:26 pm »

I had to do an interview on Hackerrank and had no problems searching for info when I got stuck.

In fact, I find it a bit inane if they dont even let you look up the javadocs. Dont even see it as cheating really. Really, its the time limit that is supposed to catch you if you look up too many stuff.
Logged

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10199 on: November 22, 2016, 03:48:14 pm »

https://medium.freecodecamp.com/the-code-im-still-ashamed-of-e4c021dff55e#.ctux664aw

It starts with:
Quote
If you write code for a living, there’s a chance that at some point in your career, someone will ask you to code something a little deceitful – if not outright unethical.
This happened to me back in the year 2000. And it’s something I’ll never be able to forget.
Logged
<Dakkan> There are human laws, and then there are laws of physics. I don't bike in the city because of the second.
Dwarf Fortress Map Archive
Pages: 1 ... 678 679 [680] 681 682 ... 796