Skip to content

Instantly share code, notes, and snippets.

@ray-sh
ray-sh / curl.md
Created June 16, 2022 07:48 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

#start psql
psql postgres
# list all databases
\l
#connect the db
\c db_name
#list all tables
@ray-sh
ray-sh / 01.README.md
Created November 11, 2020 13:21 — forked from mmmries/01.README.md
Load Test Phoenix Presence

Phoenix Nodes

First I created 3 droplets on digital ocean with 4-cores and 8GB of RAM. Login as root to each and run:

sysctl -w fs.file-max=12000500
sysctl -w fs.nr_open=20000500
ulimit -n 4000000
sysctl -w net.ipv4.tcp_mem='10000000 10000000 10000000'
@ray-sh
ray-sh / code_snip_phoenix.ex
Last active March 21, 2020 09:26
Common code snips for coding Phoenix
#A plug to get cookies from conn
defmodule AuthorizedPlug do
import Plug.Conn
import Phoenix.Controller
def init(options) do
options
end
def call(conn, name) do
https://ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php
@ray-sh
ray-sh / instructions.md
Created December 23, 2019 09:04 — forked from marteinn/instructions.md
This is a Phoenix + React-Create-App integration with very small footprint
  1. Begin with scaffolding a create-react-app, then update your package.json build script (replace DIR_TO_PHX_APP with the path to your phoenix app)
"build": "react-scripts build && rm -rf DIR_TO_PHX_APP/priv/static/build && mv build DIR_TO_PHX_APP/priv/static/build",

This will move your prod build files to DIR_TO_PHX_APP/priv/static/build on build

  1. Run yarn build
@ray-sh
ray-sh / postgres-brew.md
Last active October 6, 2020 13:55 — forked from ibraheem4/postgres-brew.md
Prepare postgres for phoenix

Prepare Postgres for phoenix

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@ray-sh
ray-sh / match.ex
Last active January 20, 2018 15:01
括号匹配算法
问题:
"(){}[]" => True
"([{}])" => True
"(}" => False
"[(])" => False
"[({})](]" => False
基本思想:在算法中设置一个栈,每读入一个括号,若是右括号,则或者与栈顶匹配的左括号相互消解,或者是不合法的情况;若是左括号,则直接压入栈中。
若括号匹配,在算法的开始和结束时,栈都应该是空的。
defmodule Challenge do
@ray-sh
ray-sh / relation.ex
Created October 5, 2017 14:09
Build relation CURD
#Build relation is very common in DB layer, like user and it's posts
#1> We need define the relation between Module user and posts
schema "users" do
has_many :posts, Blog.Post
end
schema "posts" do
belongs_to(:user, Blog.User)
end
@ray-sh
ray-sh / auth.ex
Last active September 30, 2017 02:17
Auth functions
#Function used in auth
#1>Save the user id in session and current_user in conn.assign which will exposed as @current_user for all template
#Deliver pass port to user, user will carry the :user_id in next request
def deliver_passport_to_user(conn,user) do
conn
|>assign(:current_user, user)
|>put_session(:user_id,user.id)
|>configure_session(renew: true) #Renew the session to keep our safe
end