How To Quench My Thirst For CS Without A Compiler

Pages: 123
Your computer certainly contains several interpreters. The command line shell is very much worth learning. Your browser contains a production-strength Javascript interpreter.

Does anyone have a good idea of what to do without a compiler?

Go outside?
If I had a computer I’d agree with you on the CLI and I do like to f around with it too, but I need my ide for that.

You have a point with the js though, that’s true... I guess I have to actually learn js now lol.

Go outside? Um. But, like, where’s the CS in that? lol. I guess I would go outside I am kinda too much of a lazy bum XD
I’d agree with you on the CLI and I do like to f around with it too, but I need my ide for that.


Since when do you need an IDE to work with a shell?

But, like, where’s the CS in that?


To be fair, compiling software with a compiler isn't really CS either.
Last edited on
Since I don’t have a PC. iPads don’t have a straight up CLI like normal computers do.

Idk man I just kinda used it as an umbrella concept. 🤷‍♂️ It’s a lot closer than sports though lol! You have a point though I guess.
Did you look though? Because I've used Apple products for years and happen to know there are plenty of apps to let you run a shell (iSH is a particular favorite)

edit:
although I don't believe iSH uses bash though, maybe just a regular /bin/sh
Last edited on
Huh, I guess I just didn’t look hard enough.. that’s really nice to know I think I’ll store that for later, thanks! :)
sure thing. its really fun to play with, especially now that tools like ping work properly.
creative people have managed to install stripped down versions of Linux on just about anything with a chip.
Don’t mind me, just going to use this thread for the syntax highlighting, seeing as it seems dead by now....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
63
64
65
#include <functional>

template <
  class Key_t,
  class Val_t,
  size_t TableSize,
  class Hasher_t = std::hash<Key_t>,
  Hasher_t Hasher = Hasher_t{}
>
class HashMap {
  struct Node {
    unsigned long hashedKey;
    Val_t Val;
    Node *left, *right;
  };

  // 0 for less, 1 for more, 2 for equal
  int cmpHsh(Node* x, unsigned long y) {
    return ( (x->hashedKey < y) ? (0) : ( (x->hashedKey > y) ? (1) : (2) ) );
  }

  Node* m_table[TableSize];

  public:

  HashMap() = default;

  Val_t& operator[] (Key_t key) {
    unsigned long hashedKey = Hasher(key);
    Node *& it = m_table[ hashedKey % TableSize ];

    while(1) {
      if(it == nullptr) {
        c_it = new Node{ .hashedKey=hashedKey, .left=nullptr, .right=nullptr };
        return it->val;
      }
      switch(cmpHsh(it, hashedKey)) {
        case 0:
          if(it->left != nullptr) {
            it = it->left;
          }
          else { 
            it = it->left;
            it = new Node{ .hashedKey=hashedKey, .left=nullptr, .right=nullptr };
            return it->val;
          } 
        break;
        case 1:
          if(it->right != nullptr) {
            it = it->right;
          }
          else {
            it = it->right;
            it = new Node{ .hashedKey=hashedKey, .left=nullptr, .right=nullptr };
            return it->val;
          }
        break;
        case 2:
          return it->val;
        break;
      }
    }
  }

};



Wait no....
if key less than node.key, then go to the left, and if the left is null, then make a new left node or if the left is more, then insert a node between them.
of the key is more


My logic is still way off...


What am I even trying to test for? Hum..

if the current node is null, then replace it with a new node and return that.
else if my key is equal to the current node’s key, then return the current node.
else if my key is less than the current key, then move to the left link.
else if my key is more, then move to the right link.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <functional>
#include <chrono>
#include <thread>
#include <future>

void setTimeout(std::function<void(void)> cb, std::chrono::milliseconds delay) {
  std::async([&]() {
    std::this_thread::sleep_for(delay);
    cb();
  });
}

void setInterval(std::function<void(void)> cb, std::chrono::milliseconds delay) {
  std::async([&]() {
    while(1) {
      std::this_thread::sleep_for(delay);
      cb();
    }
  });
}

