Skip to content

Instantly share code, notes, and snippets.

@tony612
tony612 / _service.md
Created July 2, 2018 13:27 — forked from naholyr/_service.md
Sample /etc/init.d script

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@tony612
tony612 / subnet_calculator.rb
Last active June 26, 2018 11:00
subnet calculator
# https://github.com/ipaddress-gem/ipaddress
require 'ipaddress'
class Calculator
def self.run(top, parts: nil, prefixes: nil)
top = IPAddress(top)
subnets = by_parts(top, parts) if parts
subnets = by_prefixes(top, prefixes) if prefixes
subnets
end
@tony612
tony612 / sentry_interceptor.ex
Created May 20, 2018 09:33
sentry interceptor for grpc-elixir
defmodule GRPCSentry.ServerInterceptor do
@behaviour GRPC.ServerInterceptor
def init(opts), do: opts
def call(req, stream, next, _opts) do
result = next.(req, stream)
case result do
@tony612
tony612 / interop-test-descriptions.md
Created March 18, 2018 10:01
grpc interop test doc
@tony612
tony612 / diff.ex
Created January 27, 2018 12:34
elixir diff(extracted from ExUnit code)
defmodule Diff do
def diff(left, right, %{diff_type: :cli} = config) do
# %{enabled: true}
Diff.Cli.diff(left, right, config)
end
def format_sides(left, right, formatter) do
case format_diff(left, right, formatter) do
{left, right} ->
{IO.iodata_to_binary(left), IO.iodata_to_binary(right)}
@tony612
tony612 / install.sh
Last active December 1, 2018 17:58
Install Elixir/Erlang in 20 seconds in China
# 1.4 on ubuntu 14.04
wget https://mirrors.tuna.tsinghua.edu.cn/erlang-solutions/ubuntu/pool/esl-erlang_19.2-1~ubuntu~trusty_amd64.deb
sudo dpkg -i esl-erlang_19.2-1~ubuntu~trusty_amd64.deb
sudo apt-get -f -y install
sudo dpkg -i esl-erlang_19.2-1~ubuntu~trusty_amd64.deb
wget https://mirrors.tuna.tsinghua.edu.cn/erlang-solutions/ubuntu/pool/elixir_1.4.1-1~ubuntu~trusty_all.deb
sudo dpkg -i elixir_1.4.1-1~ubuntu~trusty_all.deb
elixir -v
# 1.5 on ubuntu 14.04
@tony612
tony612 / Dockerfile
Last active November 22, 2017 12:12
The right way to use Elixir+Docker in China
# git clone https://github.com/hexpm/hex.git
# cd hex
# git checkout v0.15.0
# # Add this Dockerfile in the dir
# docker build .
# # Then you can use the image as your base image to speedup your usage
FROM elixir:1.5.2
RUN HEX_MIRROR=https://hexpm.upyun.com mix local.rebar --force \
# rebar3 update should be rerun if you add a new rebar dependence
@tony612
tony612 / readme.md
Created May 27, 2017 04:02 — forked from jobsamuel/readme.md
Run NodeJS as a Service on Ubuntu 14.04 LTS

Run NodeJS as a Service on Ubuntu 14.04 LTS

With Node you can write very fast JavaScript programs serverside. It's pretty easy to install Node, code your program, and run it. But > how do you make it run nicely in the background like a true server?

  • Go to /etc/init/
  • $ sudo vim yourapp.conf
  • Paste script.conf
  • $ sudo start yourapp
  • And when you wanna kill the process $ sudo stop yourapp
defmodule FSM do
defmacro __using__(opts) do
quote do
import FSM.DSL, only: [trans: 3]
Module.register_attribute(__MODULE__, :events, accumulate: true)
@before_compile FSM.DSL
end
end
end
sysctl -w fs.file-max=12000500
sysctl -w fs.nr_open=20000500
ulimit -n 4000000
sysctl -w net.ipv4.tcp_mem='10000000 10000000 10000000'
sysctl -w net.ipv4.tcp_rmem='1024 4096 16384'
sysctl -w net.ipv4.tcp_wmem='1024 4096 16384'
sysctl -w net.core.rmem_max=16384
sysctl -w net.core.wmem_max=16384
wget http://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
sudo dpkg -i erlang-solutions_1.0_all.deb