Skip to content

Instantly share code, notes, and snippets.

View thanos's full-sized avatar

thanos vassilakis thanos

View GitHub Profile
@thanos
thanos / xeni_travel_api_hotel_availability.sh
Last active August 26, 2023 17:26
Using Xeni Travel Api to fetch a hotel detail and it's availability
curl -X 'GET' "$XENI_API_HOST/api/accommodation_searches/accommodation?search_id=962c9315-0e35-45e3-b158-be10c860912d&property_id=40553&raw=true" \
-H "accept: application/json" \
-H "authorization: bearer: $XENI_TOKEN"
@thanos
thanos / xeni_search_hotel_availability.sh
Last active August 26, 2023 17:24
searching for hotel availability using the Xeni Travel API
curl -X 'POST' \
"$XENI_API_HOST/api/accommodation_searches/search" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "authorization: bearer: $XENI_TOKEN" \
-d '{
"check_in": "2023-08-27",
"check_out": "2023-08-30",
"destination_id": "bbc35c49-d2a7-431a-ac40-a4944c3a00e7",
"occupancies": [
@thanos
thanos / xeni_travel_api_set_envs.sh
Last active August 26, 2023 16:23
setting up environmental variables for XENI Trade API
export XENI_API_HOST="https://xenitravelapi-beta01.gigalixirapp.com"
export XENI_USER_EMAIL="some@email.com"
export XENI_USER_PASSWORD="some password"
export XENI_TOKEN=$(curl -X 'POST' $XENI_API_HOST/api/accounts/get_token \
-H 'accept: application/json' \
-H 'content-type: application/json' \
-d '{"user":{"email": "'"$XENI_USER_EMAIL"'", "password": "'"$XENI_USER_PASSWORD"'"}}' \
| sed "s/{.*\"token\":\"\([^\"]*\).*}/\1/g")
@thanos
thanos / xeni_travel_api_get_token.sh
Last active August 26, 2023 17:11
Get a token from the Xeni Travel API
curl -X 'POST' "$XENI_API_HOST/api/accounts/get_token" \
-H "accept: application/json" \
-H "content-type: application/json" \
-d '{"user":{"email": "'"$XENI_USER_EMAIL"'", "password": "'"$XENI_USER_PASSWORD"'"}}'
{"token":"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ4ZW5pX3RyYXZlbF9hcGkiLCJleHAiOjE2OTI0MTA1ND9A"}
@thanos
thanos / fetch_locations.sh
Last active August 26, 2023 17:14
Gets a list of locations, based on a search thing, from the Xeni travel api
# an alternative to "python -m json.tool" is "json_pp -json_opt pretty,canonical"
curl -X 'GET' \
"$XENI_API_HOST/api/locations/search?starts_with=New%20York" \
-H "accept: application/json" \
-H "authorization: bearer: $XENI_TOKEN" \
| python -m json.tool
{
"data": [
@thanos
thanos / zentrum-hotel.json
Last active February 3, 2023 17:37
A Zentrum hotel record
{
"category": "Hotel",
"chainName": "HYATT",
"checkinInfo": {
"minAge": "0"
},
"checkoutInfo": {},
"contact": {
@thanos
thanos / batch_process.ex
Created September 4, 2022 14:41
Processing a stream in batches
batch_size = 100
# 8 tasks running at the same time and we don't care about the results order
async_options = [max_concurrency: 8, ordered: false]
csv_rows
|> Stream.chunk(batch_size)
|> Task.async_stream(fn batch ->
batch
|> Enum.map(&CSV.generate_xml/1)
@thanos
thanos / Slug.ex
Last active April 30, 2019 17:26
Using a slug as your primary key with Elixir's Ecto and Phoenix
#
# Define a simple slug type stating the source for the slug and the primary key field name
# see documention https://hexdocs.pm/ecto_autoslug_field/readme.html
#
defmodule CheckpointCharlie.PlayPen.Slug do
use EctoAutoslugField.Slug, from: :name, to: :id
end
import hashlib
from functools import wraps
from django.core.cache import cache
from django.utils.encoding import force_text, force_bytes
def cache_memoize(
timeout,
prefix='',
@thanos
thanos / install-rdkafka.sh
Created March 7, 2018 02:29
A script to install kafka rdkafka drivers for python
sudo apt-get update -y
sudo apt-get upgrade -y
wget -qO - http://packages.confluent.io/deb/3.2/archive.key | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] http://packages.confluent.io/deb/3.2 stable main"
sudo apt-get update && sudo apt-get install confluent-platform-oss-2.11
sudo apt-get install librdkafka-dev
ldconfig -p | grep librdkafka