Skip to content

Instantly share code, notes, and snippets.

Alex Loukissas aloukissas

  • Los Angeles, CA
Block or report user

Report or block aloukissas

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View create_subscription_with_v2.ex
def create_subscription(email, plan_id, payment_method_id) do
with {:user_lookup, %User{customer_id: nil, name: name} = user} <-
{:user_lookup, Repo.get_by(User, email: email)},
{:customer_creation, {:ok, %Stripe.Customer{id: customer_id}}} <-
{:customer_creation,
Stripe.Customer.create(%{
name: name,
email: email,
payment_method: payment_method_id,
invoice_settings: %{
View create_subscription_with.ex
def create_subscription(email, plan_id, payment_method_id) do
with %User{customer_id: nil, name: name} = user <-
Repo.get_by(User, email: email),
{:ok, %Stripe.Customer{id: customer_id}} <-
Stripe.Customer.create(%{
name: name,
email: email,
payment_method: payment_method_id,
invoice_settings: %{
default_payment_method: payment_method_id
View create_subscription_nested.ex
def create_subscription(email, plan_id, payment_method_id) do
case Repo.get_by(User, email: email) do
%User{customer_id: nil, name: name} = user ->
params = %{
name: name,
email: email,
payment_method: payment_method_id,
invoice_settings: %{
default_payment_method: payment_method_id
}
View lookup_country.ex
iex(1)> Geolix.lookup("45.50.161.38", [as: :raw, where: :country])
%{
continent: %{
code: "NA",
geoname_id: 6255149,
names: %{
de: "Nordamerika",
en: "North America",
es: "Norteamérica",
fr: "Amérique du Nord",
View lookup_options.ex
iex(1)> Geolix.lookup("45.50.161.38", [as: :raw, where: :country])
%{
continent: %{
code: "NA",
geoname_id: 6255149,
names: %{
de: "Nordamerika",
en: "North America",
es: "Norteamérica",
fr: "Amérique du Nord",
View lookup_simple.ex
iex(1)> Geolix.lookup("45.50.161.38")
%{
city: %Geolix.Adapter.MMDB2.Result.City{
city: %Geolix.Adapter.MMDB2.Record.City{
geoname_id: 5368361,
name: "Los Angeles",
names: %{
de: "Los Angeles",
en: "Los Angeles",
es: "Los Ángeles",
View config.exs
config :geolix, :databases, [
%{
id: :city,
adapter: Geolix.Adapter.MMDB2,
source: "https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz"
},
%{
id: :country,
adapter: Geolix.Adapter.MMDB2,
source: "https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz"
View email_check.ex
defmodule Acme.Tasks.Email do
import Bamboo.Email
alias Acme.Models.User
def welcome_user(%User{first_name: first_name, email: email, state: "ACTIVE"})
when first_name != "" do
new_email(
to: {first_name, email},
from: {"Acme Products", "hello@acme.com"},
subject: "Welcome to Acme Products",
View email_basic.ex
defmodule Acme.Tasks.Email do
import Bamboo.Email
alias Acme.Models.User
def welcome_user(%User{first_name: first_name, email: email}) do
new_email(
to: {first_name, email},
from: {"Acme Products", "hello@acme.com"},
subject: "Welcome to Acme Products",
text_body: """
View email_test.exs
defmodule Acme.EmailTest do
use ExUnit.Case
alias Acme.Models.User
test "welcome email" do
user = %User{first_name: "John", email: "person@example.com"}
email = Acme.Email.welcome_user(user)
assert email.to == user
You can’t perform that action at this time.