Skip to content

Instantly share code, notes, and snippets.

View lopezm1's full-sized avatar
💭
🤔

Miguel Lopez lopezm1

💭
🤔
View GitHub Profile
@lopezm1
lopezm1 / ddl.sql
Last active August 29, 2015 14:11
SQL Database -- Practice using function calls and query calls
/*
** ----------------------------------------------------------------------------
** script to create the employee table
** --------------------------------------------------------------------------*/
CREATE TABLE employee (
fName VARCHAR2(20)NOT NULL,
mInit CHAR(1),
lName VARCHAR2(20) NOT NULL,
@lopezm1
lopezm1 / brew-install-mac-dev-environment.sh
Last active June 11, 2020 05:30
Brew Install My Dev Environment for macOS High Sierra - Slack, Docker, iTerm, IntelliJ, Google, SourceTree, Spotify, etc.
#!/bin/bash
APP_FOLDER_LOCATION=/Applications
IFS=""
## Install applications via brew cask
brew_install() {
execute="$(brew cask install $1 2>&1)"
case $execute in
*Warning*|*Error*) echo "Warning while installing $1: $execute" ;;
*successfully*) echo "$execute \n Installed $1." ;;
@lopezm1
lopezm1 / flip-string-without-specials.py
Created May 19, 2018 21:27
Given a string S, containing special characters and all the alphabets, reverse the string without affecting the positions of the special characters.
import location
import os
#Given a string S, containing special characters and all the alphabets, reverse the string without affecting the positions of the special characters.
def flipString(theString):
holdThese = ""
listChars = list(theString)
@lopezm1
lopezm1 / palindrome.py
Created May 19, 2018 21:49
Palindrome?
import location
import os
# function which return reverse of a string
def reverse(s):
return s[::-1]
def isPalindrome(theString):
flip = reverse(theString)
@lopezm1
lopezm1 / triplet-sums.py
Created May 19, 2018 22:22
Given an array of distinct integers and a sum value. Find count of triplets with sum smaller than given sum value.
import os
from itertools import combinations
#Given an array of distinct integers and a sum value. Find count of triplets with sum smaller than given sum value.
"""
Input : arr[] = {-2, 0, 1, 3}
sum = 2.
Output : 2
Explanation : Below are triplets with sum less than 2
@lopezm1
lopezm1 / bubblesort.py
Last active May 20, 2018 21:48
bubblesort
# Let's bubblesort
def swap(a, b):
return b, a
def bubblesort(numbers):
length = len(numbers)
swapped = True
@lopezm1
lopezm1 / pythagorean.py
Created May 20, 2018 00:10
Given an array of integers, write a function that returns true if there is a triplet (a, b, c) that satisfies a**2 + b**2 = c**2.
from itertools import combinations
# Given an array of integers, write a function that returns true if there is a triplet (a, b, c) that satisfies a2 + b2 = c2.
"""
Input: arr[] = {3, 1, 4, 6, 5}
Output: True
There is a Pythagorean triplet (3, 4, 5).
"""
@lopezm1
lopezm1 / prototype.js
Created May 20, 2018 18:21
js prototype
function Animal(animal, noise) {
this.noise = noise;
this.animal = animal;
}
Animal.prototype.makeNoise = function() {
console.log('I\'m a ' + this.animal + ' - ' + this.noise)
}
@lopezm1
lopezm1 / smallest-subarray-large-than-value.py
Created May 20, 2018 20:06
# Given an array of integers and a number x, find the smallest subarray with sum greater than the given value.
# Given an array of integers and a number x, find the smallest subarray with sum greater than the given value.
"""
arr[] = {1, 4, 45, 6, 0, 19}
x = 51
Output: 3
Minimum length subarray is {4, 45, 6}
"""
save = None
# The cost of a stock on each day is given in an array, find the max profit that you can make by buying and selling in those days. For example, if the given array is {100, 180, 260, 310, 40, 535, 695}, the maximum profit can earned by buying on day 0, selling on day 3. Again buy on day 4 and sell on day 6. If the given array of prices is sorted in decreasing order, then profit cannot be earned at all.
def sell(lowidx, highidx):
print("time to sell -------")
print("buy:", lowidx)
print("sell:", highidx)
def stock(arr):
low = None
lowidx = None