Skip to content

Instantly share code, notes, and snippets.

@RachelSa
RachelSa / removeLargest
Created July 7, 2016 22:57
removes n number of elements from an array, largest to smallest
//remove n number of elements from an array, largest to smallest
function removeLargest(arr,n){
for (var i = 0; i < n; i ++){
var sorted = Math.max.apply(null, arr);
//run through array, funding largest
var rem = arr.splice(arr.indexOf(sorted),1);
//remove largest
} console.log(arr);
}
@RachelSa
RachelSa / add
Created July 7, 2016 23:11
adds elements in array
function add(arr){
sum = 0
arr.forEach(function(num){
sum += num;
}); console.log(sum);
}
add([1,2,3,4,5])
add([-1,0,2])
add([3,3,3])
@RachelSa
RachelSa / Local_fresh.rb
Created September 19, 2016 02:28
My first command-line app, which suggests fresh foods based on user's location and the current month.
#A command-line app that suggests fresh foods
#based on user's location and the current month.
#The app automatically retrieves date and asks
#user for their region in the continental US.
#Ideas for expansion and improvements:
#allow user to choose alternate date,
#sort results by fruit and veg
cd /Users/rachel/dev
def image_list(file_path)
puts Dir.entries(file_path)
end
def emoji_finder(file_path)
Dir.foreach(file_path) {|pic|
if pic[-3..-1] == 'png'
puts pic
end
}
end
emoji_finder('/Users/rachel/dev/EmojiFinder/ProfileImages')
searchURL = "https://api.spotify.com/v1/search?q=#{artist_name}&type=artist"
response = RestClient.get(searchURL)
@artist_data = JSON.parse(response)["artists"]["items"][0]
top_tracks_url = "https://api.spotify.com/v1/artists/#{@artist_data["id"]}/top-tracks?country=US"
top_tracks_results = JSON.parse(RestClient.get(top_tracks_url))
client_token = Base64.strict_encode64("#{ENV['spotify_id']}:#{ENV['spotify_secret']}")
spotify_token = RestClient.post("https://accounts.spotify.com/api/token",{"grant_type": "client_credentials"}, {"Authorization": "Basic #{client_token}"})
parsed_token = JSON.parse(spotify_token)
tracks = RestClient.get(query_url, {"Authorization": "Bearer #{parsed_token["access_token"]}"})
parsed_tracks = JSON.parse(tracks)