Skip to content

Instantly share code, notes, and snippets.

@PJUllrich
PJUllrich / big-o.md
Last active April 28, 2024 14:19
Big-O Time Complexities for Elixir Data Structures

Big-O Time Complexities for Elixir data structures

Map [1]

Operation Time Complexity
Access O(log n)
Search O(log n)
Insertion O(n) for <= 32 elements, O(log n) for > 32 elements [2]
Deletion O(n) for <= 32 elements, O(log n) for > 32 elements
@mindflayer
mindflayer / deploy.py
Last active November 26, 2021 10:20
Spawn a deploy for a DO Docker Registry image `tag` for a specific `app` on DigitalOcean App Platform
import argparse
import json
import os
import subprocess
ENCODING = "utf-8"
def check_output(cmd, split_lines=False):
@uobikiemukot
uobikiemukot / emoji.go
Created December 11, 2018 07:58
emoji and text renderer
package main
import (
"bufio"
"bytes"
"fmt"
"image"
"image/jpeg"
_ "image/png"
"io"
@miguelmota
miguelmota / rsa_util.go
Last active May 10, 2024 20:54
Golang RSA encrypt and decrypt example
package ciphers
import (
"crypto/rand"
"crypto/rsa"
"crypto/sha512"
"crypto/x509"
"encoding/pem"
"log"
)
@nikneroz
nikneroz / Guardian JWT.md
Last active October 10, 2023 19:13
Elixir + Phoenix Framework + Guardian + JWT. This is tutorial and step by step installation guide.

Elixir + Phoenix Framework + Guardian + JWT + Comeonin

Preparing environment

We need to generate secret key for development environment.

mix phoenix.gen.secret
# ednkXywWll1d2svDEpbA39R5kfkc9l96j0+u7A8MgKM+pbwbeDsuYB8MP2WUW1hf

Let's generate User model and controller.

@simonw
simonw / recover_source_code.md
Last active May 29, 2024 12:37
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@chalmagean
chalmagean / enc.ex
Last active July 30, 2021 18:42
RC4 encryption/decryption in Elixir/Erlang
# Install https://github.com/rubencaro/cipher first
require Cipher.Helpers, as: H
defmodule Enc do
@random_key H.env(:keyphrase) |> Cipher.Digest.generate_key
def stream_encrypt(xml) do
{_, result} =
:crypto.stream_init(:rc4, @random_key)
|> :crypto.stream_encrypt(xml)
@sid24rane
sid24rane / StackBalancedParenthesis.c
Created September 28, 2016 17:55
Balanced Parenthesis in C using stack
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#define MAX_SIZE 100
struct Stack{
int top;
char arr[MAX_SIZE];
} st;
@moeseth
moeseth / waveform.py
Created October 12, 2015 08:19
Create Soundcloud style waveform from Audio in Python
from pydub import AudioSegment
from matplotlib import pyplot as plot
from PIL import Image, ImageDraw
import numpy as np
import os
src = "./test.mp3"
audio = AudioSegment.from_file(src)
data = np.fromstring(audio._data, np.int16)
@sirex
sirex / main.py
Last active April 5, 2024 19:31
sqlalchemy joins with AS
import sqlalchemy as sa
import sqlparse
metadata = sa.MetaData()
tasks = sa.Table(
'tasks', metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('bot', sa.String(255), nullable=False),
sa.Column('task', sa.String(255), nullable=False),