Skip to content

Instantly share code, notes, and snippets.

View johntran's full-sized avatar
🌈
Make it last forever, FRIENDSHIP NEVER ENDS

johntran

🌈
Make it last forever, FRIENDSHIP NEVER ENDS
View GitHub Profile
@johntran
johntran / .bash_profile
Created July 13, 2016 18:18
ONEHOPE.bash_profile - works for iTerm2
alias bashdir='cd ~'
alias atom='open -a "Atom"'
alias prof='atom ~/.bash_profile'
alias cassandra='cd ~/Documents/Cassandra/datastax-ddc-3.4.0/bin && ./cassandra'
alias ms='cd ~/Documents/ONEHOPE/microservice'
alias hc='cd ~/hopecommerce-proto'
alias devApp='cd ~/hopecommerce-proto && npm run dev-a'
alias devGQL='cd ~/hopecommerce-proto && npm run dev-g'
alias rDev='cd ~/Documents/ONEHOPE/microservice && npm run dev'
@johntran
johntran / parameterDefaultES6.js
Last active July 19, 2016 22:00
Function Parameter Default Pattern
/**
* Let's say you have
* function getPromoCodeErrors(accountId, cart, cartProductItems, cartItems)
*
* If you don't have one or more of these parameters, then you need nulls in to fill out the parameters
* getPromoCodeErrors(accountId, null, null, cartItems)
*
* With the below this is valid
* getPromoCodeErrors({accountId, cartItems})
*
@johntran
johntran / BillingInformationForm.js
Created July 26, 2016 17:47
Lazy Loading JavaScript files in React
import makeAsyncScriptLoader from 'react-async-script';
const BillingInformationForm = () => (<div>Stripe!</div>)
export const BillingInformationFormAsync = makeAsyncScriptLoader(BillingInformationForm, 'https://js.stripe.com/v2/', {
globalName: 'Stripe',
callbackName: 'stripeCallBack',
});
@johntran
johntran / wineTax.js
Last active October 24, 2023 13:50
ES7 async/await with SOAP requests in NodeJS
import soap from 'soap';
import moment from 'moment';
const taxServiceUrl = 'http://hehexd.com/services/1.2/taxservice.asmx?WSDL'
export function generateJsonForTaxRate(json) {
const EffectiveDate = moment().toISOString();
const {
city: City,
state: State,
addressLineOne: Street1,
@johntran
johntran / es7AsyncAwaitParallel.js
Last active September 22, 2020 18:54
ES7 multiple async/await functions in parallel execution.
//old: productReviews.js - lines 121 - 125
async function productReviewsByProductAllGet(request, response) {
try {
const { productId } = request.params;
// get all reviews for a product id
const reviews = await productReviewsQuery.selectAllByProductId(productId);
const result = [];
// Loop from beginning of reviews array to reviews
for(let i = 0; i < reviews.length; i++) {
const ProfileImage = () => (
<li>
<a>
<span class="image"><img src="images/img.jpg" alt="Profile Image" /></span>
<span>
<span>John Smith</span>
<span class="time">3 mins ago</span>
</span>
<span class="message">
Film festivals used to be do-or-die moments for movie makers. They were where...
function log(input, str) {
if (str) return console.log(str, input)
console.log('logging', input)
return 'Program finished'
}
// var x = 1;
// log(x);
// var y = 2;
// log(y, 'hihihihihi');
log('Hi john')
// This is a comment! Machines can't read comments.
// Comment and uncomment lines by presssing 'Ctrl + /'
// There are five primitive types in JavaScript.
// Number. Example: 1, 2, 3
// String Example: 'Hi John', 'Dog', 'Cat'
@johntran
johntran / jsxShorthand.jsx
Last active October 17, 2016 06:39
JSX shorthand
// before
<AccountCardInformationFields
cardType={cardType}
cardForm={cardForm}
cardFormErrors={cardFormErrors}
cardFieldOnChange={this.cardFieldOnChange}
/>
// after
<AccountCardInformationFields {
@johntran
johntran / loader.js
Last active January 28, 2017 02:17
Higher-Order Functions: Loading Indicator
// Working with loading indicators
// before
class PersonRenderer extends Component {
render() {
if (this.props.person) {
return (<div>personcontent</div>)
}
return <LoadingIndicator/>
}
}