Skip to content

Commit dcae0b9

Browse files
Hail atom
1 parent 503a1e2 commit dcae0b9

File tree

10 files changed

+160
-51
lines changed

10 files changed

+160
-51
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ todo.txt
55
main.py
66
rough.js
77
rough2.js
8+
rough3.js

lib/config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ export default {
1616
default: 31,
1717
enum: [
1818
{ value: 43, description: 'GNU GCC C11 5.1.0' },
19-
{ value: 61, description: 'GNU G++17 9.2.0 (64 bit, msys 2)' },
2019
{ value: 54, description: 'GNU G++17 7.3.0' },
2120
{ value: 31, description: 'Python 3.7.2' },
22-
{ value: 41, description: 'PyPy 3.6 (7.2.0)' },
23-
{ value: 34, description: 'JavaScript V8 4.8.0' },
24-
{ value: 55, description: 'Node.js 9.4.0' }
21+
{ value: 41, description: 'PyPy 3.6 (7.2.0)' }
2522
]
2623
},
2724

lib/view/actions.js

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,89 @@ const Actions = ({prob,tests})=>{
1616
// console.log(ele.target.nextElementSibling);
1717
}
1818

19+
const runexamples = ()=>{
20+
const path = require('path');
21+
var langcode = atom.config.get("codeblue.programmingLanguage")
22+
var ext = ""
23+
if(langcode==43) ext=".c"
24+
else if(langcode==54) ext=".cpp"
25+
else ext=".py"
26+
var wd = atom.config.get("codeblue.workingDirectory")
27+
var towhere = path.join(wd,prob.index)
28+
var torun = path.join(towhere,prob.index+ext)
29+
var inputfile = path.join(towhere,"examples/input1.in")
30+
31+
cmd = "python "+ torun +" < " + inputfile
32+
33+
const { exec } = require('child_process');
34+
exec(cmd,{
35+
timeout: 2500,
36+
maxBuffer: 1024*32,
37+
} ,function (error, stdout, stderr) {
38+
var res = {error: false, verdict: "none"}
39+
res.stdout = stdout
40+
if(error !== null){
41+
res.error = true
42+
if(error.killed){
43+
res.verdict = "TIME_LIMIT_EXCEEDED"
44+
}else if(error.code=="ERR_CHILD_PROCESS_STDIO_MAXBUFFER"){
45+
res.verdict = "MEMORY_LIMIT_EXCEEDED"
46+
}else{
47+
res.verdict = "RUNTIME_ERROR"
48+
}
49+
res.stderr = stderr
50+
}
51+
console.log(res);
52+
})
53+
54+
55+
}
56+
57+
const togglesubmit = (ele)=>{
58+
var parent = ele.target.parentElement
59+
for (var i = 1; i < parent.children.length; i++) {
60+
var child = parent.children[i]
61+
var val = child.style.display
62+
if(val=="block"){
63+
child.style.display = "none";
64+
}else{
65+
child.style.display = "block";
66+
}
67+
}
68+
}
69+
1970
return (
2071
<div className="actions">
2172
<h2 className="title titlename">{prob.index} - {prob.name}</h2>
2273
<div className="tasks">
2374
<div className="task">
2475
<div className="up">
2576
<span onClick={change} className="icon icon-chevron-right">Examples</span>
26-
<button className="actionbutton">Run all</button>
77+
<button className="actionbutton" onClick={runexamples}>Run all</button>
2778
</div>
2879
<div className="down">
2980
{tests && tests.map(test=>{
30-
return <div className="verdict"> <span>example {test.n+1}</span> <i className="icon-check"></i> </div>
81+
return <div className="verdict"> <span>example {test.n+1}</span> <i className={"icon-"+test.icon}></i> </div>
3182
})}
3283
</div>
3384
</div>
85+
<div className="task">
86+
<div className="up">
87+
<span className="icon icon-light-bulb">Submissions</span>
88+
<button onClick={togglesubmit} className="actionbutton" style={{display: "block"}}>Submit</button>
89+
<button onClick={togglesubmit} className="actionbutton realsubmit" style={{display: "none"}}>Submit</button>
90+
<button onClick={togglesubmit} className="actionbutton cancel" style={{display: "none"}}>Cancel</button>
91+
</div>
92+
</div>
3493
</div>
3594
</div>
3695
)
3796
}
3897

