Abra el navegador para http://codegolf.stackexchange.com


33

Su trabajo es abrir una ventana del navegador del navegador predeterminado a http://codegolf.stackexchange.com .

Su código debe abrir el navegador y no puede confiar en uno abierto.

Este es el , por lo que gana la respuesta más corta en bytes.


8
¿Se permiten acortadores de URL?
isaacg

44
¿Está permitido ejecutar JavaScript en el navegador predeterminado para abrir una ventana?
Mwr247

44
@ Mwr247 No, no lo es.
noɥʇʎԀʎzɐɹƆ

15
Debe agregar aclaraciones / restricciones a la pregunta en sí, ya que no se garantiza que los comentarios permanezcan para siempre.
Mego

8
Su especificación es mínima, lo que generó una gran incertidumbre sobre lo que está permitido para realizar la tarea. Además, algunos probablemente lo consideren una tarea trivial. Aún así, estás en lo positivo;)
Mwr247

Respuestas:


35

 GNU Emacs, 29 27 14 bytes

(eww"ppcg.ga")

EWW es un navegador dentro de Emacs. La browse-webfunción es un alias para eww, y eso hace que ewwel navegador predeterminado en Emacs:

Su trabajo es abrir una ventana del navegador del navegador predeterminado a http://codegolf.stackexchange.com .

Gracias a @CoolestVeto, @Jonathan Leech-Pepin y @ zyabin101.


¿Se puede usar en www.ppcg.lollugar de http://ppcg.lol?
AdmBorkBork

1
@TimmyD No, al principio lo intenté con "www" pero se debe proporcionar el protocolo (el comportamiento es diferente, por ejemplo, con "mailto: //"). Para la interacción del usuario, hay "browse-url-at-point" que antecede a "http", pero esto es más largo, por supuesto.
coredump

No deberías necesitar el //, no creo. (No uso emacs, pero generalmente se acepta sin el //)
Addison Crump

11
ಠ_ಠ PPCG no es algo para "ewwww" eso, eso es revisión de código: P
Downgoat

3
Al parecer hay ppcg.ga . Puede ahorrarle un byte.
user48538

46

Oración , 41 bytes

No ganar, pero seguro fue divertido. ¡A partir de ahora, solo estoy 1 bytee detrás de Python!

I need webbrowser
Now open "http:ppcg.ga"

Explicación:

I need compila a import $1 con webbrowserser el módulo.

Now ejecuta el siguiente comando desde el módulo como module.command con los argumentos de todo lo que sigue.

Entonces esto se compila para:

#!/usr/bin/env python3
import webbrowser
webbrowser.open("http:ppcg.ga")

Sin http:embargo, termino necesitando la parte, y no se puede acortar.


17
Como propietario de ppcg.lol , apruebo este mensaje.
Quill

Esta conversación se ha movido al chat .
Dennis

Estoy casi seguro de que se puede reemplazar "http://ppcg.lol"con "http:ppcg.lol". No estoy seguro de si puedes eliminar el espacio entre openy "http:...", pero ¿intentarlo?
Addison Crump

2
@Quill Quise decir, ¿cómo sabemos que Rick no nos rodará a todos en algún momento futuro?
PyRulez

1
@Quill eso depende de cuánto te guste Rick ...
TMH

43

Lote, 17 bytes

Guardado 3 bytes gracias a Mego.

start www.ppcg.ga

Esto se abrirá en su navegador predeterminado si lo ejecuta desde la línea de comandos de Windows.

Creo que también funcionará en Powershell, pero no estoy seguro.


3
Puedes usar en startlugar de explorer.
Mego

8
En su start www.ppcg.lollugar, puede utilizarlo para que Windows lo analice implícitamente como HTTP. Funciona tanto en CMD como en PowerShell.
AdmBorkBork

2
¿Por qué necesitas el www.?
Blender

3
@Blender Porque de lo contrario intenta encontrar un programa local llamado pccg con la extensión de archivo .lol y ejecutarlo.
Morgan Thrapp

