Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Yongzhi Yang sgyyz

🎯
Focusing
Block or report user

Report or block sgyyz

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
@sgyyz
sgyyz / base_calculator.ex
Last active May 7, 2019
Elixir Abstract and Extends
View base_calculator.ex
defmodule BaseCalculator do
@moduledoc """
Define the base calculator and provide public API.
Define the callback to implement specific logic in child module.
"""
# it should be implemented by child module
@callback do_calculate(num1 :: Integer.t(), num2 :: Integer.t()) :: {:ok, Integer.t()} | {:error, any()}
defmacro __using__(_opts) do
View rel_config.ex
## ....
environment :prod do
set include_erts: true
set include_src: false
set cookie: :"8[^a{lsZs|em/)Xg^pI}m2hXlmbzuuioM|[6mB6Pbno9MFuzWCNN{9TvK}(%]D<S"
set vm_args: "rel/vm.args"
set pre_start_hooks: "rel/hooks/pre_start"
set post_start_hooks: "rel/hooks/post_start"
end
View dockerize_elixir_migrate_db.sh
#!/usr/bin/env bash
### Comment below block if it's a command ###
set +e
while true; do
nodetool ping
EXIT_CODE=$?
if [[ ${EXIT_CODE} -eq 0 ]]; then
echo "Application is up!"
View dockerize_elixir_create_db.sh
#!/usr/bin/env bash
echo "Running database creation"
bin/dockerize_elixir command Elixir.Release.Tasks create_db
echo "DB created successfully"
View release.ex
defmodule Release.Tasks do
@start_apps [
:postgrex,
:ecto,
:ecto_sql
]
@app_mods [
DockerizeElixir
]
View build_elixir_docker_image.sh
$ docker build --build-arg APP_NAME=dockerize_elixir --build-arg APP_VSN=0.1.0 --build-arg SKIP_PHOENIX=true -t app:0.1.0 .
View elixir_dockerfile
# The version of Alpine to use for the final image
# This should match the version of Alpine that the `elixir:1.7.2-alpine` image uses
ARG ALPINE_VERSION=3.8
FROM elixir:1.7.2-alpine AS builder
# The following are build arguments used to change variable parts of the image.
# The name of your application/release (required)
ARG APP_NAME
# The version of the application we are building (required)
View uao.sh
#!/bin/sh
fullFileName=$1
suffix=${fullFileName#*.}
if [ "$suffix" != "zip" ];then
echo "Must be a valid zip file"
else
filename=${fullFileName%.*}
@sgyyz
sgyyz / uao.md
Last active Sep 2, 2019
uao command - unzip your project and import to intellij automatically
View uao.md
  1. import project into idea command
$ curl -L "https://gist.githubusercontent.com/chrisdarroch/7018927/raw/9a6d663fd7a52aa76a943fe8a9bc6091ad06b18d/idea" -o /usr/local/bin/idea
$ chmod +x /usr/local/bin/idea
  1. unzip and open project command
$ curl -L "https://gist.githubusercontent.com/sgyyz/adfa4f05af3d81cf0e17e19cf7044c85/raw/b6b9e871d5a4f5435a09d00b0a52e3db0b90699a/uao.sh" -o /usr/local/bin/uao.sh
$ chmod +x /usr/local/bin/uao.sh
$ ln -sf /usr/local/bin/uao.sh /usr/local/bin/uao
@sgyyz
sgyyz / GreetingService.java
Created Feb 2, 2019
email-spring-boot-starter example
View GreetingService.java
public class GreetingService {
@Autowired
private EmailService emailService;
public void sendEmail() {
try {
Map<String, Object> ctx = ImmutableMap.of("name", "Mr. Smith");
emailService.sendHtmlMail("Sender <sender@somecompany.com>", "greeting", Locale.CHINESE, ctx, "Mr. Smith <smith@somedomain.com>");
} catch (MessagingException e) {
You can’t perform that action at this time.