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 / remove_all_styles.js
Last active December 8, 2016 06:55
[Javascript] Remove all styles from HTML String with Javascript
function removeStyle(all) {
var i = all.length;
var j, is_hidden;
var attr = [
'align',
'background',
'bgcolor',
'border',
'cellpadding',
@dineshsprabu
dineshsprabu / fire_and_forget_http_client.rb
Last active December 2, 2016 13:51
[RUBY] Fire and Forget HTTP Request with Net::HTTP
require 'net/https'
require 'json'
class Net::HTTPGenericRequest
#overriding request execution on Net::HTTP
def exec(sock, ver, path)
custom_request_method sock, ver, path, @body
end
private
@dineshsprabu
dineshsprabu / rvm_installation.txt
Created November 26, 2016 06:58
[Mac][Installation][RVM]
https://gist.github.com/denji/8706676
@dineshsprabu
dineshsprabu / paginating_responses_mongodb_nodejs.md
Last active November 17, 2016 05:37
[NodeJS][MongoDB] Achieving Pagination on REST API responses with NodeJS and MongoDB Native Driver.

##Pagination, for avoiding queries which respond with millions of docs on api implemetations.

  • The response can be chucked with limits, say 20, we can make our endpoint to accept limit=20.
  • On the backend we can continue qurying consequent docs with options like { limit: 20, skip: 20}.
  • The continious increase of 'skip' by 20 will provide us the next set of records.
@dineshsprabu
dineshsprabu / start_monogd_in_ubuntu_server.sh
Created November 7, 2016 08:44
[Mongodb] Starting MongoDB as a service with wiredTiger, default DBPath and LogPath
sudo mongod --dbpath="/var/lib/mongodb" --fork --logpath /var/log/mongodb.log --storageEngine "wiredTiger"
@dineshsprabu
dineshsprabu / simple_countdown_timer.js
Created October 20, 2016 16:27
[JAVASCRIPT] Simple Javascript CountDown Timer
<script>
var insertZero = n => n < 10 ? "0"+n : ""+n,
displayTime = n => n ? time.textContent = insertZero(~~(n/3600)%3600) + ":" +
insertZero(~~(n/60)%60) + ":" +
insertZero(n%60)
: time.textContent = "IGNITION..!",
countDownFrom = n => (displayTime(n), setTimeout(_ => n ? sid = countDownFrom(--n)
: displayTime(n), 1000)),
sid;
countDownFrom(3610);
@dineshsprabu
dineshsprabu / timer_with_javascript.js
Created October 20, 2016 15:09
[JAVASCRIPT] Timer with javascript.
<script>
function pretty_time_string(num) {
return ( num < 10 ? "0" : "" ) + num;
}
var start = new Date;
setInterval(function() {
var total_seconds = (new Date - start) / 1000;
@dineshsprabu
dineshsprabu / push_notification_on_browsers_from_javascript.js
Created October 18, 2016 12:06
[JAVASCRIPT] Push Notification on browsers from Javascript
// request permission on page load
document.addEventListener('DOMContentLoaded', function () {
if (Notification.permission !== "granted")
Notification.requestPermission();
});
function notifyMe() {
if (!Notification) {
alert('Desktop notifications not available in your browser. Try Chromium.');
return;
@dineshsprabu
dineshsprabu / openresty_installation_usage.txt
Last active November 26, 2016 06:37
[RUBY] OpenResty Installation on Mac and Usage
brew tap killercup/homebrew-openresty
brew install openresty
brew services start homebrew/nginx/openresty
brew services stop homebrew/nginx/openresty
Installation Errors:
******** OpenSSL error(default) ************
Last 15 lines from /Users/user/Library/Logs/Homebrew/ngx_openresty/01.configure:
@dineshsprabu
dineshsprabu / phantomjs_horseman_dynamic_page_crawling_with_crawlera.js
Created September 27, 2016 03:36
[NodeJS] PhantomJS Horseman with Crawlera Proxies.
var Horseman = require('node-horseman');
var horseman = new Horseman();
var apiKey = '' //upated the api key.
horseman
.authentication(apiKey, '')
.open('http://proxy.crawlera.com:8010/fetch?url=https://httpbin.org/ip')
.html('body')
.then(function(body) {