2
@PyRulez No es un acortador de URL, técnicamente. Quill compró ese dominio hace un tiempo y configuró una redirección de DNS.
Mego

24

PowerShell, 17 16 bytes

saps www.ppcg.lol 

Usando un dominio aún más corto proporcionado por Milo.

saps www.ppcg.ga

Si bien startes un alias conocido, Start-Processhay otro para saps. Puedes ver esto desde Get-Alias. Sigue la convención para similares Start-y Stop-cmdlets.


psst puede usar www.ppcg.ga ahora
Milo

@ Mil gracias. Creo que otras personas pueden escucharte.
Matt

ppcg.ga no funciona
anukul 03 de

2
Hmm Todavía funciona para mí y presumiré milo. Quizás es nuevo y el dns no se ha propagado por completo
Matt

21

Terminal (OSX), 20 18 17 bytes

open http:ppcg.ga

Guardado 2 gracias a CoolestVeto


55
openes una utilidad OSX, no bash; esto se llamaría más apropiadamente "línea de comando OSX".
Skyler

1
@Skyler ¿Es esto incorrecto entonces? ss64.com/bash/open.html
Mwr247

1
la primera línea: "Abra un archivo en su aplicación predeterminada, usando la terminal virtual (VT)". Si intenta ejecutar eso en Unix, le dirá "No se pudo obtener un descriptor de archivo que se refiera a la consola", porque está tratando de abrir en un terminal, no en un navegador.
Skyler

3
Puedes deshacerte de él //.
Addison Crump

2
Puede guardar otro byte:open http:ppcg.ga
DarkDust

14

MATLAB, 28 25 bytes

web www.ppcg.lol -browser
  • wwwes más corto http://y garantiza que la dirección se procese como una URL
  • Esto es más corto utilizando la llamada de función implícita (que convierte las entradas como cadenas) en lugar de la versión explícita web('www.ppcg.lol', '-browser').
  • Si está en un OS X, esto puede simplificarse web ppcg.lol -browserya que MATLAB agregará automáticamente un http://( 21 bytes )

Alternativas :

  • En Windows, esto se puede acortar a ( 19 bytes )

    !start www.ppcg.lol
    
  • En OS X ( 21 bytes )

    !open http://ppcg.lol
    
  • Lo siguiente funcionaría en una aplicación MATLAB implementada ( 16 bytes )

    web www.ppcg.lol
    
  • Si se pudiera usar el navegador incorporado, esto podría reducirse aún más, como httpestá implícito ( 12 bytes )

    web ppcg.lol
    

OS X es redundante porque el opencomando incorporado hace lo mismo.
noɥʇʎԀʎzɐɹƆ

1
@CrazyPython Eso es precisamente lo que !hace en MATLAB, es el equivalente de system(command). Lo tuve como una demostración de otras alternativas que podrían ejecutarse desde MATLAB. ¿Eso esta bien?
Suever

¿Necesitas el www.?
Addison Crump

@CoolestVeto A veces lo haces a veces no. Cuando usa el navegador externo, lo hace, sin embargo, el navegador interno no lo hace. Si no lo especifica, no se abrirá ninguna ventana del navegador. Si puede hacer que funcione, ¡estoy más que feliz de cambiarlo!
Suever

@CoolestVeto So I dug a little more and it looks like the www is unnecessary only on OS X
Suever

13

AutoHotKey, 16 bytes

Run www.ppcg.lol

7
Unfortunately, not everybody has *shudder* Google Chrome *shudder* set as their default browser (or installed at all!).
wizzwizz4

5
Not everyone has AHK either...both facts are very shudder worthy
Michelfrancis Bustillos

5
I was shuddering because I had to type... never mind.
wizzwizz4

2
The challenge spec requires opening PPCG in the default browser, which may or may not be Chrome.
Dennis

1
You don't need the comma
Engineer Toast

13

Python, 52 48 47 45 44 bytes

