What's my name?

9

Given a PPCG User ID, output that user's current username.

Examples

Input -> Output
61563 -> MD XF
2     -> Geoff Dalgas
12012 -> Dennis
foo   -> 
-3    -> 

Rules

  • Input/output can be taken via any allowed means.
  • The output must be the full username with proper capitalization and spacing, nothing more and nothing less.
  • If the input is not a valid UserID, or the user does not exist, your program should output nothing or error output.
  • Your program must work for any valid user, even one created after this challenge.
  • Your program does not have to work for the Community user.
  • Your program does not have to work for deleted users.
  • URL shorteners are disallowed.

Scoring

Shortest code in each language wins.

MD XF

Posted 2017-08-01T17:31:00.130

Reputation: 11 605

5Very closely related, but since my vote is a hammer, I'm not close-voting yet. – AdmBorkBork – 2017-08-01T17:43:18.530

@AdmBorkBork Yeah, those are pretty closely related, but this is significantly easier. – MD XF – 2017-08-01T17:44:23.290

Oh, that one will be soooo easy in C++ – HatsuPointerKun – 2017-08-01T18:01:34.513

I'm curious about also doing the reverse of is. Does anyone know if display names are unique? – geokavel – 2017-08-01T19:02:38.823

@geokavel They are not. – MD XF – 2017-08-01T19:07:18.357

1English, 3 bytes: Okx. Yes, that's my name. – Okx – 2017-08-01T19:33:45.710

@Old In real life? – NoOneIsHere – 2017-08-01T23:09:23.143

@NoOneIsHere who is Old? – MD XF – 2017-08-01T23:11:57.670

@MDXF I meant Okx, typoed on mobile :( – NoOneIsHere – 2017-08-01T23:23:22.527

1Everybody can save 4 bytes (in “normal” languages): xxx.stackexchange.com/u/123 redirects to xxx.stackexchange.com/users/123 – Gilles 'SO- stop being evil' – 2017-08-02T09:11:55.807

Answers

4

05AB1E, 35 34 bytes

Doesn't work online because of internet restrictions.

Code

’ƒËŠˆ.‚‹º.ŒŒ/†š/ÿ’.w'>¡4è5F¦}60F¨

Explanation

The compressed string:

’ƒËŠˆ.‚‹º.ŒŒ/†š/ÿ’

pushes the following string:

codegolf.stackexchange.com/users/<input>

Whereas <input> is the user input. After this, we read all data using .w and do some string manipulation tricks on the data:

'>¡4è5F¦}60F¨

'>¡             # Split on '>' (Usernames aren't allowed to have '>' so we're safe)
   4è           # Take the 5th element (which is in the header of the HTML page)
     5F¦}       # Remove the first 5 characters, which is "User "
         60F¨   # Remove the last 60 characters, which is:
                  " - Programming Puzzles &amp; Code Golf Stack Exchange</title"
                # Implicitly output the username

When run locally, I get the following output:

enter image description here

Adnan

Posted 2017-08-01T17:31:00.130

Reputation: 41 965

I think that an explanation will be needed for this brand of black magic – Taylor Scott – 2017-08-01T19:49:20.860

I'm looking at my screen at an angle, am I supposed to se an outline of totallyhuman's flair and "apparently" next to your username? – NoOneIsHere – 2017-08-01T19:57:26.767

1@TaylorScott Done. – Adnan – 2017-08-01T20:00:00.073

3

@NoOneIsHere Yeah, cmder is a tiny bit transparent. That is actually this answer what you are seeing.

– Adnan – 2017-08-01T20:00:30.230

Umm, part of your explanation is „ -¡¬. – Erik the Outgolfer – 2017-08-02T09:17:01.540

@EriktheOutgolfer fixed. – Adnan – 2017-08-02T11:20:17.020

8

Bash, 120 112 106 102 80 76 74 bytes

