Skip to content

Instantly share code, notes, and snippets.

View farhad0085's full-sized avatar
🏠
Working from home

Farhad Hossain farhad0085

🏠
Working from home
  • Varsity Gate, Akhalia, Sylhet Sadar, Sylhet, Bangladesh
View GitHub Profile
@farhad0085
farhad0085 / steps.md
Last active May 13, 2025 13:10
Deploy Flask App to Pythonanywhere

Setting up Flask applications on PythonAnywhere

There are two main ways to set up a Flask application on PythonAnywhere:

  1. Starting from scratch using our default versions of Flask
  2. Importing a pre-existing app using Manual configuration, and using a virtualenv

The first option works well if you're just playing around and want to throw something together from scratch. Go to the Web Tab and hit Add a new Web App, and choose Flask and the Python version you want.

The second option is described in more detail below

@farhad0085
farhad0085 / createUUID.js
Last active November 3, 2020 17:01
Create Unique ID (Javascript)
function createUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r && 0x3 | 0x8);
return v.toString(16);
});
}
console.log(createUUID());
@farhad0085
farhad0085 / modal.html
Created August 26, 2020 22:14
Vertically centered modal - BS4
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
@farhad0085
farhad0085 / CSRF Token.js
Created September 4, 2020 11:48
Django form submission CSRF Token
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
@farhad0085
farhad0085 / navbar.html
Created September 4, 2020 17:25
Bootstrap 4 - Navbar
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
@farhad0085
farhad0085 / decorator.py
Created September 6, 2020 13:40
Python Decorator
def check_zero(my_func):
def wrapper_function(a, b):
if a == 0 or b == 0:
return "Either a or b is zero"
else:
return my_func(a, b)
return wrapper_function
@farhad0085
farhad0085 / Google Auth2.py
Created September 11, 2020 10:22
Google Auth2.py
import os
import flask
import requests
import google.oauth2.credentials
import google_auth_oauthlib.flow
import googleapiclient.discovery
# This variable specifies the name of a file that contains the OAuth 2.0
# information for this application, including its client_id and client_secret.
@farhad0085
farhad0085 / manage.py
Created September 17, 2020 12:28
Change django default port number
from django.core.management.commands.runserver import Command as runserver
runserver.default_port = 8001 # now django will run at port 8001 instead of 8000
@farhad0085
farhad0085 / Create Custom User Model along with custom manager.md
Last active December 11, 2020 18:35
Custom User Model along with custom manager

Create Custom User Model along with custom manager

Steps

  1. First create a new model
  2. Make a new manager for objects
  3. Change default auth model in settings
@farhad0085
farhad0085 / App.jsx
Created November 12, 2020 21:58
React Redux setup boilerplate
// src/App.jsx
import React, { Component } from 'react';
import { connect } from 'react-redux'
import Count from './components/Count';
import Controller from './components/Controller'
import { login, logout } from "./store/actions/authActions";