Shamelessly borrowing that shortened link.

from webbrowser import*;open("http:ppcg.ga")

Thanks to CrazyPython for -4 bytes, and Sp3000 for a further one.

Edit: shaved 2 more off thanks to CoolestVeto

Edit: thanks to MD XF for registering ppcg.ga and saving another byte


The former change leaves it exactly the same length. As for the http://, if you leave that out it tries to open a local file called "ppcg.lol", which doesn't exist.
Skyler

1
You don't need //.
Addison Crump

Thanks! I wonder why that works?
Skyler

1
You can also do this with just command line options python -m webbrowser -t http:ppcg.lol which I think counts as 30 chars
gnibbler

1
ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

10

Bash, 24 22 bytes

xdg-open http:ppcg.lol

Not as short as some others. firefox ppcg.lol is shorter, but it doesn't meet question spec.


xdg-open www.ppcg.lol works for me as well.
Digital Trauma

@digital_trauma interesting, it didn't for me. It looked for www.ppcg.lol on the file system. Ubuntu 15.10.
Ogaday

Weird. Ubuntu 14.04 for me. xdg-utils 1.0.
Digital Trauma

1
You shouldn't need the //.
Addison Crump

1
@CoolestVeto Correct. xdg-open http:ppcg.lol also works for me.
Digital Trauma

10

Java 7, 118 115 bytes

class P{public static void main(String[]a)throws Exception{java.awt.Desktop.getDesktop().browse(new java.net.URI("http://ppcg.lol"));}}

Java is not the best language for golfing... Here's the same program in a more readable format:

class P {
    public static void main (String[] a) throws Exception {
        java.awt.Desktop.getDesktop().browse(new java.net.URI("http:ppcg.ga"));
    }
}

Saved 2 bytes by removing // in the URI/L, and another byte by switching to .ga from .lol (indirectly thanks to @Milo)



1
@Mego I could do that, but then it would be Java 8. This is a Java 7 answer. But thanks for the tip!
HyperNeutrino

1
Replace "http://ppcg.lol" with "http:ppcg.lol"
Addison Crump

8
code-golf specifies that functions are sufficient, you do not have to write a full program. So void f(){ .... } would be enough.
flawr

1
Your program in more readable format is missing a closing parenthesis
Nzall

9

Pylongolf, 11 bytes (Non-Competing)

"ppcg.lol"p

Pushes ppcg.lol into the stack then p opens it.


Will that open it as a local file, or as a website address?
wizzwizz4

And did you just add the changes that allowed this to work?
Rɪᴋᴇʀ

@wizzwizz4 As an address. Yes, so this does not compete with others, just for fun.

5
If I were you, I would edit "(Non-competing)" into the title, so people don't downvote.
wizzwizz4

@wizzwizz4 done.
Rɪᴋᴇʀ

9

Java 8, 115 112 bytes

interface P{static void main(String[]a)throws Exception{java.awt.Desktop.getDesktop().browse(new java.net.URI("http:ppcg.ga"));}}

Java is not the best language for golfing... Here's the same program in a more readable format:

interface P {
    static void main (String[] a) throws Exception {
        java.awt.Desktop.getDesktop().browse(new java.net.URI("http:ppcg.ga"));
    }
}

Saved 2 bytes by removing // (thanks @CoolestVeto), and another byte by switching to .ga from .lol (indirect thanks to @Milo)


You can remove the //.
Addison Crump

Isn't it supposed to be java.net?
Ryan

cant you replace interface with class?
MCMastery

@MCMastery Yes. However, with an interface, you can save 3 bytes because even though interface is longer than class, you save more bytes because the public modifier is implied.
HyperNeutrino

@Ryan Whoops. Fail. Yes, you're right. Thanks!
HyperNeutrino

8

JavaScript, 34 bytes

require('open')('http://ppcg.lol')

Uses Node.js


Do you need //?
Addison Crump

2
If node.js supports ES6: require`open``http://ppcg.lol`; (added ; to avoid tripping the formatting)
Ismael Miguel

