Skip to content

Instantly share code, notes, and snippets.

View tiagopog's full-sized avatar

Tiago Guedes tiagopog

View GitHub Profile
@tiagopog
tiagopog / client.c
Created September 30, 2023 01:27
TCP Client/Server with Sockets API (Berkeley Sockets)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
int main(void) {
struct sockaddr_in server_address; /* address of the server */
int client_socket; /* FD of socket to connect with servers */
@tiagopog
tiagopog / Dockerfile.phoenix.api
Last active November 2, 2020 18:22
Elixir – Dockerfiles
FROM elixir:1.10.4
##
# Install system dependencies & tooling
##
RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get install -y bash curl apt-utils build-essential inotify-tools
@tiagopog
tiagopog / fetching_bookings_with_wall_clock_time.sql
Last active August 31, 2020 15:54
Bookings – Example of how to fetch bookings stored with wall-clock times.
/*
* 1. Create a sample table to store our bookings:
*/
> CREATE TABLE bookings (id INT, scheduled_date DATE, start_time TIMESTAMP, end_time TIMESTAMP, timezone_id VARCHAR(40))
> \d bookings
-- +----------------+-----------------------------+-------------+
-- | Column | Type | Modifiers |
-- |----------------+-----------------------------+-------------|
@tiagopog
tiagopog / inject_dependency_as_adapter.exs
Last active August 28, 2019 16:42
Elixir - Ways of using test mocks
##
# Implementation
##
# config/config.exs
config :my_app, :kv_store_adapter, KVStore
defmodule KVStore do
#...
end
# Configuration for Alacritty, the GPU enhanced terminal emulator.
# Any items in the `env` entry below will be added as
# environment variables. Some entries may override variables
# set by alacritty itself.
# env:
# TERM variable
#
# This value is used to set the `$TERM` environment variable for
# each instance of Alacritty. If it is not present, alacritty will
@tiagopog
tiagopog / classes.py
Last active February 28, 2021 12:23
Python - Techniques & Concepts
# An usual class is a subclass of object
class Human(object):
# Defining class variables
species = "H. Sapiens"
def __init__(self, first_name, last_name):
# Assign instance variables (also called attributes):
self.__internal = "secret" # Private attribute (externally accessed via: human._Human_internal)
self.first_name = first_name # Public attribute (externally accessed via human.first_name)
self.last_name = last_name # Since last_name has not a getter/setter below
@tiagopog
tiagopog / sample_api
Created March 4, 2019 14:24
GraphQL - Samples
type Query {
allPersons(last: Int): [Person!]!
}
type Mutation {
createPerson(name: String!, age: Int!): Person!
}
type Subscription {
newPerson: Person!
@tiagopog
tiagopog / 20180711220702_create_foos.rb
Last active July 12, 2018 04:14
ActiveRecord - Outside Rails (microservice example)
class CreateFoo < ActiveRecord::Migration[5.0]
def change
create_table(:foos, force: true) do |t|
t.text :message, null: false
t.datetime :created_at, null: false
end
end
end
@tiagopog
tiagopog / fibonacci.ex
Last active July 11, 2018 13:20
Elixir - Body-recursion vs Tail-Recursion for Fibonacci
# Body-recursive
#
# Note: "+" is actually the last call, not calculate/1.
defmodule Fibonacci do
def calculate(x) when x <= 2, do: 1
def calculate(x), do: calculate(x - 1) + calculate(x - 2)
end
# Tail-recursive (Tail Call Optimization)
#
@tiagopog
tiagopog / Dockerfile.build
Last active April 3, 2018 11:55
Elixir - Deploy with mix_docker, Distillery, Docker and k8s
FROM elixir:1.4.2
ENV DEBIAN_FRONTEND=noninteractive
ENV HOME=/opt/app/ TERM=xterm
# Install Hex+Rebar
RUN mix local.hex --force && \
mix local.rebar --force
WORKDIR /opt/app