Spaces:
Sleeping
Sleeping
Update app.py
Browse files12 unmodified lines1314151617181993 unmodified lines11311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531612 unmodified lines# 预定义代码片段CODE_SNIPPETS = ["System.out.println(\"Hello, World!\");","public static int sum(int a, int b) { return a + b; }","import java.util.Random; public static int generateRandomNumber() { return new Random().nextInt(); }","public static boolean isEven(int number) { return number % 2 == 0; }",93 unmodified lines"public static Object getAttribute(Object obj, String attribute) throws Exception { return obj.getClass().getDeclaredField(attribute).get(obj); }","public static void setAttribute(Object obj, String attribute, Object value) throws Exception { obj.getClass().getDeclaredField(attribute).set(obj, value); }","public static void deleteAttribute(Object obj, String attribute) throws Exception { obj.getClass().getDeclaredField(attribute).set(obj, null); }""try { int result = 10 / 0; } catch (Exception e) { System.out.println(\"Exception caught\"); }","class CustomException extends Exception { public CustomException(String message) { super(message); } }","try { int result = 10 / 0; } catch (Exception e) { System.out.println(e.getMessage()); }","import java.util.logging.Logger; Logger logger = Logger.getLogger(MyClass.class.getName()); logger.severe(\"Error occurred\");","long startTime = System.currentTimeMillis();","long endTime = System.currentTimeMillis(); long elapsedTime = endTime - startTime;","for (int i = 0; i <= 100; i++) { System.out.print(\"\\rProgress: \" + i + \"%\"); Thread.sleep(50); }","Thread.sleep(1000);","Runnable r = () -> System.out.println(\"Lambda expression\"); r.run();","List<Integer> numbers = Arrays.asList(1, 2, 3); List<Integer> squares = numbers.stream().map(x -> x * x).collect(Collectors.toList());","List<Integer> numbers = Arrays.asList(1, 2, 3); List<Integer> evens = numbers.stream().filter(x -> x % 2 == 0).collect(Collectors.toList());","import java.util.stream.Collectors; List<Integer> numbers = Arrays.asList(1, 2, 3); int sum = numbers.stream().reduce(0, Integer::sum);","List<Integer> squares = IntStream.range(0, 10).map(x -> x * x).boxed().collect(Collectors.toList());","Map<String, Integer> map = IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> \"key\" + i, i -> i));","Set<Integer> set = IntStream.range(0, 10).boxed().collect(Collectors.toSet());","Set<Integer> set1 = new HashSet<>(Arrays.asList(1, 2, 3)); Set<Integer> set2 = new HashSet<>(Arrays.asList(2, 3, 4)); set1.retainAll(set2);","Set<Integer> set1 = new HashSet<>(Arrays.asList(1, 2, 3)); Set<Integer> set2 = new HashSet<>(Arrays.asList(2, 3, 4)); set1.addAll(set2);","Set<Integer> set1 = new HashSet<>(Arrays.asList(1, 2, 3)); Set<Integer> set2 = new HashSet<>(Arrays.asList(2, 3, 4)); set1.removeAll(set2);","List<Integer> list = Arrays.asList(1, null, 2, null); list.removeIf(Objects::isNull);","try (BufferedReader br = new BufferedReader(new FileReader(\"file.txt\"))) { br.readLine(); } catch (IOException e) { System.out.println(\"File cannot be opened\"); }","if (variable instanceof Integer) { System.out.println(\"Variable is an Integer\"); }","boolean bool = Boolean.parseBoolean(\"true\");","if (condition) { System.out.println(\"Condition is true\"); }","while (condition) { System.out.println(\"Looping\"); }","for (int i : list) { System.out.println(i); }","for (Map.Entry<String, Integer> entry : map.entrySet()) { System.out.println(entry.getKey() + \": \" + entry.getValue()); }","for (char c : str.toCharArray()) { System.out.println(c); }","for (int i = 0; i < 10; i++) { if (i == 5) break; System.out.println(i); }","for (int i = 0; i < 10; i++) { if (i == 5) continue; System.out.println(i); }","public void myFunction() { System.out.println(\"Function executed\"); }","public void myFunction(String param = \"default\") { System.out.println(param); }","public int[] returnMultipleValues() { return new int[]{1, 2}; }","public void myFunction(int... numbers) { for (int num : numbers) System.out.println(num); }","public void myFunction(Map<String, Object> kwargs) { System.out.println(kwargs); }","long startTime = System.nanoTime(); myFunction(); long endTime = System.nanoTime(); long duration = (endTime - startTime);","public static <T> Function<T, T> memoize(Function<T, T> function) { return new Function<T, T>() { private final Map<T, T> cache = new HashMap<>(); public T apply(T input) { return cache.computeIfAbsent(input, function); } }; }","public class MyGenerator implements Iterator<Integer> { private int current = 0; public boolean hasNext() { return current < 10; } public Integer next() { return current++; } }","public class MyGenerator { public Iterator<Integer> iterator() { return new Iterator<Integer>() { private int current = 0; public boolean hasNext() { return current < 10; } public Integer next() { return current++; } }; } }","MyGenerator generator = new MyGenerator(); while (generator.hasNext()) { System.out.println(generator.next()); }","for (int i = 0; i < list.size(); i++) { System.out.println(i + \": \" + list.get(i)); }","List<Integer> list1 = Arrays.asList(1, 2, 3); List<Integer> list2 = Arrays.asList(4, 5, 6); List<Integer> zipped = IntStream.range(0, Math.min(list1.size(), list2.size())).mapToObj(i -> list1.get(i) + list2.get(i)).collect(Collectors.toList());","List<String> keys = Arrays.asList(\"a\", \"b\"); List<Integer> values = Arrays.asList(1, 2); Map<String, Integer> map = IntStream.range(0, keys.size()).boxed().collect(Collectors.toMap(keys::get, values::get));","boolean areEqual = list1.equals(list2);","boolean areEqual = map1.equals(map2);","boolean areEqual = set1.equals(set2);","Set<Integer> set = new HashSet<>(Arrays.asList(1, 2, 2, 3));","set.clear();","boolean isEmpty = set.isEmpty();","set.add(4);","set.remove(3);","boolean contains = set.contains(2);","int size = set.size();","boolean hasIntersection = !Collections.disjoint(set1, set2);","boolean isSubset = new HashSet<>(list1).containsAll(list2);","boolean isSubstring = str.contains(sub);","char firstChar = str.charAt(0);","char lastChar = str.charAt(str.length() - 1);","boolean isTextFile = Files.probeContentType(Paths.get(\"file.txt\")).startsWith(\"text\");","boolean isImageFile = Files.probeContentType(Paths.get(\"file.jpg\")).startsWith(\"image\");","double rounded = Math.round(3.14159);","double ceil = Math.ceil(3.14159);","double floor = Math.floor(3.14159);","double formatted = Double.parseDouble(String.format(\"%.2f\", 3.14159));","String randomString = new Random().ints(48, 122).filter(i -> (i <= 57 || i >= 65) && (i <= 90 || i >= 97)).limit(10).collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append).toString();","boolean pathExists = Files.exists(Paths.get(\"path\"));","Files.walk(Paths.get(\"path\")).forEach(System.out::println);","String extension = FilenameUtils.getExtension(\"file.txt\");","String fileName = FilenameUtils.getName(\"path/to/file.txt\");","String fullPath = Paths.get(\"path/to/file.txt\").toAbsolutePath().toString();","String version = System.getProperty(\"java.version\");","String os = System.getProperty(\"os.name\");","int cores = Runtime.getRuntime().availableProcessors();","long memory = Runtime.getRuntime().totalMemory();","File[] roots = File.listRoots(); for (File root : roots) { System.out.println(root.getUsableSpace()); }","String ip = InetAddress.getLocalHost().getHostAddress();","boolean isConnected = InetAddress.getByName(\"www.google.com\").isReachable(5000);","URL url = new URL(\"http://example.com/file.txt\"); Files.copy(url.openStream(), Paths.get(\"file.txt\"));","String response = new HttpPost(\"http://example.com/upload\").execute().returnContent().asString();","String response = new HttpPost(\"http://example.com\").execute().returnContent().asString();","String response = new HttpPost(\"http://example.com\").addParameter(\"key\", \"value\").execute().returnContent().asString();","String response = new HttpPost(\"http://example.com\").addHeader(\"key\", \"value\").execute().returnContent().asString();","Document doc = Jsoup.connect(\"http://example.com\").get();","String title = doc.title();","Elements links = doc.select(\"a[href]\");","Elements images = doc.select(\"img[src]\"); for (Element img : images) { URL imgUrl = new URL(img.attr(\"src\")); Files.copy(imgUrl.openStream(), Paths.get(imgUrl.getFile())); }","Map<String, Integer> wordCount = new HashMap<>(); for (String word : doc.text().split(\"\\\\s+\")) { wordCount.put(word, wordCount.getOrDefault(word, 0) + 1); }","String response = new HttpPost(\"http://example.com/login\").addParameter(\"username\", \"user\").addParameter(\"password\", \"pass\").execute().returnContent().asString();","String text = Jsoup.parse(html).text();","Pattern emailPattern = Pattern.compile(\"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}\"); Matcher matcher = emailPattern.matcher(text); while (matcher.find()) { System.out.println(matcher.group()); }","Pattern phonePattern = Pattern.compile(\"\\\\+?\\\\d{10,13}\"); Matcher matcher = phonePattern.matcher(text); while (matcher.find()) { System.out.println(matcher.group()); }","Pattern numberPattern = Pattern.compile(\"\\\\d+\"); Matcher matcher = numberPattern.matcher(text); while (matcher.find()) { System.out.println(matcher.group()); }","String replaced = text.replaceAll(\"pattern\", \"replacement\");","boolean matches = text.matches(\"pattern\");","String stripped = Jsoup.parse(html).text();","String encoded = StringEscapeUtils.escapeHtml4(html);","String decoded = StringEscapeUtils.unescapeHtml4(html);","JFrame frame = new JFrame(\"Simple GUI\"); frame.setSize(300, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);""JButton button = new JButton(\"Click Me\"); frame.add(button);","button.addActionListener(e -> System.out.println(\"Button clicked\"));","JOptionPane.showMessageDialog(frame, \"This is a message\");","JTextField textField = new JTextField(); String input = textField.getText();","frame.setTitle(\"New Title\");","frame.setSize(400, 300);","frame.setLocationRelativeTo(null);","JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu(\"File\"); menuBar.add(menu); frame.setJMenuBar(menuBar);","JComboBox<String> comboBox = new JComboBox<>(new String[]{\"Option 1\", \"Option 2\"}); frame.add(comboBox);","JRadioButton radioButton = new JRadioButton(\"Select Me\"); frame.add(radioButton);","JCheckBox checkBox = new JCheckBox(\"Check Me\"); frame.add(checkBox);","JLabel label = new JLabel(new ImageIcon(\"image.jpg\")); frame.add(label);","Clip clip = AudioSystem.getClip(); clip.open(AudioSystem.getAudioInputStream(new File(\"audio.wav\"))); clip.start();","Player player = Manager.createRealizedPlayer(new File(\"video.mp4\").toURI().toURL()); player.start();","long currentTime = player.getTimeNanoseconds();","Robot robot = new Robot(); BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));","ScreenRecorder screenRecorder = new ScreenRecorder(new ScreenRecorderParameters()); screenRecorder.start(); Thread.sleep(5000); screenRecorder.stop();","PointerInfo pointerInfo = MouseInfo.getPointerInfo(); Point point = pointerInfo.getLocation();","robot.keyPress(KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_A);","robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);","long timestamp = System.currentTimeMillis();","Date date = new Date(timestamp);","long timestamp = date.getTime();","int dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);","int daysInMonth = Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH);","Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, 1); Date firstDay = cal.getTime();","Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, cal.getActualMaximum(Calendar.DAY_OF_YEAR)); Date lastDay = cal.getTime();","Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, 1); Date firstDay = cal.getTime();","Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); Date lastDay = cal.getTime();","int dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); boolean isWeekday = dayOfWeek != Calendar.SATURDAY && dayOfWeek != Calendar.SUNDAY;","int dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); boolean isWeekend = dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY;","int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);","int minute = Calendar.getInstance().get(Calendar.MINUTE);","int second = Calendar.getInstance().get(Calendar.SECOND);","Thread.sleep(1000);","long millis = System.currentTimeMillis();","SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\"); String formattedDate = sdf.format(new Date());","SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\"); Date date = sdf.parse(\"2023-10-01 12:00:00\");","Thread thread = new Thread(() -> System.out.println(\"Thread running\")); thread.start();","Thread.sleep(1000);","ExecutorService executor = Executors.newFixedThreadPool(2); executor.submit(() -> System.out.println(\"Task 1\")); executor.submit(() -> System.out.println(\"Task 2\"));","String threadName = Thread.currentThread().getName();","thread.setDaemon(true);","ReentrantLock lock = new ReentrantLock(); lock.lock(); try { System.out.println(\"Locked\"); } finally { lock.unlock(); }","Process process = Runtime.getRuntime().exec(\"notepad.exe\");","long pid = process.pid();","boolean isAlive = process.isAlive();","ExecutorService executor = Executors.newFixedThreadPool(2); executor.submit(() -> System.out.println(\"Task 1\")); executor.submit(() -> System.out.println(\"Task 2\"));","BlockingQueue<String> queue = new LinkedBlockingQueue<>(); queue.put(\"Message\"); String message = queue.take();","PipedInputStream in = new PipedInputStream(); PipedOutputStream out = new PipedOutputStream(in); out.write(\"Message\".getBytes());","Thread.sleep(1000);","Process process = Runtime.getRuntime().exec(\"ls\"); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = reader.readLine()) != null) { System.out.println(line); }","int exitCode = process.waitFor();","boolean success = exitCode == 0;","String scriptPath = new File(\"\").getAbsolutePath();","String[] args = new String[]{\"arg1\", \"arg2\"};","ArgumentParser parser = ArgumentParser(); parser.addArgument(\"--arg\"); Namespace ns = parser.parseArgs(args);","parser.printHelp();","ModuleFinder finder = ModuleFinder.ofSystem(); Set<ModuleReference> modules = finder.findAll();","Process process = Runtime.getRuntime().exec(\"pip install package\");","Process process = Runtime.getRuntime().exec(\"pip uninstall package\");","String version = Package.getPackage(\"package\").getImplementationVersion();","Process process = Runtime.getRuntime().exec(\"python -m venv venv\");","Process process = Runtime.getRuntime().exec(\"pip list\");","Process process = Runtime.getRuntime().exec(\"pip install --upgrade package\");","Connection conn = DriverManager.getConnection(\"jdbc:sqlite:sample.db\");","Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(\"SELECT * FROM table\");","stmt.executeUpdate(\"INSERT INTO table (column) VALUES ('value')\");","stmt.executeUpdate(\"DELETE FROM table WHERE id = 1\");","stmt.executeUpdate(\"UPDATE table SET column = 'new_value' WHERE id = 1\");","while (rs.next()) { System.out.println(rs.getString(\"column\")); }","PreparedStatement pstmt = conn.prepareStatement(\"SELECT * FROM table WHERE id = ?\"); pstmt.setInt(1, 1); ResultSet rs = pstmt.executeQuery();","conn.close();","stmt.executeUpdate(\"CREATE TABLE table (id INT, name TEXT)\");","stmt.executeUpdate(\"DROP TABLE table\");","DatabaseMetaData meta = conn.getMetaData(); ResultSet rs = meta.getTables(null, null, \"table\", null); boolean exists = rs.next();","ResultSet rs = meta.getTables(null, null, \"%\", null); while (rs.next()) { System.out.println(rs.getString(\"TABLE_NAME\")); }","EntityManager em = Persistence.createEntityManagerFactory(\"pu\").createEntityManager(); em.getTransaction().begin(); em.persist(entity); em.getTransaction().commit();","EntityManager em = Persistence.createEntityManagerFactory(\"pu\").createEntityManager(); Query query = em.createQuery(\"SELECT e FROM Entity e\"); List<Entity> entities = query.getResultList();","EntityManager em = Persistence.createEntityManagerFactory(\"pu\").createEntityManager(); em.getTransaction().begin(); em.remove(entity); em.getTransaction().commit();","EntityManager em = Persistence.createEntityManagerFactory(\"pu\").createEntityManager(); em.getTransaction().begin(); em.merge(entity); em.getTransaction().commit();","@Entity public class Entity { @Id @GeneratedValue private Long id; private String name; }","@Entity public class ChildEntity extends ParentEntity { private String childField; }","@Id @GeneratedValue private Long id;","@Column(unique = true) private String uniqueField;","@Column(columnDefinition = \"varchar(255) default 'default_value'\") private String field;","CSVWriter writer = new CSVWriter(new FileWriter(\"data.csv\")); writer.writeAll(data); writer.close();","Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet(\"Sheet1\"); FileOutputStream fileOut = new FileOutputStream(\"workbook.xlsx\"); workbook.write(fileOut); fileOut.close();","ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(new File(\"data.json\"), data);","Workbook workbook = WorkbookFactory.create(new File(\"workbook.xlsx\")); Sheet sheet = workbook.getSheetAt(0);","Workbook workbook1 = WorkbookFactory.create(new File(\"workbook1.xlsx\")); Workbook workbook2 = WorkbookFactory.create(new File(\"workbook2.xlsx\")); Sheet sheet1 = workbook1.getSheetAt(0); Sheet sheet2 = workbook2.getSheetAt(0); Sheet newSheet = workbook1.createSheet(\"Merged\");","Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet(\"New Sheet\");","CellStyle style = workbook.createCellStyle(); style.cloneStyleFrom(cell.getCellStyle());","CellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.RED.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND);","Font font = workbook.createFont(); font.setBold(true); CellStyle style = workbook.createCellStyle(); style.setFont(font);","Row row = sheet.getRow(0); Cell cell = row.getCell(0); String cellValue = cell.getStringCellValue();","Row row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellValue(\"New Value\");","BufferedImage img = ImageIO.read(new File(\"image.jpg\")); int width = img.getWidth(); int height = img.getHeight();","BufferedImage resizedImg = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g = resizedImg.createGraphics(); g.drawImage(img, 0, 0, newWidth, newHeight, null); g.dispose();"]12 unmodified lines13141516171819202193 unmodified lines11511611711811912012 unmodified lines# 预定义代码片段CODE_SNIPPETS = [以下是所有功能转换为纯 Java 语言实现的代码块,严格按照要求输出:"System.out.println(\"Hello, World!\");","public static int sum(int a, int b) { return a + b; }","import java.util.Random; public static int generateRandomNumber() { return new Random().nextInt(); }","public static boolean isEven(int number) { return number % 2 == 0; }",93 unmodified lines"public static Object getAttribute(Object obj, String attribute) throws Exception { return obj.getClass().getDeclaredField(attribute).get(obj); }","public static void setAttribute(Object obj, String attribute, Object value) throws Exception { obj.getClass().getDeclaredField(attribute).set(obj, value); }","public static void deleteAttribute(Object obj, String attribute) throws Exception { obj.getClass().getDeclaredField(attribute).set(obj, null); }"]
app.py+3-199