2
Alternatively, does it require a protocol? eg require('open')('//ppcg.lol') to save 5 bytes
Martijn

2
@Martijn Shh...
wizzwizz4

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

7

Racket, 41 40 bytes

(require net/sendurl)(send-url"ppcg.ga")

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

Thanks for commenting. I'll update my answer in front of a computer later today. :)
Winny

6

Applescript, 28 bytes

  • 3 bytes saved thanks to @CoolestVeto.
open location"http:ppcg.lol"

how dare a high-rep user not format their header correctly D:
cat

1
@cat actually, I've never been called out on this before - I've always operated on the assumption that bytes is the default for codegolf (and is even explicitly specified in this question), so explicitly respecifying in answers is just redundant information. Do you know of a meta post about this?
Digital Trauma

Well, first and foremost, my comment was messing around -- I only changed it for consistency with all the other answers, and it's really insignificant but it bothered me. I'm pretty sure there's no meta post on formatting specifically, and that this format came from the Leaderboard Stack Snippets, but I'm almost certain there's a meta post for Defaults for Scoring Code Golf that says it's bytes unless otherwise specified.
cat

1
@cat Yep, I don't think its a big deal either way - I'm certainly not planning on rolling back your edit :). Scoring by bytes by default is in the code-golf tag wiki
Digital Trauma

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF


5

R, 26 bytes

shell.exec("www.ppcg.lol")

I don't know of any shorter way to do this in R.


1
Duplicate of this. Simply wrapping another answer in a system/fork/whatever call is a trivial modification.
Mego

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

5

Actionscript 3, 117 bytes

package{import flash.display.Sprite;public class A extends Sprite{function A(){navigateToUrl("ppcg.lol","_blank")}}}

Like Java, this is not a great golfing language. Here's the code with formatting:

package
{
    import flash.display.Sprite;

    public class A extends Sprite
    {
        function A()
        {
            navigateToUrl("ppcg.lol", "_blank")
        }
    }
}

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

5

Rebol 2, 16 15 bytes

browse"ppcg.ga" 

if you accept an error before opening the page on Linux, no error on Windows

20 bytes without an error

browse http:ppcg.lol

Alternative to the first one (although with the same score): browse #ppcg.lol
Izkata

