Skip to content

Instantly share code, notes, and snippets.

@salmanx
salmanx / caesar_cipher.rb
Last active November 18, 2017 18:57
Simple ruby program for caesar cipher sollution
# Julius Caesar protected his confidential information by encrypting it in a cipher. Caesar’s cipher rotated every letter
# in a string by a fixed number, K , making it unreadable by his enemies. Given a string, S , and a number, K ,
# encrypt S and print the resulting string.
# Note: The cipher only encrypts letters; symbols, such as − , remain unencrypted.
# Input Format
# The first line contains an integer, N , which is the length of the unencrypted string.
# The second line contains the unencrypted string, S .
# The third line contains the integer encryption key, K , which is the number of letters to rotate.
# Constraints
# 1 ≤ N ≤ 100
# Sami’s spaceship crashed on Mars! She sends sequential SOS messages to Earth for help.
# Letters in some of the SOS messages are altered by cosmic radiation during transmission. Given the signal
# received by Earth as a string, S , determine how many letters of Sami’s SOS have been changed by radiation.
# Input Format
# There is one line of input: a single string, S .
# Note: As the original message is just SOS repeated n times, S ’s length will be a multiple of 3 .
# Constraints
# 1 ≤ |S| ≤ 99
@salmanx
salmanx / flatten_array.rb
Created October 3, 2017 10:24
A simple ruby method for array flatten
class FlattenArray
def self.flattify(array,init=[])
array.each do |a|
if a.class==Array
flattify(a,init)
else
init << a
end
end
init
@salmanx
salmanx / postgres-cheatsheet.md
Created May 2, 2017 12:23 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

If run with -E flag, it will describe the underlaying queries of the \ commands (cool for learning!).

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*