This file contains hidden or 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
| # 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 |
This file contains hidden or 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
| #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) |
This file contains hidden or 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
| #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 | |
This file contains hidden or 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 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 ) | |
This file contains hidden or 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
| #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 |
This file contains hidden or 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
| #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) |
This file contains hidden or 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
| #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 |
This file contains hidden or 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
| 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. | |
This file contains hidden or 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
| ## | |
| * 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. | |
| ********** |
This file contains hidden or 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
| 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: |