Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

zfleeman posted:

The web design/development thread must be on DB3, or something, so I'm going to ask my potentially asinine question here.

I run a headless server in my basement that hosts my low-traffic websites/low-traffic every other project I work on. It's dinky and held together with paperclips and duct tape, but it has worked for me for the most part for many years. Well, I'm kind of fed up with random outages and router+AT&T modem issues, so I'm looking to migrate a lot of the things I do on my server to some hosting service. My roommate suggested that I use a LAMP instance with AWS, and even though that EC2 service is free for 12 months, it kind of sounds like overkill for what I need it to do: host a couple simple websites I have built with HTML and PHP. I also need to upload four JPEGs a minute via FTP for my security camera.

I'm not super well-versed on what AWS can provide me. Most, if not all of my knowledge in this realm is self-taught without any formal training, so forgive me if I'm being incredibly ignorant. I think AWS would get the job done for what I need it to do, but if there is a cheaper long-term solution to my very simple hosting needs, I'm all ears.

TLDR: I need a cheap/low-maintenance host. Any suggestions?

Check out vNucleus, they are a goon run virtual host provider in SA-MART. They have pretty good prices, give goons a discount, and even offer packages where they will do all maintenance for you.

Adbot
ADBOT LOVES YOU

EAT THE EGGS RICOLA
May 29, 2008

zfleeman posted:

TLDR: I need a cheap/low-maintenance host. Any suggestions?

I've had nothing but good luck with a $5/mo digitalocean droplet for stuff like this.

LP0 ON FIRE
Jan 25, 2006

beep boop

LP0 ON FIRE posted:

I have one table missing from the sidebar on phpMyAdmin. How do I get it back? I can still access the table if I click on the database and go to the list of tables.

By the way I figured this out: Show hidden navigation tree items. (The lightbulb)

Linear Zoetrope
Nov 28, 2011

A hero must cook
In a graph, what's the best way to find the shortest path between a vertex and a region/subgraph? I think in an arbitrary graph with no special/nice properties you're stuck taking the min path between the source and all possible target vertices adjacent to nodes outside the subgraph?

Linear Zoetrope fucked around with this message at 13:33 on Nov 14, 2015

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Jsor posted:

In a graph, what's the best way to find the shortest path between a vertex and a region/subgraph? I think in an arbitrary graph with no special/nice properties you're stuck taking the min path between the source and all possible target vertices adjacent to nodes outside the subgraph?

You can start by modifying the graph and collapsing the entire region-of-interest to a single vertex. Then you just do a single vertex-vertex shortest-path.

Linear Zoetrope
Nov 28, 2011

A hero must cook

Jabor posted:

You can start by modifying the graph and collapsing the entire region-of-interest to a single vertex. Then you just do a single vertex-vertex shortest-path.

Right, and then you can just do a linear search on the vertices in the region to find one adjacent to the last node in the path to your region-vertex. :downs:

(Though I guess this method starts to break down if you allow arbitrarily disjoint subgraphs)

nielsm
Jun 1, 2009



Use a single source shortest path algorithm to find the shortest path to every node in the graph, then pick the best node inside the subgraph.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Jsor posted:

Right, and then you can just do a linear search on the vertices in the region to find one adjacent to the last node in the path to your region-vertex. :downs:

Specifically you'd want the one with the shortest edge-weight to an adjacent node, though obviously that's not an issue if you have an unweighted graph. You could also tag the edges leading into your merged region with their original destination vertex as you're constructing the modified graph, instead of doing a separate scan at the end to figure it out.

I don't see any reason it wouldn't work on a disjoint region-of-interest?

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Collapsing the region of interest is fine if all the edge weights are positive, but it might be tricky if you have negative edge weights or the region spans several connected components.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

I have a few coworkers who struggle with regular expressions. Would it be a good idea to introduce VerbalExpressions into our code base? Has anybody used it and liked it?

mystes
May 31, 2006

NihilCredo posted:

I have a few coworkers who struggle with regular expressions. Would it be a good idea to introduce VerbalExpressions into our code base? Has anybody used it and liked it?
Are your coworkers struggling with assembly language too? Maybe you should try VerbalAssembly(TM):
CopyValuetoRegister(0, RegisterNumber1).IncrementRegister(RegisterNumber1).AddFirstRegistertoSecondRegister(Register1,Register2).GotoSection("My Section")

