Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,123 +14,142 @@ app.logger = logging.getLogger("CodeSearchAPI")
|
|
| 14 |
# 预定义代码片段
|
| 15 |
CODE_SNIPPETS = [
|
| 16 |
|
| 17 |
-
"
|
| 18 |
-
"
|
| 19 |
-
"
|
| 20 |
-
"
|
| 21 |
-
"
|
| 22 |
-
"
|
| 23 |
-
"
|
| 24 |
-
"
|
| 25 |
-
"
|
| 26 |
-
"
|
| 27 |
-
"
|
| 28 |
-
"
|
| 29 |
-
"
|
| 30 |
-
"
|
| 31 |
-
"max(
|
| 32 |
-
"min(
|
| 33 |
-
"sort(
|
| 34 |
-
"
|
| 35 |
-
"
|
| 36 |
-
"
|
| 37 |
-
"
|
| 38 |
-
"
|
| 39 |
-
"
|
| 40 |
-
"
|
| 41 |
-
"
|
| 42 |
-
"
|
| 43 |
-
"
|
| 44 |
-
"
|
| 45 |
-
"
|
| 46 |
-
"
|
| 47 |
-
"
|
| 48 |
-
"
|
| 49 |
-
"
|
| 50 |
-
"
|
| 51 |
-
"
|
| 52 |
-
"
|
| 53 |
-
"
|
| 54 |
-
"
|
| 55 |
-
"
|
| 56 |
-
"
|
| 57 |
-
"
|
| 58 |
-
"
|
| 59 |
-
"
|
| 60 |
-
"
|
| 61 |
-
"
|
| 62 |
-
"date('
|
| 63 |
-
"(
|
| 64 |
-
"
|
| 65 |
-
"
|
| 66 |
-
"
|
| 67 |
-
"
|
| 68 |
-
"
|
| 69 |
-
"
|
| 70 |
-
"
|
| 71 |
-
"
|
| 72 |
-
"
|
| 73 |
-
"
|
| 74 |
-
"
|
| 75 |
-
"
|
| 76 |
-
"
|
| 77 |
-
"
|
| 78 |
-
"
|
| 79 |
-
"
|
| 80 |
-
"
|
| 81 |
-
"
|
| 82 |
-
"
|
| 83 |
-
"
|
| 84 |
-
"
|
| 85 |
-
"
|
| 86 |
-
"
|
| 87 |
-
"
|
| 88 |
-
"
|
| 89 |
-
"
|
| 90 |
-
"
|
| 91 |
-
"
|
| 92 |
-
"
|
| 93 |
-
"
|
| 94 |
-
"
|
| 95 |
-
"
|
| 96 |
-
"
|
| 97 |
-
"
|
| 98 |
-
"
|
| 99 |
-
"
|
| 100 |
-
"
|
| 101 |
-
"
|
| 102 |
-
"
|
| 103 |
-
"
|
| 104 |
-
"
|
| 105 |
-
"
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
"
|
| 109 |
-
"class
|
| 110 |
-
|
| 111 |
-
"
|
| 112 |
-
"
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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/
|
| 123 |
"const delay=(ms)=>new Promise(r=>setTimeout(r,ms))",
|
| 124 |
-
"const f=(x)=>
|
| 125 |
-
"const m=arr.map(x=>
|
| 126 |
"const f2=arr.filter(x=>x>0)",
|
| 127 |
"const r=arr.reduce((a,x)=>a+x,0)",
|
| 128 |
-
"const a
|
| 129 |
-
"const o={a:1,b:2};const d={k
|
| 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'",
|
|
@@ -144,43 +163,43 @@ CODE_SNIPPETS = [
|
|
| 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 |
-
"
|
| 154 |
"const g=gen();",
|
| 155 |
-
"const it={i:0,next(){return this.i<2?{value
|
| 156 |
"for(const x of it){}",
|
| 157 |
-
"for(const [i,x] of arr.entries()){}",
|
| 158 |
-
"const z=arr1.map((v,i)
|
| 159 |
-
"const dict=Object.fromEntries(arr1.map((v,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
|
| 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
|
| 176 |
-
"""const isImage=path
|
| 177 |
"Math.round(n)",
|
| 178 |
"Math.ceil(n)",
|
| 179 |
"Math.floor(n)",
|
| 180 |
"n.toFixed(2)",
|
| 181 |
-
"""const randStr=(l)
|
| 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)
|
| 184 |
"""const ext=require('path').extname(fp)""",
|
| 185 |
"""const name=require('path').basename(fp)""",
|
| 186 |
"""const full=require('path').resolve(fp)""",
|
|
@@ -188,131 +207,129 @@ CODE_SNIPPETS = [
|
|
| 188 |
"process.platform",
|
| 189 |
"require('os').cpus().length",
|
| 190 |
"require('os').totalmem()",
|
| 191 |
-
"""const d=require('os').diskUsageSync?require('os').diskUsageSync('/')
|
| 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
|
| 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
|
| 201 |
-
"""const links
|
| 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
|
| 205 |
-
"""const text=html.replace(
|
| 206 |
-
"""const emails=html.match(
|
| 207 |
-
"""const phones=html.match(
|
| 208 |
"""const nums=html.match(/\d+/g)""",
|
| 209 |
"""const newHtml=html.replace(/foo/g,'bar')""",
|
| 210 |
-
"""const ok=/^\d{3}
|
| 211 |
-
"""const noTags=html.replace(
|
| 212 |
-
"""const enc=html.replace(/./g,c=>'
|
| 213 |
-
"""const dec=enc.replace(
|
| 214 |
-
"""const {app,BrowserWindow}=require('electron');app.on('ready',()=>new BrowserWindow().loadURL('about
|
| 215 |
-
"
|
| 216 |
-
"
|
| 217 |
-
"
|
| 218 |
-
"
|
| 219 |
-
"
|
| 220 |
-
"
|
| 221 |
-
"
|
| 222 |
-
"
|
| 223 |
-
"
|
| 224 |
-
"
|
| 225 |
-
"
|
| 226 |
-
"
|
| 227 |
-
"
|
| 228 |
-
"
|
| 229 |
-
"
|
| 230 |
-
"
|
| 231 |
-
"
|
| 232 |
-
"
|
| 233 |
-
"
|
| 234 |
-
"
|
| 235 |
-
"
|
| 236 |
-
"date
|
| 237 |
-
"
|
| 238 |
-
"
|
| 239 |
-
"
|
| 240 |
-
"
|
| 241 |
-
"
|
| 242 |
-
"
|
| 243 |
-
"
|
| 244 |
-
"
|
| 245 |
-
"
|
| 246 |
-
"
|
| 247 |
-
"
|
| 248 |
-
"
|
| 249 |
-
"
|
| 250 |
-
"
|
| 251 |
-
"
|
| 252 |
-
"
|
| 253 |
-
"
|
| 254 |
-
"
|
| 255 |
-
"
|
| 256 |
-
"
|
| 257 |
-
"
|
| 258 |
-
"
|
| 259 |
-
"
|
| 260 |
-
"
|
| 261 |
-
"
|
| 262 |
-
"
|
| 263 |
-
"
|
| 264 |
-
"
|
| 265 |
-
"
|
| 266 |
-
"
|
| 267 |
-
"
|
| 268 |
-
"
|
| 269 |
-
"
|
| 270 |
-
"
|
| 271 |
-
"
|
| 272 |
-
"
|
| 273 |
-
"
|
| 274 |
-
"
|
| 275 |
-
"exec('pip
|
| 276 |
-
"
|
| 277 |
-
"exec('
|
| 278 |
-
"exec('
|
| 279 |
-
"exec('pip
|
| 280 |
-
"
|
| 281 |
-
"
|
| 282 |
-
"
|
| 283 |
-
"
|
| 284 |
-
"
|
| 285 |
-
"
|
| 286 |
-
"
|
| 287 |
-
"
|
| 288 |
-
"
|
| 289 |
-
"
|
| 290 |
-
"
|
| 291 |
-
"
|
| 292 |
-
"
|
| 293 |
-
"
|
| 294 |
-
"
|
| 295 |
-
"
|
| 296 |
-
"
|
| 297 |
-
"class
|
| 298 |
-
"
|
| 299 |
-
"
|
| 300 |
-
"
|
| 301 |
-
"
|
| 302 |
-
"
|
| 303 |
-
"
|
| 304 |
-
"
|
| 305 |
-
"
|
| 306 |
-
"
|
| 307 |
-
"
|
| 308 |
-
"
|
| 309 |
-
"
|
| 310 |
-
"
|
| 311 |
-
"
|
| 312 |
-
"
|
| 313 |
-
"
|
| 314 |
-
"$image = new Imagick('image.png'); $image->resizeImage(100, 100, Imagick::FILTER_LANCZOS, 1); $image->writeImage('resized_image.png');"
|
| 315 |
-
|
| 316 |
|
| 317 |
|
| 318 |
|
|
|
|
| 14 |
# 预定义代码片段
|
| 15 |
CODE_SNIPPETS = [
|
| 16 |
|
| 17 |
+
"console.log('Hello, World!')",
|
| 18 |
+
"const sum = (a, b) => a + b",
|
| 19 |
+
"const randomNum = Math.random()",
|
| 20 |
+
"const isEven = num => num % 2 === 0",
|
| 21 |
+
"const strLength = str => str.length",
|
| 22 |
+
"const currentDate = new Date().toLocaleDateString()",
|
| 23 |
+
"const fs = require('fs'); const fileExists = path => fs.existsSync(path)",
|
| 24 |
+
"const readFile = path => fs.readFileSync(path, 'utf8')",
|
| 25 |
+
"const writeFile = (path, content) => fs.writeFileSync(path, content)",
|
| 26 |
+
"const currentTime = new Date().toLocaleTimeString()",
|
| 27 |
+
"const toUpperCase = str => str.toUpperCase()",
|
| 28 |
+
"const toLowerCase = str => str.toLowerCase()",
|
| 29 |
+
"const reverseStr = str => str.split('').reverse().join('')",
|
| 30 |
+
"const countElements = list => list.length",
|
| 31 |
+
"const maxInList = list => Math.max(...list)",
|
| 32 |
+
"const minInList = list => Math.min(...list)",
|
| 33 |
+
"const sortList = list => list.sort()",
|
| 34 |
+
"const mergeLists = (list1, list2) => list1.concat(list2)",
|
| 35 |
+
"const removeElement = (list, element) => list.filter(e => e !== element)",
|
| 36 |
+
"const isListEmpty = list => list.length === 0",
|
| 37 |
+
"const countChar = (str, char) => str.split(char).length - 1",
|
| 38 |
+
"const containsSubstring = (str, substring) => str.includes(substring)",
|
| 39 |
+
"const numToString = num => num.toString()",
|
| 40 |
+
"const strToNum = str => Number(str)",
|
| 41 |
+
"const isNumeric = str => !isNaN(str)",
|
| 42 |
+
"const getIndex = (list, element) => list.indexOf(element)",
|
| 43 |
+
"const clearList = list => list.length = 0",
|
| 44 |
+
"const reverseList = list => list.reverse()",
|
| 45 |
+
"const removeDuplicates = list => [...new Set(list)]",
|
| 46 |
+
"const isInList = (list, value) => list.includes(value)",
|
| 47 |
+
"const createDict = () => ({})",
|
| 48 |
+
"const addToDict = (dict, key, value) => dict[key] = value",
|
| 49 |
+
"const removeKey = (dict, key) => delete dict[key]",
|
| 50 |
+
"const getDictKeys = dict => Object.keys(dict)",
|
| 51 |
+
"const getDictValues = dict => Object.values(dict)",
|
| 52 |
+
"const mergeDicts = (dict1, dict2) => ({ ...dict1, ...dict2 })",
|
| 53 |
+
"const isDictEmpty = dict => Object.keys(dict).length === 0",
|
| 54 |
+
"const getDictValue = (dict, key) => dict[key]",
|
| 55 |
+
"const keyExists = (dict, key) => key in dict",
|
| 56 |
+
"const clearDict = dict => Object.keys(dict).forEach(key => delete dict[key])",
|
| 57 |
+
"const countFileLines = path => fs.readFileSync(path, 'utf8').split('\n').length",
|
| 58 |
+
"const writeListToFile = (path, list) => fs.writeFileSync(path, list.join('\n'))",
|
| 59 |
+
"const readListFromFile = path => fs.readFileSync(path, 'utf8').split('\n')",
|
| 60 |
+
"const countFileWords = path => fs.readFileSync(path, 'utf8').split(/\s+/).length",
|
| 61 |
+
"const isLeapYear = year => (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0",
|
| 62 |
+
"const formatTime = (date, format) => date.toLocaleTimeString('en-US', format)",
|
| 63 |
+
"const daysBetween = (date1, date2) => Math.abs(date1 - date2) / (1000 * 60 * 60 * 24)",
|
| 64 |
+
"const currentDir = process.cwd()",
|
| 65 |
+
"const listFiles = path => fs.readdirSync(path)",
|
| 66 |
+
"const createDir = path => fs.mkdirSync(path)",
|
| 67 |
+
"const removeDir = path => fs.rmdirSync(path)",
|
| 68 |
+
"const isFile = path => fs.statSync(path).isFile()",
|
| 69 |
+
"const isDirectory = path => fs.statSync(path).isDirectory()",
|
| 70 |
+
"const getFileSize = path => fs.statSync(path).size",
|
| 71 |
+
"const renameFile = (oldPath, newPath) => fs.renameSync(oldPath, newPath)",
|
| 72 |
+
"const copyFile = (src, dest) => fs.copyFileSync(src, dest)",
|
| 73 |
+
"const moveFile = (src, dest) => fs.renameSync(src, dest)",
|
| 74 |
+
"const deleteFile = path => fs.unlinkSync(path)",
|
| 75 |
+
"const getEnvVar = key => process.env[key]",
|
| 76 |
+
"const setEnvVar = (key, value) => process.env[key] = value",
|
| 77 |
+
"const openLink = url => require('open')(url)",
|
| 78 |
+
"const sendGetRequest = async url => await (await fetch(url)).text()",
|
| 79 |
+
"const parseJSON = json => JSON.parse(json)",
|
| 80 |
+
"const writeJSON = (path, data) => fs.writeFileSync(path, JSON.stringify(data))",
|
| 81 |
+
"const readJSON = path => JSON.parse(fs.readFileSync(path, 'utf8'))",
|
| 82 |
+
"const listToString = list => list.join('')",
|
| 83 |
+
"const stringToList = str => str.split('')",
|
| 84 |
+
"const joinWithComma = list => list.join(',')",
|
| 85 |
+
"const joinWithNewline = list => list.join('\n')",
|
| 86 |
+
"const splitBySpace = str => str.split(' ')",
|
| 87 |
+
"const splitByChar = (str, char) => str.split(char)",
|
| 88 |
+
"const splitToChars = str => str.split('')",
|
| 89 |
+
"const replaceInStr = (str, old, newStr) => str.replace(old, newStr)",
|
| 90 |
+
"const removeSpaces = str => str.replace(/\s+/g, '')",
|
| 91 |
+
"const removePunctuation = str => str.replace(/[^\w\s]/g, '')",
|
| 92 |
+
"const isStrEmpty = str => str.length === 0",
|
| 93 |
+
"const isPalindrome = str => str === str.split('').reverse().join('')",
|
| 94 |
+
"const writeCSV = (path, data) => fs.writeFileSync(path, data.map(row => row.join(',')).join('\n'))",
|
| 95 |
+
"const readCSV = path => fs.readFileSync(path, 'utf8').split('\n').map(row => row.split(','))",
|
| 96 |
+
"const countCSVLines = path => fs.readFileSync(path, 'utf8').split('\n').length",
|
| 97 |
+
"const shuffleList = list => list.sort(() => Math.random() - 0.5)",
|
| 98 |
+
"const randomElement = list => list[Math.floor(Math.random() * list.length)]",
|
| 99 |
+
"const randomElements = (list, count) => list.sort(() => Math.random() - 0.5).slice(0, count)",
|
| 100 |
+
"const rollDice = () => Math.floor(Math.random() * 6) + 1",
|
| 101 |
+
"const flipCoin = () => Math.random() < 0.5 ? 'Heads' : 'Tails'",
|
| 102 |
+
"const randomPassword = length => Array.from({ length }, () => Math.random().toString(36).charAt(2)).join('')",
|
| 103 |
+
"const randomColor = () => `#${Math.floor(Math.random() * 16777215).toString(16)}`",
|
| 104 |
+
"const uniqueID = () => Math.random().toString(36).substring(2) + Date.now().toString(36)",
|
| 105 |
+
"""class MyClass {
|
| 106 |
+
constructor() {}
|
| 107 |
+
}""",
|
| 108 |
+
"const myInstance = new MyClass()",
|
| 109 |
+
"""class MyClass {
|
| 110 |
+
myMethod() {}
|
| 111 |
+
}""",
|
| 112 |
+
"""class MyClass {
|
| 113 |
+
constructor() {
|
| 114 |
+
this.myProp = 'value'
|
| 115 |
+
}
|
| 116 |
+
}""",
|
| 117 |
+
"""class ChildClass extends MyClass {
|
| 118 |
+
constructor() {
|
| 119 |
+
super()
|
| 120 |
+
}
|
| 121 |
+
}""",
|
| 122 |
+
"""class ChildClass extends MyClass {
|
| 123 |
+
myMethod() {
|
| 124 |
+
super.myMethod()
|
| 125 |
+
}
|
| 126 |
+
}""",
|
| 127 |
+
"const instance = new MyClass(); instance.myMethod()",
|
| 128 |
+
"""class MyClass {
|
| 129 |
+
static myStaticMethod() {}
|
| 130 |
+
}""",
|
| 131 |
+
"const typeOf = obj => typeof obj",
|
| 132 |
+
"const getProp = (obj, prop) => obj[prop]",
|
| 133 |
+
"const setProp = (obj, prop, value) => obj[prop] = value",
|
| 134 |
+
"const deleteProp = (obj, prop) => delete obj[prop]",
|
| 135 |
"try{foo();}catch(e){}",
|
| 136 |
"throw new Error('CustomError')",
|
| 137 |
"""try{foo();}catch(e){const info=e.message;}""",
|
| 138 |
"console.error(err)",
|
| 139 |
"const timer={start(){this.s=Date.now()},stop(){return Date.now()-this.s}}",
|
| 140 |
"const runtime=(s)=>Date.now()-s",
|
| 141 |
+
"""const progress=(i,n)=>process.stdout.write(Math.floor(i/n*100)+'%\r')""",
|
| 142 |
"const delay=(ms)=>new Promise(r=>setTimeout(r,ms))",
|
| 143 |
+
"const f=(x)=>x*2",
|
| 144 |
+
"const m=arr.map(x=>x*2)",
|
| 145 |
"const f2=arr.filter(x=>x>0)",
|
| 146 |
"const r=arr.reduce((a,x)=>a+x,0)",
|
| 147 |
+
"const a=\[1,2,3].map(x=>x)",
|
| 148 |
+
"const o={a:1,b:2};const d={k\:v for(\[k,v] of Object.entries(o))}",
|
| 149 |
+
"const s=new Set(\[1,2,3]);const p=new Set(x for(x of s))",
|
| 150 |
+
"const inter=new Set(\[...a].filter(x=>b.has(x)))",
|
| 151 |
+
"const uni=new Set(\[...a,...b])",
|
| 152 |
+
"const diff=new Set(\[...a].filter(x=>!b.has(x)))",
|
| 153 |
"const noNone=list.filter(x=>x!=null)",
|
| 154 |
"""try{fs.openSync(path)}catch{}""",
|
| 155 |
"typeof x==='string'",
|
|
|
|
| 163 |
"for(...){if(cond)continue}",
|
| 164 |
"function fn(){}",
|
| 165 |
"function fn(a=1){}",
|
| 166 |
+
"function fn(){return \[1,2]}",
|
| 167 |
"function fn(...a){}",
|
| 168 |
"function fn(kwargs){const{a,b}=kwargs}",
|
| 169 |
"""function timed(fn){return(...a)=>{const s=Date.now();const r=fn(...a);console.log(Date.now()-s);return r}}""",
|
| 170 |
"""const deco=fn=>(...a)=>fn(...a)""",
|
| 171 |
+
"""const memo=fn=>{const c={};return x=>c\[x]||=(fn(x))}""",
|
| 172 |
+
"function*gen(){yield 1;yield 2}",
|
| 173 |
"const g=gen();",
|
| 174 |
+
"const it={i:0,next(){return this.i<2?{value\:this.i++,done\:false}:{done\:true}}}",
|
| 175 |
"for(const x of it){}",
|
| 176 |
+
"for(const \[i,x] of arr.entries()){}",
|
| 177 |
+
"const z=arr1.map((v,i)=>\[v,arr2\[i]])",
|
| 178 |
+
"const dict=Object.fromEntries(arr1.map((v,i)=>\[v,arr2\[i]]))",
|
| 179 |
"JSON.stringify(arr1)===JSON.stringify(arr2)",
|
| 180 |
"JSON.stringify(obj1)===JSON.stringify(obj2)",
|
| 181 |
"JSON.stringify(new Set(a))===JSON.stringify(new Set(b))",
|
| 182 |
+
"const uniq=\[...new Set(arr)]",
|
| 183 |
"set.clear()",
|
| 184 |
"set.size===0",
|
| 185 |
"set.add(x)",
|
| 186 |
"set.delete(x)",
|
| 187 |
"set.has(x)",
|
| 188 |
"set.size",
|
| 189 |
+
"const hasInt=(\[...a].some(x=>b.has(x)))",
|
| 190 |
"arr1.every(x=>arr2.includes(x))",
|
| 191 |
"str.includes(sub)",
|
| 192 |
+
"str\[0]",
|
| 193 |
+
"str\[str.length-1]",
|
| 194 |
+
"""const isText=path=>\['.txt','.md'].includes(require('path').extname(path))""",
|
| 195 |
+
"""const isImage=path=>\['.png','.jpg','.jpeg','.gif'].includes(require('path').extname(path))""",
|
| 196 |
"Math.round(n)",
|
| 197 |
"Math.ceil(n)",
|
| 198 |
"Math.floor(n)",
|
| 199 |
"n.toFixed(2)",
|
| 200 |
+
"""const randStr=(l)=>\[...Array(l)].map(()=>Math.random().toString(36).charAt(2)).join('')""",
|
| 201 |
"const exists=require('fs').existsSync(path)",
|
| 202 |
+
"""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})""",
|
| 203 |
"""const ext=require('path').extname(fp)""",
|
| 204 |
"""const name=require('path').basename(fp)""",
|
| 205 |
"""const full=require('path').resolve(fp)""",
|
|
|
|
| 207 |
"process.platform",
|
| 208 |
"require('os').cpus().length",
|
| 209 |
"require('os').totalmem()",
|
| 210 |
+
"""const d=require('os').diskUsageSync?require('os').diskUsageSync('/')\:null""",
|
| 211 |
"require('os').networkInterfaces()",
|
| 212 |
+
"""require('dns').resolve('[www.google.com',e=>console.log(!e)](http://www.google.com',e=>console.log%28!e%29))""",
|
| 213 |
"""require('https').get(url,res=>res.pipe(require('fs').createWriteStream(dest)))""",
|
| 214 |
"""const upload=async f=>Promise.resolve('ok')""",
|
| 215 |
+
"""require('https').request({method:'POST',host,u\:path},()=>{}).end(data)""",
|
| 216 |
"""require('https').get(url+'?'+new URLSearchParams(params),res=>{})""",
|
| 217 |
"""const req=()=>fetch(url,{headers})""",
|
| 218 |
"""const jsdom=require('jsdom');const d=new jsdom.JSDOM(html)""",
|
| 219 |
+
"""const title=jsdom.JSDOM(html).window\.document.querySelector('title').textContent""",
|
| 220 |
+
"""const links=\[...d.window\.document.querySelectorAll('a')].map(a=>a.href)""",
|
| 221 |
"""Promise.all(links.map(u=>fetch(u).then(r=>r.blob()).then(b=>require('fs').writeFileSync(require('path').basename(u),Buffer.from(b)))))""",
|
| 222 |
+
"""const freq=html.split(/\W+/).reduce((c,w)=>{c\[w]=(c\[w]||0)+1;return c},{})""",
|
| 223 |
+
"""const login=()=>fetch(url,{method:'POST',body\:creds})""",
|
| 224 |
+
"""const text=html.replace(/<\[^>]+>/g,'')""",
|
| 225 |
+
"""const emails=html.match(/\[\w\.-]+@\[\w\.-]+/g)""",
|
| 226 |
+
"""const phones=html.match(/\\+?\d\[\d -]{7,}\d/g)""",
|
| 227 |
"""const nums=html.match(/\d+/g)""",
|
| 228 |
"""const newHtml=html.replace(/foo/g,'bar')""",
|
| 229 |
+
"""const ok=/^\d{3}\$/.test(str)""",
|
| 230 |
+
"""const noTags=html.replace(/<\[^>]\*>/g,'')""",
|
| 231 |
+
"""const enc=html.replace(/./g,c=>'\&#'+c.charCodeAt(0)+';')""",
|
| 232 |
+
"""const dec=enc.replace(/\&#(\d+);/g,(m,n)=>String.fromCharCode(n))""",
|
| 233 |
+
"""const {app,BrowserWindow}=require('electron');app.on('ready',()=>new BrowserWindow().loadURL('about\:blank'))""",
|
| 234 |
+
"const button = document.createElement('button'); button.textContent = 'Click Me'; document.body.appendChild(button)",
|
| 235 |
+
"button.addEventListener('click', () => alert('Button Clicked!'))",
|
| 236 |
+
"const input = document.createElement('input'); input.type = 'text'; document.body.appendChild(input)",
|
| 237 |
+
"const inputValue = input.value",
|
| 238 |
+
"document.title = 'New Title'",
|
| 239 |
+
"window.resizeTo(800, 600)",
|
| 240 |
+
"window.moveTo((window.screen.width - window.outerWidth) / 2, (window.screen.height - window.outerHeight) / 2)",
|
| 241 |
+
"const menuBar = document.createElement('menu'); document.body.appendChild(menuBar)",
|
| 242 |
+
"const select = document.createElement('select'); document.body.appendChild(select)",
|
| 243 |
+
"const radio = document.createElement('input'); radio.type = 'radio'; document.body.appendChild(radio)",
|
| 244 |
+
"const checkbox = document.createElement('input'); checkbox.type = 'checkbox'; document.body.appendChild(checkbox)",
|
| 245 |
+
"const img = document.createElement('img'); img.src = 'image.png'; document.body.appendChild(img)",
|
| 246 |
+
"const audio = new Audio('audio.mp3'); audio.play()",
|
| 247 |
+
"const video = document.createElement('video'); video.src = 'video.mp4'; document.body.appendChild(video); video.play()",
|
| 248 |
+
"const currentTime = audio.currentTime",
|
| 249 |
+
"navigator.mediaDevices.getDisplayMedia().then(stream => {})",
|
| 250 |
+
"navigator.mediaDevices.getUserMedia({ video: true }).then(stream => {})",
|
| 251 |
+
"document.addEventListener('mousemove', (event) => { const x = event.clientX; const y = event.clientY })",
|
| 252 |
+
"document.execCommand('insertText', false, 'Hello World')",
|
| 253 |
+
"document.elementFromPoint(100, 100).click()",
|
| 254 |
+
"const timestamp = Date.now()",
|
| 255 |
+
"const date = new Date(timestamp)",
|
| 256 |
+
"const timestampFromDate = date.getTime()",
|
| 257 |
+
"const dayOfWeek = new Date().getDay()",
|
| 258 |
+
"const daysInMonth = new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate()",
|
| 259 |
+
"const firstDayOfYear = new Date(new Date().getFullYear(), 0, 1)",
|
| 260 |
+
"const lastDayOfYear = new Date(new Date().getFullYear(), 11, 31)",
|
| 261 |
+
"const firstDayOfMonth = new Date(new Date().getFullYear(), new Date().getMonth(), 1)",
|
| 262 |
+
"const lastDayOfMonth = new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0)",
|
| 263 |
+
"const isWeekday = new Date().getDay() !== 0 && new Date().getDay() !== 6",
|
| 264 |
+
"const isWeekend = new Date().getDay() === 0 || new Date().getDay() === 6",
|
| 265 |
+
"const currentHour = new Date().getHours()",
|
| 266 |
+
"const currentMinute = new Date().getMinutes()",
|
| 267 |
+
"const currentSecond = new Date().getSeconds()",
|
| 268 |
+
"setTimeout(() => {}, 1000)",
|
| 269 |
+
"const millisecondsTimestamp = Date.now()",
|
| 270 |
+
"const formattedTime = new Date().toLocaleTimeString()",
|
| 271 |
+
"const parsedTime = Date.parse('2023-10-01T00:00:00Z')",
|
| 272 |
+
"const worker = new Worker('worker.js')",
|
| 273 |
+
"worker.postMessage('pause')",
|
| 274 |
+
"new Worker('worker.js').postMessage('start')",
|
| 275 |
+
"const threadName = self.name",
|
| 276 |
+
"worker.terminate()",
|
| 277 |
+
"const lock = new Mutex(); lock.acquire()",
|
| 278 |
+
"const process = new Worker('process.js')",
|
| 279 |
+
"const pid = process.pid",
|
| 280 |
+
"const isAlive = process.terminated === false",
|
| 281 |
+
"new Worker('process.js').postMessage('start')",
|
| 282 |
+
"const queue = new MessageChannel()",
|
| 283 |
+
"const pipe = new MessageChannel()",
|
| 284 |
+
"const cpuUsage = performance.now()",
|
| 285 |
+
"const output = new Response('ls -la').text()",
|
| 286 |
+
"const statusCode = new Response('ls -la').status",
|
| 287 |
+
"const isSuccess = new Response('ls -la').ok",
|
| 288 |
+
"const scriptPath = import.meta.url",
|
| 289 |
+
"const args = process.argv",
|
| 290 |
+
"const parser = new ArgumentParser(); parser.parse_args()",
|
| 291 |
+
"parser.print_help()",
|
| 292 |
+
"Object.keys(require.cache).forEach(module => console.log(module))",
|
| 293 |
+
"const { exec } = require('child_process'); exec('pip install package')",
|
| 294 |
+
"const { exec } = require('child_process'); exec('pip uninstall package')",
|
| 295 |
+
"const packageVersion = require('package').version",
|
| 296 |
+
"const { exec } = require('child_process'); exec('python -m venv venv')",
|
| 297 |
+
"const { exec } = require('child_process'); exec('pip list')",
|
| 298 |
+
"const { exec } = require('child_process'); exec('pip install --upgrade package')",
|
| 299 |
+
"const db = require('sqlite3').Database('db.sqlite')",
|
| 300 |
+
"db.all('SELECT * FROM table', (err, rows) => {})",
|
| 301 |
+
"db.run('INSERT INTO table (column) VALUES (?)', ['value'])",
|
| 302 |
+
"db.run('DELETE FROM table WHERE id = ?', [1])",
|
| 303 |
+
"db.run('UPDATE table SET column = ? WHERE id = ?', ['new_value', 1])",
|
| 304 |
+
"db.all('SELECT * FROM table', (err, rows) => {})",
|
| 305 |
+
"db.run('SELECT * FROM table WHERE column = ?', ['value'], (err, row) => {})",
|
| 306 |
+
"db.close()",
|
| 307 |
+
"db.run('CREATE TABLE table (column TEXT)')",
|
| 308 |
+
"db.run('DROP TABLE table')",
|
| 309 |
+
"db.get('SELECT name FROM sqlite_master WHERE type = \"table\" AND name = ?', ['table'], (err, row) => {})",
|
| 310 |
+
"db.all('SELECT name FROM sqlite_master WHERE type = \"table\"', (err, rows) => {})",
|
| 311 |
+
"const { Model } = require('sequelize'); Model.create({ column: 'value' })",
|
| 312 |
+
"Model.findAll({ where: { column: 'value' } })",
|
| 313 |
+
"Model.destroy({ where: { id: 1 } })",
|
| 314 |
+
"Model.update({ column: 'new_value' }, { where: { id: 1 } })",
|
| 315 |
+
"class Table extends Model {}",
|
| 316 |
+
"class ChildTable extends ParentTable {}",
|
| 317 |
+
"Model.init({ id: { type: DataTypes.INTEGER, primaryKey: true } }, { sequelize })",
|
| 318 |
+
"Model.init({ column: { type: DataTypes.STRING, unique: true } }, { sequelize })",
|
| 319 |
+
"Model.init({ column: { type: DataTypes.STRING, defaultValue: 'default' } }, { sequelize })",
|
| 320 |
+
"const csv = require('csv-parser'); fs.createReadStream('data.csv').pipe(csv())",
|
| 321 |
+
"const xlsx = require('xlsx'); xlsx.writeFile(data, 'data.xlsx')",
|
| 322 |
+
"const json = JSON.stringify(data)",
|
| 323 |
+
"const workbook = xlsx.readFile('data.xlsx')",
|
| 324 |
+
"const mergedWorkbook = xlsx.utils.book_append_sheet(workbook1, workbook2)",
|
| 325 |
+
"xlsx.utils.book_append_sheet(workbook, worksheet, 'New Sheet')",
|
| 326 |
+
"const style = workbook.Sheets['Sheet1']['A1'].s",
|
| 327 |
+
"const color = workbook.Sheets['Sheet1']['A1'].s.fill.fgColor",
|
| 328 |
+
"const font = workbook.Sheets['Sheet1']['A1'].s.font",
|
| 329 |
+
"const cellValue = workbook.Sheets['Sheet1']['A1'].v",
|
| 330 |
+
"workbook.Sheets['Sheet1']['A1'].v = 'New Value'",
|
| 331 |
+
"const { width, height } = require('image-size')('image.png')",
|
| 332 |
+
"const sharp = require('sharp'); sharp('image.png').resize(200, 200)"
|
|
|
|
|
|
|
| 333 |
|
| 334 |
|
| 335 |
|