Skip to content

Instantly share code, notes, and snippets.

@suryart
suryart / spiral_print_matrix.ex
Last active Jun 17, 2019
Solution to Spiral print of elements of a matrix(2D array)
View spiral_print_matrix.ex
defmodule MatrixSpiralPrint do
@moduledoc """
Solution to Spiral print of elements of a matrix(2D array)
"""
@doc """
prints elements of matrix(2D array) in a spiral
## Examples
@suryart
suryart / gist:4db3482d5f5fc47b7722dfdd6b5b657e
Created Mar 26, 2019 — forked from dreamwords/gist:149518
activeresource client certificate
View gist:4db3482d5f5fc47b7722dfdd6b5b657e
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index dc24e71..f814b8b 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -102,6 +102,8 @@ module ActiveResource
#
# Many REST APIs will require authentication, usually in the form of basic
# HTTP authentication. Authentication can be specified by:
+ #
+ # === HTTP Basic Authentication
View prawn_column.rb
require 'prawn'
Prawn::Document.generate("./my_pdf.pdf") do
# Print Name
fill_color "565656"
font_size(38) { text "HEADING", align: :center }
move_down 20
stroke_color "c0c0c0" #dimgray color code
@suryart
suryart / appliance.rb
Created Feb 25, 2018
observer-pattern
View appliance.rb
class Appliance
attr_accessor :name, :state , :switch
def initialize(name, switch = nil)
@name = name
@state = switch.nil? ? :off : switch.state
@switch = switch
end
def update(changed_state)
self.state = changed_state
View mixin.rb
module InstanceModule
def track
"Tracking todo: #{self.name}"
end
end
module ClassModule
def class_name
"Tracking class: #{self.name}"
@suryart
suryart / file-change.rb
Created May 23, 2017
change duplicate file names
View file-change.rb
file_extension = '.rb'
files = Dir["./*#{file_extension}"]
puts "="*10
puts " Total files: #{files.count}"
puts "="*10
files_deleted = 0
file_timestamp = Time.now.strftime('%Y%m%d')
files.each do |file|
puts File.basename file, file_extension
View db schema
users:
id, username, password
tickets:
id, booking_id, amount, discount, seat_id, show_id
bookings
id, user_id, total, ticket_counts
screens
@suryart
suryart / sort_array_bin.rb
Created Sep 26, 2016
sort by binary 1 count then by digit value
View sort_array_bin.rb
# sort by binary 1 count then by digit value
a.sort_by{ |v1| [v1.to_s(2).split('').count('1'), v1] }.reverse
@suryart
suryart / binary_tree.rb
Last active Aug 24, 2016
Algo and DS implementations in Ruby
View binary_tree.rb
class BinaryTreeNode
attr_accessor :left, :right, :data
def initialize(data)
@data = data
end
end
class TreeQueue
View README.md

Implementation of flatten method of Array#flatten

Requires Ruby 1.9.2 or above. This implementation adds Array#my_flatten to an Array object, which is itself a replica of Array#flatten which is done in C.

Run test

Make sure you have minitest gem installed: $ gem install minitest. Then run:

ruby my_flatten_test.rb
You can’t perform that action at this time.