Skip to content

Instantly share code, notes, and snippets.

@karpathy
karpathy / microgpt.py
Last active February 26, 2026 07:27
microgpt
"""
The most atomic way to train and run inference for a GPT in pure, dependency-free Python.
This file is the complete algorithm.
Everything else is just efficiency.
@karpathy
"""
import os # os.path.exists
import math # math.log, math.exp
@premek
premek / mv.sh
Last active March 5, 2024 17:43
Rename files in linux / bash using mv command without typing the full name two times
# Put this function to your .bashrc file.
# Usage: mv oldfilename
# If you call mv without the second parameter it will prompt you to edit the filename on command line.
# Original mv is called when it's called with more than one argument.
# It's useful when you want to change just a few letters in a long name.
#
# Also see:
# - imv from renameutils
# - Ctrl-W Ctrl-Y Ctrl-Y (cut last word, paste, paste)

๊ฐ„๊ฒฐํ•˜๊ณ  ๋ถ€์ •ํ™•ํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์˜ ์—ญ์‚ฌ

์›๋ฌธ์—์„œ ๋ฒˆ์—ญ ๋ฐ (์žผ์„ ์ถ”๊ฐ€ํ•˜๊ธฐ ์œ„ํ•ด)์ฒจ์‚ญ.

1800

์กฐ์ œํ”„ ๋งˆ๋ฆฌ ์ž์นด๋ฅด Joseph Marie Jacquard๋Š” ์˜ค๋ฐ”๋กœํฌ ๊ธฐ๊ณ„์—(์›๋ฌธ์€ ๋ฐฉ์ง๊ธฐ๊ณ„) ์ฒœ๊ณต์นด๋“œ๋ฅผ ๋จน์—ฌ ์ตœ์ดˆ์˜ ์ดˆ-๋‹ค์ค‘์“ฐ๋ ˆ๋“œ ์ฒ˜๋ฆฌ์žฅ์น˜๋ฅผ ๊ฐœ๋ฐœํ–ˆ๋‹ค (์—ญ์ฃผ: thread์—๋Š” ๋ฐ”๋А์งˆ ์‹ค์ด๋ผ๋Š” ๋œป์ด ์žˆ๋‹ค). ์ด ๋ฐœ๋ช…ํ’ˆ์€ ๋กœ๋ด‡์ด ์ผ๊ฐ์„ ๋นผ์•—์„ ๊ฒƒ์„ ์šฐ๋ คํ•˜๋Š” ๋‹น์‹œ์˜ ๋…ธ๋™์ž์—๊ฒŒ ๊ฑฐ๋Œ€ํ•œ ๋ฐ˜๋Œ€๋ฅผ ๋ฐ›์•˜๋‹ค.