-8 bytes because wget is smart enough to redirect HTTP to HTTPS when necessary
-6 bytes thanks to another sed suggestion from Cows quack
-26 bytes thanks to Digital Trauma
-4 bytes thanks to Gilles - codegolf.stackexchange.com/u/123 redirects
-2 bytes thanks to Digital Trauma's answer's wget flags

wget -qO- codegolf.stackexchange.com/u/$1|sed -nr 's/.*>User (.*) -.*/\1/p'

No TIO link since the TIO arenas can't access the internet.

Thanks to the answers here and the people in chat for helping me with this. I used an approach similar to HyperNeutrino's.

  1. wget -qO- codegolf.stackexchange.com/users/$1 downloads the user's profile page and prints the file to STDOUT. -q does it quietly (no speed information).

  2. sed -nr 's/.*User (.*) -.*/\1/p' searches for the first string User<space>, then prints up until it reaches the end of the name, found using sed magic.


Previous answer that I wrote more independently (102 bytes):

wget codegolf.stackexchange.com/users/$1 2>y
sed '6!d' <$1|cut -c 13-|cut -d '&' -f1|sed 's/.\{23\}$//'
  1. wget codegolf.stackexchange.com/users/$1 2>y saves the user profile HTML to a file titled with their UserID and dumps STDERR to y.

  2. cat $1 pipes the file into the parts that cut away the useless HTML.

  3. sed '6!d' (in the place of head -6 | tail -1) gets the sixth line by itself.

  4. cut -c 13- strips away the first 13 characters, getting the username to start at the first character of the string.

  5. cut -d '&' -f1 cuts everything after the &. This relies on the fact that an ampersand is not allowed to be in a username, nor an HTML title.
    Now the string is <username> - Programming Puzzles

  6. sed 's/.\{23\}$//' was a suggestion from cows quack to remove the last 15 bytes of a file. This gets the username by itself.

Here's a full bash script.

MD XF

Posted 2017-08-01T17:31:00.130

Reputation: 11 605

...TIO arenas can't access the internet They can, that's how you're able to access it. :P User-submitted code is not permitted access to the internet . </nitpick> – totallyhuman – 2017-08-01T18:59:18.447

@totallyhuman You can access TIO arenas via the internet. But the arenas themselves cannot access the internet. Even Dennis' code running on an arena cannot access the internet. – MD XF – 2017-08-01T19:06:50.453

@totallyhuman afaik no they can't. You give the main server your code, the main server connects to an arena and runs the code. That might be outdated info though – Stephen – 2017-08-01T20:41:27.293

For userID 11259, the output is Digital Trauma - Progr – Digital Trauma – 2017-08-01T22:14:32.053

@DigitalTrauma Whoops, forgot to fix the second sed bytecount. – MD XF – 2017-08-01T22:19:25.683

You have a useless use of cat. Also some more minor optimisations of line 2: sed 6\!d $1|cut -c 13-|cut -d\& -f1|sed 's/.\{23\}$//'

– Digital Trauma – 2017-08-01T22:21:32.303

Also, your line 2 can be cut down to just one sed: sed -nr 's/.*r (.*) -.*/\1/p' $1 – Digital Trauma – 2017-08-01T22:28:43.043

@DigitalTrauma Doesn't work for user 65535 for some reason. (second comment) – MD XF – 2017-08-01T22:57:37.553

@MDXF You'd have to use sed -nr 's/.*User (.*) -.*/\1/p' $1 then. – Digital Trauma – 2017-08-01T23:24:00.663

@DigitalTrauma Thanks. Will that work if the username contains User? – MD XF – 2017-08-01T23:43:40.507

@MDXF I guess not. You could do sed -nr 's/.*>User (.*) -.*/\1/p' $1 instead and I think you'd be safe. – Digital Trauma – 2017-08-01T23:48:41.270

@DigitalTrauma Ok, thanks. Does your answer work if the username contains User? I see it uses a similar approach. – MD XF – 2017-08-01T23:49:49.200

@MDXF yep, I just added in a " take care of that. – Digital Trauma – 2017-08-01T23:51:34.713

