Skip to content

Instantly share code, notes, and snippets.

View ganmahmud's full-sized avatar
🎯
Focusing

Gan Mahmud ganmahmud

🎯
Focusing
View GitHub Profile
@ganmahmud
ganmahmud / textToSpeech.js
Last active October 21, 2021 05:49
Text to Speech with JavaScript
const textToSpeech = (text) => {
const speech = new SpeechSynthesisUtterance(text);
[speech.voice] = speechSynthesis.getVoices();
// sp.rate = ?; //speed of the voice. Default value is 1. lowest = 0.1 and highest = 10
// sp.pitch = ?; //pitch of the voice. Default value is 1. lowest = 0 and highest = 2
speechSynthesis.speak(speech);
};
textToSpeech('Hello TalkJS!');
@ganmahmud
ganmahmud / consistency.py
Created September 2, 2021 17:52
Consistency Problem From Facebook Hacker Cup 2021
import sys
def isVowel(char):
return char.lower() in 'aeiou';
def characterFreq(string):
v = {}
c = {}
out_dict = {}
vowel_num = 0
@ganmahmud
ganmahmud / excel2post.php
Created December 25, 2018 06:37
Excel file (.csv) to WP post Plugin
<?php
add_action('admin_menu', 'excel2post_plugin_setup_menu');
function excel2post_plugin_setup_menu(){
add_menu_page('Shoppers Mag CSV Import Page', 'Shoppers Mag CSV Import', 'manage_options', 'csv-import', 'e2p', "dashicons-image-rotate-right", 2);
}
function e2p(){
@ganmahmud
ganmahmud / OppView.page
Created November 23, 2018 09:47
Create a Visualforce page which displays a variety of output fields
<apex:page standardController="Opportunity">
<apex:pageBlock title="Opportunity Details">
<apex:pageBlockSection>
<apex:outputField value="{! Opportunity.Name }"/>
<apex:outputField value="{! Opportunity.Amount }"/>
<apex:outputField value="{! Opportunity.CloseDate }"/>
<apex:outputField value="{! Opportunity.Account.Name }"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
@ganmahmud
ganmahmud / ContactView.page
Created November 23, 2018 09:46
Create a Visualforce page which shows a basic Contact record
<apex:page standardController="Contact">
<apex:pageBlock title="Contact Info">
<apex:pageBlockSection >
First Name: {! Contact.FirstName } <br/>
Last Name: {! Contact.LastName } <br/>
Owner Email: {! Contact.Owner.Email } <br/>
</apex:pageBlockSection>
@ganmahmud
ganmahmud / DisplayUserInfo.page
Created November 23, 2018 09:45
Create a Visualforce page that shows user information.
<apex:page >
<apex:pageBlock >
<apex:pageBlockSection >
{! $User.FirstName }
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
@ganmahmud
ganmahmud / DisplayImage.page
Created November 23, 2018 09:44
Create a simple Visualforce page that displays an image
<apex:page showHeader="false">
<apex:pageBlock >
<apex:pageBlockSection columns="2">
<apex:pageblocksectionitem >
{! $User.FirstName } {! $User.LastName }
({! $User.Username })
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:image url="https://developer.salesforce.com/files/salesforce-developer-network-logo.png"/>
@ganmahmud
ganmahmud / ClosedOpportunityTrigger.tgr
Last active May 1, 2024 12:03
Create an Apex trigger for Opportunity that adds a task to any opportunity set to 'Closed Won'.
trigger ClosedOpportunityTrigger on Opportunity(after insert, after update) {
List<Task> oppList = new List<Task>();
for (Opportunity a : [SELECT Id,StageName,(SELECT WhatId,Subject FROM Tasks) FROM Opportunity
WHERE Id IN :Trigger.New AND StageName LIKE '%Closed Won%']) {
oppList.add(new Task( WhatId=a.Id, Subject='Follow Up Test Task'));
}
if (oppList.size() > 0) {
@ganmahmud
ganmahmud / AddRelatedRecord_Optimized.tgr
Last active November 23, 2018 09:48
The trigger adds a default opportunity for every account that doesn’t already have an opportunity ( Bulk Query Optimized )
trigger AddRelatedRecord on Account(after insert, after update) {
List<Opportunity> oppList = new List<Opportunity>();
// Add an opportunity for each account if it doesn't already have one.
// Iterate over accounts that are in this trigger but that don't have opportunities.
for (Account a : [SELECT Id,Name FROM Account
WHERE Id IN :Trigger.New AND
Id NOT IN (SELECT AccountId FROM Opportunity)]) {
// Add a default opportunity for this account
oppList.add(new Opportunity(Name=a.Name + ' Opportunity',
@ganmahmud
ganmahmud / AddRelatedRecord.tgr
Last active November 23, 2018 09:48
The trigger adds a default opportunity for every account that doesn’t already have an opportunity
trigger AddRelatedRecord on Account(after insert, after update) {
List<Opportunity> oppList = new List<Opportunity>();
// Get the related opportunities for the accounts in this trigger
Map<Id,Account> acctsWithOpps = new Map<Id,Account>(
[SELECT Id,(SELECT Id FROM Opportunities) FROM Account WHERE Id IN :Trigger.New]);
// Add an opportunity for each account if it doesn't already have one.
// Iterate through each account.
for(Account a : Trigger.New) {