mystes fucked around with this message at 20:34 on Nov 15, 2015

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
ADD ONE TO COUNT GIVING COUNT

Xerophyte
Mar 17, 2008

This space intentionally left blank

mystes posted:

Are your coworkers struggling with assembly language too? Maybe you should try VerbalAssembly(TM):
CopyValuetoRegister(0, RegisterNumber1).IncrementRegister(RegisterNumber1).AddFirstRegistertoSecondRegister(Register1,Register2).GotoSection("My Section")

You joke, but x86 extension set mnemonics are now up to things like VCVTTPD2UQQ (or the slightly clearer _mm512_mask_cvtt_roundpd_epu64 in practice in C/C++-world) so you'd better clarify what you intended somewhere when you use the things.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I have the dangerous notion of trying to get one more 3rd-party layer to put on top of an enterprise web framework (ASP.NET, J2EE, Django--doesn't matter) for representing what really is just a giant, searchable table through a web UI. It would be easy enough to declare all the values I care about, but the data is just so regular that I don't see a need to actually have to code most of it. Mostly I want to make sure other users can toy with it without me having to monkey with the code most of the time. There are a few fields were I anticipate having to do some things, but it should be rare. Is there any stuff I can readily try for this kind of thing?

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

mystes posted:

Are your coworkers struggling with assembly language too? Maybe you should try VerbalAssembly(TM):
CopyValuetoRegister(0, RegisterNumber1).IncrementRegister(RegisterNumber1).AddFirstRegistertoSecondRegister(Register1,Register2).GotoSection("My Section")
If I had to read assembly code only every now and then, yeah, I'd totally appreciate a more verbose syntax in exchange for not having to memorise the command list. If it were a more frequent activity then it'd be worth the effort to remember the compact syntax.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

NihilCredo posted:

If I had to read assembly code only every now and then, yeah, I'd totally appreciate a more verbose syntax in exchange for not having to memorise the command list. If it were a more frequent activity then it'd be worth the effort to remember the compact syntax.

But if you only have to read it now and then, then you're not losing that much time googling the ops you don't remember when you do have to read it.

dangling pointer
Feb 12, 2010

I had this question in an interview: Given 6 coins, 5 are real and one is fake. The fake one can be either heavier or lighter than the real ones. I had write a solution to find the fake coin using a balance only three times and find if the fake coin is heavy or light.

I stumbled through the problem by writing a bunch of if statements for every case. What would be a more elegant way to solve this by iterating through it? I realized I needed to use an adversarial algorithm but couldn't figure out how to do it without a bunch of repetitive if/else statements.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

dangling pointer posted:

I had this question in an interview: Given 6 coins, 5 are real and one is fake. The fake one can be either heavier or lighter than the real ones. I had write a solution to find the fake coin using a balance only three times and find if the fake coin is heavy or light.

I stumbled through the problem by writing a bunch of if statements for every case. What would be a more elegant way to solve this by iterating through it? I realized I needed to use an adversarial algorithm but couldn't figure out how to do it without a bunch of repetitive if/else statements.

Divide and conquer.

Sex Bumbo
Aug 14, 2004

LeftistMuslimObama posted:

Divide and conquer.

"no I'm not answering this dumb question"
or
"hold on let me google this because that's what I'd do in a real life scenario"

Is what I always want to say but don't.

Compare 2v2 and they'll either be equal or not equal. Then just do some other stuff based on the result. If they're equal the fake is in the other 2, if they're not then the other 2 are legit.

Sex Bumbo fucked around with this message at 04:10 on Nov 19, 2015

dangling pointer
Feb 12, 2010

Sex Bumbo posted:

Compare 2v2 and they'll either be equal or not equal. Then just do some other stuff based on the result. If they're equal the fake is in the other 2, if they're not then the other 2 are legit.

Ya, thats what I did just broke them into sets of 2 and made a bunch of if statements from there. Seemed like there was a better way to do it besides make an if statement for ever case but maybe not.

Sex Bumbo
Aug 14, 2004
It's not a very good interview question.

Cryolite
Oct 2, 2006
sodium aluminum fluoride
I noticed a few typos recently in the documentation for an open source library I'm using for a side project. The documentation is up on GitHub (the documentation site itself is generated using Sphinx) and there's even a "edit this page on GitHub" link at the top of all the pages on the deployed website.

