Skip to content

Instantly share code, notes, and snippets.

View ghaiklor's full-sized avatar

Eugene Obrezkov ghaiklor

View GitHub Profile
@ghaiklor
ghaiklor / disk-read.asm
Last active August 6, 2021 18:54
Read from hard drive implementation in Assembly
disk_read:
;; store all register values
pusha
push dx
;; prepare data for reading the disk
;; al = number of sectors to read (1 - 128)
;; ch = track/cylinder number
;; dh = head number
;; cl = sector number
@ghaiklor
ghaiklor / settings.json
Created July 31, 2021 17:42
Visual Studio Code Settings (TypeScript\Rust\Ruby\Bash)
{
"[dockerfile]": {
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
},
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
@ghaiklor
ghaiklor / cloudSettings
Last active August 6, 2020 14:04
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-08-06T14:04:38.018Z","extensionVersion":"v3.4.3"}
@ghaiklor
ghaiklor / compiler.ts
Last active May 24, 2020 12:46
Tiny compiler for mathematical expressions written in TypeScript
// Feel free to change this constant and Run the playground
// It will emit assembly into Logs tab to your right
const EXPRESSION_TO_COMPILE = "5 + 10 * 10";
// Tokens
enum TokenType { NUMBER, PLUS, MINUS, STAR, SLASH, LEFT_PAREN, RIGHT_PAREN, EOF }
interface Token { type: TokenType, value: string }
// Lexical Analysis
class Scanner {
@ghaiklor
ghaiklor / cool-tree.h
Created January 9, 2020 19:41
Semantic analysis phase for COOL language
#ifndef COOL_TREE_H
#define COOL_TREE_H
//////////////////////////////////////////////////////////
//
// file: cool-tree.h
//
// This file defines classes for each phylum and constructor
//
//////////////////////////////////////////////////////////
@ghaiklor
ghaiklor / cool.y
Created December 23, 2019 20:36
Bison parser definition for the COOL language
/*
* cool.y
* Parser definition for the COOL language.
*
*/
%{
#include <iostream>
#include "cool-tree.h"
#include "stringtab.h"
#include "utilities.h"
@ghaiklor
ghaiklor / cool.flex
Created December 16, 2019 19:22
Flex specification for COOL language
%{
#include <cool-parse.h>
#include <stringtab.h>
#include <utilities.h>
#include <string.h>
#define yylval cool_yylval
#define yylex cool_yylex
#define MAX_STR_CONST 1025
#define YY_NO_UNPUT /* keep g++ happy */
@ghaiklor
ghaiklor / nodejs-binding-method.cc
Last active October 13, 2019 13:28
NodeJS method that returns JavaScript object from bindings
static void Binding(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Local<String> module = args[0]->ToString(env->isolate());
node::Utf8Value module_v(env->isolate(), module);
Local<Object> cache = env->binding_cache_object();
Local<Object> exports;
if (cache->Has(module)) {
@ghaiklor
ghaiklor / v8-templates-example.cc
Last active October 12, 2019 11:27
Simple example how V8 Function\Object Templates can be used
// Create a template for the global object and set the built-in global functions
Local<ObjectTemplate> global = ObjectTemplate::New(isolate);
global->Set(
String::NewFromUtf8(isolate, "log"),
FunctionTemplate::New(isolate, LogCallback)
);
// Each processor gets its own context so different processors do not affect each other
Persistent<Context> context = Context::New(isolate, NULL, global);
@ghaiklor
ghaiklor / output.txt
Created July 30, 2019 14:48
Wix Technical Task (Jul 2019)
$ tsc --target es6 --module commonjs wix.ts && node wix.js
---serialize---
13,A,9,12;9,B,5,8;5,C,0,4;0,0,0,0;4,E,1,2;1,0,0,0;2,0,0,0;8,P,5,6;5,0,0,0;6,0,0,0;12,G,9,10;9,0,0,0;10,0,0,0
---deserialize---
BinaryTree {
root: BinaryNode {
value: 'A',
left: BinaryNode { value: 'B', left: [BinaryNode], right: [BinaryNode] },
right: BinaryNode { value: 'G', left: null, right: null }