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
Seaside Loafer
Feb 7, 2012

Waiting for a train, I needed a shit. You won't bee-lieve what happened next

psudocode:

code:
ReadTextIntoMemory
ConvertEverythingToLowerCase
Loop
    If InString(hiring) add to results
end loop
e: It would be interesting if you did it via a regex and programmaticly of whatever language you use on a large input dataset and see what goes faster! Try a million or something.

Seaside Loafer fucked around with this message at 12:02 on Dec 19, 2017

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

huhu posted:

code:
seach_term = 'hiring'
search_string = '[HIRING] Democratic National Committee: Data Science Lead (jobs.lever.co)'


search_term in search_string.lower() # convert to lower case
# -> True


If the "[hiring]" bit is always at the beginning you might eliminate false positives like so:

code:
seach_term = '[hiring]'
search_string = '[HIRING] Democratic National Committee: Data Science Lead (jobs.lever.co)'


search_string.lower().startswith(search_term) # convert to lower case
# -> True

Capri Sun Tzu
Oct 24, 2017

by Reene

Shy posted:

What are the trial limitations on Sublime Text? I can't justify paying for it right now and will probably stick to VS and JetBrains anyway but it looks really neat. I installed it a few days ago and it's not asking for anything.
Absolutely no limitations other than the occasional nagging.

AgentCow007
May 20, 2004
TITLE TEXT
Is there anything legitimately useful/productive that you can do with recursion, or is it just retarded mental gymnastics for CompSci classes? I don't imagine there's a lot of money to be made checking strings for palindromes or calculating Fibonacci numbers.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


AgentCow007 posted:

Is there anything legitimately useful/productive that you can do with recursion, or is it just retarded mental gymnastics for CompSci classes? I don't imagine there's a lot of money to be made checking strings for palindromes or calculating Fibonacci numbers.

Any computations on tree structures are a good fit for recursive methods. That includes things like binary search trees and their variations, but also things like expression parsing.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

AgentCow007 posted:

Is there anything legitimately useful/productive that you can do with recursion, or is it just retarded mental gymnastics for CompSci classes? I don't imagine there's a lot of money to be made checking strings for palindromes or calculating Fibonacci numbers.

Recursion is very useful and it pays to be able to think about problems in that way. Also, you'll get along with people better if you don't call things retarded.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Recursion is pretty much the best way for dealing with immutable collection types, but some Scheme implementations (thinking of Racket) have for constructs that combine the convenience of looping with the rigor of recursion.

spiritual bypass fucked around with this message at 18:02 on Dec 20, 2017

nielsm
Jun 1, 2009



AgentCow007 posted:

Is there anything legitimately useful/productive that you can do with recursion, or is it just retarded mental gymnastics for CompSci classes? I don't imagine there's a lot of money to be made checking strings for palindromes or calculating Fibonacci numbers.

The reason recursive algorithms presented in class seem boring or stupid are because the interesting things take too long to explain and don't fit on a single slide per example. It absolutely solves real problems in real software.
You will also see recursion used in several common sorting algorithms, in particular quick sort and merge sort are naturally expressed with recursion.

Edit: Traditional AI algorithms in games will often involve some kind of path of pathfinding or backtracking algorithms, that are natural to express with recursion, for one example. You might encounter something like the 8 Queens problem later on, it's not quite AI but it's close to the kind of solving you do in it.

nielsm fucked around with this message at 18:09 on Dec 20, 2017

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Nowadays my for-pay programming is nothing comp-sci heavy. It's all web backend stuff which is mostly just simple logic.

I still find myself using recursion. Most recently it was for the canonical example of walking files in a directory tree.

Eela6
May 25, 2007
Shredded Hen
Recursion comes up rarely but consistently in normal programming work. Also, sometimes your co-workers write something that doesn't need to be recursive recursively, so you need to understand recursion in order to refactor it to the iteretive version.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Eela6 posted:

Also, sometimes your co-workers write something that doesn't need to be recursive recursively, so you need to understand recursion in order to refactor it to the iteretive version.

Yeah, this happens too. Sometimes we're too busy asking if we can do this recursively without asking if we should!

baquerd
Jul 2, 2007

by FactsAreUseless

AgentCow007 posted:

Is there anything legitimately useful/productive that you can do with recursion, or is it just retarded mental gymnastics for CompSci classes? I don't imagine there's a lot of money to be made checking strings for palindromes or calculating Fibonacci numbers.

It will come up more frequently in interview questions too, so you're hosed if you don't know it.

reversefungi
Nov 27, 2003

Master of the high hat!
Recursion is cool. I haven't seen it in anything at my job yet, but I remember during my bootcamp I ended up using it for a few things, such as rendering nested comments. Also if you believe everyone who says functional programming is the future, then in functional languages (like Elixir, for example), you'll often see tons of recursion as alternatives to loops.

Volguus
Mar 3, 2009

The Dark Wind posted:

