changing source on html5 video tag

I hated all these answers because they were too short or relied on other frameworks. Here is “one” vanilla JS way of doing this, working in Chrome, please test in other browsers: var video = document.getElementById(‘video’); var source = document.createElement(‘source’); source.setAttribute(‘src’, ‘http://techslides.com/demos/sample-videos/small.mp4’); source.setAttribute(‘type’, ‘video/mp4’); video.appendChild(source); video.play(); console.log({ src: source.getAttribute(‘src’), type: source.getAttribute(‘type’), }); setTimeout(function() { video.pause(); … Read more

How do you dynamically compile and load external java classes? [duplicate]

Take a look at JavaCompiler The following is based on the example given in the JavaDocs This will save a File in the testcompile directory (based on the package name requirements) and the compile the File to a Java class… package inlinecompiler; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; import java.net.URL; import java.net.URLClassLoader; import … Read more

Can I get JSON to load into an OrderedDict?

Yes, you can. By specifying the object_pairs_hook argument to JSONDecoder. In fact, this is the exact example given in the documentation. >>> json.JSONDecoder(object_pairs_hook=collections.OrderedDict).decode(‘{“foo”:1, “bar”: 2}’) OrderedDict([(‘foo’, 1), (‘bar’, 2)]) >>> You can pass this parameter to json.loads (if you don’t need a Decoder instance for other purposes) like so: >>> import json >>> from collections … Read more