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 / return_monk_existing_promise.js
Created March 10, 2016 07:22
[NodeJS] Using Monk existing Promise
/*Insert collection returns promise*/
var insertCollection = function(collectionName,doc){
var collection = db.get(collectionName);
return collection.insert(doc);
}
/* using the function which returns promise */
insertCollection('collection_name',{'key':'value'})
.success(function(){
@dineshsprabu
dineshsprabu / insert_multiple_document_monk.js
Last active March 10, 2016 08:27
[NodeJS] Inserting Multiple Documents using Monk
var Promise = require('bluebird');
var monk = require('monk');
var db = //your db connection;
/*Inserting multiple doc is possible collection.col.insert
But it will not return promise, so returning our own promise*/
var insertMultiple = function(collectionName, docArray){
return new Promise(function(resolve,reject){
@dineshsprabu
dineshsprabu / jekyll_install_ubuntu_14_04.txt
Last active March 13, 2016 11:46
[JEKYLL] Installing jekyll on ubuntu 14.04
Dependencies
sudo apt-get install ruby ruby-dev make gcc nodejs
Jekyll Installation:
sudo gem install jekyll --no-rdoc --no-ri
If jekyll installation fails use the below command to install.
@dineshsprabu
dineshsprabu / github_pages_adding_cname.txt
Last active March 13, 2016 12:34
[GITHUB-PAGES] Adding custom domain name to github pages
1. Create a file CNAME on the gh-pages Branch.
2. Type your domain name and save the CNAME file. eg. dppages.com
3. Goto you domain settings on domain registered site (godaddy, bigrock, etc.,).
4. Add the IPs below on the 'A' record.
192.30.252.153
192.30.252.154
@dineshsprabu
dineshsprabu / jekyll_outside_access.md
Last active March 15, 2016 03:37
[JEKYLL] Making jekyll site accessible from outside

By Default 'jekyll serve' makes jekyll accessible on 127.0.0.1 (localhost).

To make it accessible by outsiders, use --host 0.0.0.0 with it.

jekyll serve --host 0.0.0.0

@dineshsprabu
dineshsprabu / finding_document_size_mongodb.js
Created March 21, 2016 12:41
[Mongo] Finding Document Size in MongoDB
/* This will return size of document object in bytes */
Object.bsonsize(<document>);
@dineshsprabu
dineshsprabu / shadow_div.css
Created March 24, 2016 14:05
[CSS] Div with Shadow
.shadow-div{
-moz-box-shadow:5px 5px 7px rgba(33,33,33,1);
/* Safari+Chrome */
-webkit-box-shadow: 5px 5px 7px rgba(33,33,33,.7);
/* Opera */
box-shadow: 5px 5px 7px rgba(33,33,33,.7);
}
@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'