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 / 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",
<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 / 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())
@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 / 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 / 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 / reactiveVsRefs.js
Last active October 31, 2020 15:37
Vue3 Composition API > Example > refs vs reactive
// Taken from https://medium.com/swlh/vue3-using-ref-or-reactive-88d47c8f6944
// ##001 : import from vue3:
// - reactive for making properties reactive;
// - computed for computed function like total
// - toRefs for destructuring object for template
import { reactive, computed, toRefs } from "vue";
export default {
name: 'RollTheDiceReactive',
// ##002 : implement setup function
@sarojbelbase
sarojbelbase / fetchMyGithubRepo.vue
Last active October 30, 2020 10:02
VueJs : Vue3 | Composition API | Github Repository | Axios | Dayjs
<template>
<section class="resume-content p-3 p-lg-5 d-flex justify-content-center" id="projects">
<div class="w-100">
<h2 class="mb-5 text-darker">Projects</h2>
<div
class="resume-item d-flex flex-column flex-md-row justify-content-between mb-5"
v-for="(repo, index) in projects"
:key="index"
>
<div class="resume-content">
@sarojbelbase
sarojbelbase / index.html
Last active October 29, 2020 05:21
Default webpack/vue index template in public folder
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
@sarojbelbase
sarojbelbase / fetch_tweets.py
Created October 28, 2020 05:44
Get recent tweets from a desired account with images and saves them as csv or json
# Possible due to https://gist.github.com/yanofsky/5436496
import csv
import json
import re
import pytz
import tweepy
def those_tweets(screen_name=TWEETARATI):