Skip to content

Instantly share code, notes, and snippets.

View ntamvl's full-sized avatar
🏠
Working from home

Tam Nguyen ntamvl

🏠
Working from home
View GitHub Profile
@ntamvl
ntamvl / delete-git-branch-locally-and-remotely.md
Created May 16, 2016 14:42
Delete Git branch locally and remotely

Delete Git branch locally and remotely

I stumble across this one every so often. And since I have to look it up every time, I may as well document it. Today's post is small and easy.

To delete a Git branch after the completion of a feature or bug fix, you can use the following commands. Cause the CLI rules, right, RIGHT? Anyway, back to the task at hand.

## Delete a remote branch
$ git push origin --delete <branch> # Git version 1.7.0 or newer 
$ git push origin :<branch> # Git versions older than 1.7.0
@ntamvl
ntamvl / elasticsearch-result-window-is-too-large-from-size.md
Last active February 21, 2024 11:16
ElasticSearch - Result window is too large, from + size must be less than or equal to: [10000]

Result window is too large, from + size must be less than or equal to: [10000] but was [1000000]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level parameter

I suppose the proper fix would be to modify the code to use the scroll API, but for a quick fix, you can use the following:

curl -XPUT http://localhost:9200/doraana/_settings -d '{ "index" : { "max_result_window" : 1000000 } }'

Use kibana

With Elastic server: http://localhost:9200/doraana, with index: doraana

@ntamvl
ntamvl / Mina.md
Created June 21, 2016 10:21 — forked from stevenyap/Mina.md
Mina - Faster deployment than Capistrano!!!

Cross-platform means of getting user's home directory in Ruby

On unix platforms (linux, OS X, etc), ENV["HOME"], File.expandpath('~') or Dir.home all rely on the HOME environment variable being set. But sometimes you'll find that the environment variable isn't set--this is common if you're running from a startup script, or from some batch schedulers. If you're in this situation, you can still get your correct home directory via the following:

require 'etc'
Etc.getpwuid.dir

Having said that, since this question is asking for a "cross-platform" method it must be noted that this won't work on Windows (Etc.getpwuid will return nil there.) On Windows, ENV["HOME"] and the methods mentioned above that rely on it will work, despite the HOME variable not being commonly set on Windows--at startup, Ruby will fill in ENV["HOME"] based on the windows HOMEPATH and HOMEDRIVE environment variables. If the windows HOMEDRIVE and HOMEPATH environment variables aren't set then this won't

@ntamvl
ntamvl / getting_a_readable_text_in_iterm2_how_do_i_color.md
Last active January 27, 2025 19:57
iTerm2 - color 'ls' and other outputs for MacOS

iTerm2 - color 'ls' and other outputs for MacOS

That's right. For OS X and BSD's ls, the flag is -G. Many people customize the behavior of ls by replacing it with an alias that adds extra options. I have the following in my .bashrc, for example:

alias ls='LSCOLORS=gxfxcxdxbxexexabagacad /bin/ls -bFHGLOPW'

Besides enabling colors in general, this sets the LSCOLORS variable in order to change which ones ls uses.

@ntamvl
ntamvl / elasticsearch-addsynonyms-to-a-model.md
Created July 1, 2016 08:52
How to add synonyms to a model

How to add synonyms to a model

require 'pry'

require 'logger'
require 'ansi/core'
require 'active_record'
require 'active_support/core_ext/numeric'
require 'active_support/core_ext/hash'
package main
import (
"database/sql"
"gopkg.in/gorp.v1"
"log"
"strconv"
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
@ntamvl
ntamvl / elasticsearch.rb
Last active February 21, 2024 11:16
It would be nice if you can configure the connection to the elasticsearch cluster per yml file in the config directory.
# config/initializers/elasticsearch.rb
# elasticSearch
# configuration in config/elasticsearch.yml
# this file could lock like:
## host: localhost
## port: 9200
## user: my_username
## password: my_password
@ntamvl
ntamvl / rabbit.rake
Created July 11, 2016 16:49 — forked from johnkellar/rabbit.rake
RabbitMQ Configuration Rake Tasks
namespace :rabbit do
def get_queues
`#{@base_command} list queues | awk '{print$4}' | grep -vw '|' | grep -vw 'name' | awk 'NF'`
end
def get_queues_with_count
`#{@base_command} list queues | awk '{print$18, $4}' | grep -vw '|' | grep -vw 'name' | awk 'NF'`
end
@ntamvl
ntamvl / fix-homebrew-permissions-osx-el-capitan.md
Created July 13, 2016 04:48
How to fix permission issues on Homebrew in OS X El Capitan?

How to fix permission issues on Homebrew in OS X El Capitan?

Here is how you can fix the permission issues with Homebrew in Mac OS X El Capitan:

If you had created the /usr/local directory already, then run this command in terminal:

sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local

source: http://digitizor.com/fix-homebrew-permissions-osx-el-capitan/