Skip to content

Instantly share code, notes, and snippets.

@gouthamvel
gouthamvel / arithmetic_opp.rb
Created July 4, 2014 04:30
parse string of arithmetic operation and perform the operations
input = "20+4+2-1"
class String
def is_i?
!!(self =~ /\A[0-9]+\z/)
end
end
def operation(op)
case op
@gouthamvel
gouthamvel / compute_displacement.rb
Created May 29, 2014 05:56
Displacement calculation when bearing and distance with point relation are given.
# displacement calculation
# Instructions
# A car travels from one point to the next. It starts at point A, then moves to point B, then C and so on. Between each point it travels in a straight line. The car's travel is described in the input string in the following format:
# <<start_point>|<end_point>>[<heading>:<distance>],...
# Heading values can be 0 through 355 degrees (in increments of 5)
# For example, input might be:
@gouthamvel
gouthamvel / rover.rb
Created May 26, 2014 14:14
Mars rover problem
## MARS ROVER TEST ##
# A squad of robotic rovers are to be landed by NASA on a plateau on Mars. This plateau, which is curiously rectangular, must be navigated by the rovers so that their on-board cameras can get a complete view of the surrounding terrain to send back to Earth.
# A rover's position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North.
# In order to control a rover, NASA sends a simple string of letters. The possible letters are 'L', 'R' and 'M'. 'L' and 'R' makes the rover spin 90 degrees left or right respectively, without moving from its current spot. 'M' means move forward one grid point, and maintain the same heading.
# Assume that the square directly North from (x, y) is (x, y+1).
@gouthamvel
gouthamvel / titan-gremlin-load-script.grm
Created March 18, 2014 18:13
titan-gremlin-load-script
g = TitanFactory.open('conf/titan-cassandra.properties')
bg = new BatchGraph(g, VertexIDType.NUMBER , 1300)
file = new File("/tmp/data.csv")
get_fields = {line->
line_list = line.split(",")
size = line_list.size()
(ind_object_id, ind_temp_moneyhouse_id, ind_temp_moneyhouse_url, first_name, last_name, city_of_residence, ind_derived_state, relationship_type, org_object_id, org_temp_moneyhouse_id, org_temp_moneyhouse_url, name, city_of_registration, org_derived_state) = line_list[0..(size-1)]
return [ind_object_id, first_name, last_name, relationship_type, org_object_id]
@gouthamvel
gouthamvel / startup_mailer.rb
Created February 26, 2014 14:06
NameError: undefined local variable or method `respond_to_new_founder' for StartupMailer:Class; Issue with space(like char) before def
class StartupMailer < ActionMailer::Base
default from: "from@example.com"
  def respond_to_new_founder
send('mail', to: 'email@gmail.com', subject: 'Welcome to My Awesome Site')
  end
end
destroy: function(opt){
if(!this.id){
console.log('differing')
var fun = _.bind(Backbone.Model.prototype.destroy.call, this)
_.delay(fun,1000,[this,opt]);
}
else
Backbone.Model.prototype.destroy.call(this,opt);
},
// console logs in browser
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
class Deliveryguy.Routers.PostsRouter extends Backbone.Router
initialize: (options) ->
@posts = new Deliveryguy.Collections.PostsCollection()
@posts.reset options.posts
routes:
"/new" : "newPost"
"/index" : "index"
"/:id/edit" : "edit"
"/:id" : "show"
# in /app/models/tag_note.rb
class TagNote < ActiveRecord::Base
belongs_to :tag
end
# in /app/models/acts_as_taggable_on/tag.rb
class ActsAsTaggableOn::Tag
has_one :tag_note
end
#ruby -v # 1.9.2
#gem list|grep em-ssh # em-ssh(0.1.0)
require 'em-ssh'
# runs the command on server and gives the callback call
def do_ssh(cmd)
do_ssh_var = 'ssh'
EM::Ssh.start('localhost','goutham') do |ssh|
puts 'ssh start'
ssh.exec!(cmd) do |channel, stream, data|