Is it obnoxious to open a pull request just to fix small typos? I've noticed things like "the" spelled as "tbe" or an extra word that makes a sentence grammatically incorrect and looks like it was meant to be deleted. It seems like it would be really obnoxious to open a pull request for a single typo, but maybe if I found a bunch and did it in one PR it wouldn't be so bad.

Are these types of minor contributions welcome, or are they generally considered rude?

If it matters it's a project backed by a commercial company.

Cryolite fucked around with this message at 05:43 on Nov 19, 2015

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
I wouldn't make a PR for each individual one, but you could definitely try doing a bunch of them in a single PR. All they have to do to to accept your changes is click on one button, so it's not very hard for them. If they can't be arsed to do it then gently caress 'em.

Sedro
Dec 31, 2008
Any contribution is welcome. Feel free to open a PR even to fix a single character typo. If anything they will appreciate the involvement.

If they have lots of open PRs with no activity then don't bother, the project is dead.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

dangling pointer posted:

I had this question in an interview: Given 6 coins, 5 are real and one is fake. The fake one can be either heavier or lighter than the real ones. I had write a solution to find the fake coin using a balance only three times and find if the fake coin is heavy or light.

I stumbled through the problem by writing a bunch of if statements for every case. What would be a more elegant way to solve this by iterating through it? I realized I needed to use an adversarial algorithm but couldn't figure out how to do it without a bunch of repetitive if/else statements.

This is a bad interview question. Not only has everyone heard it, but it's not a terribly interesting implementation.

BigRedDot
Mar 6, 2008

Cryolite posted:

I noticed a few typos recently in the documentation for an open source library I'm using for a side project. The documentation is up on GitHub (the documentation site itself is generated using Sphinx) and there's even a "edit this page on GitHub" link at the top of all the pages on the deployed website.

Is it obnoxious to open a pull request just to fix small typos? I've noticed things like "the" spelled as "tbe" or an extra word that makes a sentence grammatically incorrect and looks like it was meant to be deleted. It seems like it would be really obnoxious to open a pull request for a single typo, but maybe if I found a bunch and did it in one PR it wouldn't be so bad.

Are these type of minor contributions welcome, or are they generally considered rude?

If it matters it's a project backed by a commercial company.

I'm nominally in charge of an OSS library on GH (also largely backed by a company, though I'm not sure that matters) and I can say PRs for corrections or improvements are always welcome.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
A PR for a single typo in a comment would make me wonder why you're wasting my time, but anything more substantial is always appreciated.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Cryolite posted:

I noticed a few typos recently in the documentation for an open source library I'm using for a side project. The documentation is up on GitHub (the documentation site itself is generated using Sphinx) and there's even a "edit this page on GitHub" link at the top of all the pages on the deployed website.

Is it obnoxious to open a pull request just to fix small typos? I've noticed things like "the" spelled as "tbe" or an extra word that makes a sentence grammatically incorrect and looks like it was meant to be deleted. It seems like it would be really obnoxious to open a pull request for a single typo, but maybe if I found a bunch and did it in one PR it wouldn't be so bad.

Are these type of minor contributions welcome, or are they generally considered rude?

Do it. Not rude at all. If you make a PR and don't hear back for a month, well, you tried but they're not interested. Personally I'd press the "merge" button lickety-split.

quote:

If it matters it's a project backed by a commercial company.

They might want you to sign something giving them the rights to your changes, but hopefully they've made that easy.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

dangling pointer posted:

Ya, thats what I did just broke them into sets of 2 and made a bunch of if statements from there. Seemed like there was a better way to do it besides make an if statement for ever case but maybe not.

You can use recursion (which typically goes hand-in-hand with divide and conquer) and end up with only a single if statement (for detecting your base case).

Everyone is saying it's a lame interview question, but it's not intended to be challenging. It's intended to see if you know about divide and conquer and recursion, because if you don't there's probably some followup questions necessary.

raminasi
Jan 25, 2005

a last drink with no ice

LeftistMuslimObama posted:

You can use recursion (which typically goes hand-in-hand with divide and conquer) and end up with only a single if statement (for detecting your base case).