3998
export default Actions;
4099

41-
// check
42-
// x
43-
// clock
44-
// alert
100+
// var langcode = atom.config.get("codeblue.programmingLanguage")
101+
// var ext = ""
102+
// if(langcode==43) ext=".c"
103+
// else if(langcode==54) ext=".cpp"
104+
// else ext=".py"

lib/view/index.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ import Problems from './problems';
55
import config from '../config'
66
import cheerio from 'cheerio'
77

8-
function exec(cmd, handler = function(error, stdout, stderr){
9-
console.log(stdout);
10-
if(error !== null){
11-
console.log(stderr)}
12-
}){
13-
const childfork = require('child_process');
14-
return childfork.exec(cmd, handler);
15-
}
16-
178
function couple(x) {
189
if(x<10){
1910
return "0"+x
@@ -87,18 +78,6 @@ export default class Root extends React.PureComponent {
8778
},1000)
8879
}
8980

90-
pathfinder(){
91-
92-
// var editor = atom.workspace.getActiveTextEditor();
93-
// if(editor){
94-
// var file = editor.buffer.file
95-
// if(file){
96-
// var filepath = file.path
97-
// exec("python "+filepath);
98-
// }
99-
// }
100-
}
101-
10281
Timer({sec}){
10382
return(
10483
<div className="timer">

lib/view/problems.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class Problems extends React.PureComponent {
1111
constructor(props){
1212
super(props);
1313
this.state = {
14-
curr: 1,
14+
curr: 0,
1515
mystanding: -1,
1616
probs: [],
1717
noftests: [],
@@ -61,19 +61,20 @@ export default class Problems extends React.PureComponent {
6161
}
6262
const setup = require('./setup');
6363
var wd = atom.config.get("codeblue.workingDirectory")
64-
wd = wd.split("\\")
65-
wd = wd.join("/")
66-
if(wd.substring(-1)!="/"){
67-
wd+="/"
68-
}
6964

7065
var i = 0
7166
console.log("Setup initiated");
67+
var langcode = atom.config.get("codeblue.programmingLanguage")
68+
var ext = ""
69+
if(langcode==43) ext=".c"
70+
else if(langcode==54) ext=".cpp"
71+
else ext=".py"
72+
7273
for (var prob of this.state.probs) {
7374
setup(wd, {
7475
alpha: prob.index,
7576
tot: this.state.noftests[i]} ,
76-
".py",
77+
ext,
7778
this.state.allinputs[prob.index],
7879
this.state.alloutputs[prob.index])
7980
i++
@@ -99,7 +100,7 @@ export default class Problems extends React.PureComponent {
99100
outputs.push(io)
100101
}else{
101102
inputs.push(io)
102-
verdicts.push({n: Math.floor(i/2), verdict: "NONE"})
103+
verdicts.push({n: Math.floor(i/2), verdict: "NONE", icon: "none"})
103104
}
104105
}else{
105106
noftests[index] = Math.floor(i/2)
@@ -114,6 +115,7 @@ export default class Problems extends React.PureComponent {
114115
this.setState({allinputs: allinputs})
115116
this.setState({alloutputs: alloutputs})
116117
this.setState({allverdicts: allverdicts})
118+
// console.log(this.state.allverdicts);
117119
// this.createnv()
118120
}
119121

@@ -153,7 +155,7 @@ export default class Problems extends React.PureComponent {
153155
}
154156

155157
loadmystanding(){
156-
console.log("Loading my staning");
158+
console.log("Loading my standing");
157159
var url = "https://codeforces.com/api/contest.standings?contestId="+ this.props.contest.id +"&from=1&handles=" + atom.config.get("codeblue.codeforcesHandle")
158160
fetch(url)
159161
.then(res=> res.json())
@@ -248,7 +250,7 @@ export default class Problems extends React.PureComponent {
248250
}
249251

250252
fetchactions(){
251-
console.log("Loading my standing");
253+
console.log("Loading my actions");
252254
var url = "https://codeforces.com/api/contest.status?contestId="+ this.props.contest.id +"&handle="+ atom.config.get("codeblue.codeforcesHandle")
253255
fetch(url)
254256
.then(res=> res.json())

lib/view/rough.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1-
const writeFiles = require('./writeFiles');
1+
var timer = 1
2+
var d1 = new Date()
23

3-
writeFiles("C:/Users/Rohan/OneDrive/Atom/codeforces/C/examples/", 2, ["Hi", "Hi2"], ["Hello","Hello2"])
4+
function exec(cmd, handler = function(error, stdout, stderr){
5+
console.log(stdout);
6+
var d2 = new Date()
7+
console.log(d2.getTime() - d1.getTime());
8+
if(error !== null){
9+
console.log(stderr)}
10+
}){
11+
const childfork = require('child_process');
12+
return childfork.exec(cmd, handler);
13+
}
14+
15+
const path = require('path');
16+
17+
var dir = "C:/Users/Rohan/OneDrive/Atom/codeforces/A"//A.py"
18+
var pyfile = path.join(dir,"A.py")
19+
var outfile = path.join(dir,"examples/run1.out")
20+
var inputfile = path.join(dir,"examples/input1.in")
21+
22+
exec("python "+pyfile+ " < " + inputfile +" > "+outfile)

lib/view/setup.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
const fs = require('fs');
2+
const path = require('path');
23

3-
const setup = (path, prob, ext, inputs, outputs) => {
4+
const setup = (wd, prob, ext, inputs, outputs) => {
45

5-
var dir = path + prob.alpha
6-
var fl = dir + "/" + prob.alpha + ext
7-
var exp = dir + "/examples/"
6+
var dir = path.join(wd, prob.alpha)
7+
var fl = path.join(dir,prob.alpha + ext)
8+
var exp = path.join(dir,"examples")
89

910
var inputpaths = []
1011
for (var i = 1; i <= prob.tot; i++) {
11-
inputpaths.push({dir : exp + "input" + i + ".in", value: inputs[i-1]})
12+
inputpaths.push({dir : path.join(exp,"input" + i + ".in") , value: inputs[i-1]})
1213
}
1314

1415
var outputpaths = []
1516
for (var i = 1; i <= prob.tot; i++) {
16-
outputpaths.push({dir : exp + "output" + i + ".out", value: outputs[i-1]})
17+
outputpaths.push({dir : path.join(exp,"output" + i + ".out"), value: outputs[i-1]})
1718
}
1819

1920
fs.mkdir(dir, (err) => {

package-lock.json

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
"atom": ">=1.0.0 <2.0.0"
1414
},
1515
"dependencies": {
16+
"axios": "^0.19.2",
1617
"cheerio": "^1.0.0-rc.3",
1718
"child_process": "^1.0.2",
1819
"fs": "0.0.1-security",
1920
"path": "^0.12.7",
2021
"react": "^16.13.1",
2122
"react-dom": "^16.13.1",
22-
"request": "^2.88.2"
23+
"request": "^2.88.2",
24+
"tunnel": "0.0.6"
2325
}
2426
}

styles/codeblue.less

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
height: 30px;
2222
overflow: hidden;
2323
border-radius: 50%;
24-
border: 2px solid #585858;
24+
border: 1px solid #3e3e42;
2525

2626
img {
2727
position: relative;
@@ -326,6 +326,16 @@
326326
}
327327
}
328328

329+
.realsubmit{
330+
background: #188330 !important;
331+
color: #fff;
332+
}
333+
334+
.cancel{
335+
background: #a11c18 !important;
336+
color: #fff;
337+
}
338+
329339
.down {
330340
display: none;
331341
flex-direction: column;
@@ -372,6 +382,10 @@
372382
color: #b553e4;
373383
}
374384

385+
.icon-light-bulb{
386+
color: #d1a915;
387+
}
388+
375389
.action-view {
376390
display: flex;
377391
flex-direction: row;

0 commit comments

Comments
 (0)