Hacker Rank Solutions: Anagram
Hacker Rank Solutions: Anagram
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Hacker Rank Solutions: Anagram
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Hacker Rank Solutions: Chocolate Feast
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Hacker Rank Solutions: Gem Stones
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Inplace quicksort algorithum implemented in Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
Ruby has a native implementation of the greatest common divisor.
1 2 |
|
However as a pure academic exercise lets implement Euclid’s algorithm for finding the greatest common divisor between any number of numbers in ruby!
1 2 3 4 5 6 7 |
|
Greatest Common Divisor for three numbers
1 2 3 |
|
Extending this to a generic algorithm that can take any number of numbers
1 2 3 4 5 6 7 8 |
|
A recent hack / sketchy 1st product draft required datasets that live in two different database to be joined together to do some analysis on. Initially thoughts of denormalization or key/value lookup crossed peoples minds but wanting a quick win to try and get the idea validated as quickly as possible, I kept on digging.
As always stackoverflow provided the start of the journey of discovery with something called dblink.
dblink is a hidden gem of a extension that made doing a join across two databases (weather there local or remote) a total breeze. Firstly the extension needs to be installed on the database with the following command.
1
|
|
Once added to your database using it requires three pieces of information
1 2 3 |
|
I personally use this format of string as it allows easy access to both local and remote DBs.
postgres://PG_USER:PG_PASSWORD@HOST:PORT/DATABSE_NAME'
eg
postgres://pguser:abcd@127.0.0.1:5432/test_db'
Read on →
Notes from Refactoring Ruby by Jay Fields, Shane Harvie, Martin Fowler & Kent Beck.
Duplicated Code
Problem – This stinks, when you have the same expression in two different methods in the same class
Solution – Extract the method to a new method in the class and use in place
Duplication in Sibling Classes
Problem – Two methods in sibling class that that have the same expression.
Solution – Extract the method into one on the shared base class and use this instead.
Duplication across unrelated classes
Problem – The same method or expression across two unrelated classes
Solution – Extract the method into a new class or module and then use either inheritance or composition to give the class the new method.
Read on →i = insert mode
h,j,k,l = move left, up, down, left
w = move from word to word
b = move back word to word
W = jumps the whole word
B = jusmps back a word to word
$ = go to end of the line
^ = go to the begining of the line
0 = goes to the very beginning
gg = goes to the begginig of the file
G = goes to the bottom of the file
{ } = jumps paragraphs
f = finds the first occurence of a string in the file
F = fins the first occurance of a string backward
number followed by comman (4dd) – deletes four lines
3gg = goes 3 lines from the top
:13 = goes to line 13
3 G = goes three lines from the bottom
For when i cant find it, here is the best instructions i found for removing
There are numerous guides available on line for setting up a fresh install of Jenkins with numerous different configurations but i wanted to create a chef recipe that would give me a clean Jenkins install with my required project dependencies (excluding rvm) at the click of a button.
The reasons the excluding RVM in the chef process, even though the chef-rvm cookback is fantastic having used it before in the creation of a Rails stack is that i just could get system level RVM to play nice with Jenkins and user specific RVM (to the Jenkins user) to automatically install without asking for the Jenkins password. Better minds will probably be able to solve this issue but i opted for a different approach.
Read on →