Skip to content

Instantly share code, notes, and snippets.

View ddeveloperr's full-sized avatar
👨‍💻
Doist

Kemal C. ddeveloperr

👨‍💻
Doist
View GitHub Profile
@ddeveloperr
ddeveloperr / Merge_Sort.rb
Last active February 6, 2016 00:34
Algorithm and Data Structures With Ruby - #4 Merge Sort
def mergeArrays(arr,start_1,end_1,start_2,end_2)
temp = Array.new(end_1 + end_2 - start_1 - start_2 + 2)
index_1 = start_1 # Marks the index in the first sub-array, which needs to be put into the temporary array next
index_2 = start_2 # Marks the index in the second sub-array, which needs to be put into the temporary array next
index = 0 # Mark the index in the Temporary array which is being filled
while ( index_1 <= end_1 ) || ( index_2 <= end_2 )
@ddeveloperr
ddeveloperr / Stack.rb
Created February 6, 2016 00:17
Algorithm and Data Structures With Ruby - #5 Stack
#Ruby doesn't provide an explicit 'stack' but for all practical purposes, the Array provided by Ruby can be treated as a full-fledged stack.
# Based on the ideas from : http://macdevelopertips.com/ruby/using-a-stack-with-ruby.html
# Stacks are a Last In First Out Data Structure
class Stack
def initialize
@elements = []
end
@ddeveloperr
ddeveloperr / Queues.rb
Created February 6, 2016 00:19
Algorithm and Data Structures With Ruby - #6 Queues
#Queues as provided by Ruby.
require 'thread'
# Queues are a First in First Out Data Structure
# Ruby provides you with synchronoized/thread-safe queues
testQueue = Queue.new
testQueue.enq(10)
@ddeveloperr
ddeveloperr / LinkedList.rb
Created February 6, 2016 00:20
Algorithm and Data Structures With Ruby - #7 LinkedList
# Quick Example of a Self Referential Data Structure in Ruby
# NODE -> contains a value and a pointer to (next_node)
# LinkedList -> This class holds the linked list functions - adding a node, traversing and displaying the linked list
class Node
attr_accessor :value, :next_node
def initialize val,next_in_line
@value = val
@ddeveloperr
ddeveloperr / Binary_Tree.rb
Created February 6, 2016 00:22
Algorithm and Data Structures With Ruby - #8 Binary Tree
# Example of Self-Referential Data Structures - A Binary Tree
class TreeNode
attr_accessor :value, :left, :right
# The Tree node contains a value, and a pointer to two children - left and right
# Values lesser than this node will be inserted on its left
# Values greater than it will be inserted on its right
def initialize val,left,right
@value = val
@ddeveloperr
ddeveloperr / recursive_examples.rb
Created February 6, 2016 00:46
A recursive functions/methods in Ruby?
## More details: http://ruby.bastardsbook.com/chapters/recursion/
#1
def countdown(n)
return if n.zero? # base case
puts n
countdown(n-1) # getting closer to base case
end
countdown(5) # > 5 4 3 2 1
@ddeveloperr
ddeveloperr / cURL.txt
Created February 7, 2016 17:18
Using cURL to automate HTTP jobs
TO LEARN: https://curl.haxx.se/docs/httpscripting.html
Why cURL?
Because: http://code.tutsplus.com/tutorials/techniques-for-mastering-curl--net-8470
@ddeveloperr
ddeveloperr / hover_over_link.txt
Last active February 11, 2016 16:19
Ho to Preview Image When I Hover Over Link?
@ddeveloperr
ddeveloperr / ror_migrate.txt
Last active February 22, 2016 07:50
Migrations in Ruby on Rails
Migration Overview
Migrations are a convenient way to alter your database schema over time in a consistent and easy way.
They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be
database independent.
db:migrate runs (single) migrations that have not run yet.
db:create creates the database
db:drop deletes the database
db:schema:load creates tables and columns within the (existing) database following schema.rb
@ddeveloperr
ddeveloperr / params_hash.txt
Created February 22, 2016 14:16
Deep learning The Params Hash in Ruby on Rails
Deep learning here: https://www.youtube.com/watch?v=y57OnWV6dRE
https://gorails.com/episodes/the-params-hash?autoplay=1