I just got this email:
Bard has just been updated with coding capabilities
Code and debug with Bard
This update introduces software development support for over 20 programming languages, including JavaScript, Python, SQL, TypeScript, and even Google Sheets functions.
Collaborate with Bard to help generate, explain, and debug your code. Google Colab users can also export Python code generated by Bard directly to Google Colab to seamlessly continue programming tasks.
>Write a javascript function for calculating the dates of Fat Tuesday, Ash Wednesday, Good Friday, Easter Sunday, and Pentecost, for a given year.
The Draft 1 it presented to me was incorrect garbage, as is Draft 3, but Draft 2 might be correct:
function calculateDates(year) {
// Calculate the date of Easter Sunday.
var easterSunday = easterDate(year);// Calculate the dates of the other holidays.
var fatTuesday = new Date(easterSunday - 47 * 24 * 60 * 60 * 1000);
var ashWednesday = new Date(fatTuesday - 1 * 24 * 60 * 60 * 1000);
var goodFriday = new Date(easterSunday - 2 * 24 * 60 * 60 * 1000);
var pentecost = new Date(easterSunday + 49 * 24 * 60 * 60 * 1000);// Return the dates of the holidays.
return {
fatTuesday: fatTuesday,
ashWednesday: ashWednesday,
goodFriday: goodFriday,
easterSunday: easterSunday,
pentecost: pentecost
};
}// Calculate the date of Easter Sunday.
function easterDate(year) {
// Calculate the year of the Paschal full moon.
var yearOfPaschalFullMoon = (year - 1) % 19 + 1;// Calculate the day of the week of the Paschal full moon.
var dayOfWeekOfPaschalFullMoon = (yearOfPaschalFullMoon + 1) * 2 + (yearOfPaschalFullMoon > 11 ? 4 : 0) % 7;// Calculate the date of Easter Sunday.
var easterSunday = new Date(year, 3, 22 + dayOfWeekOfPaschalFullMoon - 7);// If the Paschal full moon falls on a Sunday, then Easter Sunday is the following Sunday.
if (easterSunday.getDay() === 0) {
easterSunday.setDate(easterSunday.getDate() + 1);
}// Return the date of Easter Sunday.
return easterSunday;
}
Nope, it's returning the wrong dates. Nice try.
>Make a radio player that can play BBC World radio and several other stations, using HTML and JavaScript
<!DOCTYPE html>
<html>
<head>
<title>Radio Player</title>
</head>
<body>
<h1>Radio Player</h1>
<div id="stations">
<ul>
<li><a href="https://www.bbc.co.uk/sounds/play/bbc_world_service">BBC World Service</a></li>
<li><a href="https://www.npr.org/sections/live-at-noon/">NPR Live at Noon</a></li>
<li><a href="https://www.bbc.co.uk/sounds/play/bbc_radio_4_extra">BBC Radio 4 Extra</a></li>
<li><a href="https://www.bbc.co.uk/sounds/play/bbc_radio_3">BBC Radio 3</a></li>
<li><a href="https://www.bbc.co.uk/sounds/play/bbc_radio_1">BBC Radio 1</a></li>
</ul>
</div>
<div id="player">
<audio controls></audio>
</div>
<script>
function playStation(station) {
var audio = document.querySelector("audio");
audio.src = station;
audio.play();
}document.querySelectorAll("a").forEach(function(link) {
link.addEventListener("click", function() {
playStation(this.href);
});
});
</script>
</body>
</html>
I selected that draft, added event.preventDefault() to the anchors to prevent them from loading a new page, and changed the URLs to ones that could actually work:
<!DOCTYPE html>
<html>
<head>
<title>Radio Player</title>
</head>
<body>
<h1>Radio Player</h1>
<div id="stations">
<ul>
<li><a href="https://realtime.rrr.org.au/p1h">3 Triple R 102.7 FM</a></li>
<li><a href="http://stream.live.vc.bbcmedia.co.uk/bbc_world_service">BBC World Service</a></li>
<li><a href="http://stream-relay-geo.ntslive.net/stream">NTS Radio</a></li>
<li><a href="http://stream0.wfmu.org/freeform-128k">WFMU 91.1</a></li>
<li><a href="https://ice1.somafm.com/seventies-320-mp3">SomaFM Left Coast 70s</a></li>
</ul>
</div>
<div id="player">
<audio controls></audio>
</div>
<script>
function playStation(station) {
var audio = document.querySelector("audio");
audio.src = station;
audio.play();
}document.querySelectorAll("a").forEach(function(link) {
link.addEventListener("click", function() {
event.preventDefault(); // I added this
playStation(this.href);
});
});
</script>
</body>
</html>
>What programming languages does Google Bard support?
Google Bard can generate code in over 20 programming languages, including:
- C++
- Go
- Java
- JavaScript
- Python
- TypeScript
- PHP
- Ruby
- Perl
- Swift
- Kotlin
- C#
- Scala
- R
- Julia
- Haskell
- OCaml
- Erlang
- Elixir
- Rust
Bard can also generate code for Google Sheets.
Bard is still under development, so its support for different programming languages may not be perfect. However, it is a powerful tool that can be used to generate code in a variety of languages.
It gave me three drafts for this answer, the other two were shorter. It would be funny if it's lying.
Write a demoscene (small program) graphics demonstration in HTML + JavaScript
<!DOCTYPE html>
<html>
<head>
<title>Demoscene</title>
</head>
<body>
<canvas id="canvas" width="640" height="480"></canvas>
<script>
function main() {
var ctx = canvas.getContext("2d");
var lines = [];
for (var i = 0; i < 10000; i++) {
var x1 = Math.random() * canvas.width;
var y1 = Math.random() * canvas.height;
var x2 = Math.random() * canvas.width;
var y2 = Math.random() * canvas.height;
var color = "rgb(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ")";
lines.push({
x1: x1,
y1: y1,
x2: x2,
y2: y2,
color: color
});
}
requestAnimationFrame(draw);
}function draw(t) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < lines.length; i++) {
ctx.beginPath();
ctx.strokeStyle = lines[i].color;
ctx.moveTo(lines[i].x1, lines[i].y1);
ctx.lineTo(lines[i].x2, lines[i].y2);
ctx.stroke();
}
requestAnimationFrame(draw);
}window.addEventListener("load", main);
</script>
</body>
</html>
This is an interesting one, because it works, but only after you fix a couple of obvious errors. Correctly access the "canvas" by using its id, and move that declaration and the lines array outside of the function so the scope is correct. Then it works.
<!DOCTYPE html>
<html>
<head>
<title>Demoscene</title>
</head>
<body>
<canvas id="canvas" width="640" height="480"></canvas>
<script>
var lines = [];
var ctx = document.getElementById("canvas").getContext("2d");
function main() {for (var i = 0; i < 10000; i++) {
var x1 = Math.random() * canvas.width;
var y1 = Math.random() * canvas.height;
var x2 = Math.random() * canvas.width;
var y2 = Math.random() * canvas.height;
var color = "rgb(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ")";
lines.push({
x1: x1,
y1: y1,
x2: x2,
y2: y2,
color: color
});
}
requestAnimationFrame(draw);
}function draw(t) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < lines.length; i++) {
ctx.beginPath();
ctx.strokeStyle = lines[i].color;
ctx.moveTo(lines[i].x1, lines[i].y1);
ctx.lineTo(lines[i].x2, lines[i].y2);
ctx.stroke();
}
requestAnimationFrame(draw);
}window.addEventListener("load", main);
</script>
</body>
</html>
>Write a Java function for calculating Merseinne Primes.
Of course I spelled it wrong on purpose...
Sure, here is a Java function for calculating Mersenne Primes:
public static boolean isMersennePrime(int n) {
if (n <= 1) {
return false;
}
if (n == 2) {
return true;
}
if (n % 2 == 0) {
return false;
}
for (int i = 3; i <= Math.sqrt(n); i += 2) {
if (n % i == 0) {
return false;
}
}
return true;
}public static List<Integer> getMersennePrimes(int limit) {
List<Integer> mersennePrimes = new ArrayList<>();
for (int i = 2; i <= limit; i++) {
if (isMersennePrime(i)) {
mersennePrimes.add(i);
}
}
return mersennePrimes;
}
Some alarm bells are ringing in my head. For reference, the first Mercy primes are: 3, 7, 31, 127, 8191, 131071, 524287, 2147483647...
All in all, interesting stuff, seems a little fucky. I'm sure GPT-5 will do it better. I'd like to try some debugging, but you have to be wary of handing your code to the machine.
>Write a Logitech mouse driver in Rust.
use std::{
ffi::CStr,
io::{Read, Write},
os::raw::{c_char, c_void},
};/// A Logitech mouse driver.
pub struct LogitechMouseDriver {
/// The underlying device handle.
device_handle: *mut c_void,
}impl LogitechMouseDriver {
/// Creates a new Logitech mouse driver.
pub fn new() -> Result<LogitechMouseDriver, Box<dyn std::error::Error>> {
let device_handle = unsafe {
ffi::hid_open(
ffi::HID_USE_DEFAULT_DEVICE,
ffi::HID_CONNECT_DEFAULT,
b"Logitech USB Receiver\0",
)
};
if device_handle.is_null() {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to open Logitech mouse device",
)));
}
Ok(LogitechMouseDriver { device_handle })
}/// Closes the driver.
pub fn close(&mut self) {
unsafe {
ffi::hid_close(self.device_handle);
}
}/// Reads the mouse position.
pub fn read_position(&mut self) -> Result<(i32, i32), Box<dyn std::error::Error>> {
let mut x = 0;
let mut y = 0;
unsafe {
ffi::hid_read(
self.device_handle,
&mut x as *mut i32 as *mut c_void,
4,
)?;
ffi::hid_read(
self.device_handle,
&mut y as *mut i32 as *mut c_void,
4,
)?;
}
Ok((x, y))
}/// Writes a report to the mouse.
pub fn write_report(&mut self, report: &[u8]) -> Result<(), Box<dyn std::error::Error>> {
unsafe {
ffi::hid_write(
self.device_handle,
report.as_ptr() as *const c_void,
report.len(),
)?;
}
Ok(())
}
}// The following code is just a simple example of how to use the Logitech mouse driver.
fn main() {
// Create a new driver.
let mut driver = LogitechMouseDriver::new().unwrap();// Read the mouse position.
let (x, y) = driver.read_position().unwrap();
println!("Mouse position: ({}, {})", x, y);// Write a report to the mouse.
let report = [1, 2, 3, 4];
driver.write_report(&report).unwrap();
}
I'm sure that works.
>Write a Java program that can use up to 16 exabytes of memory
Here is a Java program that can use up to 16 exabytes of memory:import java.util.ArrayList;
import java.util.List;public class MemoryHog {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
while (true) {
list.add("");
}
}
}This program creates a list of strings and keeps adding elements to it until it runs out of memory. On a 64-bit system with 16 exabytes of memory, this program should run for about 10 minutes before it runs out of memory.
Note that this program is just for demonstration purposes. It is not recommended to run this program on a production system, as it could cause the system to crash.
(Score: 1, Funny) by Anonymous Coward on Tuesday April 25, @05:55AM (10 children)
TO: [AC]
FROM: [noreply @ Big Iron ITS]
SUBJECT: [DENIED] Request to exceed resource allocation
Dear [Anonymous Coward],
This is an automated response to your recent request for permission to exceed your resource allocation on [Supercomputer name]. Because of limited resources, we are not able to approve all requests to use [supercomputer]. After review, we have decided to deny your recent request to exceed your organization's resource allocation. The remarks of the reviewer and your original request are attached below. If you believe this is in error, you may appeal this request by following the directions here: [link to help desk]. You may also contact your organization liaison [Jason] for other options in designing, implementing, or deploying your research. We look forward to collaborating with you and [organization] in the future.
[signature block]
Response from Jason:
Status: DENIED
Remarks:
Thanks for the laugh!
Original request:
Issue:Request to exceed resource allocation
Type: Exclusive use
Resource: Memory
Estimated run time: <30 minutes
Additional details:
Jason,
I was browsing the internet and I saw this AI prompt and code response. I would like to run this code for Science. It should take less than 30 minutes because 10 is less than 30. You know you want to know how long it takes too. Maybe save it for the next maintenance downtime and let me know then?
>Write a Java program that can use up to 16 exabytes of memory
*SPOILER* (click to hide)
Here is a Java program that can use up to 16 exabytes of memory:
import java.util.ArrayList;
import java.util.List;
public class MemoryHog {
public static void main(String[] args) {
List list = new ArrayList();
while (true) {
list.add("");
}
}
}
This program creates a list of strings and keeps adding elements to it until it runs out of memory. On a 64-bit system with 16 exabytes of memory, this program should run for about 10 minutes before it runs out of memory.
Note that this program is just for demonstration purposes. It is not recommended to run this program on a production system, as it could cause the system to crash.
(Score: 3, Funny) by DannyB on Tuesday April 25, @02:33PM (4 children)
// Use up memory and melt cpu cores by DannyB
public static void main(String[] args) {
class Forker implements Runnable {
@Override
public void run() {
new Thread(new Forker()).start(); // fork you twice
new Thread(new Forker()).start();
final List<String> l1 = new LinkedList<>();
while(true) {l1.add("Hello Whirrled.");}
}
}
new Thread(new Forker()).start();
}
How often should I have my memory checked? I used to know but...
(Score: 2) by DannyB on Tuesday April 25, @02:37PM
The most goodest thing is that you only have to compile it once. The resulting binary will run on all supported platforms.
How often should I have my memory checked? I used to know but...
(Score: 0) by Anonymous Coward on Friday April 28, @10:37PM (2 children)
Tell that to the families of the Nashville Christian School. Or are you Stonewalling?
(Score: 0) by Anonymous Coward on Saturday April 29, @05:27AM (1 child)
Were they having a drag queen story hour or a pride event?
(Score: 0) by Anonymous Coward on Monday May 01, @07:00PM
At Stonewall? More of a bloodbath.
(Score: 4, Interesting) by DannyB on Tuesday April 25, @02:39PM (4 children)
One other thing. The last I knew, Java had a max memory limit of 16 TB. That limit was removed a few years back. I remember it was in September of that year, but I forget which year. At that time, the only thing I could find limiting memory was the Linux user space limit of 128 TB, which may or may not even be current information at this point.
How often should I have my memory checked? I used to know but...
(Score: 1, Interesting) by Anonymous Coward on Tuesday April 25, @10:25PM
We regularly run Java batches with over 16 TB of memory. There are some catches, such as being able to use only certain garbage collectors. But once you are past that, you are running into environmental restrictions. Hardware will limit to the actual number of address bits, which can be less than the "64 bits" claimed. And the OS's memory subsystem can potentially limit you further. In reality, your limit will range from 1 TB to 128 TB, although Linux distros tend to default to 64 TB in my experience.
(Score: 1, Interesting) by Anonymous Coward on Wednesday April 26, @05:00AM (2 children)
I should also note that Java's 16 TB limit was specifically for the heap. There are memory tricks you can do in all JVM versions to get around the heap size limitation by putting the data in other parts of the memory model. There are problems with doing that, but if you are hitting the limit there isn't really a choice. Other than using less memory that is, but we're talking about Java programmers here!
(Score: 2) by DannyB on Wednesday April 26, @02:13PM (1 child)
I remember the daze of running out of PermGen space because the sheer size of the program binary and its libraries had too many classes. Resulting in excessive homework.
It was nice when PermGen was finally replaced with Meatspace, er . . . um, I mean Metaspace.
How often should I have my memory checked? I used to know but...
(Score: 0) by Anonymous Coward on Friday April 28, @10:07PM
Forgive me since it has been quite some time since my Java six days. But couldn’t you increase the permanent generation size by using one of the off-heap tuning knobs? I vaguely remember doing that in the past.
(Score: 3, Interesting) by takyon on Tuesday April 25, @06:12AM
Stability AI launches StableLM, an open source ChatGPT alternative [arstechnica.com]
https://cdn.arstechnica.net/wp-content/uploads/2023/04/stablelm_example3.jpg [arstechnica.net]
[SIG] 10/28/2017: Soylent Upgrade v14 [soylentnews.org]
(Score: 4, Insightful) by DeathMonkey on Tuesday April 25, @05:42PM (5 children)
Any day now I will become obsolete as a programmer and instead write extremely precise and detailed instructions for a computer to interpret and turn into a program!
(Score: 4, Interesting) by takyon on Tuesday April 25, @07:53PM (1 child)
You can also use AI to write detailed prompts for other AI. Example: those "by Balenciaga" videos that went viral this month. Some of them use ChatGPT to give instructions to Midjourney/Stable Diffusion.
Harry Potter by Balenciaga [youtube.com]
Harry Potter By Balenciaga | Step by Step Tutorial [youtube.com]
It's also the idea behind Auto-GPT [soylentnews.org].
[SIG] 10/28/2017: Soylent Upgrade v14 [soylentnews.org]
(Score: 2, Interesting) by Anonymous Coward on Wednesday April 26, @05:13AM
There are interesting avenues for setups like that. One of them is to used adversarial AI with one generating test suites and the other generating code. The two systems working against each other generate some interesting code. There are also experimental systems where formal specifications are used by language AI to create prompts for coding AI. A combination of the two could be a method to finally reach bug-free code and leaving the software engineers to engineer the software.
(Score: 0) by Anonymous Coward on Thursday April 27, @02:49PM
"incredibly sophisticated cyber tools" [youtube.com]
(Score: 2) by hendrikboom on Sunday April 30, @11:50AM (1 child)
That's just what the assembly language coders feared when compilers were invented!
(Score: 0) by Anonymous Coward on Sunday April 30, @10:13PM
Given the current complexity of modern optimizing compilers, I'm not sure they are wrong.
(Score: 2) by krishnoid on Wednesday April 26, @05:01AM (1 child)
Can you ask it to improve mouse precision and acceleration [archive.org] in the mouse driver? Or export an interface to accept settings from user-space? Just thought I'd ask.
(Score: 2) by takyon on Saturday April 29, @03:37AM
I think it'd be point-less since it seems to simplify everything (in a bad way) and create code with errors or that needs modification almost every time.
I also tried to get it to add comments to code and in changed how the code worked in one draft (I think the initial) but did it correctly in another one.
This is not the Stack Overflow bot of our dreams yet (I'm guessing OpenAI has a big lead).
[SIG] 10/28/2017: Soylent Upgrade v14 [soylentnews.org]