Skip to content

Instantly share code, notes, and snippets.

View parallel588's full-sized avatar

Maksim Pechnikov parallel588

  • WELLNUTS
  • Tampere
View GitHub Profile
@parallel588
parallel588 / jsonapi_paginator.ex
Created May 16, 2022 17:24 — forked from edipox/jsonapi_paginator.ex
elixir scrivener handle slow couting example
# Paginate
@spec handle_pagination(conn :: Plug.Conn.t(), page :: number | atom, page_size :: number | atom, query :: module) ::
Plug.Conn.t()
defp handle_pagination(conn, page, page_size, query) do
config = %Scrivener.Config{
module: Repo,
page_number: page,
page_size: page_size,
options: [total_entries: total_entries(query)]
}
@parallel588
parallel588 / util_convert_cowboy_ipv6_string_to_string.ex
Created January 28, 2022 08:46 — forked from z5ottu/util_convert_cowboy_ipv6_string_to_string.ex
Erlang cowboy IPv6 address string conversion to readable string in Elixir.
defmodule Utils.Cowboy do
use Bitwise
#
# ipv4 cowboy string example: "0.0.0.0.0.65535.20060.31747"
# ipv6 cowboy string example: "10754.43916.45826.36224.35230.44219.15941.63302"
def erlangCowboyIpv6StringToString(string) do
if String.starts_with?(string, "0.0.0.0.0.65535") do
String.split(string,".") |> Enum.take(-2) |> Enum.map(fn(x)-> String.to_integer x end) |> Enum.map(fn(x)-> [x >>> 8,x &&& 255] end) |> List.flatten |> Enum.join(".")
@parallel588
parallel588 / elastic_search.ex
Created October 12, 2021 13:37 — forked from joshnuss/elastic_search.ex
ElasticSearch Elixir client using Mojito/Mint 🍹
# Mojito: https://github.com/appcues/mojito/
# Mint: https://github.com/elixir-mint/mint
defmodule ElasticSearch do
@config Application.get_env(:my_app, ElasticSearch)
@root @config[:root] # ie http://localhost:9200
@headers [
{"content-type", "application/json"}
]
def put(index, id, doc) do
version: '3.8'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- 22181:2181
@parallel588
parallel588 / downloader.ex
Created July 29, 2021 12:51 — forked from alexandremcosta/downloader.ex
Stream HTTP body with Elixir Mint
defmodule Downloader do
defstruct completed: false,
content_length: 0,
max_body_length: 200 * 1024 * 1024,
max_redirect: 3,
receive_timeout: 10_000,
redirect_count: 0,
redirect_location: nil,
status: 0
http://invisible-island.net/xterm/
XTerm Control Sequences
Edward Moy
University of California, Berkeley
Revised by
@parallel588
parallel588 / deploy.rb
Created January 8, 2020 05:03 — forked from noma4i/deploy.rb
Deploy Phoenix Elixir by mina
require 'mina/bundler'
require 'mina/git'
require 'mina/rbenv'
set :domain, 'your_domain.com'
set :deploy_to, '/home/deployer/app_name'
set :repository, 'git@github.com:user_name/app_name'
set :branch, ENV["brunch"] || 'master'
set :app_name, "app_name"
@parallel588
parallel588 / Joken.md
Created September 3, 2018 09:30 — forked from UA3MQJ/Joken.md
Elixir Joken JWT Examples

https://github.com/bryanjos/joken - A JSON Web Token (JWT) Library

1. Закодировать JWT - подпись секретным текстовым ключем "my_secret_key"

  token = %{user_id: 123}
  |> Joken.token()
  |> Joken.with_signer(Joken.hs256("my_secret_key"))
  |> Joken.sign()
  |> Joken.get_compact()
@parallel588
parallel588 / install.sh
Created October 10, 2017 12:33 — forked from ziadoz/install.sh
Install Chrome, ChromeDriver and Selenium on Ubuntu 16.04
#!/usr/bin/env bash
# https://developers.supportbee.com/blog/setting-up-cucumber-to-run-with-Chrome-on-Linux/
# https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c
# http://stackoverflow.com/questions/10792403/how-do-i-get-chrome-working-with-selenium-using-php-webdriver
# http://stackoverflow.com/questions/26133486/how-to-specify-binary-path-for-remote-chromedriver-in-codeception
# http://stackoverflow.com/questions/40262682/how-to-run-selenium-3-x-with-chrome-driver-through-terminal
# http://askubuntu.com/questions/760085/how-do-you-install-google-chrome-on-ubuntu-16-04
# Versions
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
@parallel588
parallel588 / 00.howto_install_phantomjs.md
Created August 26, 2017 18:41 — forked from julionc/00.howto_install_phantomjs.md
How to install PhantomJS on Debian/Ubuntu

How to install PhantomJS on Ubuntu

Version: 1.9.8

Platform: x86_64

First, install or update to the latest system software.

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev