Skip to content

Instantly share code, notes, and snippets.

View raviwu's full-sized avatar

Ravi Wu raviwu

  • Taiwan
View GitHub Profile
@raviwu
raviwu / Dockerfile
Created March 15, 2019 06:28
CentOS openJDK Dockerfile
FROM centos:7
RUN yum -y update && yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel epel-release libffi-devel gcc-c++ make openssl-devel git sudo
ENV JAVA_HOME /etc/alternatives/jre
# Add entrypoint script
ADD scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
@raviwu
raviwu / common_regex.rb
Created February 14, 2017 07:33
Common Regex
# URL with http:// or https://
%r{\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\z}ix
# email
/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
@raviwu
raviwu / elixir-programming-notes.md
Last active February 8, 2017 10:01
Elixir Notes

Chapter 2 - Pattern Matching

Simple Match operator =

In Elixir, the equals sign = is not an assignment, instead i's like an assertion. It succeeds if Elixir can find a way of making the left-hand side equal the right-hand side. Elixir calls = a match operator.

a = 1
=> 1
@raviwu
raviwu / rspec_pattens.rb
Last active February 2, 2017 08:00
RSpec Patterns
# app/models/user.rb
class User < ActiveRecord::Base
has_secure_password
validates :firstname, presence: true, length: 4..20
validates :middlename, length: 4..20, allow_blank: true
validates :lastname, presence: true, length: 4..20
validates :email, format: { with: /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i }
validates :password, presence: true, confirmation: true, length: { minimum: 8 }
@raviwu
raviwu / notes_soft_skills.md
Last active May 5, 2022 06:43
[Notes] Soft Skills: The software developer's life manual

Page 47

This kind of mindset is crucial to managing your career, because when you start to think of yourself as a business, you start to make good business decisions.

Page 52

Every step you take without a clear direction is a wasted step. Don’t randomly walk through life without a purpose for your career.

Your big goal should be something not too specific, but clear enough that you can know if you’re steering toward it or not. Think about what you want to ultimately do with your career.

@raviwu
raviwu / google_sheets_api_1_setup.rb
Created July 9, 2016 01:58
Use Google Sheets API and Service Account to import Data to Rails APP
# Gemfile
gem 'google-api-client'
gem 'googleauth'
@raviwu
raviwu / push_services_wrapper.rb
Created June 24, 2016 10:19
PushServicesWrapper
# In app/services/push_services_wrapper.rb
require 'json/ext'
class PushServicesWrapper
attr_reader :message, :to_email, :channels, :badge, :from_id, :push_time, :addition, :push_uri, :to_id
def initialize(options = {})
@message = options[:message]
@to_email = options[:to_email].kind_of?(Array) ? options[:to_email] : [options[:to_email]]
# In your api call endpoint for update_push_subscription
# I use Grape, but the logic is similar in RailsAPI
resource :update_push_subscription do
desc "Update the user mobil push notification registration on Amazon SNS"
params do
requires :push_platform, type: String, desc: "Push Service Platform", values: %w(apns gcm)
requires :device_token, type: String, desc: "Device Token for Mobile Push Notification"
end
post do
@raviwu
raviwu / parse_installation_wrapper.rb
Last active June 24, 2016 10:04
ParseInstallationWrapper Setup
# In app/services/parse_installation_wrapper.rb
class ParseInstallationWrapper
def self.check_and_unregister(options = {})
# provide no params will clear out the Parse installation with no device_token
object_ids = get_push_registered_installation_object_ids(options)
delete_push_installations(object_ids)
end
private
@raviwu
raviwu / amazon_sns_info.rb
Last active June 24, 2016 10:06
AmazonSnsInfo Model Setup
# In db/migrate/XXXXXXX_create_amazon_sns_infos.rb
class CreateAmazonSnsInfos < ActiveRecord::Migration
def change
create_table :amazon_sns_infos do |t|
t.references :user, :foreign_key => true, :index => true, :null => false
t.string :platform
t.string :device_token
t.string :endpoint_arn
t.string :platform_application_arn