Skip to content

Instantly share code, notes, and snippets.

View mraaroncruz's full-sized avatar
🏃‍♂️

Aaron Cruz mraaroncruz

🏃‍♂️
View GitHub Profile
@mraaroncruz
mraaroncruz / gce_auth.ex
Created November 7, 2017 13:44 — forked from plamb/gce_auth.ex
Authenticate with Google Cloud using service account json key and Elixir
# https://developers.google.com/identity/protocols/OAuth2ServiceAccount
key_json = File.read!("some-service-account-key-file.json")
key_map = JOSE.decode(key_json)
jwk = JOSE.JWK.from_pem(key_map["private_key"])
jws = %{"alg" => "RS256"}
header = %{
@mraaroncruz
mraaroncruz / jwtRS256.sh
Created November 10, 2017 16:10 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@mraaroncruz
mraaroncruz / ecto_batch_stream.ex
Created November 17, 2017 07:49 — forked from maxim/ecto_batch_stream.ex
Similar to Rails `find_each`, but for Elixir's Ecto, using Stream
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 # => […]
@mraaroncruz
mraaroncruz / page_controller.ex
Created November 17, 2017 08:14 — forked from bsuh/page_controller.ex
proxying responses
defmodule PhoenixTest.PageController do
use PhoenixTest.Web, :controller
def index(conn, _params) do
render conn, "index.html"
end
def proxy(conn, params) do
query_string = conn.query_string
path = Enum.join(params["path"], "/")
@mraaroncruz
mraaroncruz / circle.yml
Created December 1, 2017 12:35 — forked from tompesman/circle.yml
CicleCI config for Elixir with Phoenix Framework and deployment to Heroku
machine:
node:
version: 6.2.0
environment:
PATH: "$HOME/.asdf/bin:$HOME/.asdf/shims:$PATH"
MIX_ENV: "test"
services:
- postgresql
database:
@mraaroncruz
mraaroncruz / crawl.rake
Created December 9, 2017 21:42 — forked from tansengming/crawl.rake
Rake task to crawl you rails app for broken links
# Use this to look for broken links in your app.
# crawls the development server http://localhost:3000
# Suggestion: Also check to make sure that intentional 404s
# are handled gracefully by app.
task :crawl => :environment do
require 'anemone'
root = 'http://localhost:3000'
options = {:discard_page_bodies => true, :verbose => true}
@mraaroncruz
mraaroncruz / cmd.sh
Created December 30, 2017 10:42 — forked from kelvinn/cmd.sh
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
@mraaroncruz
mraaroncruz / ethminer_ubuntu_nvidia.md
Created January 10, 2018 11:16 — forked from johnstcn/ethminer_ubuntu_nvidia.md
NVIDIA/CUDA ethminer setup under Ubuntu Server 16.04

Headless Ethminer (nVidia) Setup Guide

Cian Johnston, July 2017

A couple of weeks ago, I decided I should put my gaming rig to work crypto mining. I did not expect to make any significant profit on this, it was more of a fun project to set up. However, there were a large number of tutorials and guides already out there, and many were more than a year out of date.

This guide assumes the reader already has a crypto wallet set up, is comfortable with Linux and the command line, and knows how to use Google if they run into problems.

The end result is an Ubuntu 16.04 LTS headless server running CUDA ethminer via systemd.

Hardware

@mraaroncruz
mraaroncruz / autossh.service
Created January 25, 2018 21:03 — forked from thomasfr/autossh.service
Systemd service for autossh
[Unit]
Description=Keeps a tunnel to 'remote.example.com' open
After=network.target
[Service]
User=autossh
# -p [PORT]
# -l [user]
# -M 0 --> no monitoring
# -N Just open the connection and do nothing (not interactive)
@mraaroncruz
mraaroncruz / README-setup-tunnel-as-systemd-service.md
Created February 2, 2018 14:47 — forked from drmalex07/README-setup-tunnel-as-systemd-service.md
Setup a secure (SSH) tunnel as a systemd service. #systemd #ssh #ssh-tunnel #ssh-forward

README

Create a template service file at /etc/systemd/system/secure-tunnel@.service. The template parameter will correspond to the name of target host:

[Unit]
Description=Setup a secure tunnel to %I
After=network.target