Skip to content

Instantly share code, notes, and snippets.

View deps.exs
defp deps do
[
{:cowboy, [env: :prod, git: "https://github.com/ninenines/cowboy.git", tag: "2.2.0", override: true, manager: :make]},
{:ranch, [env: :prod, git: "https://github.com/ninenines/ranch.git", override: true, manager: :make]},
{:grpc, github: "tony612/grpc-elixir"},
]
end
View app.exs
def application do
[
mod: {ChattyApp, []},
applications: [:grpc]
]
end
View chatty.proto
syntax = "proto3";
package chatty;
service ChatService {
rpc SendMessage (SendMessageRequest) returns (SendMessageReply) {}
rpc FetchMessages (FetchMessagesRequest) returns (FetchMessagesReply) {}
}
message SendMessageRequest {
View chatty.proto
syntax = "proto3";
package chatty;
service ChatService {
rpc SendMessage (SendMessageRequest) returns (SendMessageReply) {}
rpc FetchMessages (FetchMessagesRequest) returns (FetchMessagesReply) {}
}
message SendMessageRequest {
View chatty.proto
syntax = "proto3";
package chatty;
service ChatService {
rpc SendMessage (SendMessageRequest) returns (SendMessageReply) {}
rpc FetchMessages (FetchMessagesRequest) returns (FetchMessagesReply) {}
}
message SendMessageRequest {
View server.ex
defmodule Chatty.ChatService.Server do
use GRPC.Server, service: Chatty.ChatService.Service
def send_message(request, _stream) do
Chatty.ChatState.put_message(request.chat_message)
Chatty.SendMessageReply.new()
end
def fetch_messages(_request, _stream) do
messages = Chatty.ChatState.get_messages()
View agent.ex
defmodule Chatty.ChatState do
def start_link do
Agent.start_link(fn -> %{} end, name: __MODULE__)
end
def put_message(message) do
Agent.update(__MODULE__, &Map.put_new(&1, :os.system_time(:millisecond), message))
end
View chatty_app.ex
defmodule ChattyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec
children = [
supervisor(GRPC.Server.Supervisor, [{Chatty.ChatService.Server, 8080}]),
worker(Chatty.ChatState, []),
]
View find_jones_smith_query.sql
SELECT
*
FROM
users
WHERE
MATCH(surename) AGAINST ("Jones-Smith");
View package.json
{
"name": "test",
"displayName": "test",
"description": "",
"version": "0.0.1",
"publisher": "aleksandra",
"engines": {
"vscode": "^1.30.0"
},
"categories": [