Skip to content

Instantly share code, notes, and snippets.

View pplonski's full-sized avatar
😄
Enjoy programming and writing

Piotr pplonski

😄
Enjoy programming and writing
View GitHub Profile
@pplonski
pplonski / dashboard_mercury.ipynb
Created February 26, 2022 14:14
Dashboard Notebook with Mercury
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rmiyazaki6499
rmiyazaki6499 / deploy-django.md
Last active April 27, 2024 15:48
Deploying a Production ready Django app on AWS

Deploying a Production ready Django app on AWS

In this tutorial, I will be going over to how to deploy a Django app from start to finish using AWS and EC2. Recently, my partner Tu and I launched our app Hygge Homes (a vacation home rental app for searching and booking vacation homes based off Airbnb) and we wanted to share with other developers some of the lessons we learned along the way.

Following this tutorial, you will have an application that has:

  • An AWS EC2 server configured to host your application
  • SSL-certification with Certbot
  • A custom domain name
  • Continuous deployment with Github Actions/SSM Agent
import numpy as np
import pandas as pd
from sqlalchemy import create_engine
import psycopg2
import time
host = "host-address-here"
user = "db-user-here"
password = "db-password"
db = "db-name"
@pplonski
pplonski / read_only_user_in_postgres.sql
Created March 4, 2019 10:42
Read only user in postgres database
-- create a group
CREATE ROLE readaccess;
-- grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
import openml
import pandas as pd
openml.config.apikey = "aaas8a89sd87as87d8as7d98a" # it is some fake API key, please set your key here!
dataset_id = 1590 # Adults data set, see https://www.openml.org/d/1590
# get data directly fom openml
dataset = openml.datasets.get_dataset(dataset_id)
(X, y, categorical, names) = dataset.get_data(
@yangshun
yangshun / docusaurus-copy-button.md
Last active April 4, 2023 07:07
How to add the "Copy" button to code blocks in Docusaurus

Adding "Copy" (to Clipboard) Button

If you would like to add a button to your fenced code blocks so that users may copy the code, you can do so in Docusaurus. You will have to add some code to your Docusaurus project, as seen below.

Under static/js, create a file called code-block-buttons.js with the following:

// Turn off ESLint for this file because it's sent down to users as-is.
/* eslint-disable */
window.addEventListener('load', function() {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@korakot
korakot / js_link.py
Created August 6, 2018 04:38
Calling python function from JS in Colab
@rluts
rluts / token_auth.py
Last active October 13, 2023 20:56
Token authorization middleware for Django Channels 2
from channels.auth import AuthMiddlewareStack
from rest_framework.authtoken.models import Token
from django.contrib.auth.models import AnonymousUser
from django.db import close_old_connections
class TokenAuthMiddleware:
"""
Token authorization middleware for Django Channels 2
"""
@fodra
fodra / electron-packager-extra-resource.md
Created December 18, 2017 06:29
Command to add extra resources in your electron app

This is the example usage of electron-packager that I never found online anywhere else.

To add resource.exe and resource2.dll in the resource folder when you create an installer, this is how you do it with the --extra-resource commandline switch.

--extra-resource

electron-packager . --overwrite --asar --extra-resource="resource1.exe" --extra-resource="resource2.dll" --platform=win32 --arch=ia32 --icon=./frontend/dist/assets/icon.ico --prune=true --out=./build --version-string.ProductName='Hot Pan de sal'

within the backend code you can refer to the files as: