Skip to content

Instantly share code, notes, and snippets.

View trafficinc's full-sized avatar

Ron trafficinc

  • Greater Philadelphia
View GitHub Profile
@trafficinc
trafficinc / debounce.js
Created February 17, 2023 16:39
Debounce function
export function debounce(func, wait, immediate) {
var timeout
return function () {
var context = this,
args = arguments
var later = function () {
timeout = null
if (!immediate) func.apply(context, args)
}
var callNow = immediate && !timeout
@trafficinc
trafficinc / valid_parentheses.py
Created November 11, 2022 18:00
Leetcode: Valid Parentheses (Python)
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
if len(s) % 2 != 0:
return False
par_dict = {'(':')','{':'}','[':']'}
stack = []
@trafficinc
trafficinc / canJump.js
Created October 13, 2022 12:58
Leetcode - Can Jump Game
const canJump = function(nums) {
let len = nums.length;
let max = 0;
for (let i = 0; i < len; i++) {
if (i > max) return false;
max = Math.max(max, i + nums[i]);
}
return true;
};
@trafficinc
trafficinc / isBalanced.js
Created October 13, 2022 12:56
Leetcode - Matching brackets
const isBalanced = function (input) {
let open = ['{', '[', '('];
let close = ['}', ']', ')'];
let stack = [];
for (let i = 0; i < input.length; i++) {
if (open.indexOf(input[i]) >= 0) {
stack.push(input[i]);
} else {
if (close.indexOf(input[i]) !== open.indexOf(stack.pop())) {
return false;
@trafficinc
trafficinc / TwoSum-solution.js
Created October 13, 2022 12:53
Leetcode - Two Sum Solution
/*
Two Sum
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Input: nums = [3,2,4], target = 6
Output: [1,2]
Input: nums = [3,3], target = 6
Output: [0,1]
@trafficinc
trafficinc / find-dep-npm.sh
Created September 30, 2022 21:27
Find Dependency in Node Modules Directory - NPM
find ./node_modules/ -name package.json | xargs grep <package name>
# Example: find where bootstrap is being used.
# find ./node_modules/ -name package.json | xargs grep bootstrap
@trafficinc
trafficinc / API-to-Table.php
Created July 20, 2022 14:40
Get API data to display in a HTML table
<?php
/*
* APIData::get(string $name) : array
*
* v1/people - array(array(name, phoneNumber, address, occupation), ...)
* v1/jobs - array(array(occupation, salary, numberOfPeople), ...)
* v1/employers - array(array(businessName, address, goodOrService), ...)
*
* Given a $name, return an HTML table displaying the data the API call returns
*
@trafficinc
trafficinc / backup_project.py
Created April 10, 2022 00:25
PHP Web Project Backup Python Script
# !/usr/local/bin/python3
"""
Back-up PHP web projects and not include the modules or vendor directories, will put back up in same DIR as script'
* need TAR installed on machine
To run: $ python3 backup_projects.py
"""
from datetime import datetime
from pathlib import Path
@trafficinc
trafficinc / EventBus.js
Last active August 5, 2021 18:30
Event Bus for use in React/Vanilla
/*
To Use:
:: Component A ::
import eventBus from "./EventBus";
- Dispatch an Event to component B -
eventBus.dispatch("aResource", { resource: this.state.resource });
@trafficinc
trafficinc / array_match_pair_algo.js
Last active October 13, 2022 13:10
Leetcode - Sales by Match Algorithm
/*
There is a large pile of socks that must be paired by color. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are.
Example
n = 7
ar = [1,2,1,2,3,1,2]
There is one pair of color 1 and one of color 2. There are three odd socks left, one of each color. The number of pairs is 2.
Function Description