Skip to content

Instantly share code, notes, and snippets.

View gouravtiwari's full-sized avatar

Gourav Tiwari gouravtiwari

View GitHub Profile
@gouravtiwari
gouravtiwari / splitter_and_parser_using_threads.rb
Last active December 22, 2015 10:48
Split CSVs without parsing and then parse them using Ruby threads, a continuation of http://grosser.it/2011/08/31/splitting-1-big-csv-file-into-multiple-smaller-without-parsing-it/
#http://grosser.it/2011/08/31/splitting-1-big-csv-file-into-multiple-smaller-without-parsing-it/
require 'rubygems'
require 'rake'
# split giga-csv into n smaller files
def self.split_csv(original, file_count)
header_lines = 1
lines = `cat #{original} | wc -l`.to_i - header_lines
lines_per_file = (lines / file_count) + header_lines
header = `head -n #{header_lines} #{original}`
@gouravtiwari
gouravtiwari / turtle.rb
Last active December 22, 2015 02:29
turtuled
# Turtle shapes
# Not at all necessory, but just to show that you can define attr_accessor from module as well
module AttrLoader
def attr_loader(*attrs)
attr_accessor *attrs
end
end
@gouravtiwari
gouravtiwari / fibered_prismatic.rb
Last active December 22, 2015 02:28
fibered prismatic shapes
# Prism shapes - naive implementation
counter = 1
stars = 5
(1..20).each do |row|
if counter == stars * 2 - 1
counter = 1
else
if counter > stars
puts '*'*(stars * 2 - counter)
@gouravtiwari
gouravtiwari / include-extend-idiom.rb
Created August 31, 2013 05:01
include-extend-idiom
module Goodness
def great?
@language == 'Ruby'
end
def self.included(base)
base.extend ClassMethods
def interesting
'there are thousands of spoken languages around the world'
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")