Skip to content

Instantly share code, notes, and snippets.

Lawrence Nara nara-l

Block or report user

Report or block nara-l

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nara-l
nara-l / basic.md
Created Mar 31, 2019 — forked from zenorocha/basic.md
New Firebase Auth vs Old Firebase Auth
View basic.md
@nara-l
nara-l / markdown-cheatsheet.md
Created Mar 29, 2019 — forked from jonschlinkert/markdown-cheatsheet.md
A better markdown cheatsheet.
View markdown-cheatsheet.md
View gist:28f1fd00af9e03b550102285794475c4

SHORTCUTS

Key/Command Description
Tab Auto-complete files and folder names
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + U Clear the line before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + W Delete the word before the cursor
Ctrl + T Swap the last two characters before the cursor
@nara-l
nara-l / add_to_git_ignore_after_uploading
Created Feb 7, 2019
Add files to gitignore even after uploading to github
View add_to_git_ignore_after_uploading
a. git rm -r --cached . # unstage all files on your local machine
b. add the said files to gitignore
c. git add . # add all files again
d. commit and push again or rebase. use rebase guide
@nara-l
nara-l / name_migration_files
Created Nov 30, 2018
Name django migration files
View name_migration_files
# To add a name to migration files rather than 001_auto_20189084774
python manage.py makemigrations --name DESIRED_NAME appName
# e.g. if app name is `site` and you want to name migration, `new_side_bar`
python manage.py makemigrations --name new_side_bar site
@nara-l
nara-l / get_model_object_django
Last active Nov 1, 2018
How to get a model object from instance in Django
View get_model_object_django
# Sometimes you need to determine a model name from an object, before using
# First long approach may work in every version of Django? not tested
import sys
model_obj # let model_obj be the model object ( instance) from some input
model_name_str = type(model_obj).__name__ # this is model name as string, but we need the object to do the
model_object = getattr(sys.modules[__name__], model_name_str)
# now we can use model object normally
@nara-l
nara-l / reverse_lookup_django
Created Oct 25, 2018
Django What is reverse relationship?
View reverse_lookup_django
`class Blog(models.Model):
#some attributes
class Entry(models.Model):
blog = models.ForeignKey(Group, related_name='entries') . # this is a ForeignKey relationship, not a OneToOneField
#more attributes
`
@nara-l
nara-l / Heroku_Monthly_Scheduler
Created Sep 26, 2018
Heroku Monthly Scheduler
View Heroku_Monthly_Scheduler
# funny thing Heroku scheduler has no way of running a task monthly easily, one has to use a command like this:
if [ "$(date +%d)" = 01 ]; then MY_COMMAND; fi
# Run task every monday
if [ "$(date +%u)" = 1 ]; then MY_COMMAND; fi
# Run task every 24th of the year
if [ "$(date +%m)" = 12 ] && [ "$(date +%d)" = 24 ]; then MY_COMMAND; fi
@nara-l
nara-l / Fixtures - with Tenant Command Django
Created Sep 20, 2018
Django Fixtures for with tenant_command
View Fixtures - with Tenant Command Django
python manage.py tenant_command dumpdata --schema="schema-name" app.personalitytypes > app/fixtures/data.json
# 'app' and 'schema-name' to be replaced with necessary variables
@nara-l
nara-l / gist:2dcd9c569d0ca484a64db24d0c38e6ea
Created Aug 28, 2018
Tenary Operator Python 2.7 ( since 2.5 )
View gist:2dcd9c569d0ca484a64db24d0c38e6ea
# tenary opeartor
foo = test? True: False
# python equivalent with if else on same line
foo = "True" if test else "False"
You can’t perform that action at this time.