GitHub Actions provides a great way to automate workflow processes and make development and deployment more efficient. Linting is an important part of any software development project to ensure code consistency and maintain uniform standards. In this post, I will explain how to setup a Github Actions workflow lint to automate your linting process.
Setting up a GitHub Actions workflow lint is easy and can help keep your codebase consistent and maintainable.
First, you need to create a workflow file in your project’s root directory. This file should be named .github/workflows/lint.yml and should contain the configuration necessary to run your linting script.
Sending push notifications from pushengage.com dashboard is pretty easy but what about f we want to automate some process in our web site? For instance, let say we want to send a push notification every time you create a blog post
Note: have in mind we are sending the notification as a draft: notification_type=draft. Once ready, remove that parameter to send the real notification
Output
The first console log will print 200 status code and the second one the operation result as json
{
companies: [
{
endpoint: "/frandom/api/companies",
description: "Companies from US"
},
{
endpoint: "/frandom/api/companies?countryCode=mx&quantity=5",
description: "Companies from MX"
}
],
persons: [
{
endpoint: "/frandom/api/persons",
description: "A person from US"
},
{
endpoint: "/frandom/api/persons?countryCode=mx&quantity=5",
description: "A person from MX"
}
],
numbers: [
{
endpoint: "/frandom/api/numbers",
description: "A person from US"
},
{
endpoint: "/frandom/api/numbers?min=0&max=700&quantity=5",
description: "Random numbers between two numbers"
}
]
}
public class OpportunitiesTabController {
@AuraEnabled
public static void toLowerCase(Id opptyId){
try{
Opportunity opp = [SELECT Id, Name FROM Opportunity WHERE Id = :opptyId];
opp.Name = opp.Name.toLowerCase();
update opp;
}catch(Exception e){
throw new AuraException(e.getMessage());
}
}
@AuraEnabled
public static void toUpperCase(Id opptyId){
try{
Opportunity opp = [SELECT Id, Name FROM Opportunity WHERE Id = :opptyId];
opp.Name = opp.Name.toUpperCase();
update opp;
}catch(Exception e){
throw new AuraException(e.getMessage());
}
}
@AuraEnabled
public static List<Opportunity> getOpportunities(){
return [SELECT Id, Name, StageName, CreatedDate, Account.Name, AccountId
FROM Opportunity ORDER BY CreatedDate DESC LIMIT 10];
}
}
flexsearch It’s an awesome package to index in-memory data. You can use it to implement justa. search box in your site or to show related data with the content you are displaying
How to install it
yarn add flexsearch
Or
npm install flexsearch
Example
const { Index } = require("flexsearch");
const options = {
charset: "latin:extra",
preset: 'match',
tokenize: 'strict',
cache: false
}
const index = new Index(options);
// my collection
const recipes = [
{id:1, title: 'Orange cake'},
{id:2, title: 'New York-Style Bacon Egg and Cheese Sandwich'},
{id:3, title: 'Bacon Wrapped Cheese Stuffed Meatloaf'},
{id:4, title: 'French Yogurt Cake'},
{id:5, title: 'Gougeres (French Cheese Puffs)'},
{id:6, title: 'Authentic Brazilian Cheese Bread (Pão de Queijo)'},
{id:7, title: 'Camarão na Moranga (Brazilian Shrimp Stuffed Pumpkin)'},
{id:8, title: 'Parmesan Cheese Muffins'},
{id:9, title: 'Cookie Dough Stuffed Oreos'},
]
// index my collection
recipes.forEach((recipe) =>{
index.add(recipe.id, recipe.title)
})
// search (it will return an array of ids)
const ids = index.search('Cookie', 5);
console.debug(ids);
// based on the ids returned by the index, look for the recipes for those ids
const result = recipes.filter((recipe) => ids.includes(recipe.id));
console.debug(result);
Regular expressions are those I don’t use so frequently so I need to wrap them all in a method with a short explanation about what they do. So I created a simple JavaScript method that removes all newlines and multiple spaces (including tab spaces) by a single space
/**
* It replace all new lines and multiple spaces (including tab spaces) by a single space
* @param {string } text
* @return {string} a new cleaned string
*/
function cleanUpSpaces(text) {
if (!text) {
return text;
}
// s{2,} matches any white space (length >= 2) character (equal to [rntfv ])
return text.replace(/s{2,}/g, ' ');
};
Output example
// given
`SELECT *
FROM account WHERE id = 1234`
// output
SELECT * FROM account WHERE id = 1234
Let say you have a Lightning Component placed on the Account record page and you want to listen to changes that occur outside our component. For example, in your component, you display some Account data and that must be refreshed once the user clicks on the standard save button.
We are going to write an example to show how we can accomplish this.
So we need to:
Create a Lightning Component
Create a Lightning Component controller
Create an Apex class to simuate some backend work
Example of listening to changes outside our component
Let’s create an example to see how it works.
For sake of simplicity, this component just displays the name of the Account that we get from an Apex controller
Now we want our Lightning Component to be updated once the Account’s name was changed through the standard layout.
Create a component
It’s important to check the “Lightning Record Page” to receive the record id by URL parameter and also to be able to place this component into the Account record page.
<aura:component controller="MyAccountComponentController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="recordId" type="String" />
<aura:attribute name="accountName" type="String" />
<!-- To listen to when the Account was changed and update our component -->
<force:recordData aura:id="forceRecord"
recordId="{!v.recordId}"
fields="Name"
recordUpdated="{!c.doInit}" />
<article class="slds-card">
<div class="slds-card__body slds-card__body_inner">
<span class="slds-text-body_regular">{!v.accountName}</span>
</div>
</article>
</aura:component>
In our example, we are not asking for the event type but we could this way tho make different actions
if (changeType === "ERROR") { /* handle error; do this first! */ }
else if (changeType === "LOADED") { /* handle record load */ }
else if (changeType === "REMOVED") { /* handle record removal */ }
else if (changeType === "CHANGED") { /* handle record change */ }
Create the Apex controller
public class MyAccountComponentController {
@AuraEnabled
public static Account getAccount(String recordId){
try{
return [SELECT Name FROM Account WHERE Id = :recordId];
}catch(Exception e ){
throw new AuraHandledException('Error getting Account '+e.getMessage() + ' record id: '+recordId);
}
}
}
Add the component
After we create our Lightning Component, let’s add it to our Account’s record page
Drag and drop our Component. In this case, I’m positioning at the top of our side bar
Save the page and activate it if it is necessary.
Test it
Our last step is to change the name of any account and see how our component is updated.
Have in mind we are making an API call to our Apex controller. That change doesn’t come from the frontend, we have to go to our Salesforce backend and run the query to get the new name.
Reload record
In case we are in edit mode, we may call this method to reload our component based on new changes that come from outside
Regular expressions, commonly shortened to regex, are a powerful tool for working with text data in programming. One common task is determining whether a given string is a number. Fortunately, this is a task that can be accomplished with a relatively simple regex pattern.
To implement this regex pattern in code, simply use a regex matching function such as JavaScript’s `test()` method, which returns true or false depending on whether the pattern matches the input string. With this simple regex pattern, you can easily detect whether a given string is a number, making it a valuable addition to your programming toolkit.
/**
* It's not strictly the same than isNumber()
*
* @param text
* @return true if the given text is s number
*/
function isNumberText (text) {
if (!text) return false;
// the value must be a number, including float and not empty.
const reg = new RegExp('^-?\d+\.?\d*$');
return reg.test(text);
};