Instead of wget -qO-, you can also use curl -Ls, this should save 1 byte, provided I looked at all edge cases – Ferrybig – 2017-08-02T18:01:21.010

6

Bash + GNU utilities, 66

  • 3 bytes saved thanks to @Arnauld.
  • 4 bytes saved thanks to @Gilles.
wget -qO- codegolf.stackexchange.com/u/$1|grep -Po '"User \K[^"]+'

Uses -PCRE regex flavour to do a \K match start reset for much shorter output filtering.


If your system already has curl installed, we can use @Gilles' suggestion:

Bash + curl + GNU utilities, 64

curl -L codegolf.stackexchange.com/u/$1|grep -Po '"User \K[^"]+'

Digital Trauma

Posted 2017-08-01T17:31:00.130

Reputation: 64 644

What is the purpose of O-? – user41805 – 2017-08-01T19:39:03.283

@Cowsquack -O- sends the downloaded output to STDOUT instead of a file, so it can be simply piped to grep – Digital Trauma – 2017-08-01T19:40:06.360

1You can do grep -Po '"User \K[^"]+' to save 3 bytes. – Arnauld – 2017-08-01T20:45:08.423

@Arnauld thanks! – Digital Trauma – 2017-08-01T21:00:15.530

1curl -L is shorter than wget -qO-. You can use /u instead of /users. – Gilles 'SO- stop being evil' – 2017-08-02T09:09:25.013

@Gilles Yes - I went with wget instead of curl as its a "cleaner" answer (no dependency on 3rd-party installations). But a 2 byte saving is a 2 bytes saving so I've noted it :). Thanks for the s/users/u/ tip! – Digital Trauma – 2017-08-02T16:29:42.780

You need to -s flag for curl to suppress the process bar, as the question doesn't say you are allowed to output things to the error stream (or I misread the rules somewhere, they are really scattered around) – Ferrybig – 2017-08-02T18:03:39.470

1

@Ferrybig I'm assuming its ok to ignore STDERR by default

– Digital Trauma – 2017-08-02T18:36:01.400

wget and curl are both third-party to bash anyway. In default Linux installations I think curl is a bit more common than wget. So wget isn't “cleaner” than curl. Cleaner would be doing it in pure bash (<>/dev/tcp/codegolf.stackexchange.com/80 — good luck with the HTTPS redirect!). – Gilles 'SO- stop being evil' – 2017-08-02T18:59:33.053

@Gilles yep, pure bash is definitely "cleanest". In my experience (which is likely less than yours) I've never had to install wget, but I do remember installing curl on a couple of occasions (I think Ubuntu is this way). My claim is that sticking to purely GNU tools is cleaner, but this is not a strongly held conviction :). The answer now contains both anyway - Thanks! – Digital Trauma – 2017-08-02T19:10:21.540

4

Python 2 + requests, 112 bytes

from requests import*
t=get('http://codegolf.stackexchange.com/users/'+input()).text
print t[49:t.index('&')-23]

note

once SE goes fully https, the http needs to be changed to https, which will make this 113 bytes.

The beginning of a user profile looks like this:

<!DOCTYPE html>
<html>

<head>

<title>User MD XF - Programming Puzzles &amp; Code Golf Stack Exchange</title>

The username starts at index 49 and the ampersand occurs 23 characters to the right of where it ends (- Programming Puzzles)

-3 bytes thanks to StepHen/Mego by removing the unused re import
-1 byte thanks to Uriel

HyperNeutrino

Posted 2017-08-01T17:31:00.130

Reputation: 26 575

You never use re so you can drop 3 bytes – Mego – 2017-08-01T17:35:22.817

@Mego lol I'm dumb. thanks – HyperNeutrino – 2017-08-01T17:35:47.117

You can also use http for the time being, but that will be phased out eventually when SE goes full HTTPS. – Mego – 2017-08-01T17:36:14.627

@Mego I'll add that in as a side note - thanks – HyperNeutrino – 2017-08-01T17:36:50.083

