Skip to content

Instantly share code, notes, and snippets.

View richardoey's full-sized avatar
🎯
Focusing

richardoey richardoey

🎯
Focusing
View GitHub Profile
async function f() {
const fsPromises = require('fs').promises;
const data = await fsPromises.readFile('/tmp/data.json')
.catch((err) => console.error('Error: ', err));
return JSON.parse(data.toString());
}
@richardoey
richardoey / vue.config.js
Created June 8, 2021 06:18
Proxy Vue JS to server
module.exports = {
devServer: {
proxy: {
'^/api': {
target: 'http://localhost:8000',
changeOrigin: true,
secure: false,
pathRewrite: {
'^/api': '/api'
},
@richardoey
richardoey / .gitignore
Created May 26, 2021 00:45 — forked from octocat/.gitignore
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@richardoey
richardoey / views.py
Created May 18, 2021 02:38
Django make aware datetime
d = datetime.datetime.now()
timezone = pytz.timezone("Asia/Taipei")
d_aware = timezone.localize(d)
@richardoey
richardoey / pipreqs.md
Created April 6, 2021 06:20
How to automatically install required packages from a python script as necessary?

How to automatically install required packages from a python script as necessary?

Based on here

Let's assume that your Python script is example.py:

import os
import time
import sys
import fnmatch
@richardoey
richardoey / COMMAND.md
Last active March 17, 2021 01:24
Getting branches to same level as master git command

If you want to make to be the same as master

git checkout development
git reset --hard master
git push -u origin <local-branch-name>

Force your forked repo to be the same as upstream. Forces master changes into fork and throws away all changes! if no upstream remote created: git remote add upstream https://[upstream guy's repo url]

@richardoey
richardoey / merge.md
Last active March 16, 2021 07:16
The best and safest way to merge branch in Git
git checkout master
git pull origin master
git merge test
git push origin master
@richardoey
richardoey / workflow.md
Created March 16, 2021 06:14
Workflow working while waiting for pending PR

Preferred workflow for this:

  1. On branch master, git checkout -b user_story_1.
  2. Make changes to user_story_1.
  3. Open PR for user_story_1.
  4. On branch user_story_1, git checkout -b user_story_2.
  5. Make changes to user_story_2.
  6. Once user_story_1 gets merged into master, switch to user_story_2 and do git rebase -i master.
  7. This should show you a list of commits on user_story_2 that you want to include in the rebase. Delete the top few commits that came from user_story_1.
  8. The rebase should complete cleanly unless master was updated with other changes. Now you have user_story_2 rebased on master and only having its commits.
@richardoey
richardoey / Delete Files when Deleting Models Django
Last active March 9, 2021 03:58
Django basically doesn't delete the associate file in the model you delete. In order to automatically delete all the file when model is delete, put below code inside the models.py.
from django.db.models.signals import post_delete, pre_save
from django.dispatch import receiver
from django.db import models
""" Whenever ANY model is deleted, if it has a file field on it, delete the associated file too"""
@receiver(post_delete)
def delete_files_when_row_deleted_from_db(sender, instance, **kwargs):
for field in sender._meta.concrete_fields:
if isinstance(field,models.FileField):
instance_file_field = getattr(instance,field.name)
@richardoey
richardoey / git-pushing-multiple.rst
Created February 23, 2021 05:39 — forked from rvl/git-pushing-multiple.rst
How to push to multiple git remotes at once. Useful if you keep mirrors of your repo.

Pushing to Multiple Git Repos

If a project has to have multiple git repos (e.g. Bitbucket and Github) then it's better that they remain in sync.

Usually this would involve pushing each branch to each repo in turn, but actually Git allows pushing to multiple repos in one go.

If in doubt about what git is doing when you run these commands, just