Skip to content

Instantly share code, notes, and snippets.

View paveltyk's full-sized avatar

Pavel Tsiukhtsiayeu paveltyk

  • BILL
  • North Carolina, US
  • 17:20 (UTC -04:00)
View GitHub Profile
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
defmodule HealthyskinWeb.Router do
use HealthyskinWeb, :router
pipeline :api do
plug :accepts, ["json"]
end
scope "/api", HealthyskinWeb do
pipe_through :api
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);
.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;}
@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",
@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 / mock_geocoder.rb
Created October 10, 2011 14:48
Geocoder: Stub out address geocoding during RSpec unit tests
# In spec_helper:
# RSpec.configure do |config|
# ...
# config.include(MockGeocoder)
# end
#
# In your tests:
# it 'mock geocoding' do
# mock_geocoding! # You may pass additional params to override defaults (i.e. :coordinates => [10, 20])
# address = Factory(:address)
@paveltyk
paveltyk / hide_confirmation.jquey.js
Created July 27, 2011 19:16
jQuery plugin to auto show/hide confirmation field
/*!
* jQuery HideConfirmation Plugin
* version: 1.0 (27-JUL-2011)
* created by: PavelTyk https://github.com/PavelTyk
*
* This is a simple plugin to automatically hide confirmation fields if
* no changes made to observed field.
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
@paveltyk
paveltyk / attachment_fu.rake
Created June 23, 2011 22:56
Ever needed to refresh (regenerate, update) attachment_fu attachments on amazon-s3? Here you go!
def logger
@logger_for_attachment_fu_rake_task ||= Logger.new STDOUT
end
def raise_with_logger(msg)
logger.error msg
raise msg
end
def obtain_class
@paveltyk
paveltyk / gist:1002213
Created June 1, 2011 12:41
My solution to highlight correct menu item (using simple_navigation gem), when :create action fails
# In config/simple_navigation.rb
require 'simple_navigation/rails_controller_methods'
ActionController::Base.class_eval do
def self.disable_navigation_auto_highlighting(*args)
around_filter :temporary_disable_simple_navigation_auto_highlighting, *args
end
def temporary_disable_simple_navigation_auto_highlighting
auto_highlight = SimpleNavigation::Configuration.instance.auto_highlight