Skip to content

Instantly share code, notes, and snippets.

View deepak's full-sized avatar

Deepak Kannan deepak

View GitHub Profile
@deepak
deepak / cannot throw error in generator.debug.txt
Last active August 29, 2015 14:14
cannot throw error in generator
works if generator is not calling another function ?
example from http://davidwalsh.name/es6-generators-dive
similar example at https://gist.github.com/deepak/9a7337d7a641f8af9c8b
@deepak
deepak / error_in_generator.es.js
Created February 3, 2015 12:16
cannot throw error from ES6 generator
function getStockPrice() {
seq.throw('oops! could not get stock price');
// seq.next(80);
}
function executeTrade() {
setTimeout(function() {
console.log("trade done");
seq.next(true);
}, 300);
@deepak
deepak / promise-is-non-serial.es.js
Created February 2, 2015 11:30
javascript ES6 promise is not executed in serial order
var flag = false;
var promise = Promise.resolve();
// not linear execution of code!
// is the then callback pushed onto the call-stack. how ?
promise.then( (x) => {
console.log(`flag is ${flag}`); // flag is true
})
flag = true
@deepak
deepak / ignore_value_from_promise.es.js
Created February 2, 2015 11:08
can ignore value from promise
let pr1 = new Promise( (resolve, reject) => {
resolve(1);
});
// ignored value.
// would have been nice of function is required to have correct arguments
// TODO: try with JSHint
pr1.then( () => {
console.log("hello");
})
@deepak
deepak / add_to_set.es.js
Created February 2, 2015 08:27
how do sets work ? do not see any ES6 runtime ?
let s = new Set([1,2,3]);
s.add("foo");
console.log(s.size);
@deepak
deepak / output.6to5.txt
Last active August 29, 2015 14:14
iterator
// output
10
// generated code
"use strict";
var numbers = regeneratorRuntime.mark(function callee$0$0(start, end) {
var i;
return regeneratorRuntime.wrap(function callee$0$0$(context$1$0) {
while (1) switch (context$1$0.prev = context$1$0.next) {
@deepak
deepak / 6to5_output.txt
Created February 1, 2015 06:30
calling method in superclass
//output
repl: Line 30: Direct super call is illegal in non-constructor, use super.doWork() instead
28 |
29 | doWork() {
> 30 | let person = super();
| ^
31 | return `${person} paid`;
32 | }
33 | }
@deepak
deepak / coffee-generated.js
Created January 30, 2015 13:24
ES6 classes
// Generated by CoffeeScript 1.7.1
(function() {
var Employee;
Employee = (function() {
function Employee() {}
Employee.prototype.doWork = function() {
return console.log("done");
};
@deepak
deepak / local variable shadows ivar.rb
Created May 15, 2014 09:51
local variable shadows ivar
class Foo
attr_accessor :params
def initialize(params)
@params = params
end
def process(params)
puts "====> before: #{params.inspect}"
params.merge!(local: "modifications")
@deepak
deepak / lol_rspec.rb
Created May 2, 2014 07:47
lol_rspec.rb
RSpec.configure do |config|
config.around(:each) do |example|
# disabled by design
# example.call
end
end
__END__
if i have the above rspec config in `spec_helper.rb` and i run a test