also, from requests import* and drop r. for 113 bytes – Uriel – 2017-08-01T17:39:30.013

@Uriel But it can't :) – HyperNeutrino – 2017-08-01T17:39:33.927

@Hyper-Neutrino thankfully a site full of questions about validation has a proper validation – Uriel – 2017-08-01T17:40:52.440

Why are you using t.index('&')-23?! Cannot you just use t.index('-')-1]? – Mr. Xcoder – 2017-08-01T19:47:58.797

@Mr.Xcoder Names can contain - but not &. – HyperNeutrino – 2017-08-01T19:48:21.360

Ah, I see... :) – Mr. Xcoder – 2017-08-01T19:48:36.287

4

JavaScript (ES6), 111 75 bytes

Only works when run through the PPCG domain. Returns a Promise object containing the username.

i=>fetch("/users/"+i).then(r=>r.text()).then(t=>t.slice(44,t.search`&`-23))
  • Thanks to Downgoat for confirming that the alternative method I was toying with was valid, thus allowing me to save 36 bytes.

Shaggy

Posted 2017-08-01T17:31:00.130

Reputation: 24 623

77 bytes: i=>fetch(\/users/${i}`).then(r=>r.text()).then(s=>/"User ([^"]+)/.exec(s)[1])` – Downgoat – 2017-08-02T04:30:18.467

66 bytes: i=>$.get(\/users/${i}`).done(s=>alert(/"User ([^"]+)/.exec(s)[1]))` – Downgoat – 2017-08-02T04:36:45.603

you can remove the parenthesis from fetch to save 2 bytes – GilZ – 2017-08-02T07:41:06.750

Thanks, @Downgoat; I'd already toyed with the idea of fetching the user's page that way but thought it might be pushing my luck. But seeing as you've suggested it too, I'll edit it in. Do any browser's currently support .done()? I tested it quickly in Chrome & FF but it didn't work there. – Shaggy – 2017-08-02T09:18:20.540

@Gilz, I could only have done that if there wasn't a variable involved. – Shaggy – 2017-08-02T09:21:40.583

@Shaggy the latter version with done() does not use fetch APIs – Downgoat – 2017-08-02T16:25:57.383

4

Swift 3, 233 bytes

import Foundation;func f(i:String){let s=try!String(contentsOf:URL(string:"http://codegolf.stackexchange.com/users/"+i)!,encoding:.utf8);print(s[s.index(s.startIndex,offsetBy:44)...s.index(s.characters.index(of:"&")!,offsetBy:-24)])}

Sample runs:

f(i:"8478") // Martin Ender
f(i:"12012") // Dennis
f(i:"59487") // Mr. Xcoder

Mr. Xcoder

Posted 2017-08-01T17:31:00.130

Reputation: 39 774

1Yes! Swift! An oasis from a desert of golfing languages – bearacuda13 – 2017-08-01T20:25:36.347

@bearacuda13 Lol true :) – Mr. Xcoder – 2017-08-01T20:27:42.380

You could be able to use a closure and save a lot of bytes – Downgoat – 2017-08-02T04:32:05.720

@Downgoat Thanks for the tip, I'll update when I have time. – Mr. Xcoder – 2017-08-02T06:19:01.747

3

Cubically + Bash, 1654 1336 1231 bytes

-423 bytes thanks to TehPers

This needs three Cubically scripts (named 1, 2 and 3) and 1 bash script.

The Cubically scripts are really long because I haven't thought of a good way to implement loops yet.

Bash (84 bytes):

ln -s rubiks-lang /bin/r
r 1 <<<$1 2>y|xargs wget 2>y
cat $1|r 2 2>y|rev|r 3 2>y|rev

This pipes the first Cubically script into wget, then the saved file into the second Cubically script, then reverses that output, pipes it into the third Cubically script, then reverses it.

1 (385 bytes):

+5/1+551@6:5+3/1+552@66:4/1+552@6:5+2/1+552@6:4/1+51@6:2/1+5@66:5+51@6:3/1+552@6:1/1+551@6:2/1+551@6:4/1+551@6:3/1+552@6:5+52@6:3/1+551@6:1/1+5@6:5+2/1+552@6:5+3/1+552@6:5+2/1+55@6:5+51@6:5+3/1+551@6:2/1+551@6:3/1+553@6:5+51@6:5/1+551@6:5+2/1+55@6:2/1+552@6:4/1+551@6:2/1+551@6:1/1+5@6:5+51@6:3/1+552@6:1/1+552@6:2/1+5@6:5+53@6:5+2/1+552@6:2/1+551@6:5+1/1+552@6:5+2/1+552@6:2/1+5@6$7%7

This prints https://codegolf.stackexchange.com/users/, then the first integer of input.

2 (680 505 bytes):

~7777777777777777777777777777777777777777777777777
F1R1
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6
~7@7:5=7&6

This reads the unnecessary data from the saved file as input, then prints up until the ampersand in Programming Puzzles & Code Golf.

~7@7 reads a character and prints it. F1R1 and :5=7 check if the input is the ampersand. &6 exits if it is.

~7@7:5=7&6 is repeated 45 times because there are 15 bytes of unnecessary data and a 30-byte max StackExchange username.

3 (505 446 342 bytes):

U3D1R3L1F3B1U1D3
~777777777777777777777777
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7
~7-1=7&6@7

Very similar to the last script, this reads the first few unnecessary bytes, then cats until EOF. This also works due to the max SE username.

MD XF

Posted 2017-08-01T17:31:00.130

Reputation: 11 605

For file 3, why not use :0-1/1 instead of :4+4/1-1? Also, the first instance of it can just be -1/1 because notepad starts at 0. – TehPers – 2017-08-01T19:55:53.820

1Might want to warn that /bin/r is overwritten. – NoOneIsHere – 2017-08-01T19:59:37.397

For file 2, you can do F1R1 at the beginning, then use +5 throughout the program in place of +2/1+4 – TehPers – 2017-08-01T20:00:46.247

3

Python 2, 116 bytes

Just thought it's nice to have a standard library answer (that's actually quite decent in length).