Recursion is cool. I haven't seen it in anything at my job yet, but I remember during my bootcamp I ended up using it for a few things, such as rendering nested comments. Also if you believe everyone who says functional programming is the future, then in functional languages (like Elixir, for example), you'll often see tons of recursion as alternatives to loops.

Recursion is not cool. It is most often than not (depending on your compiler or JIT) a waste of cpu cycles and stack space. Usually (not always) an iterative algorithm can solve the same problem faster and cheaper. However, recursion is trivial to reason about, nice to look at and read. And sometimes, the iterative algorithm does not provide such gains to justify for the increase in complexity. Use recursion with care.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

If you're doing it properly, you're using tail recursion and not adding any stack frames

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen
Knowing how to knock up a simple recursive descent parser is a useful skill to have at your disposal.

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

Eela6 posted:

... sometimes your co-workers write something that doesn't need to be recursive recursively, so you need to understand recursion in order to refactor it to the iteretive version.

Fun fact: nothing ever NEEDS to be written recursively. Any recursive function can be refactored to be iterative.

nielsm
Jun 1, 2009



Newf posted:

Fun fact: nothing ever NEEDS to be written recursively. Any recursive function can be refactored to be iterative.

How do you traverse all nodes in a tree in constant space, without modifying the tree itself? (Assume the tree does not have "parent node" pointers.)

Nippashish
Nov 2, 2005

Let me see you dance!

nielsm posted:

How do you traverse all nodes in a tree in constant space, without modifying the tree itself? (Assume the tree does not have "parent node" pointers.)

You don't. Not even recursively.

nielsm
Jun 1, 2009



Nippashish posted:

You don't. Not even recursively.

Exactly. Whether the recursion is expressed by the language grammar used, or by manually managing a stack, it's still a recursive algorithm. You need the log(depth) space of stack to traverse a tree and that makes it a recursive algorithm.

E: Also, a professor in CS talking about inherently recursive problems that cannot be rewritten as iterative problems: https://www.youtube.com/watch?v=i7sm9dzFtEI

vvv and no that's obviously not what I mean
(the key words are not "constant space", but "maintaining a stack by necessity")

nielsm fucked around with this message at 21:29 on Dec 20, 2017

JawnV6
Jul 4, 2004

So hot ...
Dynamic memory allocation makes things recursive. Got it.

1337JiveTurkey
Feb 17, 2005

Even with traversing a tree, I honestly sorta prefer iteration because it allows you to express things that aren’t very easy with the traditional recursive call structure. Any tree traversal can be reduced to a loop where you stick the root into a data structure, then iteratively take elements from the data structure and add their children to the data structure, repeating until the data structure is empty.

In a depth-first traversal, the data structure is a stack. In a breadth-first traversal, it’s a queue. Or use both ends of a deque at random to confuse the gently caress out of people. You can paralellize the traversal over any arbitrary partition of the data structure. Or if you’re searching for something the data structure can be a priority queue ordered on a closeness heuristic.

Eela6
May 25, 2007
Shredded Hen

Newf posted:

Fun fact: nothing ever NEEDS to be written recursively. Any recursive function can be refactored to be iterative.

This is the opposite of fun.

raminasi
Jan 25, 2005

a last drink with no ice

nielsm posted:

Exactly. Whether the recursion is expressed by the language grammar used, or by manually managing a stack, it's still a recursive algorithm. You need the log(depth) space of stack to traverse a tree and that makes it a recursive algorithm.

E: Also, a professor in CS talking about inherently recursive problems that cannot be rewritten as iterative problems: https://www.youtube.com/watch?v=i7sm9dzFtEI

vvv and no that's obviously not what I mean
(the key words are not "constant space", but "maintaining a stack by necessity")

There is at least one entirely sensible definition of "recursion," used in common parlance, that does not encompass tree traversal via explicit stack management, and everyone who's ever thrown out "oh I guess you don't know what recursion means :smug:" is perfectly aware of this fact.

Jewel
May 2, 2009

imo recursively gather elements if you want, but iteratively process them. unreal 4 based its entire object loading system on recursive "load thing, load thing's dependencies, load thing's things dependencies" which made it A: impossible to profile properly, B: impossible to follow what's loading what, C: impossible to reduce to a simpler set of more important things having priority, D: impossible to be multithreaded at all. Losing multithreading is probably the biggest hit here.

unpacked robinhood
Feb 18, 2013

by Fluffdaddy
A series of unique timestamps will not compress at all in a Huffman tree right ?

e:
Thanks !

unpacked robinhood fucked around with this message at 10:57 on Dec 21, 2017

Nippashish
Nov 2, 2005

Let me see you dance!

unpacked robinhood posted:

A series of unique timestamps will not compress at all in a Huffman tree right ?

Take a segment of the series and count the number of times each character appears. Sort the counts and plot the resulting line. The flatter this line is the less Huffman coding will save you.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

baka kaba posted:

