Skip to content

Instantly share code, notes, and snippets.

View dineshsprabu's full-sized avatar

Dineshprabu S dineshsprabu

  • Bangalore, India.
View GitHub Profile
@dineshsprabu
dineshsprabu / make_request_httparty.rb
Created May 10, 2016 07:30
[Ruby] Making Request to REST API with HTTParty
#gem install httparty
require 'httparty'
url = 'http://httpbin.org/user-agent'
response = HTTParty.get(url)
p response.parsed_response
@dineshsprabu
dineshsprabu / active_record_in_ruby_script.rb
Created June 27, 2016 05:52
[RUBY] Using Active Records in Ruby Scripts
require 'active_record'
ActiveRecord::Base.establish_connection ({
:adapter => "mysql2",
:host => "localhost",
:username => "root",
:password => "",
:database => ""})
class TableName < ActiveRecord::Base
@dineshsprabu
dineshsprabu / xml_to_hash.rb
Created June 27, 2016 05:54
[RUBY] How to convert XML to HASH?
require 'active_support/core_ext/hash/conversions'
def xml_to_hash filename
doc = Nokogiri::XML.parse(File.open(filename))
Hash.from_xml(doc.to_s)
end
p xml_to_hash 'file/to/path/filename.xml'
@dineshsprabu
dineshsprabu / perform_action_when_element_available.js
Created July 28, 2016 06:36 — forked from dineshprabu-freshdesk/perform_action_when_element_available.js
[JQUERY] Perform an action only when element is Available
jQuery('element').livequery(function(){
//element available now.
});
@dineshsprabu
dineshsprabu / render_partial_multiple_label_select.rb
Created August 15, 2016 06:56
[RAILS][VIEW] Rendering partials with labels and selections
# partial '_list_form.html.erb'
<%= form_tag('/controller/action', method: :post) do %>
<% left.each do |left_label| %>
<%= label_tag "field[#{left_label}]", left_label %>
<%= select("field", left_label, right, { include_blank: true }) %>
<% end %>
<%= submit_tag "Submit" %>
<% end %>
@dineshsprabu
dineshsprabu / escape_single_double_quote_comma.rb
Created August 17, 2016 11:13
[RUBY] Escaping single quote, double quotes and comma properly
def escape_string str
str.gsub!(/\"/,'\\u0022') if str.include? '"'
str.gsub!(/\'/,'\\u0027') if str.include? "'"
str.gsub!(/\,/,'\\u002C') if str.include? ","
str
end
@dineshsprabu
dineshsprabu / dns_lookup_nodejs.js
Created January 29, 2016 07:34
DNS Lookup from NodeJS
/* npm install dns */
var dns = require('dns');
/* domain name to lookup */
domain_name = 'example.com';
dns.lookup(domain_name, function(err, addresses, family){
/* handle if look up fails inside if condition */
if(err){return console.log(err.stack);}
@dineshsprabu
dineshsprabu / xml_to_hash.rb
Created August 30, 2016 06:32
[RUBY] XML to HASH conversion in ruby
require 'active_support/core_ext/hash/conversions'
Hash.from_xml XML_STRING
@dineshsprabu
dineshsprabu / selenium_phantom_dynamic_webpage_crawling.js
Last active September 12, 2016 10:00
[SELENIUM] How to run Selenium Server and Crawl Dynamic WebPages?
/*
1. Download latest version of Selenium Standalone Server from http://selenium-release.storage.googleapis.com/index.html
2. Run java -jar selenium-server-standalone-2.53.1.jar -port 8910
3. Replace the file name with your JAR file name.
4. Download phantomjs from http://phantomjs.org/download.html and set the path to access it from anywhere in the machine.
Note: Refer https://www.npmjs.com/package/selenium-webdriver for nodejs.
*/
var webdriver = require('selenium-webdriver'); //npm install selenium-webdriver
var proxy = '127.0.0.1';
@dineshsprabu
dineshsprabu / installing_enabling_mongodb_wiredtiger_ubuntu.txt
Created September 24, 2016 13:07
[MONGODB] Installing mongodb and enabling wiredtiger as storage engine on ubuntu server.
Follow Link for installation: https://docs.mongodb.com/v3.0/tutorial/install-mongodb-on-ubuntu/
After installation
1. sudo service mongod stop
2. sudo vi ~/etc/mongod.conf
3. update #engine: to engine: wiredTiger
4. sudo rm -rf /var/lib/mongodb/*
5. sudo rm -rf /var/log/mongodb/*
6. sudo service mongod start
7. check using db.serverStatus().storageEngine on mongo.