Skip to content

Instantly share code, notes, and snippets.

🚀

Marcos Benatti Lauer mbenatti

🚀
Block or report user

Report or block mbenatti

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
@mbenatti
mbenatti / ecto_batch_stream.ex
Created Jan 24, 2020 — forked from maxim/ecto_batch_stream.ex
Similar to Rails `find_each`, but for Elixir's Ecto, using Stream
View ecto_batch_stream.ex
defmodule EctoBatchStream do
import Ecto.Query, only: [from: 1, from: 2]
@batch_size 1000
# Example:
#
# query = from u in MyApp.User, select: u.email
# stream = EctoBatchStream.stream(MyApp.Repo, query)
# stream |> Stream.take(3) |> Enum.to_list # => […]
View postgres_queries_and_commands.sql
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
View global-gitignore.md

There are certain files created by particular editors, IDEs, operating systems, etc., that do not belong in a repository. But adding system-specific files to the repo's .gitignore is considered a poor practice. This file should only exclude files and directories that are a part of the package that should not be versioned (such as the node_modules directory) as well as files that are generated (and regenerated) as artifacts of a build process.

All other files should be in your own global gitignore file. Create a file called .gitignore in your home directory and add anything you want to ignore. You then need to tell git where your global gitignore file is.

Mac

git config --global core.excludesfile ~/.gitignore

Windows

git config --global core.excludesfile %USERPROFILE%\.gitignore
@mbenatti
mbenatti / game.ex
Created Dec 1, 2018 — forked from andrewhao/game.ex
Dynamic Supervisors in Elixir
View game.ex
defmodule Game do
use GenServer
def init(game_id) do
{:ok, %{game_id: game_id}}
end
def start_link(game_id) do
GenServer.start_link(__MODULE__, game_id, name: {:global, "game:#{game_id}"})
end
View flatten.exs
defmodule ListFlatten do
def flatten(list), do: flatten(list, []) |> Enum.reverse
def flatten([h | t], acc) when h == [], do: flatten(t, acc)
def flatten([h | t], acc) when is_list(h), do: flatten(t, flatten(h, acc))
def flatten([h | t], acc), do: flatten(t, [h | acc])
def flatten([], acc), do: acc
end
list_1 = [[1,2,[3]],4]
list_2 = [[1,5,[3]],4,[[[1,2,[3]],4]]]
@mbenatti
mbenatti / up-and-running-with-edeliver-on-do.md
Created Feb 20, 2018 — forked from mattweldon/up-and-running-with-edeliver-on-do.md
Getting Elixir / Phoenix running on Digital Ocean with edeliver
View up-and-running-with-edeliver-on-do.md

Build Server

  • Go to Digital Ocean
  • Create new droplet
  • London
  • Ubuntu
  • No apps
  • Add SSH keys
@mbenatti
mbenatti / task1.exs
Created Nov 29, 2017 — forked from moklett/task1.exs
Elixir Task - Crash Handling
View task1.exs
# This demonstrates that, when using async/await, a crash in the task will crash the caller
defmodule Tasker do
def good(message) do
IO.puts message
end
def bad(message) do
IO.puts message
raise "I'm BAD!"
end
@mbenatti
mbenatti / install.sh
Created Oct 7, 2017 — forked from djudd/install.sh
Install Poppler from source on Heroku
View install.sh
cd /app/
wget http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.10.91.tar.gz
cd fontconfig-2.10.91
tar -xzf fontconfig-2.10.91.tar.gz
./configure
make
cd /app/
wget http://poppler.freedesktop.org/poppler-0.22.1.tar.gz
tar -xzf poppler-0.22.1.tar.gz
@mbenatti
mbenatti / vpn-auto-reconnect.sh
Created Aug 1, 2017 — forked from numericOverflow/vpn-auto-reconnect.sh
Auto reconnect to OpenVPN via NetworkManager
View vpn-auto-reconnect.sh
#!/bin/bash +x
# Source: http://www.gabsoftware.com/tips/automatically-reconnect-to-your-vpn-on-linux/
# Description:
# Make the script executable "chmod +x /path/to/the/script.sh
# Put the script in .profile or .bashrc so it can be run on user login:
# Example: echo "/path/to/the/script.sh start &" >> .bashrc
# The script can be bound to shortcut keys with these commands:
# /path/to/the/script.sh start # starts and monitors VPN connection
@mbenatti
mbenatti / install-opencv-2.4.13-in-ubuntu.sh
Last active Jul 4, 2017 — forked from arthurbeggs/install_opencv2_ubuntu.sh
Install opencv-2.4.13 in Ubuntu 16.04/Mint 18.1
View install-opencv-2.4.13-in-ubuntu.sh
# install dependencies
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y cmake
sudo apt-get install -y libgtk2.0-dev
sudo apt-get install -y pkg-config
sudo apt-get install -y python-numpy python-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev
You can’t perform that action at this time.