If you're doing it properly, you're using tail recursion and not adding any stack frames

If you're doing it properly, you're using a language that doesn't optimize tail recursions so you don't have to worry about that stuff. :smug:

Dominoes
Sep 20, 2007

I'm new to open-source collaboration. What do you do with your local code after you merge someone's PR on Github? Deleting and git-cloning the local code would work; is there a more elegant way?

edit: In PyCharm, I clicked VCS -> Update -> OK (Merge and Stash selected); the result seemed to be what I asked.

Dominoes fucked around with this message at 23:05 on Dec 23, 2017

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Dominoes posted:

I'm new to open-source collaboration. What do you do with your local code after you merge someone's PR on Github? Deleting and git-cloning the local code would work; is there a more elegant way?

edit: In PyCharm, I clicked VCS -> Update -> OK (Merge and Stash selected); the result seemed to be what I asked.

Why can you just pull?

Dominoes
Sep 20, 2007

I dunno; 'git init', 'git add .', 'git clone https://github.com/...' , and 'git commit -am "updated things"' are the only commands I'm familiar with.

Volguus
Mar 3, 2009

Dominoes posted:

I dunno; 'git init', 'git add .', 'git clone https://github.com/...' , and 'git commit -am "updated things"' are the only commands I'm familiar with.

add git pull to the list and you're a git master. nothing to worry about anymore.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
git pull and git push are two pretty useful commands to learn. They're what let you talk to remote repositories, such as the one on github.

If you initialized your repository with a clone, then you should be able to run "git pull" with no additional parameters to pull any changes to the master branch, assuming that you don't have any conflicts with the github repository and your directory is clean (no uncommitted work).

For a fork and pr based workflow with no branches, accepting a pr would look like
1. "git push" to bring your github master up to date with your local.
2. At this point I would download the pr and review it, but let's just say that it's fine for now
3. Accept the pull request on github
4. "git pull" to bring your local repository up to date with the one on github.

Dominoes
Sep 20, 2007

Thanks dudes; sounds like 'git pull' is the way to handle this. (I accidentally omitted 'git push' from my list of known commands earlier).

What would happen if I pushed; someone submitted a pull request; I merged the pull, and (the step that differs from what I described), I made a change locally before running git pull?

chutwig
May 28, 2001

BURLAP SATCHEL OF CRACKERJACKS

Dominoes posted:

Thanks dudes; sounds like 'git pull' is the way to handle this. (I accidentally omitted 'git push' from my list of known commands earlier).

What would happen if I pushed; someone submitted a pull request; I merged the pull, and (the step that differs from what I described), I made a change locally before running git pull?

If you're making the local change in a different branch than the one that the PR was merged into, nothing will happen. If you're making your changes on master directly, you should instead move to a workflow where you keep your changes in your own feature branches and then you can rebase them onto the new state of master after PRs are merged.

For the record, if you are making commits on your local copy of master and upstream master changes and you pull, Git will create a merge commit. You probably don't want to do this because it will uglify master's history.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
If I have a cURL command that I can run fine in the windows command line, but not in the XAMPP command line, what should I do to troubleshoot.

I've already ran phpinfo() on my local server, and cURL seems to be enabled and running.

nielsm
Jun 1, 2009



Grump posted:

If I have a cURL command that I can run fine in the windows command line, but not in the XAMPP command line, what should I do to troubleshoot.

I've already ran phpinfo() on my local server, and cURL seems to be enabled and running.

Uh start by opening your eyes and looking at what happens, instead of cowering in fear.

Does it fail to even begin the request, i.e. is it a client-side parsing problem or similar? Fail DNS lookup? Fail to connect to server? Server reached seems to be something else than requested? Server is correct but does not respond in the expected way? If the server responds, what does it actually say? Or does the request hit the correct resource with no errors but still produce a wrong result?

baquerd
Jul 2, 2007

by FactsAreUseless

Grump posted:

If I have a cURL command that I can run fine in the windows command line, but not in the XAMPP command line, what should I do to troubleshoot.

I've already ran phpinfo() on my local server, and cURL seems to be enabled and running.

curl -v ...

Also, please don't call it cURL instead of just curl, it's weird and makes me uncomfortable seeing it.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
jesus. okay obviously I'm a beginner if I'm asking this thread how to troubleshoot.

After adding the -v flag, I was able to troubleshoot. Now I can get my curl command running in the xampp shell, but not in my browser. And adding the -v flag in the browser returns nothing.

teen phone cutie fucked around with this message at 22:12 on Dec 27, 2017

Adbot
ADBOT LOVES YOU

nielsm
Jun 1, 2009



Are you calling the commandline tool "curl", or are you using the curl functions in PHP? The two may be different.

PHP code:
<?php
exec("curl http://www.example.com/ > example_homepage.txt");
PHP code:
<?php

$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
Former is calling the curl program from PHP, latter is using the curl library from PHP. What you see in phpinfo() only talks about the curl library functions available.

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