Skip to content

Instantly share code, notes, and snippets.

View ketanghumatkar's full-sized avatar

Ketan Ghumatkar ketanghumatkar

View GitHub Profile
@ketanghumatkar
ketanghumatkar / db_procedure_wh
Created June 23, 2014 13:52
Procedure to create and insert warehouses
CREATE PROCEDURE GenerateWarehouseTbl
AS
BEGIN
-- create warehouse table
CREATE TABLE IMQCDev.dbo.Warehouses ( id int IDENTITY(1,1) NOT NULL, name varchar(50) NOT NULL, siteId varchar(50) NOT NULL, PRIMARY KEY(id), UNIQUE(name, siteId) );
-- fetch warehouses from IMQCdev and insert into warehouses table
INSERT INTO IMQCDev.dbo.Warehouses (name, siteId) SELECT DISTINCT SUBSTRING(CONVERT(varchar(10), WhseLocID), 0, 3) as WhseName, SiteID as SiteId FROM IMQCDev.dbo.WhseLocDesc WHERE WhseLocID >= 10000 ORDER BY WhseName asc;
(function(ctx, $, undefined){
$(document).ready(function(){
bindEvent();
})
function bindEvent () {
//private scope for application
}
@ketanghumatkar
ketanghumatkar / ruby_challenge.rb
Created February 9, 2015 12:40
Print all numbers from 1..100 . While printing any number if that number is multiples of 3, print “Tit” instead of the number and if multiples of 5, print “Tat” instead of the number and if multiples of 3 and 5, print “TitForTat” instead of the number.
(1..100).each do |n|
if(n%3 == 0 && n%5 == 0)
puts 'TitForTat'
elsif(n%3 == 0)
puts 'Tit'
elsif(n%5 == 0)
puts 'Tat'
else
puts n
end
@ketanghumatkar
ketanghumatkar / custom_log.js
Last active August 29, 2015 14:15
Custom log for logging on browser console in attractive way
var _u = {};
_u.log = function() {
var _time = new Date();
var time = ( _time.getHours()
+ ":" + _time.getMinutes()
+ ":" + _time.getSeconds()
+ ":" + _time.getMilliseconds());
var LOG_PREFIX = "[TREENI] - " + time;
var args = Array.prototype.slice.call( arguments );
args.unshift( LOG_PREFIX + " ::" );
@ketanghumatkar
ketanghumatkar / filering_object.js
Created March 9, 2015 11:25
Filter the objects from array of objects based of array of ids
var collectionObject = [{id: 1}, {id: 2}, {id: 3}, {id: 4}]
var ids = [2,3]
_.filter(collectionObject, function(ca){
return _.contains(ids, ca.id)
})
@ketanghumatkar
ketanghumatkar / angularjs_controller.js
Last active August 29, 2015 14:17
AngularJS Controller Snippet
Sample.controller('SampleController',
[
'$scope',
'$window',
'$location',
'SampleFactory',
'SampleService'
function ($scope, $window, $location, SampleFactory, SampleService) {
@ketanghumatkar
ketanghumatkar / angularjs_factory.js
Created March 20, 2015 05:43
AngularJS Factory Snippet
// Factory can have another factory, $rootScope as dependancy but not $scope
Sample.factory('SampleFactory', ['$window', '$rootScope', 'AnotherFactory', function (_, $window, $rootScope, AnotherFactory) {
var factory = {}
factory.method1 = function() {};
factory.method2 = function() {};
return factory;
@ketanghumatkar
ketanghumatkar / angularjs_services.js
Created March 20, 2015 06:01
AngularJS Services Snippet
Sample.service('SampleService', ['$http', '$q', function($http, $q) {
this.getData = function () {
var deferred = $q.defer();
var url = Config.GET_DATA_ENDPOINT;
$http({
url: url,
method: "GET"
}).success(function (data) {
@ketanghumatkar
ketanghumatkar / treeni_workflow.json
Created March 20, 2015 16:47
treeni_workflow.json
workflow: {
states: [
{ index: 0, name: "abc" },
{ index: 1, name: "xyz" }
],
moves: [
{ index: 0,
from_state_id: 0,
to_state_id: 1,
@ketanghumatkar
ketanghumatkar / query_timezone_rails
Created May 19, 2015 07:34
Quering timezone specific data in rails project
# Set current time to API request time zone
Time.zone = 'Eastern Time (US & Canada)'
=> "Eastern Time (US & Canada)"
# Initialize api request time in api time zone
t = Time.zone.local(2015, 'may', 18, 9,10,30)
=> Mon, 18 May 2015 09:10:30 EDT -04:00
# Convert requested time to utc time
time_in_utc = t.utc