Skip to content

Instantly share code, notes, and snippets.

View sai43's full-sized avatar

Sai Ch sai43

View GitHub Profile
@sai43
sai43 / fridays the 13ths.rb
Created May 4, 2016 06:29 — forked from theHamdiz/fridays the 13ths.rb
Get all fridays the 13ths from now on...
require 'date'
lazy_dates = (Date.today..Date.new(9999)).lazy
fridays_the_13th = lazy_dates.select { |d| d.friday? and d.day == 13 }.first(10)
puts fridays_the_13th
@sai43
sai43 / flexible interface.rb
Created May 4, 2016 06:28 — forked from theHamdiz/flexible interface.rb
Learn how to build flexible interfaces using instance_eval in #ruby
class Person
def name(n)
@name = n
self
end
def age(a)
@age = a
self
end
@sai43
sai43 / bdd.md
Created April 11, 2016 19:03 — forked from xpepper/bdd.md
What is BDD

BDD stands for Behavior-driven development, and is a process of exploring, discovering, defining and driving out the desired behavior of a sw system, using conversations, concrete examples and automated tests.

Conversations with concrete examples helps explore, discover and illustrate our shared understanding of the problem we need to solve for our stakeholders. Then we refine those examples into automated tests, to describe the desired behavior of our solution, to drive the development of that behavior in the system. To do that you may use tools like Cucumber.

BDD is an agile practice, so it needs to be done just in time, at the last reponsibile moment, and not just in case. The key in BDD are conversations, and these conversations needs to be done near in time with the work you have to do.

You need to have your work broken down into user stories.

In the conversation between the 3 amigos (Dev, Testers, PO) for a user story, you'll have lots of questions raising and you'll explore the requirements

Add sorting to your product taxon page in Spree

So in following @berkes 'Add sorting to your product page in Spree' guide, I tried to repeat with my taxons controller. However there was no difference in order, despite the scopes being applied.

Another commenter Adam shared my frustration: 'How would I make this work for taxons as well? Everything I try doesn't work'.

After a little bit of research, I figured it out.

TL;DR

require 'mechanize'
def google_search(query_text)
agent=Mechanize.new
goog = agent.get "http://www.google.com"
search = goog.form_with(:action => "/search")
search.field_with(:name => 'q').value = query_text
results = search.submit
return results
end
module InstanceModule
def track
"Tracking todo: #{self.name}"
end
end
module ClassModule
def class_name
"Tracking class: #{self.name}"
@sai43
sai43 / README.md
Last active August 29, 2015 14:11 — forked from Burgestrand/README.md

Magneto

It reads your torrents. Spit out magnet URIs.

Example Usage

$ ./magneto.rb magneto.rb.torrent

Results in: