Skip to content

Instantly share code, notes, and snippets.

View berakoc's full-sized avatar

Bera berakoc

View GitHub Profile
@berakoc
berakoc / data-types.js
Created January 6, 2024 16:04
Data Types
// Primitive Data Types
const name = 'Yasemen';
const firstNumber = 3;
const isHealthy = true;
let userName;
let data = null;
// Complex Data Types
function getName() {
@berakoc
berakoc / setup.sh
Created October 22, 2023 07:36
ESLint Configs for a New Vite App
npm i -D eslint
npx eslint --init
npx install-peerdeps --dev eslint-config-airbnb
type GenericFunction<R = any> = (...args: any[]) => R;
const once = <R = any>(f: GenericFunction<R>) => {
let isRun = false, result: R;
return (...args: any[]) => {
if (!isRun) {
result = f(...args);
isRun= true;
}
@berakoc
berakoc / index.js
Created November 15, 2021 19:39
A minimal curry function for JavaScript
const curry = fn => {
let argCount = 0;
const numberOfArgs = fn.length;
if (numberOfArgs === 0) return fn;
const _magic_ = arg => {
++argCount;
fn = fn.bind(null, arg);
if (argCount === numberOfArgs) return fn();
return (arg) => _magic_(arg);
}
import React, { useRef, useEffect } from 'react'
import { onShow, OnShow } from '@solariss/react-on-show'
// Function based
function MyComponent() {
const ref = useRef(null)
useEffect(() => {
onShow(this.ref.current, () => {
console.log('Event is triggered.')
})
import React, { useRef } from 'react'
import { OnShow } from '@solariss/react-on-show'
export default function Div() {
const ref = useRef(null)
return (
<OnShow handler={() => ref.current.innerHTML = 'Now you can see me.'}>
<div ref={ref}>I am not in the screen now</div>
</OnShow>
)
import React, { useEffect, useRef } from 'react'
import { onShow } from '@solariss/react-on-show'
export default function Div() {
const ref = useRef(null)
useEffect(() => {
onShow(ref.current, () => ref.current.innerHTML = 'Now you can see me.')
}, [])
return (
<div ref={ref}>I am not in the screen now</div>
@berakoc
berakoc / Tuple.js
Last active August 23, 2020 01:44
Implementation of Tuple data type in Vanilla JS
'use strict'
const Tuple = function() {
const types = Array.prototype.slice.call(arguments, 0)
function _T() {
const generateId = () => {
let id = ''
for (let i = 0; i < 8; ++i) {
const randomChoice = Math.floor(Math.random() * 2)
if (randomChoice % 2 === 0) {
id = id.concat(Math.floor(Math.random() * 10).toString())
@berakoc
berakoc / IterableMap.js
Created August 21, 2020 20:18
An implementation of map function for iterable types
const map = (iterable, f) => {
if (Array.isArray(iterable) && !Array.prototype.get) {
Array.prototype.get = function(index) {
return this[index]
}
}
if (!iterable.push) throw new Error('Iterable does not implement push method.')
if (!iterable.get) throw new Error('Iterable does not implement get method.')
let i = 0
const length = iterable.length
@berakoc
berakoc / tasks.json
Last active August 17, 2020 10:45
A task for running Scala in VSCode (written for PowerShell)
{
"version": "2.0.0",
"tasks": [
{
"label": "clear-out",
"type": "shell",
"command": "Remove-Item -LiteralPath out -Force -Recurse; mkdir out",
"problemMatcher": []
},
{