Skip to content

Instantly share code, notes, and snippets.

@bill-mfv
bill-mfv / protocol.md
Last active March 12, 2019 03:01
Protocol between Frontend and Backend

Protocol between Frontend and Backend

  • Frontend and Backend using the same key
    Example:
    key = 'cdbdb4ff58e66858cba67787312e2e324c4b217e48680d443a42d96496556834ab549f199b5081d2926e644398e6408ba9ed72d96b1119fc7d4474938ee7c0f7';

  • The signature that Frontend send to Backend have format:
    "#{base64_encoded_timestamp}--#{sha256 hash}"

  • In Frontend

@bill-mfv
bill-mfv / install.md
Last active July 14, 2022 06:29
Install RoR env

HomeBrew is a package manager for OSX. Brew install missing stuff so easy…

  • Install Homebrew:
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Change permission for zsh

  • Change the ownership of these directories to your user:
    sudo chown -R $(whoami) /usr/local/share/zsh /usr/local/share/zsh/site-functions
  • And make sure that your user has write permission:
    chmod u+w /usr/local/share/zsh /usr/local/share/zsh/site-functions

Starting point: We build a feature that helps users unsubcribe the email subscription

Like: URL: /user/unsubcribe_email/:token

We don't want to store the token in the database, so we come with the approach that uses a dynamic token by encrypt_and_sign the user's ID with a key

Like:

require 'uri'
require 'net/http'
require 'openssl'
def get_occurrences_of_an_item read_token, item_id
url = URI("https://api.rollbar.com/api/1/item/#{item_id}/instances")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true