Skip to content

Instantly share code, notes, and snippets.

View psahni's full-sized avatar
🏠
Working from home

Prashant psahni

🏠
Working from home
View GitHub Profile
@psahni
psahni / time.at.rb
Created February 23, 2016 07:12
Time at and utc
# To Calculate time from timestamp in ruby
[9] pry(main)> Time.now
=> 2016-02-23 12:40:56 +0530
[10] pry(main)> Time.now.to_i
=> 1456211463
[11] pry(main)> Time.at(1456211463)
=> 2016-02-23 12:41:03 +0530
[12] pry(main)>
@psahni
psahni / proxy_function_use_examples.js
Created February 24, 2016 06:17
proxy use examples
jQuery Proxy Function
EXAMPLE 1
$('#myElement').click(function() {
// In this function, "this" is our DOM element.
$(this).addClass('aNewClass');
});
@psahni
psahni / conquer_thoughts.txt
Created February 25, 2016 04:46
CONQUER YOUR FEARS AND ACHIEVE SUCCESS
CONQUER YOUR FEARS AND ACHIEVE SUCCESS
Namaste,
1. Control your thoughts. It's possible to think about anything you choose. The best way to stress yourself is to think about stressful things. You're not more effective when you're afraid. You're less. That doesn't mean you should bury your head in the sand, but put yourself in a frame of mind that makes you most able to deal with the situation.
2. Consider the worst. Take a moment to consider the worst likely outcome. Can you handle it? Can you maneuver in a way that makes the worst outcome manageable? If you know you can handle the worst, there's no reason to be afraid.
Be prepared for the worst and you'll find it rarely occurs.
3. Breathe. Focus on your breath and slow your mind. Your mind will take reality and run wild with it. Focusing on your breath will calm your mind, and reality remains. When stress is at your doorstep, just stop and breathe.
var person1 = {
_name: "Nicholas",
get name() {
console.log("Reading name");
return this._name;
},
set name(value) {
console.log("Setting name to %s", value);
this._name = value;
}
function isScrolledIntoView(elem)
{
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
return ((elemTop <= docViewBottom) && (elemTop >= docViewTop));
}
//-------------------------
// Map Example
searches = _.map(response.data, (search) ->
search.isFavorite = (Math.round(Math.random() * 10)) % 2 is 0
search
)
//-------------------------
// Array for each example
favoriteSearchIds = _.forEach(data, function(obj){
console.log(obj.webSearchId)
@psahni
psahni / debouce_example.coffee
Created June 29, 2016 07:33
debouce_example
@$scope.searchesDefinition.toggleFavorite = (row) =>
wait = if @$scope.selectedTab is @tabs.favorites then @MAX_DELAY else @MIN_DELAY
debounce = _.debounce( =>
data = { UserID: @User.id, WebSearchId: row.searchId, IsFavorite: !row.isFavorite }
@SearchHelper.setFavoriteStatus data, (err, response) =>
if err
row.isFavorite = !row.isFavorite
else
@$scope.searches = _.clone(@filterSearches @$scope.searches)
@$scope.searches = @_defaultSortSearches(@$scope.searches) /// Need to check for use case accordingly
@psahni
psahni / sorted_date_boolean.js
Created July 4, 2016 10:03
Sort by multiple fields
sorted.sort(function(s1, s2){
return [ ((s1.isFavorite === s2.isFavorite) ? 0 : s1.isFavorite ? -1 : 1), new Date(s2.date) - new Date(s1.date)]
})
@psahni
psahni / device_test.js
Created July 12, 2016 05:58
To test if the device is table or mobile
'use strict';
angular.module('Page').service('Browser', class Browser {
constructor() {
const ua = navigator.userAgent;
const device = {};
device.android = (ua.match(/Android/i) || ua.match(/JellyBean/i));
device.androidTab = (device.android && !ua.match(/Mobile/ig));
device.iPad = (ua.match(/iPad/i));
device.iPhone = (ua.match(/iPhone/i) || ua.match(/iPod/i));
@psahni
psahni / button_hover_directive.js
Created July 15, 2016 04:19
Directive Example (btn)
var Button, _Button, active, disabled, hover,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
hover = 'btn-hover';
active = 'btn-active';
disabled = 'btn-disabled';