Skip to content

Instantly share code, notes, and snippets.

View westmark's full-sized avatar

Fredrik Westmark westmark

View GitHub Profile
@randycoulman
randycoulman / recompile_elixir_ls.md
Last active August 22, 2023 20:50
Recompiling ElixirLS

When ElixirLS is compiled with a different version of Elixir/Erlang than we use in our projects, it is unable to show pop-up documentation and auto-completion for certain constructs (like imports or requires done by a using block).

To check if you have a version mismatch, you can scroll to the top of the output pane for ElixirLS (VSCode View -> Output, then select ElixirLS from the dropdown list).

ElixirLS v0.13.0 and Later

In v0.13.0, vscode-elixir-ls added the ability to override the default elixirLS release path in config. This allows us to recompile elixirLS with whichever versions of Elixir and Erlang we like and then tell the extension to use that version. It should even be possible to compile with multiple different Elixir/Erlang combinations and use different versions in different projects, though I haven't tried that yet.

Here's how to do this:

@zblanco
zblanco / getting_lazy_with_dataflow_graphs_in_elixir.livemd
Last active August 29, 2024 02:59
Getting Lazy with Dataflow Graphs in Elixir

Getting Lazy with Dataflow Graphs in Elixir

Intro

What do Tensorflow, Apache Airflow, Rule Engines, and Excel have in common?

Under the hood they all use DAGs to model data-flow dependencies of the program. Using graphs to model programs is great because you can modify the program at runtime. Lets talk about doing this in Elixir for great good.

@jumpeiMano
jumpeiMano / bastion-stack.ts
Last active June 23, 2020 20:12
Create a bastion instance via CDK
import cdk = require("@aws-cdk/core");
import ec2 = require("@aws-cdk/aws-ec2");
import iam = require("@aws-cdk/aws-iam");
export class BastionStack extends cdk.Stack {
constructor(app: cdk.App, id: string, props?: cdk.StackProps) {
super(app, id, props);
const vpc = new ec2.Vpc(this, "vpc", {
cidr: "10.0.0.0/16",
@carterbryden
carterbryden / AddPostgresTriggerAndFunctionForAllTables.exs
Last active August 30, 2024 19:17
Elixir Phoenix Postgresql migration to add triggers for pubsub to run on every CRUD operation on every table. If a new table is added, it'll automatically add a trigger to that table too.
defmodule MyApp.Repo.Migrations.AddPostgresTriggerAndFunctionForAllTables do
use Ecto.Migration
def up do
# Create a function that broadcasts row changes
execute "
CREATE OR REPLACE FUNCTION broadcast_changes()
RETURNS trigger AS $$
DECLARE
current_row RECORD;
@wosephjeber
wosephjeber / instructions.md
Last active November 15, 2024 14:45
Ecto migration for renaming table with indexes and constraints

Renaming table in Ecto migration

I recently wanted to rename a model and its postgres table in a Phoenix app. Renaming the table was simple and documented, but the table also had constraints, sequences, and indexes that needed to be updated in order for the Ecto model to be able to rely on default naming conventions. I couldn't find any examples of what this would look like but was eventually able to figure it out. For anyone else in the same situation, hopefully this example helps.

In the example below, I'm renaming the Permission model to Membership. This model belongs to a User and an Account, so it has foreign key constraints that need to be renamed.

defmodule MyApp.Repo.Migrations.RenamePermissionsToMemberships do
  use Ecto.Migration
@kyranjamie
kyranjamie / countries.enum.ts
Last active April 28, 2024 09:30
TypeScript enum Country Codes ISO 3166
export enum Country {
Afghanistan = 'AF',
AlandIslands = 'AX',
Albania = 'AL',
Algeria = 'DZ',
AmericanSamoa = 'AS',
Andorra = 'AD',
Angola = 'AO',
Anguilla = 'AI',
Antarctica = 'AQ',
@andykingking
andykingking / coin.ex
Last active October 23, 2024 19:10
Using structs with Access behaviour
# An example struct.
defmodule Coin do
# Using Kernel.put_in/3 and other methods requires the target to have the Access behaviour.
@behaviour Access
# Structs by default do not implement this. It's easy to delegate this to the Map implementation however.
defdelegate get(coin, key, default), to: Map
defdelegate fetch(coin, key), to: Map
defdelegate get_and_update(coin, key, func), to: Map
defdelegate pop(coin, key), to: Map
@clemlatz
clemlatz / self-signed-ssl-certificate.md
Last active April 22, 2024 12:30
Setup a self-signed SSL certificate with Nginx (server and browser)

1. Configure server: Nginx

Create the certificate:

$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt

Create a strong Diffie-Hellman group:

$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
@jamesmacwhite
jamesmacwhite / ffmpeg_mkv_mp4_conversion.md
Last active November 11, 2024 21:28
Easy way to convert MKV to MP4 with ffmpeg

Converting mkv to mp4 with ffmpeg

Essentially just copy the existing video and audio stream as is into a new container, no funny business!

The easiest way to "convert" MKV to MP4, is to copy the existing video and audio streams and place them into a new container. This avoids any encoding task and hence no quality will be lost, it is also a fairly quick process and requires very little CPU power. The main factor is disk read/write speed.

With ffmpeg this can be achieved with -c copy. Older examples may use -vcodec copy -acodec copy which does the same thing.

These examples assume ffmpeg is in your PATH. If not just substitute with the full path to your ffmpeg binary.

Single file conversion example

@rudijs
rudijs / gulpfile.js
Last active December 1, 2023 08:20
GulpJS Jshint with Notify on Error
var gulp = require('gulp'),
watch = require('gulp-watch'),
// This will keeps pipes working after error event
plumber = require('gulp-plumber'),
// linting
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),