Skip to content

Instantly share code, notes, and snippets.

@bluzky
bluzky / request_helper.ex
Last active Jul 17, 2022
Elixir download/stream large file with hackney
View request_helper.ex
defmodule RequestHelper do
@moduledoc """
Reference from https://gist.github.com/avdi/7990684
Stream download large file from url
"""
require Logger
@doc """
Get stream data from url
mode could be `:binary` or `:line`
@arpitdsoni
arpitdsoni / PlaceHolderTextEditor.swift
Created Feb 22, 2021
SwiftUI TextEditor with placeholder and border.
View PlaceHolderTextEditor.swift
struct PlaceHolderTextEditor: View {
let placeholder: String
@Binding var text: String
var body: some View {
ZStack(alignment: Alignment(horizontal: .leading, vertical: .top)) {
if text.isEmpty {
Text(placeholder)
.foregroundColor(Color(.label))
.padding(.top, 10)
}
@andreaseriksson
andreaseriksson / _user_menu.html.eex
Created Jan 27, 2021
Use phoenix_live_session to communicate bewteen live views
View _user_menu.html.eex
<%= live_render @conn, EcommerceWeb.CartLive %>
@LordotU
LordotU / acme.json
Created Dec 20, 2019
Traefik 1.7.* as Reverse Proxy And Let's Encrypt
View acme.json
# This file should be empty and its permission should be 600
@christopherlai
christopherlai / Dockerfile
Created Sep 16, 2019
Example Dockerfile for Elixir 1.9.1 umbrella project
View Dockerfile
FROM elixir:1.9.1-alpine as build
ENV MIX_ENV=prod
WORKDIR /build
RUN apk add --no-cache build-base nodejs yarn && \
mix local.hex --force && \
mix local.rebar --force
View webpack.config.js
const path = require('path');
const glob = require('glob');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const css_loaders = [
@Kyle2142
Kyle2142 / Userbot admin scripts.md
Last active Jul 2, 2021
Some helper scripts that might be of use, for multi-userbot, multi-group administration
View Userbot admin scripts.md

All of these were created to work with multiple client situations, but you can easily pass [client] to work on one.

Note that in most cases, you will need to tweak the instructions (e.g. by adding exception handling) if the clients you run it on are not admins, or other things that happen in "less-than-perfect" situations

@anildigital
anildigital / dynamic_supervisor_example.ex
Created Feb 18, 2018
Simple Example for Dynamic Supervisor
View dynamic_supervisor_example.ex
defmodule Worker1 do
def start_link() do
Task.start_link(fn ->
Stream.repeatedly(fn -> :rand.uniform(1000) end)
|> Stream.each(&:timer.sleep/1)
|> Stream.each(fn _ -> IO.puts("worker 1") end)
|> Stream.run()
end)
end
end
@jswny
jswny / Flexible Dockerized Phoenix Deployments.md
Last active Aug 4, 2022
A guide to building and running zero-dependency Phoenix (Elixir) deployments with Docker. Works with Phoenix 1.2 and 1.3.
View Flexible Dockerized Phoenix Deployments.md

Prelude

I. Preface and Motivation

This guide was written because I don't particularly enjoy deploying Phoenix (or Elixir for that matter) applications. It's not easy. Primarily, I don't have a lot of money to spend on a nice, fancy VPS so compiling my Phoenix apps on my VPS often isn't an option. For that, we have Distillery releases. However, that requires me to either have a separate server for staging to use as a build server, or to keep a particular version of Erlang installed on my VPS, neither of which sound like great options to me and they all have the possibilities of version mismatches with ERTS. In addition to all this, theres a whole lot of configuration which needs to be done to setup a Phoenix app for deployment, and it's hard to remember.

For that reason, I wanted to use Docker so that all of my deployments would be automated and reproducable. In addition, Docker would allow me to have reproducable builds for my releases. I could build my releases on any machine that I wanted in a contai

View Dockerfile
FROM node
RUN mkdir -p /usr/src/app
COPY index.js /usr/src/app
EXPOSE 8080
CMD [ "node", "/usr/src/app/index" ]