Skip to content

Instantly share code, notes, and snippets.

@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

@sai43
sai43 / sampletest.rb
Created September 24, 2015 14:31
appium testing with ruby
require 'rubygems'
require 'appium_lib'
APP_PATH = '../../apps/TestApp/build/release-iphonesimulator/TestApp.app'
desired_caps = {
caps: {
platformName: 'iOS',
versionNumber: '8.1',
deviceName: 'iPhone 5s',
@sai43
sai43 / funcheap_events.rake
Last active June 3, 2019 22:20
api for funcheap - fetch events from funcheap
require 'chronic'
require 'nokogiri'
require 'open-uri'
require 'date'
require 'json'
require 'paperclip'
namespace :evee do
desc "Fetch Events from Funcheap"
task pull_funcheap_events: :environment do
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 / client.rb
Created June 7, 2015 14:40
Chat application in Ruby
#!/usr/bin/env ruby -w
require "socket"
class Client
def initialize( server )
@server = server
@request = nil
@response = nil
listen
send
@request.join
@sai43
sai43 / server.rb
Created June 7, 2015 14:39
Chat application in Ruby
#!/usr/bin/env ruby -w
require "socket"
class Server
def initialize( port, ip )
@server = TCPServer.open( ip, port )
@connections = Hash.new
@rooms = Hash.new
@clients = Hash.new
@connections[:server] = @server
@connections[:rooms] = @rooms