Skip to content

Instantly share code, notes, and snippets.

@dteoh
dteoh / command.md
Created September 15, 2021 00:26
Interactively delete git branches locally

Delete multiple Git branches with a UI

This assumes you have installed [fzf][1].

$ git branch --no-color | fzf -m | xargs -I {} git branch -D '{}'

Press tab to mark a branch, shift-tab to unmark. Press enter and all marked branches will be deleted.

@dteoh
dteoh / article_starcoder_macbook.md
Last active March 18, 2024 10:20
How to run StarCoderBase 1B SFT on a MacBook Pro with Apple Silicon

How to run StarCoderBase 1B SFT on a MacBook Pro with Apple Silicon

These are notes on how I managed to get StarCoderBase-1B-SFT model compiled into a quantized version such that it can run locally on my MBP M1 Pro and be queryable through an OpenAI API-compatible server. [StarCoderBase][1] is a model trained/tuned for programming tasks. The [1B parameters SFT model][2] I am using in this article is a version of the model that has had supervised fine tuning applied to it. I am just going to call this "StarCoder" in the rest of this article for the sake of simplicity. Number of parameters that a model has is going to impact resource usage, so a smaller version of the model makes it more

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

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 / .gitconfig
Created March 17, 2019 23:40
Use Neovim as git mergetool
[merge]
tool = vimdiff
[mergetool]
keepBackup = false
[mergetool "vimdiff"]
cmd = nvim -d $LOCAL $REMOTE $MERGED -c '$wincmd w' -c 'wincmd J'
@dteoh
dteoh / mysql2-gem-install.md
Created November 22, 2019 01:18
Installing mysql2 gem

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 / albedo_vs_mona_crafting_talent.md
Last active June 23, 2021 12:15
Genshin Impact: Albedo vs Mona crafting talent, who is better?

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 / put_post_json_rails_5_integration_test.md
Created July 12, 2016 07:33
PUT or POST JSON in a Rails 5 ActionDispatch::IntegrationTest

In Rails 5, the preferred base class for testing controllers is ActionDispatch::IntegrationTest.

If you have an API that receives parameters as JSON request bodies, here are some helper methods to facilitate testing:

class ActionDispatch::IntegrationTest
  def put_json(path, obj)
    put path, params: obj.to_json, headers: { 'CONTENT_TYPE' => 'application/json' }
  end
@dteoh
dteoh / neovim_python.md
Last active November 13, 2020 05:27
NeoVim + Python 3 provider

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 June 2, 2020 22:58
Solving "unused variable this." warnings when using ReasonML objects

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 / arel_select_star_from_table.rb
Last active December 2, 2019 14:45
Select all columns of an Arel table
users = User.arel_table
query = users.project(users[Arel.star])