Skip to content

Instantly share code, notes, and snippets.

@lkatney
lkatney / Usage.html
Last active February 24, 2021 03:45
Directive to handle number field scenarios on input[type=text]
<!-- Use attributes to configure input accordingly -->
<input type="text" placeholder="Enter number" numbers-only max-number="10" allow-decimals="true" set-decimal-places="3"/>
@lkatney
lkatney / crud.operations.js
Last active July 28, 2018 21:43
Wrapper code for Postgres queries to do crud operations in Salesforce Tables to sync with Heroku Connect - pg 6.0.1
var pgClient;
exports.setConnection = function(client){
pgClient = client;
}
/*************************************************************************
*************************** CRUD OPERTIONS ***************************
************************************************************************/
exports.getRecords = function(objectApiName, config, callback){
@lkatney
lkatney / file.directive.js
Last active July 22, 2018 22:55
Angular1 directive/component 'FilePicker' to handle file selection(taking pictures, choosing photos and files) from device
//file.directive.js
(function() {
'use strict';
angular
.module('starter.services')
.directive("file",function(){
return {
scope: {
onFilesSelection: '&',
@lkatney
lkatney / middleware.js
Created July 14, 2018 14:48
Open Ghost 0.X to expose Post GET API Publically
// ### Authenticate Middleware
// authentication has to be done for /ghost/* routes with
// exceptions for signin, signout, signup, forgotten, reset only
// api and frontend use different authentication mechanisms atm
authenticate: function (req, res, next) {
var path,
subPath,
scope;
// SubPath is the url path starting after any default subdirectories
@lkatney
lkatney / google-analytics-server.js
Last active July 28, 2018 20:43
Server-Server integration between NodeJS and Google APIs to get page views on pages and top viewed pages on your website
var {google} = require('googleapis'), // official https://github.com/google/google-api-nodejs-client npm module
analyticsreporting = google.analyticsreporting('v4'),
key = require('./private.json');// Secure server key file(in JSON) dowloaded from Google
/********************** GET PAGE VIEWS *******************/
app.get('/analytics/report', cors(corsOptions), function(req,res){
//passed parameter
var url = req.query.url;
@lkatney
lkatney / formattedDate.filter.js
Last active January 5, 2018 10:52
custom asynchronous filter to format date into appropriate format
(function() {
'use strict';
angular
.module('app.directives')
/**
* @ngdoc filter
* @name filter:formattedDate
* @description
String csvLine = 'Test,Check,abc@abc.com, "19, Link road, A1SH10, India", companyName, "companyStreet, CompanyCity, CompanyCountry"';
String prevLine = csvLine;
Integer startIndex;
Integer endIndex;
while(csvLine.indexOf('"') > -1){
if(startIndex == null){
startIndex = csvLine.indexOf('"');
csvLine = csvLine.substring(0, startIndex) + ':quotes:' + csvLine.substring(startIndex+1, csvLine.length());
@lkatney
lkatney / focusElement.js
Created September 11, 2017 08:59
Directive to focus an element on pages with an example to use it.
angular.module('app.directives')
.directive('focusElement', ['$timeout', function($timeout) {
return {
link: function(scope, element, attrs) {
scope.$watch(attrs.focusElement, function(value) {
if(value === true) {
$timeout(function () {
element[0].focus();
});
@lkatney
lkatney / arrowKeys.js
Created September 11, 2017 08:43
Directive to use arrow keys on forms or tables to quickly jump on to input boxes
angular.module('app.directives')
.directive('arrowKeysIndex', function() {
return {
restrict: 'A',
require: '^ngModel',
link: function (scope, element, attrs) {
element.on('keydown', function(event) {
let currentIndex = attrs.arrowKeysIndex;
let nextIndex;
@lkatney
lkatney / NamedCredentailsExample.cls
Last active January 26, 2022 12:23
NamedCredentailsExample is in Source org with named credentials to hit target salesforce org. NamedCredentailsLogCapture is in target org to handle incoming requests
public class NamedCredentailsExample {
public static String oAuth_flow(){
return makeCallout('OAuth_flow_Demo/services/apexrest/namedcredentials/demo','GET', null,null);
}
public static String oAuth_flow_Post(String body){
return makeCallout('OAuth_flow_Demo/services/apexrest/namedcredentials/demo','POST', null,body);
}