Skip to content

Instantly share code, notes, and snippets.

Avatar

Douglas Teoh dteoh

View GitHub Profile
@dteoh
dteoh / albedo_vs_mona_crafting_talent.md
Last active Dec 26, 2020
Genshin Impact: Albedo vs Mona crafting talent, who is better?
View albedo_vs_mona_crafting_talent.md

Genshin Impact: Albedo vs Mona crafting talent, who is better?

In Genshin Impact, you can craft materials of a given rank from three materials of the rank just below, eg. you can craft one gold book from three blue books.

Albedo has a talent where crafting a weapon ascension material has a 10% chance of giving double the output. Mona has a talent where crafting a weapon ascension material has a 25% chance of refunding a portion of the input materials.

@dteoh
dteoh / rspec_rails_set_session.md
Created May 29, 2020
Setting session variables in an RSpec Rails request spec
View rspec_rails_set_session.md

Setting session variables in an RSpec Rails request spec

You are writing a spec with type: :request, i.e. an integration spec instead of a controller spec. Integration specs are wrappers around Rails' ActionDispatch::IntegrationTest class. I usually write controller tests using this instead of type: :controller, mainly because it exercises more of the request and response handling stack. So instead of writing something like get :index to start the request, you would write get books_path or similar.

One of the issues with using type: :request is that you lose the ability to

@dteoh
dteoh / mysql2-gem-install.md
Created Nov 22, 2019
Installing mysql2 gem
View mysql2-gem-install.md

Installing mysql2 gem

This is always an annoying process, especially when you are setting up a new computer. I assume you are using macOS + homebrew. I also assume that you want to run an older version of MySQL (although the instructions should be adaptable).

Installing MySQL

$ brew install mysql@5.7 # change the version if needed
@dteoh
dteoh / dictionary.md
Created Oct 23, 2019
Display dictionary definition on macOS
View dictionary.md
  1. Move mouse cursor to point at a word
  2. Press Command + Ctrl + D
@dteoh
dteoh / custom_ar_relation_relay_connection.rb
Last active Oct 28, 2019
GrapQL Ruby: Custom Relay connection class for ActiveRecord::Relation objects
View custom_ar_relation_relay_connection.rb
# This custom relay connection class exists because the built-in connection
# class is broken when max_page_size is used.
#
# See: https://github.com/rmosolgo/graphql-ruby/issues/1109
class CustomArRelationRelayConnection < GraphQL::Relay::BaseConnection
def cursor_from_node(item)
cursor_col = item.class.implicit_order_column
encode(item.send(cursor_col).to_s)
end
@dteoh
dteoh / cors-curl.md
Created Sep 26, 2019
Check CORS headers with `curl`
View cors-curl.md
$ curl -X OPTIONS -H “Origin: REQUESTER-DOMAIN.com” -H “Access-Control-Request-Method: GET“ -s -v <TARGET URL HERE> 1> /dev/null
@dteoh
dteoh / neovim_python.md
Last active Nov 13, 2020
NeoVim + Python 3 provider
View neovim_python.md

Assuming that [Conda][1] is used, start by creating an environment for NeoVim:

$ conda create -n neovim36 python=3.6

Fish shell users:

$ source (conda info --root)/etc/fish/conf.d/conda.fish  
@dteoh
dteoh / unused-this.md
Last active Jun 2, 2020
Solving "unused variable this." warnings when using ReasonML objects
View unused-this.md

unused variable this

You can create [objects in ReasonML][1]. For example:

let document = {
  pub title = "My Treatise";
  pub contents = "<a lot of words>"
};
@dteoh
dteoh / records-and-bs-json.md
Last active Apr 2, 2019
A pattern for encoding records with bs-json
View records-and-bs-json.md

A pattern for encoding records with bs-json

If you have a record type like:

type post = {
  title: string,
  body: string,
};
@dteoh
dteoh / .gitconfig
Created Mar 17, 2019
Use Neovim as git mergetool
View .gitconfig
[merge]
tool = vimdiff
[mergetool]
keepBackup = false
[mergetool "vimdiff"]
cmd = nvim -d $LOCAL $REMOTE $MERGED -c '$wincmd w' -c 'wincmd J'
You can’t perform that action at this time.