Skip to content

Instantly share code, notes, and snippets.

View usmanzaheer1995's full-sized avatar

Usman Zaheer usmanzaheer1995

View GitHub Profile
class Snake {
constructor(board) {
this.board = board
}
isValid(row, col) {
const numRows = this.board.length
const numCols = this.board[0].length
return (
row >= 0 &&
class Node {
constructor(value) {
this.left = null
this.right = null
this.value = value
}
}
class BinarySearchTree {
constructor() {
@usmanzaheer1995
usmanzaheer1995 / deploy.md
Last active June 28, 2022 21:09
Deploying to a server

I have used Golang, but any other programming language would also work (only their specific installations and build commands will change)

  1. Create a server instance (preferably Ubuntu)
  2. SSH into the server as root
  3. Run the commands:
    1. apt update
    2. apt upgrade
    3. apt install postgres-12
    4. service postgres status (to check if it is running)
  4. Install Caddy server
@usmanzaheer1995
usmanzaheer1995 / add_anaconda_right_click_menu.md
Created February 24, 2021 02:01 — forked from jiewpeng/add_anaconda_right_click_menu.md
Add Anaconda Prompt to Windows right click context menu

This gist describes how to add Anaconda Prompt to the Windows right click context menu. This is because at some point, Anaconda no longer adds itself to the PATH after installation.

  1. Run regedit.exe
  2. Navigate to HKEY_CLASSES_ROOT > Directory > Background > shell
  3. Add a key named AnacondaPrompt and set its value to "Anaconda Prompt Here" (or anything you'd like it to appear as in the right click context menu)
  4. Add a key under this key, called command, and set its value to cmd.exe /K C:\Anaconda3\Scripts\activate.bat (may have to change the activate.bat file to whereever Anaconda is installed)
// Find the max element in array in O(n)
// using only primitive data types
function findCandidate(a, size)
{
let maj_index = 0, count = 1;
for (let i = 1; i < size; i++)
{
if (a[maj_index] == a[i])
count++;
#!/bin/bash
# arg can be
# 1. start
# 2. stop
# 3. check
arg=$1
start_postgres () {
sudo docker container run -d --name dev-postgres -e POSTGRES_PASSWORD=usman123 -v ${HOME}/postgres-data/:/var/lib/postgresql/data -p 5432:5432 postgres
@usmanzaheer1995
usmanzaheer1995 / aws-sdk.ts
Created April 22, 2020 12:12 — forked from jacoor/aws-sdk.ts
Manual mocks for aws-sdk.js using jest.
// inspired by: https://derikwhittaker.blog/2018/02/20/using-manual-mocks-to-test-the-aws-sdk-with-jest/
let AWS = {
// This here is to allow/prevent runtime errors if you are using
// AWS.config to do some runtime configuration of the library.
// If you do not need any runtime configuration you can omit this.
config: {
setPromisesDependency: (arg) => {},
update: (arg) => {},
},
@usmanzaheer1995
usmanzaheer1995 / deep-clone.js
Last active January 27, 2020 05:56
Snippets
// https://medium.com/javascript-in-plain-english/write-a-better-deep-clone-function-in-javascript-d0e798e5f550
function clone2(target, map = new WeakMap()) {
if (typeof target === 'object') {
const isArray = Array.isArray(target);
let cloneTarget = isArray ? [] : {};
if (map.get(target)) {
return map.get(target);
}