Skip to content

Instantly share code, notes, and snippets.

@arthurchui
arthurchui / negative_base.rb
Created March 17, 2016 22:46
Get negative-base number from an integer
# Returns an array which index [0] represents the least significant bit.
# to_negativebase(9) # => [1, 0, 0, 1, 1]
# to_negativebase(-9) # => [1, 1, 0, 1]
def to_negativebase(value, base = -2)
raise ArgumentError if base > -2
digits = []
while value != 0
value, mod = value.divmod(base)
if mod < 0
mod += -base
@arthurchui
arthurchui / git-delete-merged-remote
Created May 27, 2017 06:22
git-delete-merged-remote
#!/bin/bash
git branch -r --merged | grep origin | sed 's/origin\///' | xargs -n 1 git push --delete origin
" Great presentation on vim
" http://slidedeck.io/inside/vim-presentation
autocmd filetype crontab setlocal nobackup nowritebackup
set nocompatible
filetype off
" Python3
let g:python3_host_prog = '/usr/local/bin/python3'
" PLUG BEGIN
@arthurchui
arthurchui / database.yml
Last active December 15, 2024 11:53
Custom mysql2 adapter for connecting Rails via ProxySQL
database: &default
host: 127.0.0.1
adapter: proxy_mysql2
...
@arthurchui
arthurchui / bugsnag_errors_to_csv.rb
Last active January 29, 2020 00:44
Export Bugsnag's errors to
#!/usr/bin/env ruby
require "csv"
require "bugsnag/api"
token = ENV["TOKEN"]
Bugsnag::Api.configure do |config|
config.auth_token = token
end
def organization
@arthurchui
arthurchui / datasize.rake
Created August 19, 2022 22:17 — forked from shinzui/datasize.rake
Rake task to get database and table sizes.
# Run rake db:size to get a print of your database size in bytes.
# Run rake db:tables:size to get the sizes for individual tables
# Works for MySQL and PostgreSQL. Not tested elsewhere.
namespace :db do
desc 'Print data size for entire database'
task :size => :environment do
database_name = ActiveRecord::Base.connection.instance_variable_get("@config")[:database]
adapter = ActiveRecord::Base.connection.adapter_name.downcase