</>liveDevDocs
Snippet'ler

Snippet'ler

Projeden projeye taşıdığım küçük, dile özgü hazır parçalar.

Tek başına bir sayfayı hak etmeyen ama sürekli aradığım küçük parçalar.

Lua — tablo kopyala (deep copy)

local function deepcopy(orig)
    if type(orig) ~= 'table' then return orig end
    local copy = {}
    for k, v in pairs(orig) do
        copy[deepcopy(k)] = deepcopy(v)
    end
    return copy
end

Lua — para formatı

local function money(n)
    local formatted = tostring(n)
    while true do
        local k
        formatted, k = formatted:gsub('^(-?%d+)(%d%d%d)', '%1.%2')
        if k == 0 then break end
    end
    return '$' .. formatted
end

TS — para formatı (TRY)

export const formatTRY = (n: number) =>
  new Intl.NumberFormat('tr-TR', {
    style: 'currency',
    currency: 'TRY',
  }).format(n);

Bash — portu kullanan süreci öldür

# Linux / macOS
lsof -ti:3000 | xargs kill -9
# Windows PowerShell
Get-NetTCPConnection -LocalPort 3000 |
  Select-Object -Expand OwningProcess |
  ForEach-Object { Stop-Process -Id $_ -Force }

Regex — plaka / e-posta

const plate = /^[0-9]{2}[A-Z]{1,3}[0-9]{2,4}$/; // TR plaka (kabaca)
const email = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

On this page