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 / 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 / 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 / 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 / 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 / Quick_Sort.rb
Last active February 6, 2016 00:32
Algorithm and Data Structures With Ruby - #3 Quick Sort
#The Quick Sort is a popular sorting algorithm, which has been discussed in detail, with examples and C code over here : Arrays and Sorting: Quick Sort ( with C Program source code). In this tutorial, we will take a quick look at the ruby implementation of Quick Sort.
#1
def partition arr, lo, hi
i,j = lo+1,hi
while true
@ddeveloperr
ddeveloperr / Selection_Sort.rb
Created February 5, 2016 23:59
Algorithm and Data Structures With Ruby - #2 Selection Sort
#Selection Sort
#The Selection Sort is a popular quadratic sorting algorithm, which has been discussed in detail, with examples and C code over here : Arrays and Sorting: Selection Sort ( with C Program source code). In this tutorial, we will take a quick look at the ruby implementation of Selection Sort.
# Selection Sort *************************
# Selection Sort -> A popular quadratic sorting algorithm with O(n^2) complexity
# For Index [i] -> swap the i-th smallest element from (array[i]....array[length-1]) with array[i-1]
def selectionSort(arr)
for index in 0..(arr.length-1)
@ddeveloperr
ddeveloperr / Insertion_Sort_in_ruby.rb
Last active February 6, 2016 00:47
Algorithm and Data Structures With Ruby - #1 Insertion Sort
#Algorithm and Data Structures
# More details: http://www.theodinproject.com/ruby-programming/common-data-structures-and-algorithms
# Implementation of Insertion Sort.
# Insertion Sort ************************
# Insertion Sort -> A popular quadratic sorting algorithm with O(n^2) complexity
def insertionSort(arr)
for size in 2..arr.length
# Remember, this is a zero-start array
@ddeveloperr
ddeveloperr / API_in_Rails.txt
Created February 5, 2016 23:27
Building an API in Ruby on Rails
An API is an “application program interface”, which basically means a computer program that allows other programs to
communicate with it. In our case, our program will be a web application, and we want to make it easy for other web apps
to connect to it.
Example: let’s say I want to build a simple web app that searches Twitter for tweets that contain certain keywords.
I can use Twitter’s search API to do just that by sending a request for data to their servers and then manipulating or
displaying that data on my app. There are tons of APIs out there that make their data available to developers for things
like movie times, restaurant reviews, social media, any pretty much everything else.
@ddeveloperr
ddeveloperr / ORM_in_ror.txt
Created February 5, 2016 22:56
Explained ORM in Ruby on Rails?
##
* ORM is Object Relational Mapper. It means you don't have to manually call the database yourself; the ORM handles it for you.
* Ruby on Rails uses one called ActiveRecord, and it's a really good one.
* ORM allows you to do things such as:
User.find(50).contacts
Instead of manually writing a SELECT statement with JOINs, WHEREs, etc.
**********
@ddeveloperr
ddeveloperr / fast_push.txt
Last active June 7, 2025 14:49
How to avoid Git push: username, password in my terminal ?
Problem: Every push prompt me to input username and password.
I would like to avoid it for every push, but how to configure to avoid it?
Answer: Using SSH authentication on terminal.
1. Generate an SSH key
Linux/Mac
Open terminal to create ssh keys: