Skip to content

Instantly share code, notes, and snippets.

View minlaxz's full-sized avatar
:octocat:
👻

Min Min Latt minlaxz

:octocat:
👻
View GitHub Profile
@minlaxz
minlaxz / middleware.py
Created October 7, 2022 08:01 — forked from rbtsolis/middleware.py
Django Access the Request or User Object Inside the Models and Signals
# 1) Create a middlewares/middlewares.py file and copy this:
import threading
class RequestMiddleware:
def __init__(self, get_response, thread_local=threading.local()):
self.get_response = get_response
self.thread_local = thread_local
# One-time configuration and initialization.
@minlaxz
minlaxz / docker-compose.advanced.yml
Created August 16, 2022 05:04 — forked from w33ble/docker-compose.advanced.yml
Using jwilder/nginx-proxy with multiple compose files
version: '3'
services:
nginx-proxy:
image: nginx:alpine
container_name: proxy-nginx
environment:
- DEFAULT_HOST=hello.local
ports:
- 80:80
"""
Django ORM Optimization Tips
Caveats:
* Only use optimizations that obfuscate the code if you need to.
* Not all of these tips are hard and fast rules.
* Use your judgement to determine what improvements are appropriate for your code.
"""
# ---------------------------------------------------------------------------
@minlaxz
minlaxz / multipleImageContentReader.js
Created February 20, 2022 11:11 — forked from resistancecanyon/multipleImageContentReader.js
Reading Multiple Image Base64 data using Es6 Async/Await in a html:type:file input
// html
// <input type="file" onchange="imagesSelected" multiple accept=".gif,.jpg,.jpeg,.png" />
async function imagesSelected(event) {
let files = [...event.target.files];
let images = await Promise.all(files.map(f=>{return readAsDataURL(f)}));
//all images' base64encoded data will be available as array in images
}
function readAsDataURL(file) {
@minlaxz
minlaxz / README.md
Created February 8, 2022 03:33 — forked from lucianoratamero/README.md
Using Vite with Django, the simple way

Using Vite with Django, the simple way

This gist has most of the things I've used to develop the frontend using vite inside a monolithic django app.

A couple of things to note:

  • it runs in SPA mode by default. If you want SSR, you may want to look into django_vite;
  • static files unrelated to your app, like images or fonts, should be served by django, instead of imported directly inside your frontend app;
  • you'll need to enable manifest in your vite configs for production;
  • I've only tested this with a React app, but I'll share my notes when testing with a Svelte app later.
@minlaxz
minlaxz / memorySizeOfObject.js
Created January 17, 2022 08:05
calculate memory size of javascript object, it is not a accurate value!
function memorySizeOf(obj) {
var bytes = 0;
function sizeOf(obj) {
if(obj !== null && obj !== undefined) {
switch(typeof obj) {
case 'number':
bytes += 8;
break;
case 'string':
@minlaxz
minlaxz / mro.py
Created December 22, 2021 03:18
Method resolution order in Python - MRO
class Base(object):
def __init__(self):
print("Base init'ed")
class ChildA(Base):
def __init__(self):
print("ChildA init'ed")
Base.__init__(self)
class ChildB(Base):
@minlaxz
minlaxz / CompletelyRemoveAFileFromGitHistory.md
Created November 12, 2021 15:12
Completely remove a file from Git history

I am removing .env file from local git history.

git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch .env" HEAD

To push this to remote,

git push --force

@minlaxz
minlaxz / clean-up-repo-size.md
Last active October 26, 2021 05:29
Cleaning up a git repo for reducing the repository size

Check git repo size : git count-objects -v

First checkout to the commit, which you want to make as the initial commit. Then run the following commands :

git checkout --orphan temp_branch
git add -A
git commit -am "Initial commit message"
git branch -D main
git branch -m main
@minlaxz
minlaxz / open_source_licenses.md
Created September 17, 2021 07:32 — forked from nicolasdao/open_source_licenses.md
What you need to know to choose an open source license.