Everyone is saying it's a lame interview question, but it's not intended to be challenging. It's intended to see if you know about divide and conquer and recursion, because if you don't there's probably some followup questions necessary.

What's the way to do it with a conditionless recursive step? I can't figure it out.

And the reason it's a lame interview question isn't that it's challenging, or not challenging - the reason is that 95% of people who can answer it are just regurgitating what they've seen previously. It's trivia, not problem-solving.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

LeftistMuslimObama posted:

You can use recursion (which typically goes hand-in-hand with divide and conquer) and end up with only a single if statement (for detecting your base case).

Everyone is saying it's a lame interview question, but it's not intended to be challenging. It's intended to see if you know about divide and conquer and recursion, because if you don't there's probably some followup questions necessary.

Then ask a question about divide and conquer. This sounds like you're expecting a smug interviewer to respond "ah, you solved it, and efficiently, but not using the specific solution I was expecting!"

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Volmarias posted:

Then ask a question about divide and conquer. This sounds like you're expecting a smug interviewer to respond "ah, you solved it, and efficiently, but not using the specific solution I was expecting!"

Not smugly, no. Maybe our interviews here are weird, but if they gave a weak solution to this problem our interviewers would talk with them more about programming techniques and try to get a feel for what they've learned, and how quickly they'll grasp the solution once it's given to them. The followups can help determine if the person is at least equipped to learn anything they didn't already come in knowing.

We hire a shitload of fresh college grads though. I suspect if you had a decent amount of experience on your resume we'd just skip those sorts of soft filter questions.

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker
What kind of strange person believes that the recursive answer is the more correct one? It's ok if you want to find out how the candidate thinks and where he's as level wise, but maybe not use a gotcha question. Open ended "how would you implement this" will get you what you want while being clear to the candidate exactly what you're asking of them.

raminasi
Jan 25, 2005

a last drink with no ice
I really want to know the solution that isn't a thicket of conditional logic.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Also perhaps not limiting it to 6 coins and 3 moves.

raminasi
Jan 25, 2005

a last drink with no ice
I originally heard of it as 12 coins and 4 moves, but while the solution I know to that one shares enough principles with the 6-3 version that I was able to deduce the latter solution, it's not just a recursive expansion, and neither of them are (as far as I can tell) a recursive expansion from a base case.

Xerophyte
Mar 17, 2008

This space intentionally left blank
Is this the point where we post our buggy and crappy solutions to the problem, and then everyone complains about them?

Because I'm all for that.

C code:
bool BadCoinIsInRange(int start, int end) {
  Assert((end - start) % 2 == 0);
  // Divide range in two equal piles, check if scales are even.
}

// Assume we have some enumerated collection of N coins.
// Find the bad coin in a range [start, end) of possible bad coins.
int FindBadCoinInRange(int start, int end, int known_good_coin) {

  int range_size = end - start;

  // Empty range.
  if (range_size <= 0) {
    throw Tantrum();
  }
  
  // Only one coin in the range, so it must be bad.
  if (range_size == 1) {
    return start;
  }

  // Two coins in the range. If we don't have a known good coin (i.e. this is the first iteration) then this fails.
  if (range_size == 2) {
    // Weigh either possible bad coin versus the known good coin.
    if (ScalesAreEven(start, known_good_coin)) {
      return start + 1;
    }
    else {
      return start;
    }
  }

   // More than two coins in the range. Divide it into two halves, one of which needs to contain an even number of coins.
  int mid = (start + end) / 2;
  mid = (mid - start) % 2 == 0 ? mid : mid + 1;
  
  // Check which half of our range the bad coin is in.
  if (BadCoinIsInRange(start, mid)) {
    return FindBadCoinInRange(start, mid, mid);
  }
  else {
    return FindBadCoinInRange(mid, end, start);
  }
}
E: It's definitely possible to formulate as a divide and conquer search problem. How many base cases and if statements you need in said search depends.

Xerophyte fucked around with this message at 19:28 on Nov 19, 2015

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

GrumpyDoctor posted:

I really want to know the solution that isn't a thicket of conditional logic.

Volmarias posted:

Also perhaps not limiting it to 6 coins and 3 moves.

In principle, you can always get a solution for N coins in ceil(ln2(N)) experiments by recursive division.

