
Executable code snippets in Bing - bufbupa
http://techcrunch.com/2016/04/07/microsoft-and-hackerrank-bring-executable-code-snippets-to-bings-search-results-pages/
======
georgewfraser
This uses Monaco, the code editor behind Visual Studio Code
([https://code.visualstudio.com](https://code.visualstudio.com)) and
Typescript Playground
([https://www.typescriptlang.org/play](https://www.typescriptlang.org/play)).
I've spent time with ACE, CodeMirror, and Visual Studio Code, and Monaco puts
everything else to shame. Hopefully soon they will provide better
documentation of how to use Monaco in your own projects, there's an issue for
it:
[https://github.com/Microsoft/vscode/issues/446](https://github.com/Microsoft/vscode/issues/446)

~~~
amelius
Could you elaborate a little? In what way(s) is Monaco superior?

In my view, CodeMirror is pretty decent, and it seems to me that not much can
be improved upon it. But I haven't had the chance to compare it to anything
else.

------
chippy
Early adopters are HN readers, this is very smart from Bing - maybe we will
see the same soon in DuckDuckGo?

Why is it smart? Every major internet service is driven by it's early
adopters. Every major service is built and designed by people like us, hacker
news readers, techies, early adopters. But of course, not all services,
especially those who want to be massive are targeted to early adopters anymore
- they wrongly target the masses. To attract people to use your service, you
have to have the early adopters first, they have to attract us first and
_then_ target the masses. Thus, we are seeing Bing take a page from DuckDuckGo
in tailoring some parts of its service towards techies. It's a clever move.

~~~
irremediable
I've seen this mentioned in things like The Lean Startup, but never as the
focus. Do you know any books/studies/similar about targeting early adopters?

------
bootload
_" HackerRank co-founder Vivek Ravisankar tells me the project currently
features over 80 code snippets that focus on the most commonly searched terms.
Microsoft is positioning this as both a productivity and learning tool."_

Good startup idea could be found in this audience. Solve the coding problems
through searching for code. Just do it better than bing. [0]

[0] _" The way to win here is to build the search engine all the hackers use.
A search engine whose users consisted of the top 10,000 hackers and no one
else would be in a very powerful position despite its small size, just as
Google was when it was that search engine."_ ~
[http://paulgraham.com/ambitious.html](http://paulgraham.com/ambitious.html)

------
Estragon
No code returned. :(

[https://www.bing.com/search?q=solution+to+halting+problem](https://www.bing.com/search?q=solution+to+halting+problem)

~~~
octo_t
its because you didn't search for a specific language.

------
squeaky-clean
Pretty cool when it appears. You can edit it, and the examples are written in
a way that the output helps explain the flow (like showing the pivot and array
state in each pass of a quicksort). I'm surprised it doesn't support
Javascript though, since it's now so popular.

It also doesn't seem to support anything advanced or synonyms for terms. I can
search for "Reverse array python" but not "Reverse list python" (technically a
list is the proper name, and array is a different construct in Python), and
anything more advanced than sorting algorithms or simple features don't
appear. I tried a few pathfinding algorithms, fibonacci sequence, prime
numbers.... And I tried several variations of search terms. "Pathfinding in
Pyhton" / "Graph Search in Python" / "Djikstra's algorithm in Python",
nothing. I don't think it will be very useful because of this.

~~~
anilgulecha
I worked on this project. We're building up the list of samples of additional
programs/queries, so the number of queries you should see the editor for will
expand in the coming days.

~~~
breck
Any plans to add Javascript as a language?

~~~
anilgulecha
Yes, it will be enabled as part of the next update.

------
dc2
DuckDuckGo implemented something similar a few weeks ago:

[http://duckduckhack.com/](http://duckduckhack.com/)

This is probably Microsoft's response.

~~~
feintruled
Well, I doubt they could throw something this slick together in a copule of
weeks! Also, that DuckDuckHack looks to be something very different. I
couldn't find anywhere that allows you to sandbox code on it. Seems to need to
upload to a github repo first? What actually does it intend to be?

~~~
tagawa
DuckDuckHack is the public contribution part of DuckDuckGo. Most of our
Instant Answers are created by developers submitting code to repos on GitHub
which we then review and publish. Many of these are programming-related but a
bit different to what Bing has announced.

------
amluto
Running this is amusing:

    
    
      import os
      print '\n'.join(os.listdir('/'))
    

Personally, I'm partial to running IPython under Sandstorm for this kind of
thing. (Also, if I were to _host_ it, I'd be very nervous about any technique
not involving equal or greater paranoia.)

~~~
anilgulecha
A little more about the OS environment this is running in:
[https://www.hackerrank.com/environment](https://www.hackerrank.com/environment)

~~~
nv-vn
Ibterwsting. Is there a specific reason that Erlang's given so much more time
and memory than Elixir?

------
cha5m
Wow. Finally an actually decent bing feature. I hope this spurs google to
improve their support for non alphanumeric characters.

------
bru
Doesn't work here. None of the given examples triggered the feature.

~~~
shashwat986
So, yes. It is only enabled for the US market at the moment.

However, it's quite easy to see the result if you add `&market=en-US` to the
end of the query.

Example: [https://www.bing.com/search?q=quicksort+java&market=en-
US](https://www.bing.com/search?q=quicksort+java&market=en-US)

[Disclaimer: Dev at HackerRank. Not affiliated with this product, though]

~~~
mirekrusin
Can't find anything for "leftpad" :(

~~~
shashwat986
Damn! That's a nice idea :D Forwarding it to the relevant team.

------
hartator
I think it's weird to see Bing introducing new features first.

~~~
ideal322
It's one of the first times in a long time that Bing has partnered with
another company. HackerRank for the win!

------
cmdrfred
Microsoft is really aiming for the dev market lately.

------
blazespin
Google used to have code search but killed it.

~~~
jon_richards
They also killed being able to search for symbols. That still bugs me.

~~~
kevin_thibedeau
And they ruined Maps. It's like Google doesn't want to be in the search
business any more. No growth potential to deliver "maximum shareholder value"
and bonuses for the MBAs.

~~~
freehunter
I've been saying that Google Maps has gotten worse for a while now, and many
people just say that other maps have gotten better instead. But I don't think
that's true. I really do think that Google Maps has gotten substantially
worse.

For one, it's super slow. I've switched to Bing Maps when I need to get an
address quick on the desktop, because it's much faster. Google Maps has tons
of lag when I'm sliding around the map on every browser and every major OS.

Secondly, the "natural language" features of searching has taken a major step
back. I used to be able to say "[my town] mcdonalds to [neighboring town]
chase bank" and as long as the map view was over my town, it knew what I
meant. I just tried it now, map hovering over my town and McDonald's clearly
shown on the screen, and it asks me which McDonald's I want, all of them from
a city with the same name but in another state. It's like it doesn't know
where it is, anymore. You have to get super specific in writing your search
because it won't just assume you're talking about the McDonald's displayed on
the screen anymore.

To be fair, I stopped using a lot of Google services when I used to have a
Windows Phone and Google decided that anyone using a Windows Phone was
inherently inferior and weren't allowed to use their services[1][2] but even
now when I try to switch back, everything seems worse. Apple Maps is a better
mobile experience, Bing Maps is a better desktop experience, and Outlook
handles multiple email accounts much better than Gmail does. Bing search is
just as good as Google in my experience, but they pay me to use it (Bing
Rewards).

I'm honestly not sure what happened. Google used to be cool.

[1] [http://mashable.com/2013/01/05/google-maps-windows-
phone/#qY...](http://mashable.com/2013/01/05/google-maps-windows-
phone/#qY0X8y7SJuqG)

[2] [http://betanews.com/2013/08/15/google-once-again-blocks-
yout...](http://betanews.com/2013/08/15/google-once-again-blocks-youtube-app-
for-windows-phone/)

~~~
sapience
google is doing the opposite of "don't be evil", they are not likable any more

------
palakchokshi
I can see this being abused for phone screen technical interviews :) but I do
search for code snippets when I'm learning something new so this is great.

~~~
quadrature
theres already stack overflow for that.

------
sremani
Not only you get the result code, but you can edit the code and run it.
Nice!!!

------
koolba
The sandboxing is interesting ... Each process is running in a directory on
the same server.

Also there's some files that are visible that probably shouldn't be, including
one named "codechecker-android-release-key.keystore"...

For the curious, try running the code block. You can uncomment/commment things
out to see different results as there's a cap on the amount of stdout printed.

    
    
        import java.net.URLClassLoader;
        import java.io.*;
        import java.net.*;
        
        class  Solution
        {
        	private static void printFile(String path) throws Exception {
        		System.out.println("File: " + path);
        		InputStream in = new FileInputStream(path);
        		byte buf[] = new byte[1024];
        		int len;
        		while( (len = in.read(buf)) > 0 ) {
        			System.out.write(buf, 0, len);
        		}
        		System.out.flush();
        	}
        	
        	final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
        	private static String bytesToHex(byte[] bytes) {
        	    char[] hexChars = new char[bytes.length * 2];
        	    for ( int j = 0; j < bytes.length; j++ ) {
        	        int v = bytes[j] & 0xFF;
        	        hexChars[j * 2] = hexArray[v >>> 4];
        	        hexChars[j * 2 + 1] = hexArray[v & 0x0F];
        	    }
        	    return new String(hexChars);
        	}
        
            private static void printFileHex(String path) throws Exception {
        		System.out.println("File: " + path);
        		InputStream in = new FileInputStream(path);
        		ByteArrayOutputStream out = new ByteArrayOutputStream();
        		byte buf[] = new byte[1024];
        		int len;
        		while( (len = in.read(buf)) > 0 ) {
        			out.write(buf, 0, len);
        		}
        		byte bytes[] = out.toByteArray();
        		System.out.println(bytesToHex(bytes));
        		System.out.flush();
        	}	
        	
        	public static void main (String[] args) throws Exception
        	{
        		Class<?> clazz = Class.forName("java.lang.ClassLoader");
        		URLClassLoader cl = 
        		  (URLClassLoader) Thread.currentThread().getContextClassLoader();
        	    System.out.println("Classpath:");
        		for(java.net.URL url : cl.getURLs()) {
        			System.out.println("" + url);
        		}
        		File local = new File("");
        		System.out.println("Local path: " + local.getAbsolutePath());
        		
        		System.out.println("Files:"); 
        		File root = new File("/");  
        		String list[] = root.list();		
        		System.out.println("# root files: " + list.length);
        		
        		//printFile("/etc/passwd");
        		printFileHex("/etc/codechecker-android-release-key.keystore");
        		
        		System.out.println("# root files: " + list.length);
        		for(String base : new String[]{ "/etc", "/bin", "/sbin", "/usr"}) {
        		  for(String name : new File(base).list()) {
        		     System.out.println(base + "/" + name);
        		  }
        		}
        	}
        }

~~~
anilgulecha
You can read more about the environment here:
[https://www.hackerrank.com/environment](https://www.hackerrank.com/environment)

We have a cluster of codechecker servers of the above type, which share the
load of incoming queries. On each, sandboxing is via a chroot-based system.
Programs get a fixed amount of memory/time.

Re: the codechecker keyfile - we're looking into this, as I'm not an android
expert - but quick searching tells me this is used to sign apks. Our
codechecker supports android builds, so that's probably what this is used for.
This key is not used to sign anything official (like throwaway id_rsa you
create when needed). Again, I'm not the expert on this and I'll add a
confirmation here shortly.

That said, if anyone finds something a vulnerability/way out of the sandbox,
please shoot me a mail (anil @ hackerrank) if you'd like to do a private
disclosure.

~~~
sgdread
You might harden policy files for Java process to prevent usage of Runtime.
Not sure about any attack vectors, but I can execute linux commands. Also
interesting that you allowed threads.

import java.io.BufferedReader; import java.io.IOException; import
java.io.InputStreamReader; class Solution {

    
    
        public static void main(String[] args) throws IOException, InterruptedException {
            final Runtime rt = Runtime.getRuntime();
            final Process pr = rt.exec("uname -a");
            new Thread(new Runnable() {
                public void run() {
                    BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
                    String line = null;
    
                    try {
                        while ((line = input.readLine()) != null)
                            System.out.println(line);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
    
            pr.waitFor();
        }
    	
    		
    }

~~~
anilgulecha
* Running commands is fine -- infact bash is a programming language we support. As long as you cannot get out of the sandbox.

* Threads are allowed by the environment.

------
riyadparvez
Given that so many vertical features can be integrated in a search engine,
this seems very odd choice.

------
nimesh159
This is amazing. You should do similar engagement with Google search also!

------
bovermyer
Oh man, that is REALLY cool. I may actually have to use Bing now.

------
tomnikl
Cool to see it in Bing. Hope Google follows suit soon.

------
derwiki
Not to be flippant, but.. I assumed most coders use Google / DuckDuckGo. I
seem to remember reading that even coming from Microsoft offices, engineers
prefer Google to Bing. Does that make this simply a PR move?

~~~
tsurantino
You're right - Bing shouldn't bother improving it's product for potential new
users because people prefer to use other products which don't have these
features...

~~~
hockeybias
And certainly nobody would ever change search engines.

