Skip to content

Instantly share code, notes, and snippets.

@wpiekutowski
wpiekutowski / some_subscription_test.exs
Created August 7, 2020 13:34
Testing subscriptions: Elixir + Absinthe + Phoenix WebSocket
defmodule App.Schema.SomeSubscriptionTest do
use App.SubscriptionCase
test "subscription: someSubscription" do
subscription_query = """
subscription {
someSubscription {
someData
}
}

Output on Ruby 2.6, MacBook Pro (13-inch, 2017, 3.5 GHz Intel Core i7)

Note: I manually removed some BigDecimal deprecation warnings

Rehearsal ------------------------------------------------
as_json        0.122644   0.000508   0.123152 (  0.123823)
fast_jsonapi   0.184139   0.000829   0.184968 (  0.186195)
grape_entity   0.709880   0.003083   0.712963 (  0.714929)
blueprinter    0.220149   0.004481   0.224630 (  0.225596)
@joshnuss
joshnuss / udp_server.exs
Last active June 17, 2024 11:45
Fault tolerant UDP Server in Elixir
# to run:
# > elixir --no-halt udp_server.exs
# to test:
# > echo "hello world" | nc -u -w0 localhost 2052
# > echo "quit" | nc -u -w0 localhost 2052
# Let's call our module "UDPServer"
defmodule UDPServer do
# Our module is going to use the DSL (Domain Specific Language) for Gen(eric) Servers
use GenServer
@lanedraex
lanedraex / listener.rs
Created November 5, 2017 09:12
Rust UDP socket: send and receive
use std::net;
use std::env;
fn listen(socket: &net::UdpSocket, mut buffer: &mut [u8]) -> usize {
let (number_of_bytes, src_addr) = socket.recv_from(&mut buffer).expect("no data received");
println!("{:?}", number_of_bytes);
println!("{:?}", src_addr);
@Kartones
Kartones / postgres-cheatsheet.md
Last active June 18, 2024 15:09
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active June 20, 2024 14:04
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'