Skip to content

Instantly share code, notes, and snippets.

View paveltyk's full-sized avatar

Pavel Tsiukhtsiayeu paveltyk

  • BILL
  • North Carolina, US
  • 06:13 (UTC -04:00)
View GitHub Profile
@paveltyk
paveltyk / scatter_swap.ex
Last active October 31, 2017 10:20
This is a port of ScatterSwap integer hashing function written in Ruby to Elixir. https://github.com/namick/scatter_swap
defmodule ScatterSwap do
@moduledoc """
Usage:
Pass a number (as an integer) and random spin to the 'hash' function and it will return an obfuscated version of it.
ScatterSwap.hash(1, 0) #=> 4517239960
ScatterSwap.hash(2, 0) #=> 7023641925
ScatterSwap.hash(42, 0) #=> 2912536240
@paveltyk
paveltyk / slugify.ex
Created October 31, 2017 10:21
Slug generation for Elixir with Russian letters transliteration support.
defmodule Slugify do
@moduledoc """
The main intent of this module is to be used in slug generation for URLs.
Supports russian transliteration.
"""
@char_mappings %{"а" => "a", "б" => "b", "в" => "v", "г" => "g", "д" => "d", "е" => "e",
"ё" => "e", "ж" => "j", "з" => "z", "и" => "i", "й" => "i", "к" => "k", "л" => "l", "м" => "m",
"н" => "n", "о" => "o", "п" => "p", "р" => "r", "с" => "s", "т" => "t", "у" => "y", "ф" => "f",
"х" => "h", "ц" => "ts", "ч" => "ch", "ш" => "sh", "щ" => "sch", "ъ" => "", "ы" => "y",
.App {margin:200px 0;text-align:center;font-size:16px;}
.App form input[type="email"] {font-size:16px;padding:7px 10px;border:1px solid #ccc;border-radius:6px;}
.App p.success {color:green;}
.App p.error {color:red;}
import React, { useState } from 'react';
import axios from 'axios';
import './App.css';
function App() {
const [email, setEmail] = useState('');
const [error, setError] = useState('');
const [isSubmitted, setSubmitted] = useState(false);
const [isProcessing, setProcessing] = useState(false);
defmodule HealthyskinWeb.Router do
use HealthyskinWeb, :router
pipeline :api do
plug :accepts, ["json"]
end
scope "/api", HealthyskinWeb do
pipe_through :api
defmodule HealthyskinWeb.SubscriptionController do
use HealthyskinWeb, :controller
def create(conn, %{"email" => email}) do
IO.inspect(email, label: "Email submitted")
send_resp(conn, 200, "")
end
end
# config/prod.exs - Remove cache_manifest
config :healthyskin, HealthyskinWeb.Endpoint, url: [host: "example.com", port: 80]
# lib/healthyskin_web/endpoint.ex - Instruct Plug.Static how to serve assets
plug Plug.Static,
at: "/",
from: "assets/build",
gzip: false,
defmodule HealthyskinWeb.PageController do
use HealthyskinWeb, :controller
plug :put_layout, false
def index(conn, _params) do
render(conn, "index.html")
end
end
defmodule HealthyskinWeb.PageView do
use HealthyskinWeb, :view
def render("index.html", _assigns) do
{:safe, File.read!("assets/build/index.html")}
end
end
# config/prod.exs - url builder options and `force_ssl` behind Heroku proxy
config :healthyskin, HealthyskinWeb.Endpoint,
url: [scheme: "https", host: "example.com", port: 443],
force_ssl: [rewrite_on: [:x_forwarded_proto]]
# config/prod.secret.exs - use secure database connection
config :healthyskin, Healthyskin.Repo,
ssl: true,