Skip to content

Instantly share code, notes, and snippets.

View remoharsono's full-sized avatar

Remo Harsono remoharsono

View GitHub Profile
@remoharsono
remoharsono / extend_user_model_using_OneToOneField.py
Created May 11, 2018 00:01 — forked from toransahu/extend_user_model_using_OneToOneField.py
Django | Extend User Model | Using a One-To-One Link | Profile
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
bio = models.TextField(max_length=500, blank=True)
location = models.CharField(max_length=30, blank=True)
birth_date = models.DateField(null=True, blank=True)
@remoharsono
remoharsono / ajax_setup.js
Created May 25, 2018 02:37 — forked from rca/ajax_setup.js
Setup Django CSRF token in JQuery AJAX requests
/**
* setup JQuery's AJAX methods to setup CSRF token in the request before sending it off.
* http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
*/
function getCookie(name)
{
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
@remoharsono
remoharsono / models.py
Created June 3, 2018 14:30 — forked from tinvaan/models.py
Code snippet to demonstrate how a Django model can be made immutable on certain condition. Hint : Override the save() method for the model in question.
from django.db import models
from django.utils import timezone
class Bank(models.Model):
bank_ifsc = models.CharField(max_length=200, blank=False, primary_key=True)
bank_name = models.CharField(max_length=200, blank=False)
bank_addr = models.CharField(max_length=400, blank=True)
def __str__(self):
@remoharsono
remoharsono / django.py
Created June 3, 2018 14:36 — forked from donrokzon/django.py
Django
mkdir tutorial
cd tutorial
# Create a virtualenv to isolate our package dependencies locally
virtualenv env
source env/bin/activate # On Windows use `env\Scripts\activate`
# Install Django and Django REST framework into the virtualenv
pip install django
pip install djangorestframework
@remoharsono
remoharsono / callback.html
Created June 7, 2018 17:44 — forked from amfeng/callback.html
Stripe OAuth Example -- Python
<!doctype html>
<head>
<title>Stripe OAuth Example</title>
</head>
<body>
{{ token }}
</body>
</html>
@remoharsono
remoharsono / index.php
Created June 7, 2018 17:46 — forked from amfeng/index.php
Stripe OAuth Example -- PHP
<?php
define('CLIENT_ID', 'YOUR_CLIENT_ID');
define('API_KEY', 'YOUR_API_KEY');
define('TOKEN_URI', 'https://connect.stripe.com/oauth/token');
define('AUTHORIZE_URI', 'https://connect.stripe.com/oauth/authorize');
if (isset($_GET['code'])) { // Redirect w/ code
$code = $_GET['code'];
@remoharsono
remoharsono / .gitconfig
Created June 10, 2018 12:49 — forked from pksunkara/config
Sample of git config file (Example .gitconfig)
[user]
name = Pavan Kumar Sunkara
email = pavan.sss1991@gmail.com
username = pksunkara
[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore
[sendemail]
smtpencryption = tls
@remoharsono
remoharsono / multi-git.md
Created June 10, 2018 12:50 — forked from rosswd/multi-git-win.md
Setting up a Github and Bitbucket account on the same computer.

Setting up github and bitbucket on the same computer

Github will be the main account and bitbucket the secondary.

Create SSH Keys

ssh-keygen -t rsa -C "github email"

Enter passphrase when prompted. If you see an option to save the passphrase in your keychain, do it for an easier life.

@remoharsono
remoharsono / cors-nginx.conf
Created June 26, 2018 03:42 — forked from michiel/cors-nginx.conf
Wide-open CORS config for nginx
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
@remoharsono
remoharsono / README-Template.md
Created July 1, 2018 15:48 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites