Skip to content

Instantly share code, notes, and snippets.

View psahni's full-sized avatar

Prashant psahni

View GitHub Profile
@psahni
psahni / hypermedia.md
Created March 31, 2014 12:53
Hypermedia
      [ Hypermedia ]
  • Hypermedia allows links to be embedded in multimedia elements like images and videos.

  • HATEOAS - Hypermedia As The Engine Of Application State

  • Roy fielding creator of Http and Rest devised that REST api must be hypermedia driven. It means the the client only knows about the starting uri of the server, client should be able to navigate through one uri. The author of the api should be able to inform the client about the links.

"Roy T. Fielding REST APIs Must Be Hypertext-driven"

@psahni
psahni / cloosure.js
Created May 9, 2014 13:23
clousures in javascript
function add(x,z) {
value = function(y) {
return x + y;
};
if(typeof(z)=='undefined'){
return value;
}else{ return (x+z);}
}
alert(add(5,6));
@psahni
psahni / memcache_vs_redis.md
Last active October 3, 2016 23:11
Comparison of memcache and redis [ Ruby on Rails ]

##Memcache

Memcache can be used for caching data in main memory using key value pair. So it reduces database load significantly. It is actually a storage engine used by Rack::Cache which is a middleware in Rails that provides HTTP caching. For example we can store a complex query result into a key

Rails.cache.fetch(key) do
  #......Processing
end
@psahni
psahni / responsive_web_design_learnings.markdown
Last active August 29, 2015 14:01
Responsive Web Design

Definition

Responsive Web design is the approach that suggests that design and development should respond to the user’s behavior and environment based on screen size, platform and orientation. The practice consists of a mix of flexible grids and layouts, images and an intelligent use of CSS media queries. As the user switches from their laptop to iPad, the website should automatically switch to accommodate for resolution, image size and scripting abilities. In other words, the website should have the technology to automatically respond to the user’s preferences. This would eliminate the need for a different design and development phase for each new gadget on the market.

Challenges and suggestions

  • Deciding the break points. Mainly there are four
    • iPhone / Droid – 320px wide
    • Small Tablets – 640px wide
  • iPad / Tablet – 768px wide
@psahni
psahni / e2e_testing.md
Last active August 29, 2015 14:04
Integration (End 2 End) Testing of Angular apps.

Definitions:-

  • Jasmine - Used for BDD
  • PhantomJs - A headless browser. Which helps in testing javascript, can access to dom. Jasmine is used on the top of it.
  • Karma - A testing framework for Angular js that uses PhantomJs, jasminejs
  • Protactor - Protractor is an end to end testing framework for AngularJS applications. It uses webdriver to control browser activities, it runs on the top of Selenium because it is based on webdriver protocols. Protractor uses Jasmine for its test syntax. So its a nice wrapper over selenium and jasmine.

E2E Testing

For E2E testing there are two frameworks

{"errors":[{"type":"type_error","target":"(can.partner_id)","message":"Expected type 'Integer' but value in key-value pair '(can.partner_id) =\u003E ([email protected])' is of type String"}]}
@psahni
psahni / str.js
Last active August 29, 2015 14:09
StringPrototypes
//------------------------------------------------------------------------------------
String.prototype.capitalize_with_space = function(){
return this.replace(/([A-Z])/g, ' $1')
.replace(/^./, function(str){ return str.toUpperCase(); })
}
// Example: "userScope".capitalize_with_space() => User Scope
@psahni
psahni / ruby_garbage_collector.md
Last active August 29, 2015 14:10
RubyGarbageCollector
  • Garbage collector reclaims the memory occupied by the objects that are no longer used.

  • ObjectSpace class: We can track the memory usage by a datatype. Example count = ObjectSpace.each_object(Numeric) {|x| p x }

  • Gc works by deallocating a major collection of 'old' objects. The deallocation occurs when Ruby heap crosses certain thershold

  • We should not create big strings, becz the process start consuming more memory if it runs for long enough.

@psahni
psahni / readme_e2e_tests.md
Last active August 29, 2015 14:13
Protractor test cases