export const h=(t,p,...c)=>({t,p,c,k:p&&p.key})
export const render=(e,d,t=d.t||(d.t={}),p,r,c,m,y)=>
// arrays
e.map?e.map((e,p)=>render(e,d,t.o&&t.o[p])):
// components
e.t.call?(e.i=render((render.c=e).t(Object.assign({children:e.c},e.p),e.s=t.s||{},t=>
render(Object.assign(e.s,t)&&e,d,e)),t.i||d,t&&t.i||{}),d.t=t=e):(
// create notes
m=t.d||(e.t?document.createElement(e.t):new Text(e.p)),
// diff props

Easy Scala Publication

The following describes how you can publish artifacts for any sbt project using the GitHub Package Registry and the sbt-github-packages plugin.

Step 1: Create a GitHub Token

In your GitHub account, go to Settings > Developer settings > Personal access tokens, then click on Generate new token (or click here). Fill in some sort of meaningful name (I chose Dev) and click on the write:packages checkbox:

the new personal access token page with the above steps having been followed

@johnynek
johnynek / dotty_list.scala
Last active September 7, 2024 15:14
Implementation of linked list using dotty features (opaque type, union types, extension methods, type lambda).
// unfortunately
// opaque type Fix[F[_]] = F[Fix[F]]
// won't work (no recursion in opaque type), but this implementation is safe, but scary due to asInstanceOf
object FixImpl {
type Fix[F[_]]
inline def fix[F[_]](f: F[Fix[F]]): Fix[F] = f.asInstanceOf[Fix[F]]
inline def unfix[F[_]](f: Fix[F]): F[Fix[F]] = f.asInstanceOf[F[Fix[F]]]
}
@melvic-ybanez
melvic-ybanez / akka_http_and_cats_validation.md
Last active January 22, 2024 18:29
Request Validation with Akka-HTTP and Cats

Request Validation with Akka-HTTP and Cats

Greg Beech wrote an article on Akka HTTP Entity Validation. This post is on the same topic, except we are going to use typeclass instances, as opposed to subtyping, for form validations.

Sample Problem: User Regsitration

To start with, let us suppose that we are working on some sort of user management service using Scala/Akka. However, here we are only going to focus on the registration part, in which the client is expected to send a user data, in JSON format; and the server needs to validate them, and save the user if the validations succeed, or reject the request with all the errors detected. That said, we should keep in mind that our validations may be used through out the entire codebase, not just in the user registration endpoint.

The rules for our validation are as follows:

@lifthrasiir
lifthrasiir / daerim.md
Last active May 23, 2019 06:11
<๋Œ€๋ฆผ๋™์—์„œ ๋ณด๋‚ธ ์„œ๋ฅธ ๋ฒˆ์˜ ๋ฐค>์˜ ์›น ํ˜ธํ™˜์„ฑ ๋ฌธ์ œ์— ๋Œ€ํ•ด (2019-02-03)

์•„๋ž˜ ๋‚ด์šฉ์€ ์ง€๋‚œ 2์›” 3์ผ webmaster@sisain.co.kr์— ๋ณด๋‚ธ ๋ฉ”์ผ์„ ๊ฑฐ์˜ ๊ทธ๋Œ€๋กœ ์ „์žฌํ•œ ๊ฒƒ์ด๋‹ค. ๋‘ ๋‹ฌ ๋„˜๊ฒŒ ์‘๋‹ต์€ ์—†์—ˆ๋‹ค.

10์ผ ๋„˜๊ฒŒ ์‘๋‹ต์„ ๋ฐ›์ง€ ๋ชปํ•œ ๋’ค ๊น€๋™์ธ ๋‹ด๋‹น ๊ธฐ์ž์—๊ฒŒ ํŠธ์œ„ํ„ฐ๋กœ ์—ฐ๋ฝ์„ ์‹œ๋„ํ–ˆ์œผ๋‚˜ ์ด ๋˜ํ•œ ์‘๋‹ต๋ฐ›์ง€ ๋ชปํ–ˆ๋‹ค.

ํ•ด๋‹น ๊ธฐ์‚ฌ๋Š” ํ˜„์žฌ๋„ ์—ฌ์ „ํžˆ ํŒŒ์ด์–ดํญ์Šค์—์„œ ์ •์ƒ์ ์œผ๋กœ ํ‘œ์‹œ๋˜์ง€ ์•Š๋Š”๋‹ค. (2019-04-15)

์•ˆ๋…•ํ•˜์„ธ์š”. [<๋Œ€๋ฆผ๋™์—์„œ ๋ณด๋‚ธ ์„œ๋ฅธ ๋ฒˆ์˜ ๋ฐค>][1] ๊ธฐ์‚ฌ๋ฅผ ๋ณด๊ณ  ์‚ฌ์†Œํ•˜์ง€๋งŒ ์ค‘์š”ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ๋ฅผ ์•Œ๋ ค ๋“œ๋ฆฌ๊ณ ์ž ๊ธ€์„ ์”๋‹ˆ๋‹ค.

๋ณธ ๊ธฐ์‚ฌ๋Š” (์š”์ฆˆ์Œ์—๋Š” ๋‰ด์š•ํƒ€์ž„์ฆˆ ๋”ฐ์œ„๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์ด ์จ์„œ ์˜คํžˆ๋ ค ์‹์ƒํ•  ์ˆ˜ ์žˆ๋Š”) ์Šคํฌ๋กคํ•  ๋•Œ๋งˆ๋‹ค ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ํŠ€์–ด ๋‚˜์˜ค๋Š” ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ ํฌ๋งท์„ ์“ฐ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค๋งŒ, ํ•ด๋‹น ํฌ๋งท์ด ๊ตฌ๊ธ€ ํฌ๋กฌ์—์„œ๋งŒ ํ…Œ์ŠคํŠธ๋œ ๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค. ๋ชจ๋“  ๋ธŒ๋ผ์šฐ์ €๋ฅผ ํ…Œ์ŠคํŠธํ•˜์ง„

@outsideris
outsideris / post.md
Created January 9, 2019 09:45
terraform ๊ธ€ ๋ฌด๋‹จ ์ „์ œ ๊ด€๋ จ

์˜ค๋Š˜ ์–ด๋–ค ๋ถ„์ด(์„ฑํ•จ์„ ๋ฐํ˜€๋„ ๋˜๋Š”์ง€ ๋ชฐ๋ผ์„œ...) ์˜ค๋ผํด ํด๋ผ์šฐ๋“œ ๊ธฐ์ˆ  ๋ธ”๋กœ๊ทธ์˜ ๊ธ€์ด ์ œ๊ฐ€ ์“ด Terraform ๊ธ€์„ ๊ทธ๋Œ€๋กœ ๊ฐ€์ ธ๋‹ค๊ฐ€ ๋ฌธ์ฒด๋งŒ ๋ฐ”๊ฟ”์„œ ์˜ฌ๋ ธ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๋‹น์—ฐํžˆ ์ถœ์ฒ˜ํ‘œ๊ธฐ๋Š” ์—†์—ˆ๊ณ  ๊ธ€์˜ ๋‚ด์šฉ์„ ํ™•์ธ ๊ฒฐ๊ณผ ์ œ ๊ธ€์„ ๋ฐ”ํƒ•์œผ๋กœ ๊ตญ๋ฌธ์œผ๋กœ ์ž‘์„ฑํ•œ ์šฉ์–ด๋ฅผ ์˜๋ฌธ์œผ๋กœ ๊ต์ฒดํ•˜๊ฑฐ๋‚˜ ๋งž์ถค๋ฒ•์„ ๊ต์ •ํ•˜๊ฑฐ๋‚˜ ๋ฐ˜๋ง๋กœ ์ž‘์„ฑํ•œ ๋ฌธ์žฅ์„ ์กด๋Œ“๋ง๋กœ ๋ฐ”๊พธ๊ณ  ์ผ๋ถ€ ๋‚ด์šฉ์„ ์˜ค๋ผํด ํด๋ผ์šฐ๋“œ์— ์˜ฌ๋ ธ๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค.

์ œ ๊ธ€์˜ ๋‚ด์šฉ์ด ์ „์ฒด ๊ธ€์˜ ๋Œ€๋ถ€๋ถ„์ด๊ธฐ ๋•Œ๋ฌธ์— ์˜๋„์ ์œผ๋กœ ์ œ ๊ธ€์„ ๊ฐ€์ ธ๊ฐ€์…” ํŽธ์ง‘ ํ›„ ์ง์ ‘ ์ž‘์„ฑํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด๋„๋ก ์˜๋„ํ–ˆ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๊ณ  ์žˆ๊ณ  ์ œ ๊ธ€์ด CC BY-NC-SA 2.0 ๋ผ์ด์„ผ์Šค ํ•˜์— ๊ณต๊ฐœํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ ์ด๋Š” ๋ผ์ด์„ผ์Šค ์œ„๋ฐ˜์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•ด๋‹น ๋ธ”๋กœ๊ทธ๋Š” ์˜ค๋ผํด ํด๋ผ์šฐ๋“œ์— ๋Œ€ํ•œ ๋ธ”๋กœ๊ทธ์ด๊ณ  ๊ธ€์„ ์“ฐ์‹  "๊ฐ•์ง€์„ "๋‹˜๋„ "ํ•œ๊ตญ ์˜ค๋ผํด์˜ ํด๋ผ์šฐ๋“œ ์„ธ์ผ์ฆˆ ์ปจ์„คํŒ… ํŒ€ ์†Œ์†"์ด๋ผ๊ณ  ์จ ์žˆ๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์•„ ํ•ด๋‹น ๋ธ”๋กœ๊ทธ๋Š” ํ•œ๊ตญ ์˜ค๋ผํด์—์„œ ์šด์˜ํ•˜๋Š” ๋ธ”๋กœ๊ทธ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค.

ํ˜น์‹œ ๊ธ€์ด ๋ณ€๊ฒฝ๋˜๊ฑฐ๋‚˜ ์ง€์›Œ์งˆ ์ง€ ๋ชฐ๋ผ์„œ ์Šคํฌ๋ฆฐ์ƒท์„ ์ฒจ๋ถ€ํ•ฉ๋‹ˆ๋‹ค.