Skip to content

Instantly share code, notes, and snippets.

View raysrashmi's full-sized avatar
🏠
Working from home

Rashmi Yadav raysrashmi

🏠
Working from home
View GitHub Profile
def solution(x,y,d)
sum = x+d
i=1
while true
if sum >= y
break
else
sum+= d
i+=1
end
require 'spec_helper'
describe MessageNotification do
it_behaves_like 'notification' do
let(:subject) { create(:message) }
let(:message) { subject }
let(:project) { message.project }
let(:notification) { MessageNotification.new(message) }
let(:text) { %{#{message.creator.name} posted a message "#{message.subject}" #{Rails.application.routes.url_helpers.account_project_message_url(project.account, project, message)}} }
let(:activity_text) { I18n.t('activity.message_create') }
class Comment < ActiveRecord::Base
include Attachable, AdminPanel,
Subscribable, Activitable
belongs_to :commentable, polymorphic: true
belongs_to :creator, class_name: User
validates :content, presence: true
validates :commentable, presence: true
validates :creator, presence: true
@raysrashmi
raysrashmi / insert_text_in_multiple_lines
Last active August 29, 2015 14:02
Insert text in multiple lines
Press ctrl + v to select first character in first line and press l to select more
Press j to extend the visual block in multiple lines
Press c to go in to inset mode and type words(what you want to insert)
Press Esc
require 'json'
a=[1,2,3,4,5,6,7]
h={}
a.each do|i|
if h.keys.empty?
h[i]='rays'
else
h[i]=h.to_json
h.shift
end
{
"Country 1a": {
"Bank 1a": {
"Metric Level 1a": {
"Metric Level 2a": {
"Metric Level 3a": {
"Period 1": 0.94,
"Period 2 / % change over Period 2": -1.83,
"Period 3 / % change over Period 3": 1.83
},
@raysrashmi
raysrashmi / in console
Created June 14, 2012 17:10
authentication error while using Twitter.user_search('rays')
```ruby
1.9.3p194 :006 > Twitter.configure do |config|
1.9.3p194 :007 > config.consumer_key = PROVIDER['twitter']['key']
1.9.3p194 :008?> config.consumer_secret = PROVIDER['twitter']['secret']
1.9.3p194 :009?> config.oauth_token = PROVIDER['twitter']['oauth_token']
1.9.3p194 :010?> config.oauth_token_secret = PROVIDER['twitter']['oauth_token_secret']
1.9.3p194 :011?> end
=> Twitter
1.9.3p194 :012 > Twitter.user_search('rays')
@raysrashmi
raysrashmi / configinitializerwarden.rb
Created June 21, 2012 08:53
Basic Http auth with warden
Rails.configuration.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "Not for public eyes") do |u, p|
u == 'foo' && p == 'bar'
end
@user = User.update_attributes(params[:user])
gem 'strong_parameters'