Skip to content

Instantly share code, notes, and snippets.

View rajeshpillai's full-sized avatar

Rajesh Pillai rajeshpillai

View GitHub Profile
@rajeshpillai
rajeshpillai / _.md
Last active August 29, 2015 14:18
Tributary inlet
@rajeshpillai
rajeshpillai / _.md
Last active August 29, 2015 14:18
Tributary inlet
@rajeshpillai
rajeshpillai / bench_rails_memory_usage.rb
Created January 27, 2016 18:09 — forked from brianhempel/bench_rails_memory_usage.rb
A script to test the memory usage of your Rails application over time. It will run 30 requests against the specified action and report the final RSS. Choose the URL to hit on line 45 and then run with `ruby bench_rails_memory_usage.rb`.
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
@rajeshpillai
rajeshpillai / index.html
Created April 29, 2017 17:18 — forked from anonymous/index.html
JS Bin A better browser console log // source https://jsbin.com/qamiqiw
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="A better browser console log">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.console-container {
position: absolute;
@rajeshpillai
rajeshpillai / index.html
Created April 29, 2017 17:36 — forked from anonymous/index.html
JS Bin A better browser console log // source https://jsbin.com/qamiqiw
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="A better browser console log">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.console-container {
position: absolute;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JavaScript Ninja: Promise Explained</title>
</head>
<body>
<input type="button" id="btn" value="Click me!"/>
</body>
@rajeshpillai
rajeshpillai / app.js
Last active May 25, 2017 13:35
JavaScript Ninja - Promise - Long Running Task
function doLongRunningTask() {
var promise = new MyPromise();
setTimeout(function () {
promise.resolve("I am done.");
}, 3000);
return promise;
}
@rajeshpillai
rajeshpillai / app.js
Created May 25, 2017 13:41
JavaScript Ninja - Promise - Long Running Task Execution
var response = doLongRunningTask();
// We can subscribe as many times as required using the "then" method.
response.then(function (result) {
console.log("RECD: 1", result);
})
.then(function (result) {
console.log("RECD: 2", result);
})
.catch(function (e) {
@rajeshpillai
rajeshpillai / app.js
Created May 25, 2017 15:16
JavaScript Ninja - Promise - Button Click
var btn = document.getElementById("btn");
btn.addEventListener("click", function (e) {
response.then(function (msg) {
console.log("RECD: FROM promise: ", msg);
});
});
@rajeshpillai
rajeshpillai / MyPromise.js
Created May 25, 2017 15:20
JavaScript Ninja - Promise - Implementation
// The constructor function
var MyPromise = function () {
this.callbacks = []; // All callbacks then() will be stored here
this.resolved = false; // initially the resolved will be set to false. This will be set to true, once the promise is resolved
this.data = null; // The data returned from the promise
this.errorCallback = null; // Error callback function
this.error = false; // If any error, this variable will be set to true
}