int main() {
  setTimout([]() -> void {
    std::cout << "ya yeet." << std::endl;
  }, 1000);

  cout.sync_with_stdio(false);
  setInterval([]() -> void {
    std::cout << "ree\n";
  }, 250);

  setInterval([]() -> void { std::cout.flush() }, 3000);
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Entity;
class World;
#define extends :public

class Npc extends Entity {
  std::function<void(World&)> sub_react;

  public:

  void react(World* world) override { sub_react(*world); }
};

class World {
  std::vector<Entity*> entities;
};



REEE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <condition_variable>
#include <mutex>
#include <thread>
#include <queue>
#include <unordered_map>
#include <functional>

template <class T>
class AtomicFIFO {
  std::queue<T> m_q;
  std::condition_variable m_q_cv;
  std::mutex m_q_lck;
  public:

  void wait(void) {
    m_q_cv.wait(m_q_lck); 
  }

  T get(void) {
    m_q_cv.wait(m_q_lck);
    if(!m_q.empty());
    T x = m_q.back();
    m_q.pop();
    return T; 
  }

  void put(T x) {
    m_q_cv.wait(m_q_lck);
    m_q.push(x); 
  } 
};


class EventMachine {
  public:

  class Event {
    std::istringstream m_info;
    std::string m_id;
    public:
    Event(const std::string& id,const std::string& info): m_id(id), m_info(info) {}
    std::string what() { return m_id; }
    std::istringstream& more() { return m_info; }
  };

  EventMachine() {
    if(m_event_handlers.empty()) {
      m_checking = true;
      for(int i = 0;i < 10;i++)
        m_event_handlers.push_back(std::thread([this](){
          while(this->m_checking) {
            Event* e = this->m_event_q.get();
            if(this->m_event_handles.find(e.what()) != this->m_eventHandles.end())
              for(auto& handle : this->m_event_handles[e.what()]) 
                handle(e);
            delete e;
          }
        }));
    } 
  }

  void fire_event(Event* e) {
    m_event_queue.put(e);
  }

  void addHandler(std::string id, std::function<void(Event*)> callback) {
    m_event_handles[id].push_back(callback);
  }

  private:

  static AtomicFIFO<Event*> m_event_q;

  static std::unordered_map
       <
       std::string,
       std::vector<std::function<void(Event*)>>
       > m_event_handles;

  static std::vector<std::thread> m_event_handlers;

  static bool m_checking;
};


Humumumumum
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Semaphore {
  int* m_data;
  public:
  Semaphore(void) { m_data = new int{0}; }

  void wait(void) { // lock
    start:
    while(*m_data);
    *m_data++;
    if(*m_data > 1) {
      *m_data--;
      goto start;
    }
  }

  void signal(void) { // unlock
    *m_data--;
  }

  int* get_data(void) { return m_data; }

  Semaphore(const Semaphore& s) { m_data = s.get_data(); }

  Semaphore& operator= (Semaphore s) {
    if(m_data) delete m_data;
    m_data = s.get_data();
    return *this;
  }

  ~Semaphore(void){ delete m_data; }
};



HUMUMUMHERRRRRRMMMMGAHHHH
1
2
3
4
5
6
7
8
9
10
11
template <class T>
class _ {
  volatile T m_data;
  Semaphore m_lck;
  public:
  _(...): m_data(...), m_lck() {}

  const volatile T& get() { return std::move(m_data); }

  const volatile T& set(T& x) { return std::move((m_data = x)); }
};


GGGRRRAAAAAHHHHHHH!!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <cstdarg>
#include <string>

void mprintf(char* mmem, const char * fmt, ...) {
  std::string s;
  s.reserve(strlen(fmt));
  va_list vals;
  va_start(vals);
  for(char * it = &fmt[0];it;it++) {
    if(*it == '%') {
      switch(*it) {
        case '%':
          s += '%';
        break;
        case 'c':
          s += (va_arg(vals, char));
        break;
        case 'd':
          s += std::to_string( (va_arg(vals, int)) );
        break;
        case 'f':
          s += std::to_string( (va_arg(vals, float) );
        break;
        case 's':
          s += (va_arg(vals, const char *));
        break;
      }
    }
    else {
      s += *it;
    }
  }
  write(mmem, s.data(), s.length());
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <cstddef>

class Mutex {
  uint8_t m_switch;
  public:

  Mutex() { m_switch = 0; }

  Mutex(const Mutex&) = delete;

  Mutex(Mutex&&) = delete;

  void unlock() {
    m_switch--;
  }

  void lock() {
    while(1) {
      while(m_switch);
      m_switch++;
      if(m_switch > 1)
        m_switch--;
      else
        return;
    }
  }
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "EventMachine.hpp"

EventMachine G_Events{};

std::vector<int> G_Conns;

struct SocketEvent :public EventMachine::basic_event {
  int conn;
  public:
  
};

std::thread socket_event_generator([&G_Conns]{
  bool something_to_read = false;
  while(1) {
    // select G_Conns....
    if(something_to_read) {
      G_Events.fire(new SocketEvent(
    }
  }
});
Last edited on
Don’t mind me, just making another post for space.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <resolv.h>
#include <sys/epoll.h>
#include <arpa/inet.h>
#include <unistd.h>

#define PORT 22
#define SERVER "127.0.0.1"
#define MAXBUF 1024
#define MAX_EPOLL_EVENTS 64

int main() {
    int sockfd;
    struct sockaddr_in dest;
    char buffer[MAXBUF];
    struct epoll_event events[MAX_EPOLL_EVENTS];
    int i, num_ready;

    /*---Open socket for streaming---*/
    if ( (sockfd = socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0)) < 0 ) {
        perror("Socket");
        exit(errno);
    }

    /*---Add socket to epoll---*/
    int epfd = epoll_create(1);
    struct epoll_event event;
    event.events = EPOLLIN; // Cann append "|EPOLLOUT" for write events as well
    event.data.fd = sockfd;
    epoll_ctl(epfd, EPOLL_CTL_ADD, sockfd, &event);

    /*---Initialize server address/port struct---*/
    bzero(&dest, sizeof(dest));
    dest.sin_family = AF_INET;
    dest.sin_port = htons(PORT);
    if ( inet_pton(AF_INET, SERVER, &dest.sin_addr.s_addr) == 0 ) {
        perror(SERVER);
        exit(errno);
    }

    /*---Connect to server---*/
    if ( connect(sockfd, (struct sockaddr*)&dest, sizeof(dest)) != 0 ) {
        if(errno != EINPROGRESS) {
            perror("Connect ");
            exit(errno);
        }
    }

    /*---Wait for socket connect to complete---*/
    num_ready = epoll_wait(epfd, events, MAX_EPOLL_EVENTS, 1000/*timeout*/);
    for(i = 0; i < num_ready; i++) {
        if(events[i].events & EPOLLIN) {
            printf("Socket %d connected\n", events[i].data.fd);
        }
    }

    /*---Wait for data---*/
    num_ready = epoll_wait(epfd, events, MAX_EPOLL_EVENTS, 1000/*timeout*/);
    for(i = 0; i < num_ready; i++) {
        if(events[i].events & EPOLLIN) {
            printf("Socket %d got some data\n", events[i].data.fd);
            bzero(buffer, MAXBUF);
            recv(sockfd, buffer, sizeof(buffer), 0);
            printf("Received: %s", buffer);
        }
    }

    close(sockfd);
    return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// ... 
class EventMachine {
  public:

  class basic_event {
    public:
    virtual std::string what(void) = 0;
  };

  class Event :public basic_event {
    std::istringstream m_info;
    std::string m_id;
    public:
    Event(const std::string& id,const std::string& info): m_id(id), m_info(info) {}
    std::string what(void) override { return m_id; }
    std::istringstream& more() { return m_info; }
  };

  EventMachine() {
    if(m_event_handlers.empty()) {
      m_checking = true;
      for(int i = 0;i < 10;i++)
        m_event_handlers.push_back(std::thread([&](){
          while(m_checking) {
            basic_event* e = m_event_q.get();
            if(m_event_handles.find(e.what()) != m_eventHandles.end())
              for(auto& handle : m_event_handles[e.what()]) 
                handle(e);
            delete e;
          }
        }));
    } 
  }

  void fire_event(basic_event* e) {
    m_event_queue.put(e);
  }

  void addHandler(std::string id, std::function<void(basic_event*)> callback) {
    m_event_handles[id].push_back(callback);
  }

  private:

  static AtomicFIFO<basic_event*> m_event_q;

  static std::unordered_map
       <
       std::string,
       std::vector<std::function<void(basic_event*)>>
       > m_event_handles;

  static std::vector<std::thread> m_event_handlers;

  static bool m_checking;
};
Last edited on
What's the point of this?
What’s the point of what? There’s like 5 different things there lol.

Edit: actually 10 different things
Last edited on
Posting all this crap here.
I... just... like... perty... colors?


Edit: oo 512! Yay!


data:text/html;base8,
<html>
<head>
<title>Code Editor</title>
<style>
body{
  background:#111;
}
.scroll{
  overflow-x:auto;
  overflow-y:auto;
  white-space:nowrap;
}
#code-editor{
  margin:auto;
  margin-top:3%;
  width:90%;
  height:90%;
  color:#EEE;
  background:#000;
  font-family:monospace,monospace;
  font-size:20;
  padding:3px;
  display:block;
}
.code-comment{
  color:#0F0;
}
.code-keyword{
  color:#FA0;
}
.code-number{
  color:#FD0;
}
</style>
</head>
<body>
<form>
<textarea class="scroll"id="code-editor"contenteditable="true">#include &lt;iostream&gt;
<br/>int main(int argc,char *argv[]) {
<br>&nbsp;&nbsp;return 0;
<br>}
</textarea>
</form>
<script>
const editor = document.getElementById("code-editor");

function mktick(func) {
  function newFunc() {
    func();
    requestAnimationFrame(newFunc);
  };
  return newFunc;
}

function lint() {
  const exprs = 
  [
    [
      "/\\*(.*)\\*/" ,
      "<span class=\"code-comment\">/*$1*/</span>"
    ],
    [
      "//(.*)" ,
      "<span class="code-comment">//$1</span>"
    ],
    [
      "([\w\(\);\{\}\*/\+-%\=\!:\?&\|\^ ,])(\d+)([\w\(\);\{\}\*/\+-%\=\!:\?&\|\^ ,])" ,
      "$1<span class="code-number">$2</span>$3"
    ],
    [
      "([\\w\\(\\);\\{\\}\\*/\\+-%\\=\\!:\\?&\\|\\^,])(asm|break|case|catch|continue|default|do|else|explicit|extern|for|friend|goto|if|mutable|namespace|private|protected|public|static_assert|struct|switch|this|thread_local|try|typedef|typeid|typename|union|using|virtual|while|template|class|decltype|void|char|char16_t|char32_t|short|signed|int|unsigned|long|float|double|const|volatile|bool|true|false|typename|operator|new|alignof|enum|sizeof|static_cast|nullptr|auto|throw|dynamic_cast|reinterpret_cast|const_cast|alignas|constexpr|inline|static|noexcept|delete)([\\w\\(\\);\\{\\}\\*/\\+-%\\=\\!:\\?&\\|\\^,])" ,
      "$1<span class="code-keyword">$2</span>$3"
    ],
    [
      " ",
      "&nbsp;"
    ]
  ];
  const editor = document.getElementById("code-editor");

  var tmp = editor.innerText;
  for(let it of exprs) {
    tmp = tmp.replace(new RegExp(it[0]), it[1]);
  }
  editor.innerHTML = tmp;
}

mktick(lint)();
</script>
</body>
</html>
Last edited on
So do I, but I don't eat a bunch of glitter and go smear my feces all over your house. Please find some other way to do what it is you're trying to do.
I am it’s just taking time... I’m trying to make a syntax highlighter but it’s taking a while, and besides, if you don’t want to look at it, then don’t. I’ve tried to keep it as unobtrusive as possible. It’s an old, dead, post. If I wanted to shove it in someone’s face I would have posted somewhere else.
Last edited on
It's not dead, because you're undeadifying it. If you want to experiment with syntax-highlighted stuff, use an online compilation website (like coliru, godbolt, etc.), or just make gists in Github or something. As it is, everyone who wants to look at the lounge will always see this right up the top.
No, they will not, because for literally every 8000 characters of code I’ll be editing the same post, which doesn’t shunt it to the top or label it as new. Also, this thing hasn’t been at the top for over a week, and I’ve been coding here that entire time. Basing off that, and si c’è ya’ll just made me make like 6 new posts, you aren’t going to see this up top for a good month! Don’t worry, if I knew that editing posts would send me to the top, I wouldn’t have done it. Just ignore my occasional, probably monthly, post. And besides, I don’t think it’s gonna take a month to make a syntax highlighter. Also, if you want to comment, first read the entire thread.
Last edited on
Pages: 123