This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bun | |
| /** | |
| * Minimal GPT trainer and inference in pure TypeScript (no dependencies). | |
| * TypeScript port of Andrej Karpathy's microgpt.py. | |
| * Original: https://gist.github.com/karpathy/8627fe009c40f57531cb18360106ce95 | |
| * | |
| * A GPT (Generative Pre-trained Transformer) is a neural network that learns | |
| * to predict the next token in a sequence. This script demonstrates the full | |
| * pipeline: autograd (automatic differentiation for computing gradients), | |
| * a transformer architecture, training with the Adam optimizer, and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| node -p "require('node:util').styleText(['bold', 'italic', 'red'], 'This is bold, italic, red text')" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // containers/form_container.js | |
| import Form from '../components/form_component'; | |
| export const mapStateToProps = state => ({ username: state.username }); | |
| export default connect(mapStateToProps)(Form); | |
| // components/form_component.js | |
| import PropTypes from 'prop-types'; | |
| import React from 'react'; | |
| const Form = class extends React.Component { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // utils/get_prefix.js | |
| export const getPrefix = (lang) => { | |
| if (lang === 'fr') return 'méga'; | |
| return 'mega'; | |
| }; | |
| // utils/prefix_word.js | |
| export const prefixWord = (prefixGetter, wordToPrefix) => prefixGetter() + wordToPrefix; | |
| // spec/fixtures/prefix_fixtures.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // containers/form_container.js | |
| import Form from '../components/form_component'; | |
| // The container passes a 'username' prop (type: string) to Form | |
| export const mapStateToProps = state => ({ username: state.username }); | |
| export connect(mapStateToProps)(Form); | |
| // components/form_component.js | |
| import PropTypes from 'prop-types'; | |
| import React from 'react'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // containers/form_container.js | |
| import Form from '../components/form_component'; | |
| export const mapStateToProps = state => ({ username: state.username }); | |
| export default connect(mapStateToProps)(Form); | |
| // components/form_component.js | |
| import PropTypes from 'prop-types'; | |
| import React from 'react'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // utils/get_prefix.js | |
| // Changed the return value type from string to object | |
| export const getPrefix = () => ({ en: 'mega', fr: 'méga' }); | |
| // utils/prefix_word.js | |
| export const prefixWord = (prefixGetter, wordToPrefix) => prefixGetter() + wordToPrefix; | |
| // spec/utils/get_prefix.js | |
| import getPrefix from '../../utils/get_prefix'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // utils/get_prefix.js | |
| // Changed the return value from 'mega' to 'hyper' | |
| export const getPrefix = () => 'hyper'; | |
| // utils/prefix_word.js | |
| export const prefixWord = (prefixGetter, wordToPrefix) => prefixGetter() + wordToPrefix; | |
| // spec/utils/get_prefix_spec.js | |
| import getPrefix from '../../utils/get_prefix'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // utils/get_prefix.js | |
| export const getPrefix = () => 'mega'; | |
| // utils/prefix_word.js | |
| export const prefixWord = (prefixGetter, wordToPrefix) => prefixGetter() + wordToPrefix; | |
| // spec/utils/get_prefix_spec.js | |
| import getPrefix from '../../utils/get_prefix'; | |
| describe('getPrefix()', => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| rm my-code.txt > /dev/null 2>&1 & | |
| rm -rf .git > /dev/null 2>&1 & | |
| touch my-code.txt | |
| git init | |
| git add my-code.txt |
NewerOlder