now with shorter url.(
sqlab

5

Perl 5, 66 57 bytes

Should work everywhere, but needs that import :(

8 bytes saved with @msh210 comment.

use Browser::Open open_browser;open_browser"http:ppcg.ga"

Also, for funsies :

Perl 5 (Windows), 34 bytes

system "start http://www.ppcg.ga"

Perl 5 (Unix), 31 bytes

system "xdg-open http:ppcg.ga"

use -M instead of use to shave a coupla bytes. (Untested.) Also, I'm guessing you don't need the parens or the www.. (Also untested.)
msh210

@msh210 Can't seem to get the -M switch to work apparently on my Mac... (?), but indeed the www as well as the // can be removed. Thanks !
Paul Picard

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

Edit done. Thank you for keeping old answers up to date :)
Paul Picard


3

RFO-BASIC, 22 bytes

BROWSE "http:ppcg.lol"

Read about RFO-BASIC at laughton.com.


While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
Mego

Alright. I just figured most people wouldn't know about this "dialect" of BASIC.
TickTock

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway. Also, couldn't the space between BROWSE and " be removed, saving another byte?
MD XF

3

VBScript, 57 bytes

I used to have lots of fun creating tiny programs in VBScript, back in 2010.

I've remembered this language and used the code on: https://stackoverflow.com/a/13401872/2729937

It still works on Windows 7, at least.

set S=CreateObject("WScript.Shell")
S.run("www.ppcg.ga")

This is a bit different from the usual start www.ppcg.lol, in the sense that it executes the www.ppcg.ga directly, with an implicit start.

An alternative way would be "cmd.exe /C start www.ppcg.ga".


ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

@MDXF Thank you for that tip. While it is nice to save a byte, I won't change the score since it doesn't feel fair.
Ismael Miguel

2

C#, 33 bytes

Process.Start("http://ppcg.lol");

Opens the default browser to the web address


Nope... Replace \\ via //.
Qwertiy

not a c# program, just a single line
BryanJ

Also this needs the System.Diagnostics namespace to be added in or Process to be fully qualified to work.
TheLethalCoder

1
This is not a c# program.
Vahid Amiri

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

2

05AB1E, 16 bytes (non-competing)

Non-competing, since the features used here postdate the challenge. Code:

’…Ò ™³.ÐÏg.´¢’.E

You can try the string online here. This basically evaluates to this batch answer.

Uses the CP1252 encoding.


How do you count the bytes? Depending which program I use for counting I get from 21 to 34 bytes.
sqlab

@sqlab 05AB1E uses the CP1252 encoding.
Adnan

2

VB.NET, 32 30 bytes

Process.Start("http:ppcg.lol")

+10 for Sub Main(), and +7 for End Sub, which you need in order to run this at least in a VB.NET console program, also you would need to import System.Diagnostics.
Virtual Anomaly

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

2

Factor, 38 36 26 bytes

[ "http:ppcg.ga" open-url ]

I didn't know one could golf-off the // in the protocol.


I think you can remove the space between the end-quote and run-process, and you can wholly drop //.
Addison Crump

@CoolestVeto Thanks! I didn't know the // could be left off. As for the space between " and run-process, dropping that would require a word named "run-process to be present in the current vocabulary search path
cat

@CoolestVeto Factor's like Forth -- highly whitespace dependent
cat

Duplicate of this. Simply wrapping another answer in a system/fork/whatever call is a trivial modification.
Mego

@Mego Okay, well, not that it really matters but I did come up with this without seeing that one. But, there is really no other way to run The default browser without xdg-open in languages which are not equipped with special functions for browsing the web. A C or ASM answer would surely also have to do system("xdg-open...")
cat

2

Python, 44 bytes

from webbrowser import*;open('http:ppcg.ga')

URL from this comment
Edit: ppcg.ga seems to become more popular now (but it WAS available when I posted this answer).

Ungolfed:

from webbrowser import * # Loads everything in the webbrowser module
open("http://ppcg.ga/") # Opens default browser to http://ppcg.ga/

Python, 44 bytes

from webbrowser import*;open('http:gfa1.tk')

URL from this answer

Ungolfed:

from webbrowser import * # Loads everything in the webbrowser module
open("http://gfa1.tk/") # Opens default browser to http://gfa1.tk/

Python, 45 bytes

from webbrowser import*;open('http:ppcg.lol')

Ungolfed:

from webbrowser import * # Loads everything in the webbrowser module
open('http://ppcg.lol/') # Opens default browser to http://ppcg.lol/

Take that, ppcg.lol! (1 byte shorter)

Note: I added a separate answer leading to ppcg.lol, 'cause I've noticed the other sites doesn't work for me in Internet explorer 11, and I saw other users having this problem too.

Both are non-non-competing (read that right?)


2

Ruby, 22 20 19 bytes (on OS X)

`open http:ppcg.ga`

Simple.

Thanks to Daniel for 2 bytes off.


You can save 2 characters by using backticks instead of %x. open http:ppcg.lol
Daniel Evans

@DanielEvans Great, thanks. That saves 2 bytes.
Rɪᴋᴇʀ

1
"'open' is not recognized as an internal or external command, operable program or batch file."
Dewi Morgan

1
@DewiMorgan OS X only.
Rɪᴋᴇʀ

2

Cheddar, 65 bytes

cheddar.internal(cheddar.uid).require("open").c("http://ppcg.ga")

Accesses cheddar internals and then calls upon open package and calls it with string to PPCG. Make sure you have open npm package installed


Shouldn't this be Cheddar+Open if it requires another package?
Pavel
Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.