Skip to content

Instantly share code, notes, and snippets.

View mosdevly's full-sized avatar

Mosdev mosdevly

  • San Francisco, CA
View GitHub Profile
@mosdevly
mosdevly / gist:a5b86b0461940d36e298
Created October 16, 2014 19:32
Gem Install Error: SSL Certificate
gem install sqlite3
ERROR: Could not find a valid gem 'sqlite3' (>=0), here is why:
Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://rubygems.org/specs.4.8.gz)
@mosdevly
mosdevly / Two Sum
Last active August 29, 2015 14:08
Given an array of integers, find two numbers such that they add up to a specific number. The solution twosum should return indices of the two numbers, where index1 must be less than index2. The returned number shouldn't be zero based. Assume that each input would have exactly one solution.
def twosum nums
idx = 0
idx2 = idx + 1
while idx < nums.length
n = nums[idx]
i = nums[idx2]
sum = n + i
if sum == 0
@mosdevly
mosdevly / Three Sum
Created October 27, 2014 07:02
Given an array A of x integers, find all unique triplets in the array which gives a sum of zero. For example, if A = {-2 0 2 4 -2 -8} a solution set is: (-2, 0, 2)
def threesum
end
@mosdevly
mosdevly / Palindrome
Last active August 29, 2015 14:08
Given a string determine if it's a palindrome. Ignore case and include only alphanumeric characters (no punctuation or diacritical marks).
def rev(str)
a = 0
reverse = ""
while a < str.length
reverse = str[a] + reverse
a += 1
@mosdevly
mosdevly / Capitalize
Last active August 29, 2015 14:09
Capitalize - Write a method which will capitalize the first letter of each word in a string. Do not use the #capitalize method.
def cap(str)
words = str.split(" ")
idx = 0
while idx < words.length
word = words[idx]
word[0] = word[0].upcase # change the word within array
idx += 1
@mosdevly
mosdevly / Most Common
Last active August 29, 2015 14:09
Create an object that will check the contents of a string for the most common character. It must return the character and the number of that character.
def common(str)
most = nil
mcount = nil
idx1 = 0
while idx1 < str.length
char = str[idx1]
count = 0
idx2 = 0
@mosdevly
mosdevly / Skip Multiples
Last active August 29, 2015 14:09
Create a method that will print out the numbers 1-50. If the number is a multiple of 7, make it print out a string instead.
def skipMultiples
i = 0
range = (2...50).to_a
while i < range.length
if range[i] % 7 != 0
puts range[i]
else
range[i] = "Love conquers all!"
puts range[i]
@mosdevly
mosdevly / Anagrams
Created November 17, 2014 00:07
Write a method that takes two inputs: a single word and a dictionary of other words. The method should output all the words in the dictionary which our single word can scrabble to. For example, cat is an anagram of act.
def word_unscrambler(str, words)
idx = 0
matches = []
while idx < words.length
sorted = words[idx].chars.sort.join
match = str.chars.sort.join
word = words[idx]
if sorted == match
@mosdevly
mosdevly / Sum Nums
Created November 24, 2014 17:42
Write a function that returns the sum of numbers up to a max number given.
var sums = function(num) {
myNum = 0;
for (var i = 0; i <= num; i++) {
myNum += i;
}
console.log(myNum);
}
sums(3);
@mosdevly
mosdevly / Longest Word
Last active August 29, 2015 14:10
Write a method that takes a string and returns the longest word in it.
var longestWord = function(myString) {
words = myString.split(" ");
longest = "";
for (var word = 0; word < words.length ; word++) {
if (words[word].length > longest.length) {
longest = words[word]
}
}
return longest;