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
class Node | |
attr_reader :data, :children | |
attr_accessor :term | |
def initialize(data) | |
@data = data | |
@children = [] | |
@term = false | |
end | |
def insert(char) |
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
class Fixnum | |
def encode | |
n = self | |
bytes = [] | |
loop do | |
bytes.unshift n % 128 | |
break if n < 128 | |
n = n / 128 | |
end | |
bytes[-1] += 128 |
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
<?php | |
class Foo | |
{ | |
public function bar() | |
{ | |
// ... | |
$posts = get_posts($condition); | |
if ( !is_array($posts) ){ | |
return; | |
} |
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
<?php | |
class Something | |
{ | |
public function receiveData($data) | |
{ | |
// do something. | |
mail($to, $subject, $message); | |
// do something. |
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
<?php | |
abstract class Car | |
{ | |
protected static $price; | |
public static function getFormattedPrice() | |
{ | |
return number_format(self::$price); | |
} | |
} |
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
require 'pry' | |
require 'test/unit' | |
class String | |
def ll_quiz | |
input = self.dup | |
output = '' | |
input.split("\n").each do |line| | |
target, strings = line.split(' ') |
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
require 'pry' | |
require 'test/unit' | |
class Array | |
def quick_sort | |
ary = self.dup | |
return ary if size <= 1 | |
left, right = ary.partition_by_pivot_index(ary.pivot_index) | |
left.quick_sort + right.quick_sort |
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
require 'pry' | |
require 'test/unit' | |
class Array | |
def merge_sort | |
ary = self.dup | |
return ary if size <= 1 | |
mid = size / 2 | |
left = ary[0, mid] |
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
require 'pry' | |
require 'test/unit' | |
class Array | |
def insertion_sort | |
ary = self.dup | |
(1...size).each do |i| | |
(i).downto(1) do |j| | |
ary[j], ary[j - 1] = ary[j - 1], ary[j] if ary[j] < ary[j - 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
require 'pry' | |
require 'test/unit' | |
class Array | |
def selection_sort | |
ary = self.dup | |
(0...size).each do |i| | |
min_index = i | |
((i + 1)...size).each do |j| |