Skip to content

Instantly share code, notes, and snippets.

View ObsidianCat's full-sized avatar

Lula Leus ObsidianCat

View GitHub Profile
@ObsidianCat
ObsidianCat / algo-number-to-digits-conversions.js
Last active May 12, 2020 20:13
Can be used as foundation for algo questions which ask to split number into digits and manipulate it in some way afterward
// Can be used as foundation for algo questions which ask to split number into digits and manipulate it in some way afterward
function numberToSumOfDigits(num) {
let totalSum = 0;
while(num > 0){
const digit = num %10
num = Math.floor(num/10);
totalSum += digit
}
return totalSum
@ObsidianCat
ObsidianCat / algo-roman-numbers.js
Created May 19, 2020 17:21
2 algorithms - Conversion of roman number to integer and integer to roman number
/**
* @param {string} s
* @return {number}
*/
var romanToInt = function(s) {
let result = 0
const conversion = {
"I": 1,
"V": 5,
"X": 10,
@ObsidianCat
ObsidianCat / algo-binary-tree-traversion.js
Created May 30, 2020 10:26
Building and traversing of binary tree
// Node definition
function TreeNode(val) {
this.val = val;
this.left = this.right = null;
}
// Assemle a tree
const left = new TreeNode(2)
const right = new TreeNode(2)
const rightRight = new TreeNode(3)
@ObsidianCat
ObsidianCat / apollo-federation-directives.graph
Created April 10, 2021 11:15
Apollo federation directives
type Review {
body: String
author: User @provides(fields: "username")
product: Product
}
extend type User @key(fields: "id") {
id: ID! @external
reviews: [Review]
}
@ObsidianCat
ObsidianCat / pathfinding.js
Last active May 30, 2021 10:07
Pathfinding - useful for exercises like "floating islands" or finding path in a maze.
// Code source https://btholt.github.io/four-semesters-of-cs-part-two/pathfinding
const NO_ONE = 0;
const BY_A = 1;
const BY_B = 2;
const processSearchIteration = ()=>{
const aNeighbors = aQueue.reduce((acc, neighbor)=>{
return acc.concat(getNeighbors(visited, neighbor.x, neighbor.y))
}, [])
@ObsidianCat
ObsidianCat / tries.js
Created June 7, 2021 20:28
Basic auto-completion functionality with trie data structure
// Code originnaly belong to Front End Masters course
// 4 Semesters of CS in 5 Hours part II
//https://btholt.github.io/four-semesters-of-cs-part-two/
const CITY_NAMES = [
"New York",
"Los Angeles",
"Chicago",
"Houston",
"Philadelphia",
package doughnuts_box
import (
"fmt"
)
type doughnutsBox struct {
capacity int
doughnuts []string
}
package doughnuts_box
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPackDoughnutsBoxTableTests(t *testing.T) {
package doughnuts_box
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPackDoughnutsBoxSubtests(t *testing.T) {
@ObsidianCat
ObsidianCat / go-pointers.go
Last active July 15, 2023 10:22
Different meaning of * Sign in Go, based on situation
package main
import "fmt"
type person struct {
name string
}
// the * denotes(indicate) a pointer to a value of the type that follows the *
// *person the func return pointer