Skip to content

Instantly share code, notes, and snippets.

@arvind02
arvind02 / list.md
Last active May 16, 2018 12:05
Image Magick Fonts

List of fonts installed on machine -

convert -list font

Find out if particular font is installed

fc-list | grep -i arial

convert -list font | grep "Font:" | grep Arial

Install Typecatcher in Ubuntu

@arvind02
arvind02 / building.md
Last active May 16, 2018 12:03
Testing Ruby Gem

Option 1st

Long way of doing things (new files need to be added to staging area before building the gem)

git add . && gem build my_gem.gemspec && gem install my_gem-0.0.0.gem

Option 2nd

If using Bundler to generate the gem (rake task does the same as above)

git add . && rake install
@arvind02
arvind02 / gittag.md
Created May 21, 2018 13:39
GIT commit to existing tag

1. Create a branch with the tag

git branch {tagname}-branch {tagname} git checkout {tagname}-branch

2. Include the fix manually if it's just a change ....

`git add .`
`git ci -m "Fix included" `
or cherry-pick the commit, whatever is easier
`git cherry-pick {num_commit}`
@arvind02
arvind02 / img_url.rb
Created March 27, 2019 13:00
Simple ruby script to parse html file and download image resource. it stores all downloaded images into image directory of working directory
require 'net/http'
require 'nokogiri'
# This script parse and download image files from html documents
def get_html(url)
uri = URI(url)
response = Net::HTTP.start(uri.host, uri.port,
:use_ssl => uri.scheme == 'https') do |http|
resp = http.get(uri.path)
case resp
@arvind02
arvind02 / maximum_hourglass_sum.rb
Created April 5, 2019 07:10
ruby maximum hourglass sum
def sum_hour_glass(c, r, two_d_array)
top = two_d_array[r][c..c+2].inject(:+)
center = two_d_array[r +1][c+1]
bottom = two_d_array[r+2][c..c+2].inject(:+)
top + center + bottom
end
def array2D(arr)
max = -1.0/0.0
arr.each_with_index do |row, r_i|
@arvind02
arvind02 / bfs_dfs.rb
Created June 27, 2019 12:37
BFS and DFS in Ruby
class Node
attr_accessor :value, :left, :right, :name
def initialize(options={})
@value = options[:value]
@name = options[:name]
end
def children
[@left, @right].compact
@arvind02
arvind02 / heap.rb
Created July 11, 2019 12:41 — forked from bogdanovich/heap.rb
Heap data structure in ruby
class Heap
def initialize(type = :min)
@type = type
if @type == :min
@heap = [-1.0/0]
@compare = ->(a,b) { (a <=> b) < 0 }
elsif @type == :max
@heap = [1.0/0]
@compare = ->(a,b) { (b <=> a) > 0 }
else
@arvind02
arvind02 / readme.md
Created November 5, 2019 05:44 — forked from maxivak/readme.md
Integrating Gem/Engine and Main Rails App
@arvind02
arvind02 / s3_folder_upload.rb
Created December 12, 2019 06:14 — forked from fleveque/s3_folder_upload.rb
Upload folder to S3 recursively with ruby, multi threads and aws-sdk v2 gem, based on http://avi.io/blog/2013/12/03/upload-folder-to-s3-recursively/
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk'
class S3FolderUpload
attr_reader :folder_path, :total_files, :s3_bucket, :include_folder
attr_accessor :files
# Initialize the upload class
@arvind02
arvind02 / example1
Created July 24, 2020 05:56 — forked from daipresents/example1
Ruby rest-client file upload as multipart
require 'rest-client'
RestClient.get(url, headers={})
RestClient.post(url, payload, headers={})