Skip to content

Instantly share code, notes, and snippets.

View gist:e178d8534f35a707e33868183b134616
const useGame<State>((set, get) => ({
gameState: GameState.START,
level: 1,
line: 0,
score: 0,
matrix: buildMatrix(),
currentPiece: createCurrentPiece(generatePieceType()),
nextPieceType: generatePieceType(),
gameLoop() {
View gist:4474269c1848b9907a677e388a934b53
A game has 7 types of Tetrimino: I, L, J, Z, S, O, T.
 show board that contains 20 * 10 Blocks.
 show the current moving piece that is controlled by the player.
 show the future position where the current piece will drop
 show the next piece, and the piece that is held
 show the score, level, and line
when the game state is GAME_OVER or PAUSE
 press enter to start the game
when the game state is START
 for every tick (0.8 - (level - 1) * 0.007) ** (level - 1) second
View execute.rb
class GraphQL::Execution::Interpreter::Runtime
def run_eager
# retrieve query root intormation
root_operation = query.selected_operation
root_op_type = root_operation.operation_type || "query"
root_type = schema.root_type_for_operation(root_op_type)
selection_response = GraphQLResultHash.new(nil, nil)
# create instance of type object, the #authorized_new method checks
View gist:f3addf1bb0a041329ecd947f0f5c347c
>> GraphQL.parse(query)
=> # <GraphQL::Language::Nodes::Document:0x00007fcd9c4dea10
@definitions=
[#<GraphQL::Language::Nodes::OperationDefinition:0x00007fcd9c4deb28
@operation_type="query",
@selections=
[#<GraphQL::Language::Nodes::Field:0x00007fcd9c4dec68
@arguments=
[#<GraphQL::Language::Nodes::Argument:0x00007fcd9c4df870
@name="id",
View SuspenseFetch.js
const Unitialized = -1;
const Pending = 0;
const Resolved = 1;
const Rejected = 2;
function suspenseFetch(url) {
const payload = {
_status: Unitialized,
_result: () => fetch(url)
}
View React.lazy
const Unitialized = -1;
const Pending = 0;
const Resolved = 1;
const Rejected = 2;
function lazy(ctor) {
// hold component state in closure
const payload = {
_status: Unitialized,
_result: ctor
@Rafe
Rafe / ErrorBoundary.js
Created January 12, 2021 13:22
React Suspense and Error Boundary
View ErrorBoundary.js
<ErrorBoundary>
<ProfileDetails resource={resource}/>
</ErrorBoundary>
@Rafe
Rafe / origin.rb
Created October 26, 2020 04:08
Polly want a message
View origin.rb
class Listing
attr_reader :filename, :line_numbers, :left_just, :repository, :tag, :git_cmd
def initialize(filename:, line_numbers: nil, left_just: nil, repository: nil, tag: nil, git_cmd: nil)
@filename = filename
@line_numbers = line_numbers
@repository = repository
@left_just = left_just
@tag = tag
@git_cmd = git_cmd
View poodr_chap6_composition.rb
class Bicycle
attr_reader :size, :chain, :tire_size
def initialize(args = {})
@size = args[:size]
@chain = args[:chain]
@tire_size = args[:tire_size]
end
def self.default_chain
View Maybe.rb
class Maybe
def initialize(val)
@val = val
end
def fmap
return self if @val.nil?
self.class.new(yield @val)
end