code:
divideList :: [a] -> ([a], [a], [a])
divideList = divideList' [] []
  where
    divideList' as bs [] = (as, bs, [])
    divideList' as bs [x] = (as, bs, [x])
    divideList' as bs (a:b:xs) = divideList' (a:as) (b:bs) xs

experiment :: Show a => [a] -> [a] -> IO ()
experiment [] _ = putStrLn "Impossible situation"
experiment [a] _ = putStrLn $ "The oddly-weighted coin is " ++ show a
experiment [a,b] [] = putStrLn "Not enough information"
experiment [a,b] xs@(x:_) = do
  putStr $ "Is " ++ show [a] ++ " the same weight as " ++ show [x] ++ "? (y/n) "
  c <- getLine
  case c of
    "y" -> experiment [b] (a:xs)
    "n" -> experiment [a] (b:xs)
    _   -> experiment [a,b] xs
experiment l [] = do
  let (l', xs, r) = divideList l
  let (as, bs, r') = divideList l'
  putStr $ "Is " ++ show as ++ " the same weight as " ++ show bs ++ "? (y/n) "
  c <- getLine
  case c of
    "y" -> experiment (r++r'++xs) (as++bs)
    "n" -> experiment (as++bs) (r++r'++xs)
    _   -> experiment l []
experiment l xs = do
  let (as, bs, r) = divideList l
  let xs' = take (length as) xs
  putStr $ "Is " ++ show as ++ " the same weight as " ++ show xs' ++ "? (y/n) "
  c <- getLine
  case c of
    "y" -> experiment (bs++r) (as++xs)
    "n" -> experiment as (bs++r++xs)
    _   -> experiment l xs

main :: IO ()
main = experiment [1, 2, 3, 4, 5, 6] []
divideList is a helper function which divides a list into two equal parts, and a remainder which is either the empty list or a single-element list.

experiment is a recursive function which generates experiments. It takes two parameters: a list of coins which includes the oddly-weighted coin, and a list of coins which does not include the oddly-weighted coin.

If the list of possibly-oddly-weighted coins is empty, then we're in an impossible situation. If the list of possibly-oddly-weighted coins is a single-element list, then we know the answer.

If we have two coins of unknown weight, and no coins that we know are the correct weight, then we don't have enough information to solve the problem (all we can do is verify that the two coins are, in fact, different weights).

If we have two coins of unknown weight, and at least one coin that we know is the correct weight, then we pick one of the unknown coins and weigh it against the known one. If they are the same, then the other one of the unknowns is the oddly-weighted one.

If we have more than two coins of unknown weight, and no coins of known weight, then we divide the coins in half, then divide one of the halves again. This gives us three sets: A (1/4 of the original set), B (1/4 of the original set), and R (the remainder). If A has the same weight as B, then the oddly weighted one is in R. If A differs from B, then either A or B has the oddly-weighted one.

If we have more than two coins of unknown weight, and some coins of known weight, then we divide the unknown coins in half, pick one of the halves, and weight it against the same number of coins from the known-good set (by construction, our known-good set if we have one is always at least half the total coins rounded down, which is more than the at most one quarter of the total coins that we are weighing against it, so we will always have enough known-good coins to do this).

This algorithm works for 6 coins in 3 experiments, and it scales well, but it's not perfect; there are more division rules that are needed to get the optimal answer. For example, this algorithm fails on three coins by entering an endless loop trying to weight the empty list against itself. It also gives a suboptimal path for 7 coins, by sometimes needing 4 experiments when only 3 should suffice. Doing it properly gets a little messier, but the general idea of recursive divide-and-conquer by trying to refine the set of possibly-oddly-weighted coins by half each time is fairly simple.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

GrumpyDoctor posted:

I originally heard of it as 12 coins and 4 moves, but while the solution I know to that one shares enough principles with the 6-3 version that I was able to deduce the latter solution, it's not just a recursive expansion, and neither of them are (as far as I can tell) a recursive expansion from a base case.

It involves a bunch of return statements instead. I didn't say no conditional logic, just fewer if statements. I also didn't think about it too hard so I'm probably missing a corner case in there.

Adbot
ADBOT LOVES YOU

JawnV6
Jul 4, 2004

So hot ...
Hate conditional logic? Smuggle the decisionmaking through flow control instead!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply