Skip to content

Instantly share code, notes, and snippets.

View amos-kibet's full-sized avatar
💭
Nyiganet

Amos Kibet amos-kibet

💭
Nyiganet
View GitHub Profile
@amos-kibet
amos-kibet / instructions.md
Created September 12, 2024 12:53 — forked from wosephjeber/instructions.md
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
@amos-kibet
amos-kibet / testing-async-code
Created June 8, 2024 08:16
Testing async Elixir code
## Method 1 (from Dockyard's [blog post](https://dockyard.com/blog/2024/06/06/a-better-solution-for-waiting-for-async-tasks-in-tests))
Create a helper module, with this function:
```Elixir
def flush_task_supervisor do
pids = Task.Supervisor.children(MyApp.TaskSupervisor)
for pid <- pids do
ref = Process.monitor(pid)
@amos-kibet
amos-kibet / vs-code-settings-backup
Created September 12, 2023 03:47
VS Code Settings Backup
{
"workbench.iconTheme": "vscode-icons",
"editor.fontFamily": "Fira Code",
"editor.fontLigatures": true,
"workbench.colorCustomizations": {
"editorWhitespace.foreground": "#fbff00",
"workbench.colorTheme": "Monokai Vibrant",
"workbench.activityBar.visible": true,
"workbench.iconTheme": "vscode-icons"
},
@amos-kibet
amos-kibet / stripe-credit-card-numbers.md
Created May 29, 2023 14:17 — forked from rymawby/stripe-credit-card-numbers.md
Stripe test credit card numbers for use in development

#Test credit card numbers to use when developing with Stripe

4242424242424242 Visa

4012888888881881 Visa

4000056655665556 Visa (debit)

@amos-kibet
amos-kibet / default HTTP
Created November 8, 2022 11:33 — forked from iam-hussain/default HTTP
Serve nextJS app from a port through NGINX reverse proxy HTTP and HTTPS
# Serve nextJS app from a port through NGINX reverse proxy (HTTP)
# Path: /etc/nginx/sites-available/default
# Default server configuration for HTTP
server {
server_name www.DOMAINNAME.com DOMAINNAME.com;
# Serve any static assets with NGINX
location /_next/static {
alias /home/ubuntu/PROJECT_FOLDER/.next/static;
@amos-kibet
amos-kibet / nextjs-deploy.md
Created November 8, 2022 11:26 — forked from jjcodes78/nextjs-deploy.md
Deploying NEXTJS site with nginx + pm2

How to setup next.js app on nginx with letsencrypt

next.js, nginx, reverse-proxy, ssl

1. Install nginx and letsencrypt

$ sudo apt-get update
$ sudo apt-get install nginx letsencrypt

Also enable nginx in ufw

@amos-kibet
amos-kibet / mern-server-setup.md
Created November 7, 2022 15:22 — forked from sankaire/mern-server-setup.md
Setup Ubuntu & Deploy MERN app

Linux Server Setup & MERN App Deployment

These are the steps to setup an Ubuntu server from scratch and deploy a MERN app with the PM2 process manager and Nginx. We are using Linode, but you could just as well use a different cloud provider or your own machine or VM.

Create an account at Linode

Click on Create Linode

Choose your server options (OS, region, etc)

SSH Keys

@amos-kibet
amos-kibet / gist:f155814ef3ed2c8eb6fe8da7e3a9926a
Created August 12, 2022 06:56 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@amos-kibet
amos-kibet / randomizer.ex
Created July 29, 2022 07:20 — forked from ahmadshah/randomizer.ex
Random string in elixir
defmodule Randomizer do
@moduledoc """
Random string generator module.
"""
@doc """
Generate random string based on the given legth. It is also possible to generate certain type of randomise string using the options below:
* :all - generate alphanumeric random string
* :alpha - generate nom-numeric random string
@amos-kibet
amos-kibet / python_mysql.py
Created July 25, 2022 08:44 — forked from bradtraversy/python_mysql.py
Python & MySQL crash course for beginners
import mysql.connector
from mysql.connector import errorcode
config = {
'user': 'root',
'password': '',
'host': 'localhost',
'database': 'acme'
}