Forrest99 commited on
Commit
bfff006
·
verified ·
1 Parent(s): 278dc1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +298 -414
app.py CHANGED
@@ -14,421 +14,305 @@ app.logger = logging.getLogger("CodeSearchAPI")
14
  # 预定义代码片段
15
  CODE_SNIPPETS = [
16
 
17
- "puts 'Hello, World!'",
18
- "def sum(a, b); a + b; end",
19
- "rand",
20
- "def even?(num); num.even?; end",
21
- "str.length",
22
- "Date.today",
23
- "File.exist?('file.txt')",
24
- "File.read('file.txt')",
25
- "File.write('file.txt', 'content')",
26
- "Time.now",
27
- "str.upcase",
28
- "str.downcase",
29
- "str.reverse",
30
- "list.size",
31
- "list.max",
32
- "list.min",
33
- "list.sort",
34
- "list1 + list2",
35
- "list.delete(element)",
36
- "list.empty?",
37
- "str.count(char)",
38
- "str.include?(substring)",
39
- "num.to_s",
40
- "str.to_i",
41
- "str.match?(/^\d+$/)",
42
- "list.index(element)",
43
- "list.clear",
44
- "list.reverse",
45
- "list.uniq",
46
- "list.include?(value)",
47
- "{}",
48
- "hash[key] = value",
49
- "hash.delete(key)",
50
- "hash.keys",
51
- "hash.values",
52
- "hash1.merge(hash2)",
53
- "hash.empty?",
54
- "hash[key]",
55
- "hash.key?(key)",
56
- "hash.clear",
57
- "File.readlines('file.txt').size",
58
- "File.write('file.txt', list.join('\\n'))",
59
- "File.read('file.txt').split('\\n')",
60
- "File.read('file.txt').split.size",
61
- "def leap_year?(year); (year % 400 == 0) || (year % 100 != 0 && year % 4 == 0); end",
62
- "Time.now.strftime('%Y-%m-%d %H:%M:%S')",
63
- "(Date.today - Date.new(2023, 1, 1)).to_i",
64
- "Dir.pwd",
65
- "Dir.entries('.')",
66
- "Dir.mkdir('new_dir')",
67
- "Dir.rmdir('new_dir')",
68
- "File.file?('path')",
69
- "File.directory?('path')",
70
- "File.size('file.txt')",
71
- "File.rename('old.txt', 'new.txt')",
72
- "FileUtils.cp('source.txt', 'destination.txt')",
73
- "FileUtils.mv('source.txt', 'destination.txt')",
74
- "File.delete('file.txt')",
75
- "ENV['VAR_NAME']",
76
- "ENV['VAR_NAME'] = 'value'",
77
- "system('open https://example.com')",
78
- "require 'net/http'; Net::HTTP.get(URI('https://example.com'))",
79
- "require 'json'; JSON.parse(json_string)",
80
- "require 'json'; File.write('file.json', JSON.dump(data))",
81
- "require 'json'; JSON.parse(File.read('file.json'))",
82
- "list.join",
83
- "str.split(',')",
84
- "list.join(',')",
85
- "list.join('\\n')",
86
- "str.split",
87
- "str.split(delimiter)",
88
- "str.chars",
89
- "str.gsub(old, new)",
90
- "str.gsub(' ', '')",
91
- "str.gsub(/[^a-zA-Z0-9]/, '')",
92
- "str.empty?",
93
- "str == str.reverse",
94
- "require 'csv'; CSV.open('file.csv', 'w') { |csv| csv << ['data'] }",
95
- "require 'csv'; CSV.read('file.csv')",
96
- "require 'csv'; CSV.read('file.csv').size",
97
- "list.shuffle",
98
- "list.sample",
99
- "list.sample(n)",
100
- "rand(6) + 1",
101
- "rand(2) == 0 ? 'Heads' : 'Tails'",
102
- "SecureRandom.alphanumeric(8)",
103
- "format('#%06x', rand(0xffffff))",
104
- "SecureRandom.uuid",
105
- "class MyClass; end",
106
- "MyClass.new",
107
- "class MyClass; def my_method; end; end",
108
- "class MyClass; attr_accessor :my_attr; end",
109
- "class ChildClass < ParentClass; end",
110
- "class ChildClass < ParentClass; def my_method; super; end; end",
111
- "class MyClass; def self.class_method; end; end",
112
- "class MyClass; def self.static_method; end; end",
113
- "obj.is_a?(Class)",
114
- "obj.instance_variable_get(:@attr)",
115
- "obj.instance_variable_set(:@attr, value)",
116
- "obj.instance_variable_defined?(:@attr)",
117
- "begin; risky_operation; rescue => e; puts e; end",
118
- """class CustomError < StandardError
119
- end
120
- raise CustomError, 'error occurred'""",
121
- "begin; raise 'oops'; rescue => e; e.message; end",
122
- """require 'logger'
123
- logger = Logger.new('error.log')
124
- logger.error('error occurred')""",
125
- "start_time = Time.now",
126
- "Time.now - start_time",
127
- "20.times { |i| print \"\\r[#{'='*(i+1)}#{' '*(19-i)}]\"; sleep(0.1) }",
128
- "sleep(1)",
129
- "square = ->(x) { xx }",
130
- "squares = [1,2,3].map { |n| nn }",
131
- "evens = [1,2,3,4].select { |n| n.even? }",
132
- "sum = [1,2,3].reduce(0) { |acc,n| acc+n }",
133
- "doubles = [1,2,3,4,5].map { |n| n2 }",
134
- "hash = [1,2,3].map { |n| [n, n2] }.to_h",
135
- "require 'set'; s = Set.new([1,2,3].map { |n| n*2 })",
136
- "intersection = a & b",
137
- "union = a | b",
138
- "diff = a - b",
139
- "filtered = list.compact",
140
- "begin; File.open('file.txt'); rescue; false; end",
141
- "x.is_a?(String)",
142
- "bool = ['true','1'].include?(str.downcase)",
143
- "puts 'yes' if x > 0",
144
- "i=0; while i<5; i+=1; end",
145
- "for item in [1,2,3]; puts item; end",
146
- """h = {a:1, b:2}
147
- for k, v in h
148
- puts "#{k}:#{v}"
149
- end""",
150
- """for c in 'hello'.chars
151
- puts c
152
- end""",
153
- """for i in 1..5
154
- break if i==3
155
- puts i
156
- end""",
157
- """for i in 1..5
158
- next if i==3
159
- puts i
160
- end""",
161
- "def foo; end",
162
- "def foo(a=1); a; end",
163
- "def foo; [1,2]; end",
164
- "def foo(*args); args; end",
165
- "def foo(a:, b:); a+b; end",
166
- """def foo
167
- end
168
- start = Time.now
169
- foo
170
- puts Time.now - start""",
171
- """def decorate(f)
172
- ->(args) { puts 'before'; result = f.call(args); puts 'after'; result }
173
- end""",
174
- """def fib(n, memo={})
175
- return memo[n] if memo[n]
176
- memo[n] = n<2 ? n : fib(n-1, memo) + fib(n-2, memo)
177
- end""",
178
- "gen = Enumerator.new { |y| i=0; loop { y << i; i+=1 } }",
179
- "def foo; yield 1; end",
180
- "gen.next",
181
- "itr = [1,2,3].each",
182
- """itr = [1,2,3].each
183
- loop do
184
- puts itr.next
185
- end""",
186
- "[1,2].each_with_index { |v, i| puts i, v }",
187
- "zipped = [1,2].zip(['a','b'])",
188
- "h = [1,2].zip(['a','b']).to_h",
189
- "[1,2] == [1,2]",
190
- "{a:1, b:2} == {b:2, a:1}",
191
- "require 'set'; Set.new([1,2]) == Set.new([2,1])",
192
- "unique = [1,2,1].uniq",
193
- "s.clear",
194
- "s.empty?",
195
- "s.add(1)",
196
- "s.delete(1)",
197
- "s.include?(1)",
198
- "s.size",
199
- "!(a & b).empty?",
200
- "[1,2].all? { |e| [1,2,3].include?(e) }",
201
- "'hi'.include?('h')",
202
  "str[0]",
203
- "str[-1]",
204
- "File.extname(path) == '.txt'",
205
- "['.png','.jpg','.jpeg','.gif'].include?(File.extname(path))",
206
- "x.round",
207
- "x.ceil",
208
- "x.floor",
209
- "sprintf('%.2f', x)",
210
- "require 'securerandom'; SecureRandom.alphanumeric(8)",
211
- "File.exist?('path')",
212
- "Dir['**/'].each { |f| puts f }",
213
- "File.extname('path.txt')",
214
- "File.basename(path)",
215
- "File.expand_path(path)",
216
- "RUBY_VERSION",
217
- "RUBY_PLATFORM",
218
- "require 'etc'; Etc.nprocessors",
219
- "mem = grep MemTotal /proc/meminfo",
220
- "df = df -h /",
221
- """require 'socket'
222
- ip = Socket.ip_address_list.detect(&:ipv4_private).ip_address""",
223
- "system('ping -c1 8.8.8.8 > /dev/null 2>&1')",
224
- """require 'open-uri'
225
- File.open('file', 'wb') { |f| f.write open(url).read }""",
226
- """def upload(file)
227
- puts 'Uploading'
228
- end""",
229
- """require 'net/http'
230
- uri = URI(url)
231
- Net::HTTP.post_form(uri, key: 'value')""",
232
- """uri = URI(url)
233
- uri.query = URI.encode_www_form(params)
234
- Net::HTTP.get(uri)""",
235
- """require 'net/http'
236
- uri = URI(url)
237
- req = Net::HTTP::Get.new(uri)
238
- req['User-Agent'] = 'Custom'
239
- res = Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }""",
240
- "require 'nokogiri'; doc = Nokogiri::HTML(html)",
241
- "doc.at('title').text",
242
- "links = doc.css('a').map { |a| a['href'] }",
243
- """doc.css('img').each do |img|
244
- open(img['src']).each do |chunk|
245
- File.open(File.basename(img['src']), 'ab') { |f| f.write chunk }
246
- end
247
- end""",
248
- """freq = Hash.new(0)
249
- text.split.each { |w| freq[w] += 1 }""",
250
- """require 'net/http'
251
- res = Net::HTTP.post_form(URI(login_url), username: 'u', password: 'p')""",
252
- "Nokogiri::HTML(html).text",
253
- "emails = text.scan(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/)",
254
- "phones = text.scan(/\b\d{3}-\d{3}-\d{4}\b/)",
255
- "nums = text.scan(/\d+/)",
256
- "new = text.gsub(/foo/, 'bar')",
257
- "!!(text =~ /pattern/)",
258
- "clean = text.gsub(/<[^>]>/, '')",
259
- "CGI.escapeHTML(text)",
260
- "CGI.unescapeHTML(text)",
261
- """require 'tk'
262
- root = TkRoot.new { title 'App' }
263
- Tk.mainloop""",
264
- "require 'tk'",
265
- """root = TkRoot.new
266
- button = TkButton.new(root) {text 'Click Me'; command { Tk.messageBox(message: 'Button Clicked!') }}
267
- button.pack""",
268
- """Tk.messageBox(message: 'Hello, World!')""",
269
- """entry = TkEntry.new(root).pack
270
- entry.get""",
271
- """root.title = 'My Window'""",
272
- """root.geometry('400x300')""",
273
- """root.geometry('+%d+%d' % [(root.winfo_screenwidth() - root.winfo_reqwidth()) / 2, (root.winfo_screenheight() - root.winfo_reqheight()) / 2])""",
274
- """menu = TkMenu.new(root)
275
- root['menu'] = menu
276
- menu.add('command', 'label' => 'File')""",
277
- """combobox = Tk::Tile::Combobox.new(root).pack""",
278
- """radio = TkRadioButton.new(root) {text 'Option 1'}.pack""",
279
- """check = TkCheckButton.new(root) {text 'Check Me'}.pack""",
280
- """image = TkPhotoImage.new(file: 'image.png')
281
- label = TkLabel.new(root) {image image}.pack""",
282
- """`afplay audio.mp3`""",
283
- """`ffplay video.mp4`""",
284
- """`ffmpeg -i video.mp4 -f null - 2>&1 | grep 'time=' | awk '{print $2}'`""",
285
- """`screencapture screen.png`""",
286
- """`ffmpeg -f avfoundation -i "1" -t 10 screen.mp4`""",
287
- """`cliclick p:.`""",
288
- """`cliclick kd:cmd kp:space ku:cmd`""",
289
- """`cliclick c:.`""",
290
- """Time.now.to_i""",
291
- """Time.at(timestamp).strftime('%Y-%m-%d')""",
292
- """Time.parse(date).to_i""",
293
- """Time.now.strftime('%A')""",
294
- """Time.days_in_month(Time.now.month, Time.now.year)""",
295
- """Time.new(Time.now.year, 1, 1)""",
296
- """Time.new(Time.now.year, 12, 31)""",
297
- """Time.new(year, month, 1)""",
298
- """Time.new(year, month, -1)""",
299
- """Time.now.wday.between?(1, 5)""",
300
- """Time.now.wday.between?(6, 7)""",
301
- """Time.now.hour""",
302
- """Time.now.min""",
303
- """Time.now.sec""",
304
- """sleep(1)""",
305
- """(Time.now.to_f * 1000).to_i""",
306
- """Time.now.strftime('%Y-%m-%d %H:%M:%S')""",
307
- """Time.parse(time_str)""",
308
- """Thread.new { puts 'Hello from thread' }""",
309
- """sleep(1)""",
310
- """threads = []
311
- 3.times { threads << Thread.new { puts 'Hello from thread' } }
312
- threads.each(&:join)""",
313
- """Thread.current.name""",
314
- """thread = Thread.new { puts 'Hello from thread' }
315
- thread.abort_on_exception = true""",
316
- """mutex = Mutex.new
317
- mutex.synchronize { puts 'Hello from synchronized thread' }""",
318
- """pid = Process.spawn('sleep 5')""",
319
- """Process.pid""",
320
- """Process.kill(0, pid) rescue false""",
321
- """pids = []
322
- 3.times { pids << Process.spawn('sleep 5') }
323
- pids.each { |pid| Process.wait(pid) }""",
324
- """queue = Queue.new
325
- queue.push('Hello')
326
- queue.pop""",
327
- """reader, writer = IO.pipe
328
- writer.puts 'Hello'
329
- reader.gets""",
330
- """Process.setrlimit(:CPU, 50)""",
331
- """`ls`""",
332
- """`ls`.chomp""",
333
- """$?.exitstatus""",
334
- """$?.success?""",
335
- """File.expand_path(__FILE__)""",
336
- """ARGV""",
337
- """require 'optparse'
338
- OptionParser.new { |opts| opts.on('-h', '--help', 'Show help') { puts opts } }.parse!""",
339
- """OptionParser.new { |opts| opts.on('-h', '--help', 'Show help') { puts opts } }.parse!""",
340
- """Gem.loaded_specs.keys""",
341
- """`gem install package_name`""",
342
- """`gem uninstall package_name`""",
343
- """Gem.loaded_specs['package_name'].version.to_s""",
344
- """`bundle exec ruby script.rb`""",
345
- """Gem::Specification.map(&:name)""",
346
- """`gem update package_name`""",
347
- """require 'sqlite3'
348
- db = SQLite3::Database.new('test.db')""",
349
- """db.execute('SELECT * FROM table')""",
350
- """db.execute('INSERT INTO table (column) VALUES (?)', 'value')""",
351
- """db.execute('DELETE FROM table WHERE id = ?', 1)""",
352
- """db.execute('UPDATE table SET column = ? WHERE id = ?', 'new_value', 1)""",
353
- """db.execute('SELECT * FROM table').each { |row| puts row }""",
354
- """db.execute('SELECT * FROM table WHERE column = ?', 'value')""",
355
- """db.close""",
356
- """db.execute('CREATE TABLE table (id INTEGER PRIMARY KEY, column TEXT)')""",
357
- """db.execute('DROP TABLE table')""",
358
- """db.table_info('table').any?""",
359
- """db.execute('SELECT name FROM sqlite_master WHERE type = "table"')""",
360
- """class Model < ActiveRecord::Base
361
- end
362
- Model.create(column: 'value')""",
363
- """Model.find_by(column: 'value')""",
364
- """Model.find_by(column: 'value').destroy""",
365
- """Model.find_by(column: 'value').update(column: 'new_value')""",
366
- """class Model < ActiveRecord::Base
367
- end""",
368
- """class ChildModel < ParentModel
369
- end""",
370
- """class Model < ActiveRecord::Base
371
- self.primary_key = 'id'
372
- end""",
373
- """class Model < ActiveRecord::Base
374
- validates_uniqueness_of :column
375
- end""",
376
- """class Model < ActiveRecord::Base
377
- attribute :column, default: 'value'
378
- end""",
379
- """require 'csv'
380
- CSV.open('data.csv', 'w') { |csv| csv << ['column1', 'column2'] }""",
381
- """require 'spreadsheet'
382
- book = Spreadsheet::Workbook.new
383
- sheet = book.create_worksheet
384
- sheet[0, 0] = 'Hello'
385
- book.write('data.xls')""",
386
- """require 'json'
387
- File.write('data.json', {key: 'value'}.to_json)""",
388
- """require 'spreadsheet'
389
- book = Spreadsheet.open('data.xls')
390
- sheet = book.worksheet(0)
391
- sheet.each { |row| puts row }""",
392
- """require 'spreadsheet'
393
- book1 = Spreadsheet.open('file1.xls')
394
- book2 = Spreadsheet.open('file2.xls')
395
- book1.worksheets.each { |sheet| book2.add_worksheet(sheet) }
396
- book2.write('merged.xls')""",
397
- """require 'spreadsheet'
398
- book = Spreadsheet::Workbook.new
399
- book.create_worksheet(name: 'New Sheet')
400
- book.write('data.xls')""",
401
- """require 'spreadsheet'
402
- book = Spreadsheet.open('data.xls')
403
- sheet = book.worksheet(0)
404
- new_sheet = book.create_worksheet
405
- new_sheet.format_with(sheet)
406
- book.write('data.xls')""",
407
- """require 'spreadsheet'
408
- book = Spreadsheet.open('data.xls')
409
- sheet = book.worksheet(0)
410
- sheet.row(0).set_format(0, Spreadsheet::Format.new(color: :red))
411
- book.write('data.xls')""",
412
- """require 'spreadsheet'
413
- book = Spreadsheet.open('data.xls')
414
- sheet = book.worksheet(0)
415
- sheet.row(0).set_format(0, Spreadsheet::Format.new(weight: :bold))
416
- book.write('data.xls')""",
417
- """require 'spreadsheet'
418
- book = Spreadsheet.open('data.xls')
419
- sheet = book.worksheet(0)
420
- sheet[0, 0]""",
421
- """require 'spreadsheet'
422
- book = Spreadsheet::Workbook.new
423
- sheet = book.create_worksheet
424
- sheet[0, 0] = 'Hello'
425
- book.write('data.xls')""",
426
- """require 'rmagick'
427
- image = Magick::Image.read('image.png').first
428
- [image.columns, image.rows]""",
429
- """require 'rmagick'
430
- image = Magick::Image.read('image.png').first
431
- image.resize!(100, 100)"""
432
 
433
 
434
 
 
14
  # 预定义代码片段
15
  CODE_SNIPPETS = [
16
 
17
+ "echo 'Hello, World!';",
18
+ "function add($a, $b) { return $a + $b; }",
19
+ "$randomNumber = rand();",
20
+ "function isEven($num) { return $num % 2 == 0; }",
21
+ "strlen('example');",
22
+ "date('Y-m-d');",
23
+ "file_exists('example.txt');",
24
+ "file_get_contents('example.txt');",
25
+ "file_put_contents('example.txt', 'Hello, World!');",
26
+ "date('H:i:s');",
27
+ "strtoupper('example');",
28
+ "strtolower('EXAMPLE');",
29
+ "strrev('example');",
30
+ "count([1, 2, 3]);",
31
+ "max([1, 2, 3]);",
32
+ "min([1, 2, 3]);",
33
+ "sort([3, 1, 2]);",
34
+ "array_merge([1, 2], [3, 4]);",
35
+ "array_splice($array, $offset, $length);",
36
+ "empty([]);",
37
+ "substr_count('example', 'e');",
38
+ "strpos('example', 'amp') !== false;",
39
+ "strval(123);",
40
+ "intval('123');",
41
+ "is_numeric('123');",
42
+ "array_search('value', $array);",
43
+ "$array = [];",
44
+ "array_reverse([1, 2, 3]);",
45
+ "array_unique([1, 2, 2, 3]);",
46
+ "in_array('value', $array);",
47
+ "$array = ['key' => 'value'];",
48
+ "$array['new_key'] = 'new_value';",
49
+ "unset($array['key']);",
50
+ "array_keys($array);",
51
+ "array_values($array);",
52
+ "array_merge($array1, $array2);",
53
+ "empty($array);",
54
+ "$array['key'];",
55
+ "array_key_exists('key', $array);",
56
+ "$array = [];",
57
+ "count(file('example.txt'));",
58
+ "file_put_contents('example.txt', implode(PHP_EOL, $array));",
59
+ "file('example.txt', FILE_IGNORE_NEW_LINES);",
60
+ "str_word_count(file_get_contents('example.txt'));",
61
+ "function isLeapYear($year) { return ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)); }",
62
+ "date('Y-m-d H:i:s');",
63
+ "(strtotime('2023-12-31') - strtotime('2023-01-01')) / (60 * 60 * 24);",
64
+ "getcwd();",
65
+ "scandir('.');",
66
+ "mkdir('new_directory');",
67
+ "rmdir('directory');",
68
+ "is_file('example.txt');",
69
+ "is_dir('directory');",
70
+ "filesize('example.txt');",
71
+ "rename('old.txt', 'new.txt');",
72
+ "copy('source.txt', 'destination.txt');",
73
+ "rename('source.txt', 'destination.txt');",
74
+ "unlink('example.txt');",
75
+ "getenv('PATH');",
76
+ "putenv('PATH=/new/path');",
77
+ "exec('start https://example.com');",
78
+ "file_get_contents('https://example.com');",
79
+ "json_decode('{\"key\":\"value\"}', true);",
80
+ "file_put_contents('example.json', json_encode($data));",
81
+ "json_decode(file_get_contents('example.json'), true);",
82
+ "implode(',', $array);",
83
+ "explode(',', 'a,b,c');",
84
+ "implode(PHP_EOL, $array);",
85
+ "explode(' ', 'a b c');",
86
+ "explode(',', 'a,b,c');",
87
+ "str_split('example');",
88
+ "str_replace('old', 'new', 'old text');",
89
+ "trim(' example ');",
90
+ "preg_replace('/[^a-zA-Z0-9]/', '', 'example!');",
91
+ "empty('');",
92
+ "strrev('example') == 'example';",
93
+ "fputcsv($file, $array);",
94
+ "array_map('str_getcsv', file('example.csv'));",
95
+ "count(file('example.csv'));",
96
+ "shuffle($array);",
97
+ "$array[array_rand($array)];",
98
+ "array_rand($array, $num);",
99
+ "rand(1, 6);",
100
+ "rand(0, 1);",
101
+ "substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 8);",
102
+ "printf('#%06X', mt_rand(0, 0xFFFFFF));",
103
+ "uniqid();",
104
+ "class Example {}",
105
+ "$example = new Example();",
106
+ "class Example { function method() {} }",
107
+ "class Example { public $property; }",
108
+ "class Child extends Parent {}",
109
+ "class Child extends Parent { function method() {} }",
110
+ "Example::method();",
111
+ "Example::staticMethod();",
112
+ "is_object($example);",
113
+ "get_object_vars($example);",
114
+ "$example->property = 'value';",
115
+ "unset($example->property);",
116
+ "try{foo();}catch(e){}",
117
+ "throw new Error('CustomError')",
118
+ """try{foo();}catch(e){const info=e.message;}""",
119
+ "console.error(err)",
120
+ "const timer={start(){this.s=Date.now()},stop(){return Date.now()-this.s}}",
121
+ "const runtime=(s)=>Date.now()-s",
122
+ """const progress=(i,n)=>process.stdout.write(Math.floor(i/n100)+'%\r')""",
123
+ "const delay=(ms)=>new Promise(r=>setTimeout(r,ms))",
124
+ "const f=(x)=>x2",
125
+ "const m=arr.map(x=>x2)",
126
+ "const f2=arr.filter(x=>x>0)",
127
+ "const r=arr.reduce((a,x)=>a+x,0)",
128
+ "const a=[1,2,3].map(x=>x)",
129
+ "const o={a:1,b:2};const d={k:v for([k,v] of Object.entries(o))}",
130
+ "const s=new Set([1,2,3]);const p=new Set(x for(x of s))",
131
+ "const inter=new Set([...a].filter(x=>b.has(x)))",
132
+ "const uni=new Set([...a,...b])",
133
+ "const diff=new Set([...a].filter(x=>!b.has(x)))",
134
+ "const noNone=list.filter(x=>x!=null)",
135
+ """try{fs.openSync(path)}catch{}""",
136
+ "typeof x==='string'",
137
+ "const b=!!str",
138
+ "if(cond)doSomething()",
139
+ "while(cond){}",
140
+ "for(const x of arr){}",
141
+ "for(const k in obj){}",
142
+ "for(const c of str){}",
143
+ "for(...){if(cond)break}",
144
+ "for(...){if(cond)continue}",
145
+ "function fn(){}",
146
+ "function fn(a=1){}",
147
+ "function fn(){return [1,2]}",
148
+ "function fn(...a){}",
149
+ "function fn(kwargs){const{a,b}=kwargs}",
150
+ """function timed(fn){return(...a)=>{const s=Date.now();const r=fn(...a);console.log(Date.now()-s);return r}}""",
151
+ """const deco=fn=>(...a)=>fn(...a)""",
152
+ """const memo=fn=>{const c={};return x=>c[x]||=(fn(x))}""",
153
+ "functiongen(){yield 1;yield 2}",
154
+ "const g=gen();",
155
+ "const it={i:0,next(){return this.i<2?{value:this.i++,done:false}:{done:true}}}",
156
+ "for(const x of it){}",
157
+ "for(const [i,x] of arr.entries()){}",
158
+ "const z=arr1.map((v,i)=>[v,arr2[i]])",
159
+ "const dict=Object.fromEntries(arr1.map((v,i)=>[v,arr2[i]]))",
160
+ "JSON.stringify(arr1)===JSON.stringify(arr2)",
161
+ "JSON.stringify(obj1)===JSON.stringify(obj2)",
162
+ "JSON.stringify(new Set(a))===JSON.stringify(new Set(b))",
163
+ "const uniq=[...new Set(arr)]",
164
+ "set.clear()",
165
+ "set.size===0",
166
+ "set.add(x)",
167
+ "set.delete(x)",
168
+ "set.has(x)",
169
+ "set.size",
170
+ "const hasInt=([...a].some(x=>b.has(x)))",
171
+ "arr1.every(x=>arr2.includes(x))",
172
+ "str.includes(sub)",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  "str[0]",
174
+ "str[str.length-1]",
175
+ """const isText=path=>['.txt','.md'].includes(require('path').extname(path))""",
176
+ """const isImage=path=>['.png','.jpg','.jpeg','.gif'].includes(require('path').extname(path))""",
177
+ "Math.round(n)",
178
+ "Math.ceil(n)",
179
+ "Math.floor(n)",
180
+ "n.toFixed(2)",
181
+ """const randStr=(l)=>[...Array(l)].map(()=>Math.random().toString(36).charAt(2)).join('')""",
182
+ "const exists=require('fs').existsSync(path)",
183
+ """const walk=(d)=>require('fs').readdirSync(d).flatMap(f=>{const p=require('path').join(d,f);return require('fs').statSync(p).isDirectory()?walk(p):p})""",
184
+ """const ext=require('path').extname(fp)""",
185
+ """const name=require('path').basename(fp)""",
186
+ """const full=require('path').resolve(fp)""",
187
+ "process.version",
188
+ "process.platform",
189
+ "require('os').cpus().length",
190
+ "require('os').totalmem()",
191
+ """const d=require('os').diskUsageSync?require('os').diskUsageSync('/'):null""",
192
+ "require('os').networkInterfaces()",
193
+ """require('dns').resolve('www.google.com',e=>console.log(!e))""",
194
+ """require('https').get(url,res=>res.pipe(require('fs').createWriteStream(dest)))""",
195
+ """const upload=async f=>Promise.resolve('ok')""",
196
+ """require('https').request({method:'POST',host,u:path},()=>{}).end(data)""",
197
+ """require('https').get(url+'?'+new URLSearchParams(params),res=>{})""",
198
+ """const req=()=>fetch(url,{headers})""",
199
+ """const jsdom=require('jsdom');const d=new jsdom.JSDOM(html)""",
200
+ """const title=jsdom.JSDOM(html).window.document.querySelector('title').textContent""",
201
+ """const links=[...d.window.document.querySelectorAll('a')].map(a=>a.href)""",
202
+ """Promise.all(links.map(u=>fetch(u).then(r=>r.blob()).then(b=>require('fs').writeFileSync(require('path').basename(u),Buffer.from(b)))))""",
203
+ """const freq=html.split(/\W+/).reduce((c,w)=>{c[w]=(c[w]||0)+1;return c},{})""",
204
+ """const login=()=>fetch(url,{method:'POST',body:creds})""",
205
+ """const text=html.replace(/<[^>]+>/g,'')""",
206
+ """const emails=html.match(/[\w.-]+@[\w.-]+/g)""",
207
+ """const phones=html.match(/\+?\d[\d -]{7,}\d/g)""",
208
+ """const nums=html.match(/\d+/g)""",
209
+ """const newHtml=html.replace(/foo/g,'bar')""",
210
+ """const ok=/^\d{3}$/.test(str)""",
211
+ """const noTags=html.replace(/<[^>]*>/g,'')""",
212
+ """const enc=html.replace(/./g,c=>'&#'+c.charCodeAt(0)+';')""",
213
+ """const dec=enc.replace(/&#(\d+);/g,(m,n)=>String.fromCharCode(n))""",
214
+ """const {app,BrowserWindow}=require('electron');app.on('ready',()=>new BrowserWindow().loadURL('about:blank'))""",
215
+ "$button = new GtkButton('Click Me'); $window->add($button);",
216
+ "$button->connect('clicked', function() { echo 'Button clicked!'; });",
217
+ "$dialog = new GtkMessageDialog($window, GtkDialogFlags::MODAL, GtkMessageType::INFO, GtkButtonsType::OK, 'Hello!'); $dialog->run();",
218
+ "$entry = new GtkEntry(); $input = $entry->get_text();",
219
+ "$window->set_title('New Title');",
220
+ "$window->set_default_size(800, 600);",
221
+ "$window->set_position(Gtk::WIN_POS_CENTER);",
222
+ "$menubar = new GtkMenuBar(); $menu = new GtkMenu(); $menuitem = new GtkMenuItem('File'); $menuitem->set_submenu($menu); $menubar->append($menuitem); $window->add($menubar);",
223
+ "$combobox = new GtkComboBoxText(); $combobox->append_text('Option 1'); $combobox->append_text('Option 2'); $window->add($combobox);",
224
+ "$radiobutton1 = new GtkRadioButton('Option 1'); $radiobutton2 = new GtkRadioButton($radiobutton1, 'Option 2'); $window->add($radiobutton1); $window->add($radiobutton2);",
225
+ "$checkbutton = new GtkCheckButton('Check Me'); $window->add($checkbutton);",
226
+ "$image = new GtkImage('image.png'); $window->add($image);",
227
+ "exec('play audio.mp3');",
228
+ "exec('play video.mp4');",
229
+ "$current_time = exec('get_current_time_command');",
230
+ "exec('screenshot_command');",
231
+ "exec('record_screen_command');",
232
+ "$mouse_position = exec('get_mouse_position_command');",
233
+ "exec('simulate_keyboard_input_command');",
234
+ "exec('simulate_mouse_click_command');",
235
+ "time();",
236
+ "date('Y-m-d H:i:s', $timestamp);",
237
+ "strtotime('2023-10-01 12:00:00');",
238
+ "date('l');",
239
+ "date('t');",
240
+ "date('Y-01-01');",
241
+ "date('Y-12-31');",
242
+ "date('Y-m-01', strtotime('2023-10-01'));",
243
+ "date('Y-m-t', strtotime('2023-10-01'));",
244
+ "date('N') < 6;",
245
+ "date('N') >= 6;",
246
+ "date('H');",
247
+ "date('i');",
248
+ "date('s');",
249
+ "sleep(1);",
250
+ "floor(microtime(true) * 1000);",
251
+ "date('Y-m-d H:i:s', $time);",
252
+ "strtotime($time_string);",
253
+ "$thread = new Thread(); $thread->start();",
254
+ "$thread->sleep(1);",
255
+ "$threads = []; for ($i = 0; $i < 5; $i++) { $threads[$i] = new Thread(); $threads[$i]->start(); }",
256
+ "$thread->getName();",
257
+ "$thread->setDaemon(true);",
258
+ "$lock = new Mutex(); $lock->lock(); $lock->unlock();",
259
+ "$pid = pcntl_fork();",
260
+ "getmypid();",
261
+ "posix_kill($pid, 0);",
262
+ "$pids = []; for ($i = 0; $i < 5; $i++) { $pids[$i] = pcntl_fork(); if ($pids[$i] == 0) { exit; } }",
263
+ "$queue = new Threaded(); $queue->push('value');",
264
+ "$pipe = fopen('php://stdin', 'r'); fwrite($pipe, 'value'); fclose($pipe);",
265
+ "set_time_limit(0);",
266
+ "exec('ls');",
267
+ "exec('ls', $output);",
268
+ "exec('ls', $output, $status);",
269
+ "$status === 0;",
270
+ "__FILE__;",
271
+ "$argv;",
272
+ "$parser = new ArgParser(); $parser->addArgument('arg1'); $parser->parse($argv);",
273
+ "$parser->printHelp();",
274
+ "print_r(get_loaded_extensions());",
275
+ "exec('pip install package_name');",
276
+ "exec('pip uninstall package_name');",
277
+ "exec('pip show package_name | grep Version');",
278
+ "exec('python -m venv venv');",
279
+ "exec('pip list');",
280
+ "exec('pip install --upgrade package_name');",
281
+ "$db = new SQLite3('database.db');",
282
+ "$result = $db->query('SELECT * FROM table');",
283
+ "$db->exec(\"INSERT INTO table (column) VALUES ('value')\");",
284
+ "$db->exec(\"DELETE FROM table WHERE id = 1\");",
285
+ "$db->exec(\"UPDATE table SET column = 'new_value' WHERE id = 1\");",
286
+ "$result = $db->query('SELECT * FROM table'); while ($row = $result->fetchArray()) { print_r($row); }",
287
+ "$stmt = $db->prepare('SELECT * FROM table WHERE id = :id'); $stmt->bindValue(':id', 1); $result = $stmt->execute();",
288
+ "$db->close();",
289
+ "$db->exec('CREATE TABLE table (id INTEGER PRIMARY KEY, column TEXT)');",
290
+ "$db->exec('DROP TABLE table');",
291
+ "$result = $db->query(\"SELECT name FROM sqlite_master WHERE type='table' AND name='table'\");",
292
+ "$result = $db->query(\"SELECT name FROM sqlite_master WHERE type='table'\");",
293
+ "$model = new Model(); $model->save();",
294
+ "$model = Model::find(1);",
295
+ "$model = Model::find(1); $model->delete();",
296
+ "$model = Model::find(1); $model->column = 'new_value'; $model->save();",
297
+ "class Model extends ORM { protected static $table = 'table'; }",
298
+ "class ChildModel extends ParentModel {}",
299
+ "protected static $primaryKey = 'id';",
300
+ "protected static $unique = ['column'];",
301
+ "protected static $defaults = ['column' => 'default_value'];",
302
+ "$file = fopen('data.csv', 'w'); fputcsv($file, $data); fclose($file);",
303
+ "$excel = new ExcelWriter('data.xlsx'); $excel->write($data); $excel->close();",
304
+ "$json = json_encode($data); file_put_contents('data.json', $json);",
305
+ "$excel = new ExcelReader('data.xlsx'); $data = $excel->read(); $excel->close();",
306
+ "$excel = new ExcelWriter('merged.xlsx'); foreach ($files as $file) { $data = (new ExcelReader($file))->read(); $excel->write($data); } $excel->close();",
307
+ "$excel = new ExcelWriter('data.xlsx'); $excel->addSheet('New Sheet'); $excel->close();",
308
+ "$excel = new ExcelWriter('data.xlsx'); $excel->copyStyle('Sheet1', 'Sheet2'); $excel->close();",
309
+ "$excel = new ExcelWriter('data.xlsx'); $excel->setCellColor('A1', 'FF0000'); $excel->close();",
310
+ "$excel = new ExcelWriter('data.xlsx'); $excel->setFontStyle('A1', 'bold'); $excel->close();",
311
+ "$excel = new ExcelReader('data.xlsx'); $value = $excel->getCellValue('A1'); $excel->close();",
312
+ "$excel = new ExcelWriter('data.xlsx'); $excel->setCellValue('A1', 'Hello'); $excel->close();",
313
+ "list($width, $height) = getimagesize('image.png');",
314
+ "$image = new Imagick('image.png'); $image->resizeImage(100, 100, Imagick::FILTER_LANCZOS, 1); $image->writeImage('resized_image.png');"
315
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
 
317
 
318