Skip to content

Instantly share code, notes, and snippets.

@samuel-alves
samuel-alves / Web2Case.html
Created February 23, 2023 17:12 — forked from mhamzas/Web2Case.html
Salesforce Web to lead and Web to Case using Javascript [CORS Proof !]
<script type="text/javascript">
// Case Data preparation
var postData = {
oid: '00D0b000000xxxx', //Put your ORGID here
name:'John Smith',
company:'ACME',
email:'yyy@customercompany.com',
origin:'Web',
subject:'Web2Case using the custom API',
@samuel-alves
samuel-alves / 01-directory-structure.md
Created February 6, 2023 18:39 — forked from tracker1/01-directory-structure.md
Anatomy of a JavaScript/Node project.

Directory structure for JavaScript/Node Projects

While the following structure is not an absolute requirement or enforced by the tools, it is a recommendation based on what the JavaScript and in particular Node community at large have been following by convention.

Beyond a suggested structure, no tooling recommendations, or sub-module structure is outlined here.

Directories

  • lib/ is intended for code that can run as-is
  • src/ is intended for code that needs to be manipulated before it can be used

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@samuel-alves
samuel-alves / delete-all-woocommerce-products-and-relations.sql
Last active March 26, 2020 15:35 — forked from pejantantangguh/delete-all-woocommerce-products.php
Remove all WooCommerce products from database via SQL
DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product');
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
DELETE FROM wp_posts WHERE post_type = 'product';
@samuel-alves
samuel-alves / heroku_env_copy.sh
Created March 5, 2020 12:26 — forked from nabucosound/heroku_env_copy.sh
Script to copy environment variables from an existing heroku app to another one
#!/bin/bash
# Source: http://blog.nonuby.com/blog/2012/07/05/copying-env-vars-from-one-heroku-app-to-another/
set -e
sourceApp="$1"
targetApp="$2"
while read key value; do
@samuel-alves
samuel-alves / haversine.pgsql
Last active November 19, 2019 10:21
PostgreSQL function to calculate the distance between to points in a spherical surface.
CREATE OR REPLACE FUNCTION haversine(latitude1 numeric(10,6),longitude1 numeric(10,6), latitude2 numeric(10,6), longitude2 numeric(10,6))
RETURNS double precision AS
$BODY$
SELECT 3959 * acos( cos( radians(latitude1) ) * cos( radians( latitude2 ) ) * cos( radians( longitude1 ) - radians(longitude2) ) + sin( radians(latitude1) ) * sin( radians( latitude2 ) ) ) AS distance
$BODY$
LANGUAGE sql;
/*
SELECT id,
name,
@samuel-alves
samuel-alves / auraIfContains.cmp
Created May 18, 2018 09:56
Alternate/Workaround for contains() function in aura:if Condition in Lightning Component
<aura:component>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:handler name="change" value="{!v.element}" action="{!c.doInit}"/>
<aura:attribute name="items" type="List" />
<aura:attribute name="element" type="String" />
<aura:attribute name="condition" type="Boolean" />
<aura:if isTrue="{!v.condition}">
{!v.body}
@samuel-alves
samuel-alves / uri.js
Created April 13, 2018 10:00 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
var Books = Backbone.Collection.extend({
// Lets create function which will return the custom URL based on the method type
getCustomUrl: function (method) {
switch (method) {
case 'read':
return 'http://localhost:3000/api/Books/' + this.id;
break;
case 'create':
return 'http://localhost:3000/api/Books';
break;
@isTest static void User_can_get_contact_email()
{
// Arrange
System.runAs(createUser())
{
// Act
// Assert
system.assertEquals('contact@place.com', contact.Email, 'Email does not match');
}