Sources for my blog post about terminal–based game
This file contains 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
import Control.Applicative hiding (many) | |
import Data.Char (toLower, isAlphaNum) | |
import Data.Either (isRight) | |
import Data.List (isPrefixOf) | |
data Parser a = Parser { parse :: String -> Either String (String, a) } | |
satisfy :: (Char -> Bool) -> Parser Char | |
satisfy pr = Parser f where | |
f "" = Left "unexpected end of input" |
Snippets for the article about natural language programming with Ruby
How to run examples:
- Run $ createdb nplusonedb to create DB
- Run specs $ rspec demo.rb
This file contains 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
ActiveRecord::Migration.remove_foreign_key(:current_table, :foreign_table) # no lock | |
ActiveRecord::Migration.add_column(:current_table, :column_bigint, :bigint) # no lock | |
copy_data = lambda do | |
CurrentTable.where(column_bigint: nil).where.not(column: nil).in_batches do |batch| | |
batch.update_all("column_bigint = column") | |
end | |
end |
This file contains 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
class GraphqlController < ApplicationController | |
include EnsureHash | |
def execute | |
result = GraphqlSchema.execute( | |
params[:query], | |
variables: ensure_hash(params[:variables]), | |
context: context, | |
operation_name: params[:operationName], | |
) |
How to run examples:
- Run
$ createdb railstestdb
to create DB - Run examples with Ruby
$ ruby demo.rb
This file contains 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
require "bundler/inline" | |
gemfile do | |
source "https://rubygems.org" | |
gem "graphql" | |
end | |
class BaseObject < GraphQL::Schema::Object | |
end |
NewerOlder