from urllib import*
f=urlopen('http://codegolf.stackexchange.com/users/'+input()).read()
print f[49:f.index('&')-23]

When SE goes fully https, we need to add 1 more byte, switching urlopen('http://... with urlopen('https://....

Mr. Xcoder

Posted 2017-08-01T17:31:00.130

Reputation: 39 774

2

Powershell, 165 142 137 127 bytes

23 28 38 bytes saved thanks to AdmBorkBork!

Creates a file named 0 as a side effect.

((iwr"codegolf.stackexchange.com/u/$args").AllElements|?{$_.class-like"user-c*"})[1].innerhtml-match"(.+?) ?<|.+">0
$matches[1]

Works by going to the proper webpage, and selecting the "user-card-name" element, then extracting the proper text out of the innerhtml.

Testing

PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 61563
MD XF
PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 2
Geoff Dalgas
PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 12012
Dennis
PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 foo
Invoke-WebRequest : current community chat Programming Puzzles & Code Golf
Programming Puzzles & Code Golf Meta your communities Sign up or log in to customize your list. more stack
exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour
Start here for a quick overview of the site Help Center
Detailed answers to any questions you might have Meta
Discuss the workings and policies of this site About Us
Learn more about Stack Overflow the company Business
Learn more about hiring developers or posting ads with us
Programming Puzzles & Code Golf Questions Tags Users Badges Unanswered Ask Question
 Page Not FoundWe're sorry, we couldn't find the page you requested.
Try searching for similar questions
Browse our recent questions
Browse our popular tags
If you feel something is missing that should be here, contact us.
about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback
Technology Life / Arts Culture / Recreation Science Other
Stack Overflow
Server Fault
Super User
Web Applications
Ask Ubuntu
Webmasters
Game Development
TeX - LaTeX
Software Engineering
Unix & Linux
Ask Different (Apple)
WordPress Development
Geographic Information Systems
Electrical Engineering
Android Enthusiasts
Information Security
Database Administrators
Drupal Answers
SharePoint
User Experience
Mathematica
Salesforce
ExpressionEngine® Answers
Blender
Network Engineering
Cryptography
Code Review
Magento
Software Recommendations
Signal Processing
Emacs
Raspberry Pi
Programming Puzzles & Code Golf
Ethereum
Data Science
Arduino
more (26)
Photography
Science Fiction & Fantasy
Graphic Design
Movies & TV
Music: Practice & Theory
Worldbuilding
Seasoned Advice (cooking)
Home Improvement
Personal Finance & Money
Academia
Law
more (17)
English Language & Usage
Skeptics
Mi Yodeya (Judaism)
Travel
Christianity
English Language Learners
Japanese Language
Arqade (gaming)
Bicycles
Role-playing Games
Anime & Manga
Puzzling
Motor Vehicle Maintenance & Repair
more (32)
MathOverflow
Mathematics
Cross Validated (stats)
Theoretical Computer Science
Physics
Chemistry
Biology
Computer Science
Philosophy
more (10)
Meta Stack Exchange
Stack Apps
Area 51
Stack Overflow Talent
site design / logo © 2017 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution
required rev 2017.8.1.26652
At C:\Users\Conor O'Brien\Documents\powershell\whats-my-name-137085.ps1:1 char:3
+ ((Invoke-WebRequest -URI("codegolf.stackexchange.com/users/"+$args[0])).AllEleme ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], We
   bException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Cannot index into a null array.
At C:\Users\Conor O'Brien\Documents\powershell\whats-my-name-137085.ps1:2 char:1
+ $matches[1]
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

PS C:\Users\Conor O'Brien\Documents\powershell> .\whats-my-name-137085.ps1 -3
Invoke-WebRequest : current community chat Programming Puzzles & Code Golf
Programming Puzzles & Code Golf Meta your communities Sign up or log in to customize your list. more stack
exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour
Start here for a quick overview of the site Help Center
Detailed answers to any questions you might have Meta
Discuss the workings and policies of this site About Us
Learn more about Stack Overflow the company Business
Learn more about hiring developers or posting ads with us
Programming Puzzles & Code Golf Questions Tags Users Badges Unanswered Ask Question
 Page Not FoundWe're sorry, we couldn't find the page you requested.
Try searching for similar questions
Browse our recent questions
Browse our popular tags
If you feel something is missing that should be here, contact us.
about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback
Technology Life / Arts Culture / Recreation Science Other
Stack Overflow
Server Fault
Super User
Web Applications
Ask Ubuntu
Webmasters
Game Development
TeX - LaTeX
Software Engineering
Unix & Linux
Ask Different (Apple)
WordPress Development
Geographic Information Systems
Electrical Engineering
Android Enthusiasts
Information Security
Database Administrators
Drupal Answers
SharePoint
User Experience
Mathematica
Salesforce
ExpressionEngine® Answers
Blender
Network Engineering
Cryptography
Code Review
Magento
Software Recommendations
Signal Processing
Emacs
Raspberry Pi
Programming Puzzles & Code Golf
Ethereum
Data Science
Arduino
more (26)
Photography
Science Fiction & Fantasy
Graphic Design
Movies & TV
Music: Practice & Theory
Worldbuilding
Seasoned Advice (cooking)
Home Improvement
Personal Finance & Money
Academia
Law
more (17)
English Language & Usage
Skeptics
Mi Yodeya (Judaism)
Travel
Christianity
English Language Learners
Japanese Language
Arqade (gaming)
Bicycles
Role-playing Games
Anime & Manga
Puzzling
Motor Vehicle Maintenance & Repair
more (32)
MathOverflow
Mathematics
Cross Validated (stats)
Theoretical Computer Science
Physics
Chemistry
Biology
Computer Science
Philosophy
more (10)
Meta Stack Exchange
Stack Apps
Area 51
Stack Overflow Talent
site design / logo © 2017 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution
required rev 2017.8.1.26652
At C:\Users\Conor O'Brien\Documents\powershell\whats-my-name-137085.ps1:1 char:3
+ ((Invoke-WebRequest -URI("codegolf.stackexchange.com/users/"+$args[0])).AllEleme ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], We
   bException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Cannot index into a null array.
At C:\Users\Conor O'Brien\Documents\powershell\whats-my-name-137085.ps1:2 char:1
+ $matches[1]
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

PS C:\Users\Conor O'Brien\Documents\powershell>

Conor O'Brien

Posted 2017-08-01T17:31:00.130

Reputation: 36 228

2

PHP, 163 bytes


<?php $a=new DOMDocument;@$a->loadHTML(implode(0,file("http://codegolf.stackexchange.com/users/$argv[1]")));echo$a->getElementsByTagName('h2')->item(0)->nodeValue;

Ezenhis

Posted 2017-08-01T17:31:00.130

Reputation: 191

1

Python + requests, 126 bytes

lambda n:get('http://api.stackexchange.com/users/%d?site=codegolf'%n).json()['items'][0]['display_name']
from requests import*

Accessing the API is longer than reading the actual page apparently...

totallyhuman

Posted 2017-08-01T17:31:00.130

Reputation: 15 378

2That moment when standard library + page reading is shorter than requests :p – Mr. Xcoder – 2017-08-01T19:54:40.190

1

Jelly, 37 bytes

A port of HyperNeutrino's Python 2 answer - go give credit!

“3¬ẋṙẉṀḷo°ɓẏ8YyŒÇḣðk¦»;ŒGṾṫ51ṣ”&Ḣḣ-23

A monadic link taking a number and returning a list of characters; as a full program prints the result.

Note: not sure quite why the result of ŒG needs to be forced to become a string (done here with ) :/

How?

“3¬ẋṙẉṀḷo°ɓẏ8YyŒÇḣðk¦» = compression of:
                         "code"+"golf"+"."+"stack"+"exchange"+".com/"+"user"+"s/"

codegolf.stackexchange.com/users/

“...»;ŒGṾṫ51ṣ”&Ḣḣ-23 - Main link: number, n
“...»                - "codegolf.stackexchange.com/users/"
     ;               - concatenate with n
      ŒG             - GET request (should be to string & looks like it on output)
        Ṿ            - uneval (force to a string - shrug)
         ṫ51         - tail from index 51 (seems the ŒG result is quoted too, so 51 not 50)
            ṣ”&      - split on '&'
               Ḣ     - head (get the first chunk)
                ḣ-23 - head to index -23 (discard the last 23 characters)

Jonathan Allan

Posted 2017-08-01T17:31:00.130

Reputation: 67 804

1

Stack Exchange Data Explorer, 47 bytes

SELECT DISPLAYNAME FROM USERS WHERE ID=##N##--N

Try it online!

totallyhuman

Posted 2017-08-01T17:31:00.130

Reputation: 15 378

0

Mathematica, 126 bytes

StringTake[#&@@StringCases[Import["https://codegolf.stackexchange.com/users/"<>ToString@#,"Text"],"r "~~ __ ~~" - P"],{3,-4}]&  


input

[67961]

output

Jenny_mathy

J42161217

Posted 2017-08-01T17:31:00.130

Reputation: 15 931

0

Stratos, 22 bytes

f"¹⁸s/%²"r"⁷s"@0s"³_⁴"

Try it!

Explanation:

f"¹⁸s/%?"               Read the data from the URL: 
                        http://api.stackexchange.com/users/%?site=codegolf
                        where % is replaced with the input
         r              Get the JSON array named
          "⁷s"          items
              @0        Get the 0th element
                 s"³_⁴" Get the string "display_name"

Okx

Posted 2017-08-01T17:31:00.130

Reputation: 15 025