Skip to content

Instantly share code, notes, and snippets.

View kimyu-ng's full-sized avatar
🎯
Focusing

Kim Yu Ng kimyu-ng

🎯
Focusing
View GitHub Profile
@kimyu-ng
kimyu-ng / arel_bug.rb
Created May 2, 2018 05:40
rails arel sql bug
# frozen_string_literal: true
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
@kimyu-ng
kimyu-ng / config.yml
Created October 5, 2017 15:41
circleci 2.0 config.yml
version: 2
jobs:
build:
working_directory: /app
docker:
- image: smarthr/circleci-base
environment:
RAILS_ENV: test
DB_HOST: 127.0.0.1
@kimyu-ng
kimyu-ng / Gemfile
Created August 8, 2017 20:53 — forked from nateberkopec/Gemfile
ActionCable isn't *really* a Rails 5 dependency.
# gem 'rails'
gem "activerecord"
gem "actionpack"
gem "actionview"
gem "actionmailer"
gem "activejob"
gem "activesupport"
gem "railties"
gem "sprockets-rails"
gem 'sqlite3'

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@kimyu-ng
kimyu-ng / iterm2-solarized.md
Created April 26, 2017 19:10 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

#!/usr/bin/env bash
curl https://s3.amazonaws.com/heroku-jvm-buildpack-vi/vim-7.3.tar.gz --output vim.tar.gz
mkdir vim && tar xzvf vim.tar.gz -C vim
export PATH=$PATH:/app/vim/bin
@kimyu-ng
kimyu-ng / Java.md
Created September 23, 2016 20:04 — forked from JeOam/Java.md
Install Java 8 on OS X

on El Capitan, after installing the brew...

$ brew update
$ brew tap caskroom/cask
$ brew install Caskroom/cask/java

And Java 8 will be installed at /Library/Java/JavaVirtualMachines/jdk1.8.xxx.jdk/

Check version:

@kimyu-ng
kimyu-ng / query_planner.markdown
Created September 13, 2016 16:16 — forked from hgmnz/query_planner.markdown
PostgreSQL query plan and SQL performance notes

Types of index scans

Indexes

Sequential Scan:

  • Read every row in the table
  • No reading of index. Reading from indexes is also expensive.
@kimyu-ng
kimyu-ng / simple-linear-regression.rb
Created August 17, 2016 17:50 — forked from rweald/simple-linear-regression.rb
Simple Linear Regression in Ruby
class SimpleLinearRegression
def initialize(xs, ys)
@xs, @ys = xs, ys
if @xs.length != @ys.length
raise "Unbalanced data. xs need to be same length as ys"
end
end
def y_intercept
mean(@ys) - (slope * mean(@xs))
@kimyu-ng
kimyu-ng / 15_to_18.rb
Created April 18, 2016 22:49
Conversion of 15 to 18 digits for Salesforce
# http://codefriar.tumblr.com/post/34159033581/salesforce-15-18-digit-guid-conversion-in-ruby
def convert_guid(short_guid)
chunks = short_guid.chars.to_a
char_map = %w{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5}
extension = []
chunks.each_slice(5) { |x| y = x.reverse.map {|c| (c.match /[A-Z]/) ? 1 : 0 }.join("").to_i(2) ; extension << y}
short_guid + (extension.map {|e| char_map.at(e)}).join("").to_s
end