Skip to content

Instantly share code, notes, and snippets.

View tmjoen's full-sized avatar
🔥

T. Mjoen tmjoen

🔥
  • Bielke&Yang
  • Oslo, Norway
View GitHub Profile
@ckoch-cars
ckoch-cars / gist:15a88fcb0bc2f4abbed09b49879edf31
Last active February 9, 2025 02:06
Erlang ssh connect with SSH key
# Specifically we are trying to do 2 things with the erlang `:ssh` module:
# Make a connection (use :ssh.connect/4`) and pass in the ssh key from something other than a file on disk
# And then with an open connection, bind the connection to a local port (i.e. setup a ssh tunnel)
# use :ssh.tcpip_tunnel_to_server/5 or :ssh.tcpip_tunnel_to_server/6
# Example (working) code:
defmodule SSHTunnel do
@local_port 9999
@remote_port 1234
@cpursley
cpursley / postgres_hybrid_search.ex
Last active July 13, 2024 08:37
Postgres Hybrid Search
See: https://github.com/cpursley/vecto
@LostKobrakai
LostKobrakai / form_live.ex
Last active April 16, 2025 10:08
Phoenix LiveView form with nested embeds and add/delete buttons
defmodule NestedWeb.FormLive do
use NestedWeb, :live_view
require Logger
defmodule Form do
use Ecto.Schema
import Ecto.Changeset
embedded_schema do
field :name, :string
@angelikatyborska
angelikatyborska / gettext_test.exs
Last active January 16, 2022 16:24
A unit test for Gettext translations that checks if the original and the translation use the same HTML tags. Uses Floki to parse HTML.
defmodule MyAppWeb.GettextTest do
use ExUnit.Case
import MyAppWeb.Gettext
# A unit test for Gettext translations that checks if the original and the translation
# use the same HTML tags.
#
# Uses Floki to parse HTML.
describe "translations" do
@danielstgt
danielstgt / imagick3.4.4-PHP7.4-forge.sh
Last active April 19, 2024 11:33
Install ImageMagick / Imagick 3.4.4 on PHP 7.4 server (Laravel Forge)
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
apt-get install pkg-config libmagickwand-dev -y
cd /tmp
wget https://pecl.php.net/get/imagick-3.4.4.tgz
tar xvzf imagick-3.4.4.tgz
@tomhicks
tomhicks / plink-plonk.js
Last active November 12, 2024 19:08
Listen to your web pages
@lizthegrey
lizthegrey / attributes.rb
Last active March 27, 2025 02:16
Hardening SSH with 2fa
default['sshd']['sshd_config']['AuthenticationMethods'] = 'publickey,keyboard-interactive:pam'
default['sshd']['sshd_config']['ChallengeResponseAuthentication'] = 'yes'
default['sshd']['sshd_config']['PasswordAuthentication'] = 'no'
@JobLeonard
JobLeonard / merge.js
Last active September 26, 2017 22:30
A dumb merge function for updating simple state trees in redux
/**
* Returns a new object that merges the values of
* `newObj` into `oldObj`. Uses shallow copying.
*
* **WARNING: Do NOT pass cyclical objects!
* This includes React nodes!**
*
* **IMPORTANT:** util.merge does **NOT** behave like
* lodash merge! *TL;DR:* (typed) arrays are not merged
* but replaced by the newer array.
@bsedat
bsedat / Dockerfile
Last active August 8, 2023 05:56
Elixir Phoenix Umbrella App + Distillery Multistage Docker Build
FROM elixir:1.4.5 as asset-builder-mix-getter
ENV HOME=/opt/app
RUN mix do local.hex --force, local.rebar --force
# Cache elixir deps
COPY config/ $HOME/config/
COPY mix.exs mix.lock $HOME/
COPY apps/myproject_web/mix.exs $HOME/apps/myproject_web/
COPY apps/myproject_web/config/ $HOME/apps/myproject_web/config/
@mmmries
mmmries / 01.README.md
Last active November 11, 2022 16:59
Load Test Phoenix Presence

Phoenix Nodes

First I created 3 droplets on digital ocean with 4-cores and 8GB of RAM. Login as root to each and run:

sysctl -w fs.file-max=12000500
sysctl -w fs.nr_open=20000500
ulimit -n 4000000
sysctl -w net.ipv4.tcp_mem='10000000 10000000 10000000'