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
#!python3
def square_up(n):
"""Simple test cases in docstring
>>> square_up(2)
[0, 1, 2, 1]
>>> square_up(3)
[0, 0, 1, 0, 2, 1, 3, 2, 1]
>>> square_up(4)
@AwesomeZaidi
AwesomeZaidi / home.js
Created February 18, 2019 06:40
React Router Basic Redirect
import React, { Component } from 'react';
import { Route, Redirect } from 'react-router'
class Home extends Component {
constructor() {
super();
this.state = {
toLogin: false,
};
this.handleClick = this.handleClick.bind(this);
@AwesomeZaidi
AwesomeZaidi / redirect-simple.js
Created February 19, 2019 01:03
React one liner redirect
import React, { Component } from 'react';
class Home extends Component {
render() {
return (
<div>
<h1>Make School Club App</h1>
<button onClick={() => window.location.href = '/dashboard'}>Login</button>
</div>
);
@AwesomeZaidi
AwesomeZaidi / acronym.go
Last active February 20, 2019 19:46
Golang Easy Acronym
package main
import (
"fmt"
)
// Abbreviate should have a comment documenting it.
func Abbreviate(s string) string {
var acronym string
// fmt.Println(acronym)
@AwesomeZaidi
AwesomeZaidi / accumulate.go
Created February 21, 2019 19:44
Accumulate - return arr of strings with all letters capitalized
package accumulate
import (
"strings"
)
// Accumulate returns all caps string
func Accumulate(s []string) []string {
// var newSlice []string
for pos, word := range s {
@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
@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
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 / 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__':
@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 = {