Skip to content

Instantly share code, notes, and snippets.

@Rafe
Rafe / gist:3102414
Created July 13, 2012 02:59
AWK cheatsheet
HANDY ONE-LINE SCRIPTS FOR AWK 30 April 2008
Compiled by Eric Pement - eric [at] pement.org version 0.27
Latest version of this file (in English) is usually at:
http://www.pement.org/awk/awk1line.txt
This file will also be available in other languages:
Chinese - http://ximix.org/translation/awk1line_zh-CN.txt
USAGE:
const useGame<State>((set, get) => ({
gameState: GameState.START,
level: 1,
line: 0,
score: 0,
matrix: buildMatrix(),
currentPiece: createCurrentPiece(generatePieceType()),
nextPieceType: generatePieceType(),
gameLoop() {
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
@Rafe
Rafe / gist:960a7703ef41bfc19753
Created December 6, 2015 18:06
curl cheat sheet
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
>> 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",
const Unitialized = -1;
const Pending = 0;
const Resolved = 1;
const Rejected = 2;
function suspenseFetch(url) {
const payload = {
_status: Unitialized,
_result: () => fetch(url)
}
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
<ErrorBoundary>
<ProfileDetails resource={resource}/>
</ErrorBoundary>
pry(main)> show-doc Array#map
pry(main)> show-source Array#map
pry(main)> Pry.hooks.add_hook(:after_read, "uphook") do |text, pry|
pry(main)> puts text.upcase
pry(main)> end
pry(main)> cd <OBJECT_NAME>
pry(OBJECT_NAME)> self