View ruby_zip_demo.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'zip' | |
input_directory = '' # directory to be zipped | |
zipfile_name = '' # zip-file name | |
# zip a folder with only files (NO SUB FOLDERS) | |
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| | |
Dir[File.join(input_directory, '*')].each do |file| | |
zipfile.add(file.sub(input_directory, ''), file) | |
end |
View cloudfx-demo.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require './my_aws_helper' | |
class AwsDemo | |
include MyAwsHelper | |
def start_execution | |
p '1. Bucket Details, 2. Create Bucket 3. Upload To Bucket' | |
choice = gets.chomp.to_i | |
start_user_interaction(choice) | |
end |
View add2.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# above line used to specify which shell to be used to execute the program | |
add() # function to add 2 numbers | |
{ | |
num1=$1 | |
num2=$2 | |
sum=`expr $num1 + $num2` # things insed the backtick `are evaluate or executed | |
echo "$num1 + $num2 = $sum" | |
} |
View add1.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Above line to specify which shell to be used to execute the program | |
echo "Enter first Number" # echo used to print the message to screen | |
read first_number # read and store the input from terminal | |
echo "enter second Number" | |
read second_number | |
sum=`expr $first_number + $second_number` # things insed the backtick ` are evaluate or executed | |
echo "$first_number + $second_number = $sum" # $ to specify arguments |
View innova_hckr_rank.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filename = gets.strip | |
res = [] | |
File.open(filename).each do |line| | |
res << line.split(' ').first | |
end | |
res_hash = Hash.new(0) | |
res.each { |i| res_hash[i] += 1 } | |
text_array = res_hash.to_a.map { |res| res.join(' ') } |
View binary_gap.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bin_gap(number) | |
bin = number.to_s(2) # convert number to binary | |
zeros = bin.split('1') # extract 0's in binary | |
zeros.reject(&:empty?) # remove if any empty elements | |
zeros.pop if number % 2 == 0 # pop out last 0's | |
return 0 if zeros.empty? | |
zeros.map{ |zero| zero.length }.max # max length from 0's array | |
end |
View pgRoute_queries.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- SHORTEST PATH | |
SELECT * FROM pgr_dijkstra('SELECT gid id, source, target, cost, reverse_cost FROM ways', 645, 803, directed:=true); | |
-- COMBINING GEOMETRY | |
SELECT seq,name, node, edge, pgr.cost, agg_cost, st_astext(the_geom) AS geom FROM pgr_dijkstra('SELECT gid id, source, target, cost, reverse_cost FROM ways', 645, 803, directed:=true) AS pgr JOIN ways w ON pgr.edge = w.gid; | |
-- VIA | |
SELECT seq, node, edge, pgr.cost, agg_cost, st_astext(the_geom) AS geom FROM pgr_dijkstravia('SELECT gid id, source, target, cost, reverse_cost FROM ways', array[645, 885, 803], directed:=true) AS pgr JOIN ways w ON pgr.edge = w.gid; | |
-- ONE TO MANY |
View PostGIS_queries.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Nearby Ameneties | |
SELECT name, st_geomfromtext('POINT(77.64363 12.97069)') <-> way::geography AS dist, way FROM planet_osm_point WHERE amenity = 'police' ORDER BY dist ASC LIMIT 4 ; | |
-- Within Distance | |
SELECT name, ST_Geomfromtext('POINT(77.64363 12.97069)') <-> way::geography AS dist, way FROM planet_osm_point WHERE amenity = 'school' AND ST_Dwithin(way, ST_Geomfromtext('POINT(77.64363 12.97069)',4326), 1000) ORDER BY dist ASC LIMIT 4 ; | |
-- Finding Length | |
SELECT st_length(way::geography) FROM planet_osm_line WHERE osm_id = 35133687; | |
-- Distance between points |
View smartest_set.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### smart sets, nestaway challenge skilenza | |
# Pseudo code | |
# Take number of test case | |
# Take array size | |
# Take array elements | |
# Test all are within give range | |
# Convert array elements into binary format | |
# Group binary elements based on number of 1's present | |
# Sort grouped elements in ascending order | |
# take first element from each set and display |
View output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 | |
Enter a String | |
bengaluru | |
Enter a Sub String | |
uru | |
=> Present | |
2 | |
Enter a String | |
bengaluru |
NewerOlder