Skip to main content
Share Your Experience: Take the 2024 Developer Survey
23 votes

Appending a trailing slash if needed

You could use a ternary operator to inline the condition into a single return statement: ...
buffy's user avatar
  • 331
14 votes
Accepted

Taking YouTube links out of a list of GitHub repo READMEs

Here are some concerns/suggestions: you are reading the file twice - once to get the row count and when reading the links. And, you don't need to initialize the ...
alecxe's user avatar
  • 17.3k
11 votes

Appending a trailing slash if needed

Honestly, I'm not sure how much simpler you can make this. I'd suggest a slightly clearer name though - maybe ensureTrailingSlash? ...
BenC's user avatar
  • 2,738
10 votes

Selecting checkboxes based on URL parameters

Extract the chk parameter value from location.search and use a "lookup table" object: ...
wOxxOm's user avatar
  • 1,952
10 votes

Imgur URL parser

According to PEP 8, the official Python style guide, function names should be lower_case_with_underscores. Furthermore, this function parses the URL, rather than ...
200_success's user avatar
9 votes

Appending a trailing slash if needed

It would be less verbose to write website += "/"; instead of website = website + "/"; So, yeah, you totally ...
200_success's user avatar
9 votes
Accepted

URLify a string using Python

Your complexity analyses look correct to me. I would just say, in short, that this function works in O(n2) time. Note that this is an awkward exercise to do in Python, or any language in which ...
200_success's user avatar
8 votes
Accepted

Dynamically loading CSS files based on URL or URI in PHP

Most of questions you are asking are not fit for this site and your code does not work as intended but this is an interesting case to review The grave mistake Adding anything to your code just in case ...
Your Common Sense's user avatar
7 votes

Remove parameters from string containing URL

The simplest way, a true one-liner, would be to use strtok, an ancient but for some reason obscure function that does exactly what you need: ...
Your Common Sense's user avatar
7 votes

Selecting checkboxes based on URL parameters

First of all, it would help tremendously if you named the URL parameter values and the form element IDs consistently. Why do you have chk=webdes-check ...
200_success's user avatar
7 votes
Accepted

Joining strings to form a URL

You can simplify the solution if, instead of checking for a presence of the slash, you would str.strip() the slashes from both sides of each argument and then ...
alecxe's user avatar
  • 17.3k
7 votes

Imgur URL parser

For a first pass, not bad! Your code is pretty easy to follow. Problems: Don't use [] to match different strings. [] matches ...
Gerrit0's user avatar
  • 3,456
6 votes

C# helper class - mailto

Dmitry Nogin gave a great answer. Here are some ways to improve your original code that could help your coding style in the future. Those private variables holding strings should be constants. ...
Risky Martin's user avatar
  • 1,611
6 votes
Accepted

C# helper class - mailto

We could probably use existing .NET classes here: ...
Dmitry Nogin's user avatar
  • 6,131
6 votes

T-SQL UDF to replace replace base URLs

Your code looping over string functions doesn't seem like something SQL Server is optimized for. Database systems are optimized for set based operations, not looping. I understand the confusion ...
Tom V's user avatar
  • 161
6 votes

Selecting checkboxes based on URL parameters

I don't do javascript but what I noticed right away is that you are doing url[1].toLowerCase() for each if and ...
Heslacher's user avatar
  • 50.4k
6 votes
Accepted

Creating URL with Builder pattern

Include the required headers You use std::string extensively, but you don't include <string>. This is allowed to work (...
Jerry Coffin's user avatar
  • 33.6k
6 votes
Accepted

Extending window.location give access to query string elements

For the most part this looks good to me - your code is easily understood and well formatted. However, there is still room for improvement. Don't bother creating ...
Gerrit0's user avatar
  • 3,456
6 votes

Tiny URL creator

I know this isn't really what you're asking for, but I have a couple suggestions about how the code is setup and written. Coming from languages that use long as a ...
Carcigenicate's user avatar
5 votes

URLify a string using Python

I believe this is the simplest way to do this in python: def urlify(in_string): return "%20".join(in_string.split()) Note: There is no need for the length ...
Aris94's user avatar
  • 51
5 votes
Accepted

URLIfy a character array using Python - follow-up

\$O(n)\$ time with \$O(1)\$ space is a hard, and somewhat extreme requirement. Sure the \$O(n)\$ can be achieved easily. But the \$O(1)\$ is not. Using lists, to achieve \$O(1)\$ means you have to ...
Peilonrayz's user avatar
  • 43.4k
5 votes
Accepted

Selecting site to browse in python

Here is a list of things I would improve: variable naming - PEP8 recommends to use lower_case_with_underscores style of variable names instead of a regular expression, you can use ...
alecxe's user avatar
  • 17.3k
5 votes
Accepted

Check website for update

First things first, I really like your idea and I think with a couple of small changes it would be a really nice utility to use! To start out with, here's a couple of suggestions regarding code style: ...
Daniel's user avatar
  • 4,490
5 votes
Accepted

Create URL query string from dictionary

This isn't a bad approach - simple, effective, and gets the job done. It could be ever-so-slightly better, though. First, string concatenation (str1 & str2, <...
Der Kommissar's user avatar
5 votes
Accepted

URL-safe pseudorandom string generator in C#

const string TOKENALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-."; I learnt the hard way that the problem with using ...
Peter Taylor's user avatar
  • 24.1k
5 votes

Dynamically loading CSS files based on URL or URI in PHP

Your current battery of if conditions needs a re-think. $_SERVER['PHP_SELF'] -- as long as it has a non-falsey value will evauate to ...
mickmackusa's user avatar
  • 8,674
5 votes

Tiny URL creator

While I agree with the other answer that you should not return a special string denoting failure, in Python you should refrain from returning any special return value (though if you do, ...
Graipher's user avatar
  • 41k
5 votes
Accepted

Tiny URL creator

If you really want to cut down on the number of characters that you need to guarantee a certain amount of robustness, it would be wise to pick a greater pool of characters to choose from. At the ...
AlexV's user avatar
  • 7,260
5 votes
Accepted

Detecting the presence of multiple URL segments

Throwing custom exception I find the second version is cleaner as it clearly communicates which condition caused the exception. With the first one, you need to know it's about ...
t3chb0t's user avatar
  • 44.3k
4 votes

Isolate URLs from other text around it and put each on own line (with sed)

What about this? cat input | tr ' ' '\n' | grep -i "^http" Put every string on new line. Filter urls.
Jan Korous's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible