Skip to content

Instantly share code, notes, and snippets.

@hoanghiep90
hoanghiep90 / installing-ruby-2.6.10-on-m1.md
Last active February 1, 2023 18:36
Install Ruby 2.6.10 with rbenv (M1/M2 Mac)

Problem

I ran command install ruby 2.6.10 with rbenv.

rbenv install 2.6.10

Got the error:

# encoding: utf-8
String.class_eval do
def strip_accents
accents = {
['à','À','ả','Ả','ã','Ã','á','Á','ạ','Ạ','ă','Ă','ằ','Ằ','ẳ','Ẳ','ẵ','Ẵ','ắ','Ắ','ặ','Ặ','â','Â','ầ','Ầ','ẩ','Ẩ','ẫ','Ẫ','ấ','Ấ','ậ','Ậ'] => 'a',
['đ','Đ'] => "d",
['è','È','ẻ','Ẻ','ẽ','Ẽ','é','É','ẹ','Ẹ','ê','Ê','ề','Ề','ể','Ể','ễ','Ễ','ế','Ế','ệ','Ệ'] => "e",
['ì','Ì','ỉ','Ỉ','ĩ','Ĩ','í','Í','ị','Ị'] => 'i',
['ò','Ò','ỏ','Ỏ','õ','Õ','ó','Ó','ọ','Ọ','ô','Ô','ồ','Ồ','ổ','Ổ','ỗ','Ỗ','ố','Ố','ộ','Ộ','ơ','Ơ','ờ','Ờ','ở','Ở','ỡ','Ỡ','ớ','Ớ','ợ','Ợ'] => "o",
@hoanghiep90
hoanghiep90 / google_play_verification.rb
Created November 9, 2016 06:59 — forked from jkotchoff/google_play_verification.rb
Verifying an Android subscription in a Ruby on Rails app using the Google Play API
class GooglePlayVerification
require 'google/api_client'
# Refer:
# https://code.google.com/p/google-api-ruby-client/issues/detail?id=72
# and
# http://jonathanotto.com/blog/google_oauth2_api_quick_tutorial.html
# and
# http://milancermak.wordpress.com/2012/08/24/server-side-verification-of-google-play-subsc/
GOOGLE_KEY = 'xxx-xxx.apps.googleusercontent.com'
@hoanghiep90
hoanghiep90 / 00_pending_migrations.rb
Created November 8, 2016 09:03 — forked from runlevel5/00_pending_migrations.rb
An initialiser to prevent app to bootstrap app on dev env if pending migrations - cover Rails 3 or newer
## Place in config/initializers/00_pending_migrations.rb
# Raise an error and abort the run there are any pending migrations:
if Rails.env.development?
# Rails 4 way ;)
if Rails.version >= '4'
ActiveRecord::Migration.check_pending!
else
# Rails 3 way - TODO: remove when we up to Rails 4
migrator = ActiveRecord::Migrator.new(
# QUESTION 1
# What’s the problem with the following controller code? What would be the consequence of leaving this code in a production app? How would you fix it?
class MyController < ApplicationController
def options
options = {}
available_option_keys = [:first_option, :second_option, :third_option]
all_keys = params.keys.map(&:to_sym)
set_option_keys = all_keys & available_option_keys
set_option_keys.each do |key|
options[key] = params[key]
@hoanghiep90
hoanghiep90 / gist:7e2be752a6d04e513627
Created August 26, 2015 18:16
[AngularJS] Error: [$parse:lexerr] Lexer Error: Unexpected next character
I had some error while I used ng-click
<a ng-click="#/search/San+Francisco">test</a>
instead of ng-href
<a ng-href="#/search/San+Francisco">test</a>
I hope it might help
@hoanghiep90
hoanghiep90 / gist:79c39040227c61aaf3b7
Created July 1, 2015 16:39
Removes the deploy lock file.
$ mina deploy
-----> ERROR: another deployment is ongoing.
Delete the lock file to continue.
$ mina deploy:force_unlock
-----> Unlocking
$ rm /var/www/kickstack.me/deploy.lock
$ mina deploy
# ...The deploy should proceed now
@hoanghiep90
hoanghiep90 / gist:3933506930551e02edbb
Created June 13, 2015 17:45
Fix CORS issue with CloudFront
For nginx:
location ~* \.(ttf|ttc|otf|eot|woff|svg|font.css)$ {
add_header Access-Control-Allow-Origin *;
expires 1M;
access_log off;
add_header Cache-Control "public";
}
@hoanghiep90
hoanghiep90 / gist:5e38cc739c72a6d5b16e
Created May 30, 2015 08:21
Create a SSL Certificate
Step 1: Creating the private server key.
sudo openssl genrsa -des3 -out server.key 2048
Step 2: Creating a certificate signing request:
sudo openssl req -new -key server.key -out server.csr
This command will prompt terminal to display a lists of fields that need to be filled in.
@hoanghiep90
hoanghiep90 / gist:e3f84de652e28b0d8496
Created May 24, 2015 20:04
Can’t find the ‘libpq-fe.h header
I need to install pg 0.17.1 gem on a server running CentOS. This is the error message I saw:
# gem install pg -v '0.17.1'
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with