Skip to content

Instantly share code, notes, and snippets.

View sarojbelbase's full-sized avatar
💻
alias yeet 'rm -rf'

Saroj Belbase sarojbelbase

💻
alias yeet 'rm -rf'
View GitHub Profile
@sarojbelbase
sarojbelbase / toggler.js
Last active November 20, 2020 13:12
VanillaJs way of toggling with font awesome bars and close icons
var $ = function (selector, parent) {
return (parent ? parent : document).querySelector(selector);
};
(function () {
$('[data-toggle="offcanvas"]').addEventListener("click", function () {
$(".offcanvas-collapse").classList.toggle("open");
});
$('[data-toggle="offsection"]').addEventListener("click", function () {
@sarojbelbase
sarojbelbase / radio.py
Last active December 18, 2020 13:22
Flask wtf_forms with RadioField for star ratings system
from flask import Flask, render_template
from flask_wtf import FlaskForm
from wtforms import RadioField
SECRET_KEY = 'development'
app = Flask(__name__)
app.config.from_object(__name__)
@sarojbelbase
sarojbelbase / dictionarify.py
Created December 22, 2020 16:00
flask dictionary without marshmallow
from flask import jsonify
@app.route('/user_json')
def get_json():
user = User.query.filter_by(username='testme').first()
# Using the user object (without __dict__) will generate a runtime error
# TypeError: 'user' is not JSON serializable
return jsonify( user.__dict__ )
@sarojbelbase
sarojbelbase / pathlib.py
Created December 22, 2020 16:44
Better way to hack path system on windows, mac and linux.
from pathlib import Path
data_folder = Path("source_data/text_files/")
file_to_open = data_folder / "raw_data.txt"
f = open(file_to_open)
print(f.read())
<template>
<div class="ui cards" style="margin: 10px">
<div class="ui icon input" style="width: 100%">
<input type="text" placeholder="Search..." v-model="searchQuery" />
<i class="search icon"></i>
</div>
<div
class="card ui fluid"
v-for="product in searchedProducts"
:key="product.id"
@sarojbelbase
sarojbelbase / mongo.py
Created August 5, 2021 11:06
Getting started with MongoDB > Atlas
import pymongo
from pymongo import MongoClient
client = pymongo.MongoClient("mongodb+srv://sidbelbase:password@clusters.mongodb.net/test?retryWrites=true&w=majority")
db = client.test
collection = db.test
post = {
"_id": 1,
"name": "sid",