Skip to content

Instantly share code, notes, and snippets.

View GabrielModog's full-sized avatar
🤠

Gabriel Tavares GabrielModog

🤠
View GitHub Profile
@GabrielModog
GabrielModog / getUniqueChar.js
Last active November 8, 2023 07:48
testing labels
//arr.find((char) => arr.indexOf(char) === arr.lastIndexOf(char))
function getUniqueChar(str){
aLoop:
for(let i = 0; i < str.length; i++){
for(let j = 0; j < str.length; j++){
if(i !== j && str[i] === str[j])
continue aLoop
}
return i
}
const Methods = {
scope: {},
isInteger(number){
return this.EQ(Math.floor(Number(number)), number)
},
isFloat(number){
return this.EQ(Number(number), number) && this.NEQ(number % 1, 0)
},
isBoolean(value){
return this.EQ(Boolean(value), value)
@GabrielModog
GabrielModog / svelte-watch.js
Created September 11, 2023 05:10
this is a useEffect-like for svelte
function watch(callback, deps) {
let cleanup = null
function apply() {
if (cleanup) cleanup()
cleanup = callback()
}
if (deps) {
let values = []
@GabrielModog
GabrielModog / event-emitter-test.js
Created September 10, 2023 00:33
testing event emitter
function checkIfObjectTypeof(obj){
return obj === "object"
}
class EventEmitter {
constructor(){
this.events = {}
}
on(event, listener){
interface IDepartment {
id: string
name: string
createdAt: Date
updatedAt: Date
}
interface DepartmentMethods<in out T> {
getDepartment(): T
removeDepartment(department: T): void
@GabrielModog
GabrielModog / slice-audio-samples.js
Created August 16, 2023 03:59
testing audio slicing with javascript
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const audioURL = "./sample4.wav";
let newAudio;
// load audio by url
async function loadAudio(url) {
const response = await fetch(url, {
mode: "no-cors",
@GabrielModog
GabrielModog / traffic-state-machine.js
Created July 29, 2023 03:57
traffic-state-machine.js
const machine = {
state: "GREEN",
prevState: "YELLOW",
transitions: {
RED: {
execute(){
this.changeState("YELLOW", "RED")
}
},
YELLOW: {
@GabrielModog
GabrielModog / searching-algo-samples.js
Last active May 22, 2023 00:34
searching algorithm samples
const arr = [20, 10, 5, 1, 2, 3, 4, 11, 80, 1809, 34340, 2341, 5657]
function linearSearch(list, key){
for(let i = 0; i < list.length; i++){
if(list[i] === key){
return [list[i], i]
}
}
return null
}
@GabrielModog
GabrielModog / kthSmallestElement.py
Created April 22, 2023 08:10
k-th smallest element in BST
class Node:
def __init__(self, x):
self.data = x
self.left = None
self.right = None
self.count = 0
def insert(root, x):
if root == None:
return Node(x)
let persons = [
{name: 'Peter', profession: 'teacher', age: 20, maritalStatus: 'married'},
{name: 'Michael', profession: 'teacher', age: 50, maritalStatus: 'single'},
{name: 'Peter', profession: 'teacher', age: 20, maritalStatus: 'married'},
{name: 'Anna', profession: 'scientific', age: 20, maritalStatus: 'married'},
{name: 'Rose', profession: 'scientific', age: 50, maritalStatus: 'married'},
{name: 'Anna', profession: 'scientific', age: 20, maritalStatus: 'single'},
{name: 'Anna', profession: 'politician', age: 50, maritalStatus: 'married'}
];