Skip to content

Instantly share code, notes, and snippets.

View AwesomeZaidi's full-sized avatar
:octocat:
Coding in JavaScript and Python (React and React Native 🔥)

Asim Zaidi AwesomeZaidi

:octocat:
Coding in JavaScript and Python (React and React Native 🔥)
View GitHub Profile
@AwesomeZaidi
AwesomeZaidi / medium_format.md
Created January 15, 2024 18:37
medium_format test

Testing code syntax first.

const test: number = 4;

Done!

export function downloadCsv(csv: any, filename: string) {
const blob = new Blob([csv], { type: 'text/csv' });
/* taken from react-csv */
if (navigator && navigator.msSaveOrOpenBlob) {
navigator.msSaveOrOpenBlob(blob, filename);
} else {
const dataURI = `data:text/csv;charset=utf-8,${csv}`;
const URL = window.URL || window.webkitURL;
@AwesomeZaidi
AwesomeZaidi / ts
Created December 1, 2022 17:53
Shared Export to CSV Function
const CSV_PREFIX = 'data:text/csv;charset=utf-8,';
export const exportToCsv = (
data: { [key: string]: any }[],
prefix = CSV_PREFIX
) => {
if (data.length === 0) {
return '';
}
@AwesomeZaidi
AwesomeZaidi / index.html
Created October 22, 2019 19:00
Tiny Rich Text Editor Demo
<!DOCTYPE html>
<html>
<head>
<!-- <script src='https://cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js' referrerpolicy="origin"></script> -->
<script>
tinymce.init({
selector: '#mytextarea'
});
</script>
</head>
@AwesomeZaidi
AwesomeZaidi / Enter.js
Created September 14, 2019 16:45
React / React Native Enter Component
// ----------------------------------------------------------------------------------
// Imports
// ----------------------------------------------------------------------------------
import {
View,
Text,
Image,
ScrollView,
TextInput,
@AwesomeZaidi
AwesomeZaidi / unit-test.js
Created June 11, 2019 09:59
Unit Testing
const chai = require('chai');
const chaiHttp = require('chai-http');
const server = require('../server');
const should = chai.should();
const Pet = require('../models/pet');
// BETTER TEST COMING SOON!
const fido = {
@AwesomeZaidi
AwesomeZaidi / mystery_2.py
Created May 16, 2019 04:33
Mystery Python Puzzle 2
import string
import sys
def puzzle(ds, b):
v = {c: i for i, c in enumerate(string.printable[:36])}
return sum(v[d] * b**e for e, d in enumerate(ds[::-1]))
if __name__ == '__main__':
const User = require('../models/user');
const jwt = require('jsonwebtoken');
function checkAuth (req, res, next) {
if (req.cookies && req.cookies.nToken) {
const uid = jwt.decode(req.cookies.nToken, process.env.SECRET)._id;
User.findById(uid).then(user => {
req.user = user;
return next();
});
@AwesomeZaidi
AwesomeZaidi / recursive_tree_node_search.py
Created May 4, 2019 17:24
Searching for node in tree recursively
def _find_node_recursive(self, item, node):
"""Return the node containing the given item in this binary search tree,
or None if the given item is not found. Search is performed recursively
starting from the given node (give the root node to start recursion).
TODO: Best case running time: ??? under what conditions?
TODO: Worst case running time: ??? under what conditions?"""
# Check if starting node exists
if node is None:
# Not found (base case)
return None
@AwesomeZaidi
AwesomeZaidi / caseSwap.py
Created April 2, 2019 19:13
Asim's solution to swap a sentence by cases and alphabetize the words appropriately.
# Instructions / Question:
# Given a standard English sentence passed in as a string,
# write a method that will return a sentence comprised of the same words,
# but sorted by their first letter.
# However, the method of sorting has a twist to it:
# all words that begin with a lowercase letter should be
# at the beginning of the sorted sentence,
# and sorted in ascending order. All words that begin with
# an uppercase letter should come after that, and should be sorted